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

/* Variables */
:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #dee2e6;
  --text: #212529;
  --muted: #6c757d;
  --primary: #0d6efd;
  --primary-dark: #0b5ed7;
  --success: #198754;
  --danger: #dc3545;
  --warning: #ffc107;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

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

/* Nav */
nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  box-shadow: var(--shadow);
}

.nav-brand a {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.nav-links {
  list-style: none;
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.nav-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.15s;
}

.nav-links a:hover { color: var(--primary); }

/* Hamburger toggle (mobile only) */
.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }
.nav-toggle-label { display: none; }

@media (max-width: 640px) {
  nav { flex-wrap: wrap; }
  .nav-toggle-label {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    margin-left: auto;
    cursor: pointer;
    padding: 0.5rem;
  }
  .nav-toggle-label span {
    width: 24px;
    height: 2px;
    background: var(--text);
    border-radius: 1px;
    transition: transform 0.2s, opacity 0.2s;
  }
  .nav-links {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem 0 0;
  }
  .nav-toggle:checked ~ .nav-links { display: flex; }
  .nav-toggle:checked ~ .nav-toggle-label span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .nav-toggle:checked ~ .nav-toggle-label span:nth-child(2) { opacity: 0; }
  .nav-toggle:checked ~ .nav-toggle-label span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
}

/* Main */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* Flash */
.flash {
  background: #d1ecf1;
  border: 1px solid #bee5eb;
  color: #0c5460;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.flash.error {
  background: #f8d7da;
  border-color: #f5c6cb;
  color: #721c24;
}

/* Page headings */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

h1 { font-size: 1.6rem; font-weight: 600; }
h2 { font-size: 1.25rem; font-weight: 600; margin-bottom: 1rem; }
h3 { font-size: 1.05rem; font-weight: 600; margin-bottom: 0.5rem; }

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

.card + .card { margin-top: 1rem; }

/* Grid */
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* Stat cards */
.stat { text-align: center; }
.stat-label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 1.8rem; font-weight: 700; margin-top: 0.25rem; }
.stat-value.positive { color: var(--success); }
.stat-value.negative { color: var(--danger); }
.stat-value.neutral { color: var(--text); }

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 2px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

.table-scroll { overflow-x: auto; }

/* Mobile: collapse tables into stacked cards (opt-in via .table-stack) */
@media (max-width: 640px) {
  table.table-stack thead { display: none; }
  table.table-stack,
  table.table-stack tbody,
  table.table-stack tr,
  table.table-stack td { display: block; width: 100%; }
  table.table-stack tr {
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
  }
  table.table-stack tr:hover td { background: transparent; }
  table.table-stack td {
    border-bottom: 1px dashed var(--border);
    padding: 0.4rem 0;
    text-align: left;
  }
  table.table-stack td:last-child { border-bottom: none; }
  table.table-stack td[data-label]::before {
    content: attr(data-label);
    display: inline-block;
    min-width: 7rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    margin-right: 0.5rem;
  }
  table.table-stack td.td-actions::before { content: none; }
  table.table-stack td.td-actions { padding-top: 0.5rem; }
  table.table-stack td.text-right { text-align: left; }
}

/* Forms */
.form-group { margin-bottom: 1rem; }

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
  color: var(--text);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13,110,253,.15);
}

.form-error {
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #c6cad0; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.85; }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success { background: #d1e7dd; color: #0a3622; }
.badge-warning { background: #fff3cd; color: #664d03; }
.badge-danger  { background: #f8d7da; color: #58151c; }
.badge-neutral { background: #e2e3e5; color: #383d41; }

/* Period nav */
.period-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.period-nav h2 { margin: 0; }

/* Auth forms */
.auth-form {
  max-width: 400px;
  margin: 3rem auto;
}

/* Dashboard summary row */
.summary-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.summary-row .card { flex: 1; min-width: 160px; }

/* Utility */
.text-muted { color: var(--muted); }
.text-right { text-align: right; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.gap-1 { gap: 0.5rem; }
.flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--muted);
}

/* Inbox badge on nav */
.badge-count {
  background: var(--danger);
  color: white;
  border-radius: 999px;
  padding: 0 0.4rem;
  font-size: 0.7rem;
  font-weight: 700;
  vertical-align: top;
  margin-left: 2px;
}
