:root {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --card:     #1a1d27;
  --border:   #2a2d3a;
  --text:     #e2e6f0;
  --muted:    #7a7f94;
  --accent:   #5b8af7;
  --green:    #3dba7d;
  --red:      #e05c5c;
  --yellow:   #e0b84a;
  --radius:   6px;
  --font:     'Inter', system-ui, -apple-system, sans-serif;
  --logo-color: #ffffff;
}

:root.light {
  --bg:       #f4f6fb;
  --surface:  #ffffff;
  --card:     #ffffff;
  --border:   #dde2ee;
  --text:     #1a1d27;
  --muted:    #7a7f94;
  --accent:   #3a6be0;
  --green:    #3dba7d;
  --red:      #e05c5c;
  --yellow:   #b8860b;
  --logo-color: #000000;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
}

/* Layout */
#app { display: flex; height: 100vh; overflow: hidden; }

#sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
}

#sidebar .logo {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}
#sidebar .logo .logo-img { width: 75%; height: auto; display: block; margin: 0 auto; filter: invert(1); }
:root.light #sidebar .logo .logo-img { filter: invert(0); }

#sidebar nav { flex: 1; padding: 12px 0; }

#sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--muted);
  text-decoration: none;
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
  font-size: 13.5px;
}

#sidebar nav a:hover  { background: rgba(255,255,255,0.04); color: var(--text); }
#sidebar nav a.active { background: rgba(91,138,247,0.12);  color: var(--accent); font-weight: 600; }

.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  padding: 9px 20px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13.5px;
  user-select: none;
  transition: background 0.15s, color 0.15s;
}
.nav-group-toggle:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-group-toggle.open  { color: var(--text); }
.nav-group-toggle .chevron { transition: transform 0.2s; flex-shrink: 0; }
.nav-group-toggle.open .chevron { transform: rotate(90deg); }

.nav-group-items { display: none; }
.nav-group-items.open { display: block; }
.nav-group-items a { padding-left: 32px !important; font-size: 13px !important; }

#sidebar .user-bar {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

#sidebar .user-bar strong { color: var(--text); display: block; margin-bottom: 4px; }
#sidebar .user-bar a { color: var(--muted); cursor: pointer; text-decoration: underline; }
.theme-toggle {
  display: block;
  margin-top: 10px;
  background: var(--border);
  border: none;
  border-radius: 20px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  transition: background 0.2s;
}
.theme-toggle:hover { background: var(--accent); }

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#topbar {
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
}

#topbar h1 { font-size: 16px; font-weight: 600; }

#content {
  flex: 1;
  padding: 28px;
  overflow-y: auto;
}

/* Login */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 40px;
  width: 360px;
}

.login-box h2 { font-size: 20px; margin-bottom: 4px; }
.login-box p  { color: var(--muted); font-size: 13px; margin-bottom: 24px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }

input, select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 72px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary   { background: var(--accent); color: #fff; }
.btn-success   { background: var(--green);  color: #fff; }
.btn-danger    { background: var(--red);    color: #fff; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Tables */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  font-family: var(--font);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

/* Cabeceira do diario dentro de .filters — sticky de balde */
.journal-head-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  margin-top: 8px;
}
.journal-body-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  vertical-align: middle;
}

tbody tr:hover { background: rgba(255,255,255,0.02); }

.num { text-align: right; font-variant-numeric: tabular-nums; }
td.num { font-family: monospace; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-pending  { background: rgba(224,184,74,0.15);  color: var(--yellow); }
.badge-confirmed{ background: rgba(61,186,125,0.15);  color: var(--green); }
.badge-rejected { background: rgba(224,92,92,0.15);   color: var(--red); }
.badge-viando   { background: rgba(91,138,247,0.15);  color: var(--accent); }
.badge-galaica  { background: rgba(61,186,125,0.15);  color: var(--green); }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.card-title { font-size: 13px; color: var(--muted); margin-bottom: 8px; font-weight: 500; }
.card-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Grids */
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }

/* Filters bar */
.filters {
  display: flex;
  flex-direction: column;
  margin-bottom: 20px;
  position: sticky;
  top: -28px;
  background: var(--bg);
  z-index: 50;
  padding-top: 28px;
  padding-bottom: 12px;
}

.filters-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 12px;
}

