/* ============ Design Tokens ============ */
:root {
  --forest: #1b4332;
  --forest-dark: #0f2a1f;
  --emerald: #2d6a4f;
  --emerald-light: #40916c;
  --sage: #d8e5d3;
  --sage-soft: #eef3ea;
  --ivory: #faf7f0;
  --ivory-card: #ffffff;
  --gold: #c9a227;
  --gold-soft: #e9d8a6;
  --ink: #233027;
  --ink-soft: #5c6b61;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --success: #2d6a4f;
  --border: #e2e8df;
  --radius: 14px;
  --shadow: 0 4px 16px rgba(27, 67, 50, 0.08);
  --shadow-lg: 0 12px 32px rgba(27, 67, 50, 0.16);
  --sidebar-w: 250px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: var(--ivory);
  color: var(--ink);
}

h1, h2, h3, h4 { font-family: inherit; margin: 0; color: var(--forest-dark); }

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }

/* ============ Buttons ============ */
.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.15s ease;
}
.btn-primary {
  background: var(--emerald);
  color: #fff;
}
.btn-primary:hover { background: var(--forest); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink);
}
.btn-ghost:hover { background: var(--sage-soft); }
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: #8f1d16; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.link-btn {
  background: none;
  border: none;
  color: var(--emerald-light);
  text-decoration: underline;
  font-size: 13px;
  margin-top: 14px;
}

/* ============ Auth Screens ============ */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--forest) 0%, var(--emerald) 55%, var(--emerald-light) 100%);
  padding: 24px;
}
.auth-card {
  background: var(--ivory-card);
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  border-top: 4px solid var(--gold);
}
.brand { text-align: center; margin-bottom: 24px; }
.brand-icon { font-size: 36px; }
.brand h1 { font-size: 24px; margin-top: 6px; }
.subtitle { color: var(--ink-soft); font-size: 13px; margin-top: 4px; }
.section-title {
  font-size: 14px;
  color: var(--emerald);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 18px 0 10px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--ink);
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  background: var(--ivory);
  color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--emerald-light);
  background: #fff;
}
.checkbox-field label { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.checkbox-field input { width: auto; }
.security-note {
  font-size: 12px;
  color: var(--ink-soft);
  background: var(--sage-soft);
  border: 1px solid var(--sage);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 14px 0;
  line-height: 1.5;
}
.form-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* ============ App Shell ============ */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--forest-dark), var(--forest));
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: margin-left 0.2s ease;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px;
  font-weight: 700;
  font-size: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-nav { flex: 1; padding: 16px 10px; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 10px;
  color: rgba(255,255,255,0.82);
  font-size: 14px;
  font-weight: 500;
  background: transparent;
  border: none;
  text-align: left;
  width: 100%;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active {
  background: var(--gold);
  color: var(--forest-dark);
  font-weight: 700;
}
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--gold-soft);
  color: var(--forest-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.user-meta { font-size: 13px; }
.role-badge {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--gold-soft);
  letter-spacing: 0.05em;
}
.sidebar-footer .btn-ghost {
  color: #fff;
  border-color: rgba(255,255,255,0.3);
}
.sidebar-footer .btn-ghost:hover { background: rgba(255,255,255,0.12); }

.main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 28px;
  background: var(--ivory-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h2 { flex: 1; font-size: 19px; }
.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: 20px;
  color: var(--forest);
}
.content-area { padding: 28px; flex: 1; }

/* ============ Cards / Grid ============ */
.card {
  background: var(--ivory-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  border: 1px solid var(--border);
}
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}
.summary-card {
  background: var(--ivory-card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--emerald);
  position: relative;
}
.summary-card.gold { border-left-color: var(--gold); }
.summary-card .label { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.summary-card .value { font-size: 26px; font-weight: 700; color: var(--forest-dark); margin-top: 6px; }
.summary-card .icon { position: absolute; top: 18px; right: 18px; font-size: 22px; opacity: 0.5; }

.section-block { margin-bottom: 28px; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.section-head h3 { font-size: 17px; }

/* ============ Tables ============ */
.table-wrap { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); background: var(--ivory-card); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left;
  padding: 12px 16px;
  background: var(--sage-soft);
  color: var(--forest-dark);
  font-weight: 700;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr:hover { background: var(--sage-soft); }
tbody tr:last-child td { border-bottom: none; }
.cat-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--sage);
  color: var(--forest-dark);
  font-size: 12px;
  font-weight: 600;
}
.amount-cell { font-weight: 700; color: var(--forest-dark); }
.row-actions { display: flex; gap: 6px; }
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 13px;
}
.icon-btn:hover { background: var(--sage-soft); }
.icon-btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--ink-soft);
}

/* ============ Filters ============ */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
  align-items: flex-end;
}
.filter-bar .field { margin-bottom: 0; min-width: 150px; }
.filter-bar .field input, .filter-bar .field select { padding: 8px 10px; }

/* ============ Form Grid (dynamic expense fields) ============ */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 18px;
}
.form-grid .field.full-width { grid-column: 1 / -1; }

/* ============ Modal ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 42, 31, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-box {
  background: var(--ivory-card);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 460px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border-top: 4px solid var(--gold);
}
.modal-box.modal-wide { max-width: 680px; }
.modal-box h3 { margin-bottom: 18px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ============ Toasts ============ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  background: var(--forest-dark);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--gold);
  animation: slideIn 0.2s ease;
  max-width: 320px;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--emerald-light); }
@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============ Admin: category/field lists ============ */
.manage-list { display: flex; flex-direction: column; gap: 10px; }
.manage-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--ivory-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.manage-row .grow { flex: 1; }
.manage-row.inactive { opacity: 0.5; }
.tag-sm {
  font-size: 11px;
  background: var(--sage);
  color: var(--forest-dark);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.order-btns { display: flex; flex-direction: column; gap: 2px; }
.order-btns button { padding: 2px 6px; font-size: 11px; }

.actions-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }

/* ============ Responsive ============ */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    z-index: 50;
    height: 100vh;
    margin-left: calc(-1 * var(--sidebar-w));
  }
  .sidebar.open { margin-left: 0; box-shadow: var(--shadow-lg); }
  .hamburger { display: block; }
  .content-area { padding: 18px; }
  .topbar { padding: 14px 16px; }
}
@media (max-width: 560px) {
  .auth-card { padding: 26px; }
  .summary-grid { grid-template-columns: 1fr; }
  .topbar-actions .btn { padding: 8px 12px; font-size: 13px; }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 8px; }
  tbody td { border: none; padding: 6px 10px; }
  tbody td::before {
    content: attr(data-label);
    font-weight: 700;
    display: inline-block;
    min-width: 110px;
    color: var(--ink-soft);
    font-size: 12px;
  }
}
