/* ----------------------------------------------------------------- tokens
   Cores de série (gráficos) seguem paleta validada para daltonismo —
   não trocar sem revalidar. O resto é o chrome da interface. */
:root {
  color-scheme: light;

  --bg:            #f4f4f2;
  --surface:       #ffffff;
  --surface-2:     #fafaf9;
  --border:        rgba(11, 11, 11, 0.09);
  --border-strong: rgba(11, 11, 11, 0.16);

  --text:          #14140f;
  --text-2:        #55554e;
  --text-3:        #8a8a80;

  --accent:        #1f6feb;
  --accent-hover:  #1a5fd0;
  --accent-soft:   rgba(31, 111, 235, 0.10);
  --danger:        #d03b3b;
  --positive:      #006300;

  --gridline:      #e6e6e1;

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;

    --bg:            #0b0b0c;
    --surface:       #141416;
    --surface-2:     #1b1b1e;
    --border:        rgba(255, 255, 255, 0.09);
    --border-strong: rgba(255, 255, 255, 0.16);

    --text:          #f4f4f2;
    --text-2:        #a8a8a0;
    --text-3:        #75756d;

    --accent:        #4c8dff;
    --accent-hover:  #6aa0ff;
    --accent-soft:   rgba(76, 141, 255, 0.14);
    --danger:        #e66767;
    --positive:      #0ca30c;

    --gridline:      #232326;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg:            #0b0b0c;
  --surface:       #141416;
  --surface-2:     #1b1b1e;
  --border:        rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);

  --text:          #f4f4f2;
  --text-2:        #a8a8a0;
  --text-3:        #75756d;

  --accent:        #4c8dff;
  --accent-hover:  #6aa0ff;
  --accent-soft:   rgba(76, 141, 255, 0.14);
  --danger:        #e66767;
  --positive:      #0ca30c;

  --gridline:      #232326;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
}

/* ------------------------------------------------------------------- base */
* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.muted { color: var(--text-3); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.icon {
  width: 16px; height: 16px;
  stroke: currentColor;
  stroke-width: 1.6;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 56px;
}

/* ----------------------------------------------------------------- header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.logo {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.logo svg { width: 19px; height: 19px; stroke: #fff; stroke-width: 2; fill: none; }

.brand-text { min-width: 0; }

.brand-name {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1.2;
}

.brand-conta {
  font-size: 12.5px;
  color: var(--text-3);
  margin: 1px 0 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-acoes { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.icon-btn {
  width: 34px; height: 34px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: color .12s, border-color .12s;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.icon-btn a { color: inherit; display: grid; place-items: center; }

a.icon-btn { text-decoration: none; }

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

.card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 0;
}

.card-header h2 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
  color: var(--text-2);
}

.card-body { padding: 14px 20px 20px; }

/* --------------------------------------------------------------- registro */
.card--registrar { margin-bottom: 22px; }

.form-linha {
  display: grid;
  grid-template-columns: minmax(140px, 220px) 1fr;
  gap: 12px;
  align-items: start;
}

.campo { min-width: 0; }

.campo label,
.auth-campo label,
.rotulo {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 7px;
}

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--r-md);
  padding: 11px 13px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.45;
  resize: vertical;
  transition: border-color .12s, background .12s;
}

input::placeholder, textarea::placeholder { color: var(--text-3); }

input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}

.dica {
  margin: 9px 0 0;
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.45;
}

.form-rodape {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: none;
  border-radius: var(--r-md);
  padding: 11px 17px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: background .12s;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .55; cursor: default; }
.btn--bloco { width: 100%; justify-content: center; padding: 12px; }

.feedback { font-size: 13px; line-height: 1.4; }
.feedback.ok { color: var(--positive); }
.feedback.erro { color: var(--danger); }

/* ------------------------------------------------------------------ stats */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 22px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 18px 18px;
}

.stat-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 8px;
}