.filters .form-group,
.filters-row .form-group { margin-bottom: 0; flex-shrink: 0; }

/* Alert/Error */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
}
.alert-error   { background: rgba(224,92,92,0.1); border: 1px solid rgba(224,92,92,0.3); color: var(--red); }
.alert-success { background: rgba(61,186,125,0.1); border: 1px solid rgba(61,186,125,0.3); color: var(--green); }
.alert-warning { background: rgba(224,184,74,0.1); border: 1px solid rgba(224,184,74,0.3); color: var(--yellow); }
.alert-info    { background: rgba(91,138,247,0.1); border: 1px solid rgba(91,138,247,0.3); color: var(--accent); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 680px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
}

.modal h3 { font-size: 15px; margin-bottom: 20px; }

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Journal lines editor */
.lines-editor { margin: 16px 0; }
.lines-editor .line-row {
  display: grid;
  grid-template-columns: 220px 1fr 120px 120px auto;
  gap: 8px;
  align-items: start;
  margin-bottom: 8px;
}
.lines-editor .line-row input, .lines-editor .line-row select { font-size: 13px; }
.lines-editor .lines-header {
  display: grid;
  grid-template-columns: 220px 1fr 120px 120px auto;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 0 0 6px;
}

/* ── Autocomplete conta ── */
.acc-search-wrap { position: relative; }
.acc-search-input { width: 100%; font-size: 13px; }
.acc-search-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 2px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 2000;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.acc-search-dropdown.open { display: block; }
.acc-search-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  gap: 10px;
  align-items: baseline;
  border-bottom: 1px solid var(--border);
}
.acc-search-item:last-child { border-bottom: none; }
.acc-search-item:hover,
.acc-search-item.focused { background: rgba(91,138,247,0.12); }
.acc-search-item .acc-code { color: var(--accent); font-weight: 600; white-space: nowrap; }
.acc-search-item .acc-name { color: var(--text); }

.lines-total {
  display: flex;
  justify-content: flex-end;
  gap: 24px;
  padding: 10px 0 0;
  font-size: 13px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
.lines-total .balanced { color: var(--green); }
.lines-total .unbalanced { color: var(--red); }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  justify-content: flex-end;
  font-size: 13px;
  color: var(--muted);
}

.pagination .btn-sm { min-width: 32px; justify-content: center; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-state .icon { font-size: 36px; margin-bottom: 12px; }
.empty-state p { font-size: 13px; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── Conciliación Bancaria ─────────────────────────────────── */

.bank-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
  padding-bottom: 0;
}

.bank-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}

.bank-tab:hover { color: var(--text); }
.bank-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Barra de progreso de conciliación */
.progress-bar {
  background: var(--border);
  border-radius: 4px;
  height: 6px;
  width: 80px;
  display: inline-block;
  vertical-align: middle;
  overflow: hidden;
}

.progress-fill {
  background: var(--green);
  height: 100%;
  border-radius: 4px;
  transition: width .3s;
}

/* Candidatos de matching no modal */
.match-cands { display: flex; flex-direction: column; gap: 6px; }

.match-cand {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.match-cand:hover    { border-color: var(--accent); background: rgba(91,138,247,0.05); }
.match-cand.selected { border-color: var(--accent); background: rgba(91,138,247,0.1); }

/* Badge muted (ignorados) */
.badge-muted { background: rgba(122,127,148,0.15); color: var(--muted); }

/* Columna numérica */
td.num { text-align: right; font-variant-numeric: tabular-nums; }
th.num { text-align: right; }

/* ─── Auto-match spinner overlay ────────────────────────────── */

#automatch-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.automatch-spinner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 40px;
  text-align: center;
  min-width: 240px;
}

.automatch-spinner p {
  color: var(--text);
  margin-bottom: 0;
  font-size: 14px;
}

.spinner-ring {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 16px;
}

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

/* ─── Date Range Picker ─────────────────────────────────────── */
.drp-trigger {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 160px;
  text-align: left;
  transition: border-color 0.15s;
  font-family: var(--font);
}
.drp-trigger:hover { border-color: var(--accent); }
.drp-trigger.active { border-color: var(--accent); color: var(--accent); }

.drp-wrap { display: flex; gap: 24px; }
.drp-cal  { flex: 1; min-width: 0; }

