/* ================================================================
   ERP ARQENG — Stylesheet
================================================================ */
:root {
  --primary:       #1a56db;
  --primary-dark:  #1340a8;
  --primary-light: #e8f0fe;
  --success:       #057a55;
  --success-bg:    #def7ec;
  --danger:        #c81e1e;
  --danger-bg:     #fde8e8;
  --warning:       #92400e;
  --warning-bg:    #fef3c7;
  --info:          #0e7490;
  --info-bg:       #e0f2fe;

  --sidebar-bg:     #1e2a3b;
  --sidebar-hover:  rgba(255,255,255,0.07);
  --sidebar-active: rgba(26,86,219,0.28);
  --sidebar-text:   #94a3b8;

  --page-bg:   #f1f5f9;
  --card-bg:   #ffffff;
  --topbar-bg: #ffffff;

  --text:        #111827;
  --text-muted:  #6b7280;
  --border:      #e5e7eb;
  --border-soft: #f0f2f5;

  --radius:  8px;
  --shadow:  0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

/* ── RESET ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--page-bg);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* ── LOGIN ──────────────────────────────────────────────── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e2a3b 0%, #1a56db 100%);
}

.login-card {
  background: white;
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo h1 {
  font-size: 26px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -.5px;
}

.login-logo p {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 4px;
}

.login-hint {
  text-align: center;
  margin-top: 18px;
  color: var(--text-muted);
  font-size: 12px;
}

.alert-error {
  color: var(--danger);
  background: var(--danger-bg);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid #f9bfbf;
}

/* ── LAYOUT ─────────────────────────────────────────────── */
#app-layout {
  display: flex;
  min-height: 100vh;
}

/* SIDEBAR */
#sidebar {
  width: 220px;
  min-height: 100vh;
  background: var(--sidebar-bg);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand-logo {
  font-size: 22px;
}

.brand-name {
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -.3px;
  line-height: 1;
}

.brand-sub {
  color: var(--sidebar-text);
  font-size: 10px;
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.nav-section { margin-bottom: 6px; }

.nav-label {
  padding: 4px 8px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: rgba(148,163,184,.5);
  margin-bottom: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 7px;
  color: var(--sidebar-text);
  cursor: pointer;
  transition: background .15s, color .15s;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 1px;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
  border-left-color: var(--primary);
}

.nav-item .icon {
  font-size: 15px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 10px 8px;
  border-top: 1px solid rgba(255,255,255,.08);
}

/* MAIN AREA */
#main-area {
  flex: 1;
  margin-left: 220px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* TOPBAR */
#topbar {
  height: 58px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}

.topbar-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: default;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
}

.user-info { line-height: 1.3; }
.user-name { font-weight: 600; font-size: 13px; }
.user-role { font-size: 11px; color: var(--text-muted); }

/* CONTENT */
#content-area {
  flex: 1;
  padding: 24px;
}

/* ── PAGE HEADER ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.3px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── KPI CARDS ───────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.kpi-card { display: flex; flex-direction: column; gap: 6px; }

.kpi-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -.5px;
  line-height: 1.1;
}

.kpi-sub { font-size: 12px; color: var(--text-muted); }

.kpi-card.green .kpi-value { color: var(--success); }
.kpi-card.red   .kpi-value { color: var(--danger); }
.kpi-card.blue  .kpi-value { color: var(--primary); }

/* ── TWO-COL ROW ─────────────────────────────────────────── */
.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 800px) { .row-2 { grid-template-columns: 1fr; } }

/* ── CARD SECTION TITLE ──────────────────────────────────── */
.card-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ── INFO ROWS ───────────────────────────────────────────── */
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
  gap: 8px;
}
.info-row:last-child { border-bottom: none; }
.info-row .label { color: var(--text-muted); flex-shrink: 0; }
.info-row .value { font-weight: 600; text-align: right; }

/* ── AGING ───────────────────────────────────────────────── */
.aging-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
@media (max-width: 700px) { .aging-grid { grid-template-columns: repeat(2, 1fr); } }

