/* =========================================================
   Expense Tracker styles
   Week 3: selectors, box model, flexbox, grid, pseudo-classes,
           units, colours, z-index
   ========================================================= */

/* ---------- Variables and reset ---------- */
:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --success: #16a34a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

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

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

/* ---------- Layout ---------- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem;
}

.site-header {
  background: var(--primary);
  color: #fff;
  padding: 1rem 0;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.clock {
  font-variant-numeric: tabular-nums;
  opacity: 0.9;
}

.page {
  padding-top: 1.5rem;
  padding-bottom: 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.page.narrow {
  max-width: 560px;
}

/* ---------- Navigation ---------- */
.brand {
  color: #fff;
  text-decoration: none;
  font-size: 1.3rem;
  font-weight: 700;
}

.nav {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.nav a {
  color: #fff;
  text-decoration: none;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  font-size: 0.95rem;
  opacity: 0.85;
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.15);
  opacity: 1;
}

.nav a.active {
  background: rgba(255, 255, 255, 0.25);
  opacity: 1;
  font-weight: 600;
}

@media (max-width: 800px) {
  .header-row {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .clock {
    display: none;
  }
}

/* ---------- Welcome page ---------- */
.hero {
  padding: 2.5rem 0 1rem;
  max-width: 640px;
}

.hero h1 {
  font-size: 2.2rem;
  margin-bottom: 0.75rem;
}

.hero p {
  color: var(--muted);
  margin-bottom: 1.25rem;
}

.btn-inline {
  width: auto;
  text-decoration: none;
}

.page-list {
  list-style: none;
}

.page-list li {
  padding: 0.35rem 0;
}

.page-list a {
  color: var(--primary);
  font-weight: 600;
}

/* ---------- Stat cards ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stat-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
}

.stat-small {
  font-size: 1rem;
}

/* ---------- Simple lists ---------- */
.simple-list {
  list-style: none;
}

.simple-list li {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

.simple-list li span:last-child {
  font-weight: 600;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}

.hint code {
  background: #f3f4f6;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
}

.result {
  margin-top: 1rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.count {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 400;
}

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

.card h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

/* ---------- Forms ---------- */
.field {
  margin-bottom: 0.9rem;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

input,
select {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  background: #fff;
}

input:focus,
select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}

/* Invalid field, toggled from JavaScript */
.field.invalid input,
.field.invalid select {
  border-color: var(--danger);
}

.error {
  display: block;
  color: var(--danger);
  font-size: 0.78rem;
  min-height: 1em;
  margin-top: 0.2rem;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: 0.55rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}

.btn:hover {
  background: #f3f4f6;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  width: 100%;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

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

.btn-danger:hover {
  background: var(--danger-dark);
}

.btn-small {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  text-decoration: underline;
  font-size: inherit;
}

.convert-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.converted {
  color: var(--muted);
  font-size: 0.9rem;
}

.converted.loading::after {
  content: " ...";
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.toolbar h2 {
  margin-bottom: 0;
}

.toolbar-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.toolbar-controls input,
.toolbar-controls select {
  width: auto;
}

/* ---------- Table ---------- */
.expense-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.expense-table th,
.expense-table td {
  text-align: left;
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.expense-table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.expense-table.small td {
  padding: 0.4rem 0.5rem;
}

.expense-table .num {
  text-align: right;
}

.expense-table .actions {
  text-align: right;
  white-space: nowrap;
}

/* Pseudo-class: highlight row on hover */
.expense-table tbody tr:hover {
  background: #f9fafb;
}

/* Rows above a threshold get this class from JavaScript */
.expense-table tr.big-expense td.num {
  color: var(--danger);
  font-weight: 700;
}

/* Category badge */
.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #e5e7eb;
}

.badge-Food      { background: #fee2e2; color: #991b1b; }
.badge-Transport { background: #dbeafe; color: #1e40af; }
.badge-Books     { background: #ede9fe; color: #5b21b6; }
.badge-Rent      { background: #fef3c7; color: #92400e; }
.badge-Fun       { background: #dcfce7; color: #166534; }
.badge-Other     { background: #e5e7eb; color: #374151; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem 0;
}

.danger-zone {
  margin-top: 1rem;
  text-align: right;
}

/* ---------- Modal (z-index and overlay) ---------- */
.modal-overlay {
  display: none;            /* JavaScript adds the .open class to show it */
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.modal-actions .btn-primary {
  width: auto;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 0.6rem 1.2rem;
  border-radius: 6px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
