:root {
  --bg: #0f1419;
  --bg-elevated: #1a222d;
  --bg-card: #1e2835;
  --border: rgba(255, 255, 255, 0.08);
  --text: #eef2f6;
  --text-muted: #94a3b8;
  --accent: #3ecf9b;
  --accent-dim: rgba(62, 207, 155, 0.15);
  --warning: #f59e0b;
  --danger: #f87171;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --font: "DM Sans", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 80% -10%, rgba(62, 207, 155, 0.12), transparent),
    radial-gradient(800px 400px at 0% 100%, rgba(59, 130, 246, 0.08), transparent), var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  padding: 1.5rem 1.25rem;
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(30, 40, 53, 0.95), rgba(20, 28, 36, 0.98));
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-dim);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.25rem;
}

.brand strong {
  display: block;
  font-size: 1.05rem;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-item {
  font: inherit;
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-dim);
  border-color: rgba(62, 207, 155, 0.35);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-foot {
  margin-top: auto;
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.sidebar-foot code {
  background: rgba(0, 0, 0, 0.25);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.68rem;
}

.main {
  padding: 1.5rem 2rem 3rem;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.topbar-actions .export-link {
  text-decoration: none;
}

.period-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
}

.period-bar label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.period-bar input[type="date"] {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 0.45rem 0.6rem;
  font: inherit;
  min-width: 150px;
}

.btn {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.btn.primary {
  background: linear-gradient(135deg, #34d399, #10b981);
  border-color: transparent;
  color: #042f23;
  font-weight: 600;
}

.btn.primary:hover {
  filter: brightness(1.05);
}

.btn.ghost {
  font-size: 0.85rem;
  padding: 0.4rem 0.65rem;
}

.btn.small {
  font-size: 0.78rem;
  padding: 0.25rem 0.5rem;
}

.btn.danger {
  border-color: rgba(248, 113, 113, 0.45);
  color: var(--danger);
}

.btn.danger:hover {
  background: rgba(248, 113, 113, 0.12);
}

.pill {
  font-size: 0.72rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}

.pill.error {
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
}

.page-title {
  font-size: 1.65rem;
  margin: 0 0 0.35rem;
  letter-spacing: -0.02em;
}

.page-desc {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.hidden {
  display: none !important;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stats-grid--3 {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow);
}

.stat-card.accent {
  background: linear-gradient(145deg, rgba(62, 207, 155, 0.18), var(--bg-card));
  border-color: rgba(62, 207, 155, 0.25);
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.stat-hint {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.25rem;
  align-items: start;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.card-head h2 {
  margin: 0;
}

.category-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.category-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.category-list li:last-child {
  border-bottom: none;
}

.category-list .cat-name {
  color: var(--text);
}

.category-list .cat-meta {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.category-list .cat-total {
  font-weight: 600;
  color: var(--accent);
}

.table-wrap {
  overflow-x: auto;
  margin: 0 -0.25rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th,
.data-table td {
  padding: 0.55rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.data-table.compact td {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge.pending {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

.badge.done {
  background: rgba(62, 207, 155, 0.15);
  color: var(--accent);
}

.form-card h2 {
  margin-bottom: 1rem;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.stack-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.stack-form input,
.stack-form select,
.stack-form textarea {
  font: inherit;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
}

.stack-form textarea {
  resize: vertical;
  min-height: 64px;
}

.file-label input[type="file"] {
  font-size: 0.78rem;
}

.form-actions {
  margin-top: 0.25rem;
}

.form-actions.split {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.form-actions.split .btn {
  flex: 1;
  min-width: 120px;
}

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
  cursor: pointer;
}

.checkbox-label input {
  width: auto;
  accent-color: var(--accent);
}

.form-msg {
  min-height: 1.25rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 0;
}

.form-msg.ok {
  color: var(--accent);
}

.form-msg.err {
  color: var(--danger);
}

.inline-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.inline-filter select {
  font: inherit;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
}

.link-doc {
  color: #7dd3fc;
  text-decoration: none;
  font-weight: 500;
}

.link-doc:hover {
  text-decoration: underline;
}

.row-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.col-actions {
  white-space: nowrap;
}

.wrap-cell {
  max-width: 220px;
  word-break: break-word;
}

.desktop-table {
  display: block;
}

.mobile-only {
  display: none;
}

.list-cards {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.entity-card {
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}

.entity-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
}

.entity-date {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

.entity-amount {
  font-weight: 700;
  color: var(--accent);
  font-size: 1rem;
}

.entity-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0.25rem 0 0.35rem;
}

.entity-desc {
  margin: 0 0 0.65rem;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--text);
}

.entity-card-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.empty-hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.tabnav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  padding: 0.35rem 0.5rem calc(0.35rem + env(safe-area-inset-bottom, 0));
  background: rgba(26, 34, 45, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  justify-content: space-around;
  align-items: stretch;
  gap: 0.25rem;
}

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: rgba(15, 20, 25, 0.92);
}

.login-gate[hidden] {
  display: none;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 0.75rem;
  padding: 1.5rem;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0;
  font-size: 1.35rem;
}

.login-card p {
  margin: 0;
  color: var(--text-muted);
}

.card-form {
  max-width: 420px;
  padding: 1.25rem;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.tabnav-item {
  flex: 1;
  font: inherit;
  font-size: 0.68rem;
  padding: 0.4rem 0.25rem;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
}

.tabnav-item.active {
  color: var(--accent);
  background: var(--accent-dim);
  font-weight: 600;
}

.tabnav-icon {
  font-size: 1rem;
  line-height: 1;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 201;
  display: grid;
  place-items: end center;
  padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0));
}

.modal-panel {
  width: 100%;
  max-width: 420px;
  max-height: min(90dvh, 640px);
  overflow: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.modal-panel h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

@media (min-width: 480px) {
  .modal {
    place-items: center;
  }

  .modal-panel {
    border-radius: var(--radius);
  }
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  z-index: 100;
  max-width: min(360px, calc(100vw - 2rem));
}

.toast.error {
  border-color: rgba(248, 113, 113, 0.4);
  color: var(--danger);
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .tabnav {
    display: flex;
  }

  .main {
    padding: 1rem 1rem calc(4.5rem + env(safe-area-inset-bottom, 0));
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .period-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .period-bar label input[type="date"] {
    width: 100%;
    min-width: unset;
  }

  .topbar-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .desktop-table {
    display: none;
  }

  .mobile-only {
    display: flex;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .stats-grid,
  .stats-grid--3 {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 901px) {
  .tabnav {
    display: none !important;
  }
}
