/* =========================================================
   Family Finance — Main Stylesheet
   ========================================================= */

:root {
  --color-bg:          #f4f6f9;
  --color-surface:     #ffffff;
  --color-nav-bg:      #1a2744;
  --color-nav-text:    #c8d3e8;
  --color-nav-active:  #ffffff;
  --color-nav-hover:   #2e3f6e;
  --color-accent:      #2563eb;
  --color-accent-dark: #1d4ed8;
  --color-income:      #16a34a;
  --color-expense:     #dc2626;
  --color-text:        #1e293b;
  --color-text-muted:  #64748b;
  --color-border:      #e2e8f0;
  --color-badge:       #ef4444;
  --radius:            8px;
  --shadow:            0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md:         0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

/* ----- Reset & Base ----- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
}

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

/* ----- Layout ----- */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ----- Sidebar Navigation ----- */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--color-nav-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
}

.sidebar-brand {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-nav-active);
  letter-spacing: 0.01em;
}

.sidebar-brand p {
  font-size: 12px;
  color: var(--color-nav-text);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-section {
  padding: 12px 20px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(200,211,232,0.45);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--color-nav-text);
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
  position: relative;
}

.nav-link:hover {
  background: var(--color-nav-hover);
  color: var(--color-nav-active);
  text-decoration: none;
}

.nav-link.active {
  background: var(--color-nav-hover);
  color: var(--color-nav-active);
  font-weight: 600;
}

.nav-link.active::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--color-accent);
  border-radius: 0 2px 2px 0;
}

.nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.badge {
  margin-left: auto;
  background: var(--color-badge);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-footer a {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-nav-text);
  font-size: 13px;
}

.sidebar-footer a:hover {
  color: var(--color-nav-active);
  text-decoration: none;
}

/* ----- Main Content ----- */
.main {
  margin-left: 220px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 20px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.page-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text);
}

.page-header p {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.page-body {
  padding: 28px 32px;
  flex: 1;
}

/* ----- Cards ----- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

/* ----- Stat Cards ----- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
}

.stat-card .label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}

.stat-card .value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-card .value.income  { color: var(--color-income); }
.stat-card .value.expense { color: var(--color-expense); }
.stat-card .value.neutral { color: var(--color-text); }

/* ----- Flash Messages ----- */
.flash-messages {
  padding: 0 32px;
  margin-top: 16px;
}

.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.alert-info    { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
}

.btn:hover { text-decoration: none; opacity: 0.9; }

.btn-primary { background: var(--color-accent); color: #fff; }
.btn-primary:hover { background: var(--color-accent-dark); }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-danger { background: var(--color-expense); color: #fff; }

/* ----- Forms ----- */
.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

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

.login-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 40px;
  width: 100%;
  max-width: 380px;
}

.login-box h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 4px;
}

.login-box .subtitle {
  font-size: 14px;
  color: var(--color-text-muted);
  margin-bottom: 28px;
}

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

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

thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  border-bottom: 2px solid var(--color-border);
  background: #f8fafc;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

.amount-income  { color: var(--color-income);  font-weight: 600; }
.amount-expense { color: var(--color-expense); font-weight: 600; }

/* ----- Empty State ----- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-text-muted);
}

.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { font-size: 18px; font-weight: 600; color: var(--color-text); margin-bottom: 6px; }
.empty-state p { font-size: 14px; }

/* ----- Chart containers ----- */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.chart-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
}

.chart-card h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 16px;
}

/* ----- Responsive ----- */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .main { margin-left: 0; }
  .page-body { padding: 20px 16px; }
  .chart-grid { grid-template-columns: 1fr; }
}
