/* ==================================================================
   Painel de Quebras - Design System
   Paleta sóbria corporativa (teal/slate) com modo escuro opcional.
   ================================================================== */

:root {
  --brand-50:  #ecfeff;
  --brand-100: #cffafe;
  --brand-500: #0d9488;
  --brand-600: #0f766e;
  --brand-700: #134e4a;
  --brand-900: #0a302c;

  --surface-0: #f7f8fa;
  --surface-1: #ffffff;
  --surface-2: #f1f3f7;
  --border:    #e3e7ef;
  --border-strong: #d0d6e1;

  --text-1: #0f172a;
  --text-2: #475569;
  --text-3: #64748b;

  --danger:  #b91c1c;
  --danger-bg: #fee2e2;
  --success: #047857;
  --success-bg: #d1fae5;
  --warning: #b45309;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;

  --shadow-1: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-2: 0 6px 16px rgba(15, 23, 42, .08), 0 2px 6px rgba(15, 23, 42, .06);
  --shadow-3: 0 12px 32px rgba(15, 23, 42, .12);

  --sidebar-w: 248px;

  --font: "Poppins", system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  --surface-0: #0b1220;
  --surface-1: #111a2c;
  --surface-2: #17223a;
  --border:    #1f2b44;
  --border-strong: #2a3a5c;
  --text-1: #e6edf9;
  --text-2: #b6c2d9;
  --text-3: #8ea0c2;
  --danger-bg: #3b1414;
  --success-bg: #0f2d20;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-1);
  background: var(--surface-0);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h3 { font-size: 15px; }

a { color: inherit; }

.muted  { color: var(--text-3); }
.tiny   { font-size: 11px; }
.error  { color: var(--danger); background: var(--danger-bg); padding: 8px 12px; border-radius: var(--radius-sm); }

code { font-family: "Cascadia Mono", Consolas, monospace; background: var(--surface-2); padding: 2px 6px; border-radius: 4px; font-size: 12.5px; }

/* ============ BOTÕES ============ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  color: var(--text-1);
  cursor: pointer;
  font-family: inherit; font-size: 13.5px;
  transition: background .15s ease, transform .12s ease, box-shadow .15s ease;
}
.btn svg { width: 16px; height: 16px; fill: currentColor; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand-600); color: #fff; border-color: var(--brand-600); }
.btn.primary:hover { background: var(--brand-700); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.link {
  background: none; border: none; color: var(--brand-600);
  cursor: pointer; font-size: 12.5px; padding: 0;
}

.icon-btn {
  background: transparent; border: none; cursor: pointer;
  width: 32px; height: 32px; border-radius: 6px; color: var(--text-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text-1); }
.icon-btn svg { width: 16px; height: 16px; fill: currentColor; }

/* ============ AUTH ============ */
body.auth {
  min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(1000px 600px at 20% 10%, rgba(15,118,110,.15), transparent 70%),
              radial-gradient(1000px 600px at 80% 90%, rgba(19,78,74,.2), transparent 70%),
              var(--surface-0);
}
.auth-shell { width: min(420px, 92vw); }
.auth-card {
  background: var(--surface-1);
  padding: 32px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  border: 1px solid var(--border);
}
.auth-card h1 { font-size: 20px; }
.auth-footer { margin-top: 20px; text-align: center; }

.brand {
  display: flex; gap: 12px; align-items: center; margin-bottom: 24px;
}
.brand-badge {
  width: 48px; height: 48px; border-radius: 12px;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  color: #fff; font-weight: 700; display: grid; place-items: center; font-size: 22px;
  box-shadow: var(--shadow-1);
}
.brand-badge.sm { width: 36px; height: 36px; font-size: 16px; border-radius: 10px; }

/* ============ LAYOUT APP ============ */
body.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 20px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  text-decoration: none; color: var(--text-2);
  font-weight: 500;
}
.sidebar-nav a:hover { background: var(--surface-2); color: var(--text-1); }
.sidebar-nav a.active {
  background: linear-gradient(90deg, rgba(15,118,110,.12), transparent);
  color: var(--brand-700);
}
[data-theme="dark"] .sidebar-nav a.active { color: var(--brand-100); }
.sidebar-nav svg { width: 18px; height: 18px; fill: currentColor; }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }

.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; border-radius: 10px; background: var(--surface-2);
}
.avatar {
  width: 32px; height: 32px; border-radius: 999px;
  background: var(--brand-600); color: #fff; font-weight: 600;
  display: grid; place-items: center;
}
.user-chip .meta { flex: 1; line-height: 1.15; display: flex; flex-direction: column; }