.stat-valor {
  display: block;
  font-size: 27px;
  font-weight: 620;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.stat-valor--texto { font-size: 19px; letter-spacing: -0.01em; }

/* ---------------------------------------------------------------- gráficos */
.grid-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.card--wide { grid-column: 1 / -1; }

/* altura fixa: sem isso o Chart.js usa proporção e o gráfico de linha,
   sendo largo, fica absurdamente alto */
.chart-wrap { position: relative; height: 270px; }
.chart-wrap--linha { height: 240px; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}
.link-btn:hover { color: var(--accent-hover); }

/* ----------------------------------------------------------------- tabela */
.tx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.tx-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 0 8px 10px;
  border-bottom: 1px solid var(--gridline);
}

.tx-table td {
  padding: 11px 8px;
  border-bottom: 1px solid var(--gridline);
}

.tx-table tr:last-child td { border-bottom: none; }

.align-right { text-align: right; font-variant-numeric: tabular-nums; }

.cat-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: 1px;
}

.btn-apagar {
  border: none;
  background: none;
  color: var(--text-3);
  padding: 4px;
  border-radius: var(--r-sm);
  cursor: pointer;
  display: grid;
  place-items: center;
  margin-left: auto;
}
.btn-apagar:hover { color: var(--danger); background: var(--accent-soft); }
.btn-apagar:disabled { opacity: .4; cursor: default; }

.rodape {
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
  margin-top: 22px;
}

/* ------------------------------------------------------------------- auth */
.page--auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  max-width: 100%;
  padding: 24px 20px;
}

.auth-box { width: 100%; max-width: 380px; }

.auth-marca {
  display: flex;
  align-items: center;
  gap: 11px;
  justify-content: center;
  margin-bottom: 26px;
}

.auth-marca .brand-name { font-size: 17px; }

.auth-card { padding: 26px 24px; }

.auth-titulo {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 0 0 5px;
}

.auth-sub {
  font-size: 13px;
  color: var(--text-3);
  margin: 0 0 22px;
  line-height: 1.45;
}

.auth-campo { margin-bottom: 15px; }

.auth-erro {
  font-size: 13px;
  color: var(--danger);
  margin: 0 0 14px;
}

.auth-rodape {
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
  margin-top: 18px;
}

.auth-rodape a { color: var(--accent); text-decoration: none; }
.auth-rodape a:hover { text-decoration: underline; }

/* ------------------------------------------------------------- responsivo */
@media (max-width: 860px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .grid-charts { grid-template-columns: 1fr; }
  .form-linha { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .page { padding: 20px 16px 44px; }
  .stat-valor { font-size: 23px; }

  /* 6 colunas não cabem no celular: cada lançamento vira um bloco */
  .tx-table thead { display: none; }
  .tx-table, .tx-table tbody, .tx-table tr, .tx-table td { display: block; }

  .tx-table tr {
    position: relative;
    display: grid;
    grid-template-columns: 1fr auto;
    column-gap: 12px;
    padding: 13px 32px 13px 0;
    border-bottom: 1px solid var(--gridline);
  }

  .tx-table td { border: none; padding: 0; }

  .tx-table td:nth-child(3) { grid-column: 1; grid-row: 1; font-weight: 550; }
  .tx-table td:nth-child(5) { grid-column: 2; grid-row: 1; font-weight: 620; }
  .tx-table td:nth-child(1) { grid-column: 1; grid-row: 2; }
  .tx-table td:nth-child(2) { grid-column: 2; grid-row: 2; text-align: right; }
  .tx-table td:nth-child(4) { grid-column: 1 / -1; grid-row: 3; margin-top: 3px; }

  .tx-table td:nth-child(1),
  .tx-table td:nth-child(2),
  .tx-table td:nth-child(4) { font-size: 12px; color: var(--text-3); }

  .tx-table td:nth-child(6) { position: absolute; top: 11px; right: 0; }

  /* a tabela de categorias tem 2 colunas e cabe normalmente */
  #categoria-table, #categoria-table tbody, #categoria-table tr,
  #categoria-table td, #categoria-table thead { display: revert; }
  #categoria-table tr { padding: 0; }
  #categoria-table td { padding: 11px 8px; }
}