.aging-block {
  border-radius: 8px;
  padding: 14px 10px;
  text-align: center;
}
.aging-block.a1 { background: #fffbeb; border: 1px solid #fde68a; }
.aging-block.a2 { background: #fff7ed; border: 1px solid #fed7aa; }
.aging-block.a3 { background: #fef2f2; border: 1px solid #fecaca; }
.aging-block.a4 { background: #fdf2f8; border: 1px solid #f9a8d4; }

.aging-faixa { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; opacity: .7; margin-bottom: 4px; }
.aging-qtd   { font-size: 26px; font-weight: 800; line-height: 1; }
.aging-val   { font-size: 11px; margin-top: 4px; opacity: .85; }

.aging-block.a1 .aging-qtd { color: #b45309; }
.aging-block.a2 .aging-qtd { color: #c2410c; }
.aging-block.a3 .aging-qtd { color: var(--danger); }
.aging-block.a4 .aging-qtd { color: #9d174d; }

/* ── TABLE CARD ──────────────────────────────────────────── */
.table-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
}

.table-toolbar-title { font-weight: 700; font-size: 14px; }

.toolbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* FILTERS BAR */
.filters-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: #fafafa;
}

.filter-chip {
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: white;
  color: var(--text-muted);
  transition: all .15s;
  line-height: 1.8;
}
.filter-chip:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.filter-chip.active { background: var(--primary); border-color: var(--primary); color: white; }

/* TABLE */
table { width: 100%; border-collapse: collapse; }

thead th {
  background: #f8fafc;
  padding: 9px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
  font-size: 13.5px;
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8fafc; }

/* ── BADGES ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .2px;
  white-space: nowrap;
}
.badge-green  { background: var(--success-bg); color: var(--success); }
.badge-red    { background: var(--danger-bg);  color: var(--danger); }
.badge-yellow { background: var(--warning-bg); color: var(--warning); }
.badge-blue   { background: var(--primary-light); color: var(--primary); }
.badge-gray   { background: #f3f4f6; color: #6b7280; }
.badge-purple { background: #f3e8ff; color: #6d28d9; }

/* ── BUTTONS ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 15px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}
.btn:disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn-lg { padding: 10px 20px; font-size: 14px; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #046547; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #a51a1a; }

.btn-outline {
  background: white;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: #f8fafc; }

/* ── FORMS ───────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group:last-child { margin-bottom: 0; }

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .3px;
}

.form-control {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: white;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  font-family: inherit;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,.1);
}
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 72px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ── MODAL ───────────────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}

.modal {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.modal-lg { max-width: 760px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: white;
  z-index: 10;
}

.modal-title { font-size: 16px; font-weight: 800; }

.modal-close {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: none; border: none;
  font-size: 20px; cursor: pointer;
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.modal-close:hover { background: #f3f4f6; color: var(--text); }

.modal-body { padding: 22px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  background: #fafafa;
}

/* ── TABS ────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}

.tab {
  padding: 9px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all .15s;
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── PAGINATION ──────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 14px;
  border-top: 1px solid var(--border);
}

.pag-btn {
  min-width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: white;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  padding: 0 8px;
}
.pag-btn:hover:not(:disabled) { background: #f8fafc; border-color: var(--primary); color: var(--primary); }
.pag-btn.active { background: var(--primary); border-color: var(--primary); color: white; }
.pag-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── TOAST ───────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: white;
  box-shadow: var(--shadow-md);
  animation: slideIn .22s ease;
  min-width: 260px;
  max-width: 380px;
  pointer-events: all;
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--primary); }

@keyframes slideIn {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to   { opacity: 0; transform: translateX(110%); }
}

/* ── STATES ──────────────────────────────────────────────── */
.loading-state, .empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .icon { font-size: 44px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

.spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── UTILITIES ───────────────────────────────────────────── */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.font-bold   { font-weight: 700; }
.font-mono   { font-family: 'Courier New', monospace; font-size: .95em; }
.w-full      { width: 100%; }
.mt-2        { margin-top: 8px; }
.mt-3        { margin-top: 12px; }
.mt-4        { margin-top: 16px; }
.mb-4        { margin-bottom: 16px; }
.flex        { display: flex; }
.flex-wrap   { flex-wrap: wrap; }
.gap-2       { gap: 8px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.divider     { height: 1px; background: var(--border); margin: 14px 0; }
.small       { font-size: 12px; color: var(--text-muted); }