.drp-cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.drp-cal-header span { font-weight: 600; font-size: 13px; }
.drp-cal-nav {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 3px 8px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1;
}
.drp-cal-nav:hover { background: var(--border); }

.drp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.drp-dow {
  text-align: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  padding: 3px 0 6px;
}
.drp-day {
  text-align: center;
  padding: 5px 2px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  line-height: 1.4;
}
.drp-day:hover:not(.drp-empty)  { background: rgba(91,138,247,0.2); }
.drp-empty  { cursor: default; }
.drp-today  { font-weight: 700; color: var(--accent); }
.drp-selected { background: var(--accent) !important; color: #fff !important; border-radius: 4px; }
.drp-in-range { background: rgba(91,138,247,0.15); border-radius: 0; }
.drp-range-start { border-radius: 4px 0 0 4px !important; }
.drp-range-end   { border-radius: 0 4px 4px 0 !important; }
.drp-range-start.drp-range-end { border-radius: 4px !important; }

.drp-hint {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 16px;
  min-height: 18px;
}
.drp-hint strong { color: var(--text); }

/* ─── Split input (operador + valor) ────────────────────────── */
.split-input {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s;
}
.split-input:focus-within { border-color: var(--accent); }
.split-input select {
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 8px 2px 8px 10px;
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  width: auto;
  flex-shrink: 0;
  outline: none;
}
.split-input input[type=number] {
  border: none;
  background: transparent;
  flex: 1;
  min-width: 0;
  padding: 8px 10px 8px 6px;
  outline: none;
  width: 80px;
}
.split-input input[type=number]::-webkit-inner-spin-button,
.split-input input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; }
.split-input-sep {
  width: 1px;
  height: 16px;
  background: var(--border);
  flex-shrink: 0;
}

/* ─── Plano de Contas — type filter pills ─── */
.acc-type-pill {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.acc-type-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.acc-type-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Raz. Social clickable link in accounts table */
.legal-name-link {
  color: var(--muted);
  cursor: pointer;
  border-bottom: 1px dotted var(--muted);
  transition: color 0.15s;
}
.legal-name-link:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Plano de Contas — cabeçalho fixo (mesmo padrão que journal-head/body-table) */
.accounts-head-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  margin-top: 8px;
}
.accounts-body-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
}


/* ─── Resizable column handles ─────────────────────────────── */

thead th { position: relative; }

.col-resize-handle {
  position: absolute;
  right: -2px;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 10;
  user-select: none;
  background: transparent;
  transition: background 0.1s;
}
.col-resize-handle:hover { background: rgba(91,138,247,0.5); }
.col-resize-handle.dragging { background: var(--accent); }

/* ─── Hamburger (mobile) ─────────────────────────────────────── */

.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius);
  margin-right: 8px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
}
.hamburger:hover { background: var(--border); }

#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}
#sidebar-backdrop.visible { display: block; }

/* ─── Responsive ─────────────────────────────────────────────── */

@media (max-width: 900px) {
  body { overflow: auto; }
  #app { height: auto; min-height: 100dvh; overflow: visible; }

  #main { overflow: visible; min-height: 100dvh; }

  #content {
    flex: 1;
    overflow: visible;
    padding: 16px;
  }

  #sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
  }
  #sidebar.open { transform: translateX(0); }

  #topbar {
    position: sticky;
    top: 0;
    z-index: 90;
    padding: 12px 16px;
  }

  .hamburger { display: flex; }

  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }

  .filters { top: 0; padding-top: 16px; }
  .filters-row { flex-wrap: wrap; }
  .filters-row .form-group { flex-shrink: 1; min-width: 120px; }

  /* Split tables: hide floating head, inject thead into body via JS */
  .journal-head-table,
  .accounts-head-table { display: none; }

  /* Thead injected by JS for mobile */
  .journal-body-table thead,
  .accounts-body-table thead {
    display: table-header-group;
  }

  .modal { width: 95vw; padding: 20px 16px; }

  .lines-editor .line-row {
    grid-template-columns: 1fr 1fr;
  }
  .lines-editor .lines-header {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 560px) {
  .grid-4 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }

  #topbar h1 { font-size: 14px; }
  #topbar { padding: 10px 14px; }

  .card-value { font-size: 20px; }
}