.content { padding: 24px 28px 72px; max-width: 1680px; width: 100%; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; flex-wrap: wrap; gap: 12px;
}
.topbar-actions { display: flex; gap: 8px; align-items: center; position: relative; }

/* ============ FILTROS ============ */
.filters-panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-1);
  margin-bottom: 20px;
}
.filters-head { display: flex; justify-content: space-between; margin-bottom: 12px; }
.filters-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}
.filters-actions {
  display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap;
}
.legend {
  display: inline-flex; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--text-3);
  margin-left: auto;
}
.legend b { color: var(--text-2); margin-right: 4px; }
.legend .tag {
  display: inline-block; padding: 3px 8px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.legend .tag.quebra   { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }
.legend .tag.perda    { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.legend .tag.transf   { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
[data-theme="dark"] .legend .tag { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.field > span, .field > label { color: var(--text-2); font-weight: 500; }
.field input, .field select {
  font-family: inherit; font-size: 13.5px;
  padding: 9px 10px; border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface-1); color: var(--text-1);
  transition: border-color .15s;
}
.field input:focus, .field select:focus {
  outline: 2px solid var(--brand-100); border-color: var(--brand-600);
}

/* Multi-select chips */
.multi {
  position: relative;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-1);
  padding: 6px; min-height: 38px; cursor: pointer;
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
}
.multi:hover { border-color: var(--brand-600); }
.multi .chip {
  background: var(--brand-600); color: #fff;
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 4px;
}
.multi .chip .x { cursor: pointer; opacity: .8; }
.multi .chip .x:hover { opacity: 1; }
.multi .placeholder { color: var(--text-3); font-size: 12.5px; padding-left: 4px; }
.multi-pop {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 20;
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: 10px; box-shadow: var(--shadow-2);
  max-height: 260px; overflow: auto;
}
.multi-pop .opt {
  padding: 8px 10px; font-size: 13px; cursor: pointer;
  display: flex; gap: 8px; align-items: center;
}
.multi-pop .opt:hover { background: var(--surface-2); }
.multi-pop .opt input { accent-color: var(--brand-600); }
.multi-pop .search {
  position: sticky; top: 0; padding: 8px; background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.multi-pop .search input { width: 100%; }

/* ============ KPIs ============ */
.kpis {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: 18px;
}
.kpi {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px 18px; box-shadow: var(--shadow-1);
  position: relative; overflow: hidden;
  animation: fadeUp .25s ease both;
}
.kpi .label { color: var(--text-3); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 26px; font-weight: 600; margin-top: 6px; }
.kpi .delta { font-size: 12px; color: var(--text-3); }
.kpi .bar {
  position: absolute; left: 0; bottom: 0; height: 3px; width: 40%;
  background: linear-gradient(90deg, var(--brand-500), var(--brand-700));
}
.kpi.k-total .bar { background: linear-gradient(90deg, #0f766e, #134e4a); }
.kpi.k-quebra .bar { background: linear-gradient(90deg, #ea580c, #9a3412); }
.kpi.k-perda .bar { background: linear-gradient(90deg, #dc2626, #991b1b); }
.kpi.k-doa .bar { background: linear-gradient(90deg, #4f46e5, #1e3a8a); }
.kpi.k-transf .bar { background: linear-gradient(90deg, #2563eb, #1e40af); }

/* ============ CARDS / GRID ============ */
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px;
  box-shadow: var(--shadow-1); margin-bottom: 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 12px; flex-wrap: wrap; }
.card-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.grid-2 {
  display: grid; gap: 14px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
}

/* ============ TABELA ============ */
.table-tools { display: flex; gap: 8px; }
.table-tools input { padding: 7px 10px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface-1); color: var(--text-1); }
.table-tools select { padding: 7px 10px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface-1); color: var(--text-1); }

.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
table.analytic {
  width: 100%; border-collapse: collapse; font-size: 13px; min-width: 720px;
}
table.analytic th, table.analytic td {
  padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.analytic thead th {
  position: sticky; top: 0; background: var(--surface-2);
  font-weight: 600; color: var(--text-2); cursor: pointer; user-select: none;
}
table.analytic thead th.sortable::after {
  content: "⇅"; opacity: .35; margin-left: 6px;
}
table.analytic thead th.sort-asc::after { content: "▲"; opacity: 1; }
table.analytic thead th.sort-desc::after { content: "▼"; opacity: 1; }
table.analytic tbody tr:hover { background: var(--surface-2); }
table.analytic td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.analytic td.neg { color: var(--danger); }
table.analytic td.pos { color: var(--success); }
table.analytic tr.subtotal td {
  background: var(--surface-2); font-weight: 600; color: var(--text-1);
  border-top: 2px solid var(--border-strong);
}
table.analytic tfoot td {
  font-weight: 700; background: var(--surface-2);
  border-top: 2px solid var(--border-strong);
}

.pagination {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 2px; font-size: 12.5px; color: var(--text-3); flex-wrap: wrap; gap: 8px;
}
.pagination .pages button {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-2); cursor: pointer;
  padding: 5px 10px; border-radius: 6px; margin: 0 2px; min-width: 32px;
}
.pagination .pages button.current {
  background: var(--brand-600); color: #fff; border-color: var(--brand-600);
}
.pagination .pages button:hover { background: var(--surface-2); }
.pagination .pages button.current:hover { background: var(--brand-700); }

/* ============ LOADING ============ */
.loading {
  position: fixed; inset: 0; background: rgba(15,23,42,.32);
  display: grid; place-items: center; z-index: 40; backdrop-filter: blur(2px);
}
.loading[hidden], .toast[hidden], [hidden] { display: none !important; }
.loading p { color: #fff; margin-top: 12px; }
.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: spin 1s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ TOAST ============ */
.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow-3);
  background: var(--surface-1); border: 1px solid var(--border);
  animation: fadeUp .2s ease both;
}
.toast.error { border-color: #fca5a5; background: var(--danger-bg); color: var(--danger); }
.toast.ok    { border-color: #6ee7b7; background: var(--success-bg); color: var(--success); }

/* ============ DROPDOWN ============ */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-2); min-width: 180px; overflow: hidden;
  display: none;
}
.dropdown-menu.open { display: block; }
.dropdown-menu button {
  width: 100%; background: none; border: none; text-align: left;
  padding: 9px 14px; cursor: pointer; font: inherit; color: var(--text-1);
}
.dropdown-menu button:hover { background: var(--surface-2); }

/* ============ DIALOG ============ */
dialog.dialog {
  border: none; border-radius: 14px; padding: 0;
  box-shadow: var(--shadow-3); max-width: 480px; width: 90vw;
  background: var(--surface-1); color: var(--text-1);
}
dialog.dialog::backdrop { background: rgba(15,23,42,.5); backdrop-filter: blur(2px); }
.dialog-form { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.favorites-list {
  list-style: none; padding: 0; margin: 0;
  max-height: 360px; overflow: auto; border: 1px solid var(--border); border-radius: 8px;
}
.favorites-list li {
  padding: 10px 12px; display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border);
}
.favorites-list li:last-child { border-bottom: 0; }
.favorites-list .actions { display: flex; gap: 6px; }

/* ============ TABS ADMIN ============ */
.tabs {
  display: flex; gap: 2px; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 4px; width: fit-content; margin-bottom: 16px; flex-wrap: wrap;
}
.tab {
  background: transparent; border: none; cursor: pointer;
  padding: 8px 14px; border-radius: 8px; font: inherit; color: var(--text-2);
}
.tab:hover { background: var(--surface-2); color: var(--text-1); }
.tab.active { background: var(--brand-600); color: #fff; }

.tab-pane { display: none; animation: fadeUp .2s ease both; }
.tab-pane.active { display: block; }

.status-box {
  padding: 12px; border-radius: 8px; background: var(--surface-2); border: 1px dashed var(--border-strong);
  font-family: "Cascadia Mono", Consolas, monospace; font-size: 12.5px; white-space: pre-wrap;
}

.stack-lg { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 10px; }

.check { display: flex; gap: 8px; align-items: center; font-size: 13.5px; }
.check input { accent-color: var(--brand-600); }

/* ============ ANIMAÇÕES ============ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============ RESPONSIVO ============ */
@media (max-width: 960px) {
  body.app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row; padding: 12px; gap: 12px; overflow-x: auto; }
  .sidebar-brand { padding: 0 6px; }
  .sidebar-nav { flex-direction: row; flex: 1; }
  .sidebar-nav a span { display: none; }
  .sidebar-footer { flex-direction: row; margin-top: 0; gap: 6px; }
  .sidebar-footer .user-chip .meta { display: none; }
  .sidebar-footer #themeToggle span { display: none; }
  .content { padding: 16px; }
}

@media (max-width: 600px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
