/* =========================================================================
   Campus Life Planner — styles/main.css
   Mobile-first. Breakpoints at ~360 (base), 768 (tablet), 1024 (desktop).
   ========================================================================= */

/* ---- Design tokens ---- */
:root {
  --paper:      #eef1f4;
  --surface:    #ffffff;
  --surface-2:  #f6f8fa;
  --ink:        #18262f;
  --ink-soft:   #41545f;
  --muted:      #6b7b85;
  --line:       #dde3e8;
  --accent:     #3b5bdb;   /* confident, calm blue */
  --accent-ink: #2740a8;
  --accent-soft:#e7ecfd;
  --under:      #2f855a;   /* within cap */
  --over:       #c2410c;   /* past cap */
  --danger:     #c0392b;
  --mark:       #fde68a;   /* search highlight */

  --radius:   14px;
  --radius-sm:9px;
  --shadow:   0 1px 2px rgba(24,38,47,.06), 0 8px 24px rgba(24,38,47,.06);
  --shadow-lift: 0 2px 6px rgba(24,38,47,.10), 0 14px 36px rgba(24,38,47,.12);

  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-body:    "Inter", system-ui, -apple-system, sans-serif;
  --font-mono:    "Spline Sans Mono", ui-monospace, "SF Mono", monospace;

  --maxw: 1080px;
  --step: clamp(.9rem, .85rem + .3vw, 1rem);
}

[data-theme="dark"] {
  --paper:      #0f1620;
  --surface:    #182230;
  --surface-2:  #1f2b3a;
  --ink:        #eaf0f5;
  --ink-soft:   #b9c6d1;
  --muted:      #8fa1ae;
  --line:       #2a394a;
  --accent:     #7d97ff;
  --accent-ink: #aebeff;
  --accent-soft:#26334d;
  --under:      #4ade80;
  --over:       #fb923c;
  --danger:     #f87171;
  --mark:       #b59100;
  --shadow:     0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  --shadow-lift:0 2px 6px rgba(0,0,0,.45), 0 14px 36px rgba(0,0,0,.5);
}

/* ---- Reset-ish ---- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 76px; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--step);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--font-display); line-height: 1.12; letter-spacing: -.01em; margin: 0; }
a { color: var(--accent-ink); }
img { max-width: 100%; }

.wrap { width: 100%; max-width: var(--maxw); margin-inline: auto; padding-inline: 1rem; }

/* ---- Accessibility helpers ---- */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 1rem; top: -3rem; z-index: 50;
  background: var(--accent); color: #fff; padding: .6rem 1rem;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm); font-weight: 600;
  transition: top .15s ease;
}
.skip-link:focus { top: 0; }

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---- Header / nav ---- */
.app-header {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; gap: 1rem; min-height: 60px; }
.brand { display: flex; align-items: center; gap: .5rem; font-family: var(--font-display); font-weight: 800; }
.brand-mark { color: var(--accent); font-size: 1.25rem; }
.brand-name { font-size: 1rem; }
.primary-nav { margin-left: auto; }
.primary-nav ul { display: flex; gap: .25rem; list-style: none; margin: 0; padding: 0; flex-wrap: wrap; }
.primary-nav a {
  display: inline-block; padding: .4rem .6rem; border-radius: var(--radius-sm);
  color: var(--ink-soft); text-decoration: none; font-weight: 500; font-size: .9rem;
  transition: background .15s ease, color .15s ease;
}
.primary-nav a:hover { background: var(--accent-soft); color: var(--accent-ink); }
.theme-toggle { padding: .4rem .55rem; }

/* ---- Buttons ---- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: .55rem .9rem; transition: transform .08s ease, background .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

/* ---- Sections ---- */
main { padding-block: 1.75rem 3rem; }
section { margin-bottom: 2.5rem; scroll-margin-top: 76px; }
.section-head { margin-bottom: 1rem; }
.eyebrow {
  text-transform: uppercase; letter-spacing: .14em; font-size: .7rem;
  font-weight: 600; color: var(--accent-ink); margin: 0 0 .25rem;
}
#dashboard-h { font-size: clamp(1.7rem, 1.3rem + 2vw, 2.5rem); font-weight: 800; }
section h2 { font-size: clamp(1.3rem, 1.1rem + 1vw, 1.7rem); font-weight: 700; }

/* ---- Stat grid (mobile-first: 1 col) ---- */
.stat-grid { display: grid; grid-template-columns: 1fr; gap: .75rem; }
.stat-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; box-shadow: var(--shadow);
}
.stat-label { margin: 0; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.stat-value { margin: .15rem 0 0; font-family: var(--font-display); font-weight: 800; font-size: 2rem; line-height: 1; }
.stat-value--text { font-size: 1.4rem; }
.stat-unit { font-size: .9rem; color: var(--muted); margin-left: .25rem; font-family: var(--font-mono); }
.stat-sub { margin: .35rem 0 0; color: var(--muted); font-size: .82rem; }

.cap-meter {
  margin-top: .6rem; height: 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); overflow: hidden;
}
.cap-fill {
  height: 100%; width: 0%; background: var(--under);
  transition: width .5s cubic-bezier(.22,.61,.36,1), background .3s ease;
}
.cap-fill.over { background: var(--over); }

/* ---- Week ribbon (signature element) ---- */
.week-ribbon-card {
  margin-top: .75rem; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; }
.card-head h2 { font-size: 1.05rem; }
.card-sub { margin: 0; color: var(--muted); font-size: .8rem; }
.week-ribbon {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: .5rem; align-items: end;
  height: 120px;
}
.ribbon-day { display: flex; flex-direction: column; align-items: center; gap: .4rem; height: 100%; justify-content: flex-end; }
.ribbon-bar {
  width: 100%; background: linear-gradient(var(--accent), var(--accent-ink));
  border-radius: 6px 6px 3px 3px; min-height: 3px;
  transform-origin: bottom; animation: grow .5s cubic-bezier(.22,.61,.36,1) both;
}
.ribbon-bar.empty { background: var(--line); }
.ribbon-label { font-size: .68rem; color: var(--muted); font-family: var(--font-mono); }
@keyframes grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }

/* ---- Toolbar / search ---- */
.toolbar { display: flex; flex-direction: column; gap: 1rem; margin-bottom: 1rem; }
.search-field label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: .3rem; }
.toolbar-controls { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; }

input[type="text"], input[type="search"], input[type="date"], select {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .55rem .7rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
input[aria-invalid="true"] { border-color: var(--danger); }
#search-input { font-family: var(--font-mono); font-size: .9rem; }

.checkbox, .radio { display: inline-flex; align-items: center; gap: .45rem; font-size: .9rem; cursor: pointer; }
.select-field { display: inline-flex; flex-direction: column; gap: .25rem; font-size: .85rem; font-weight: 600; }
.select-field select { min-width: 150px; }

.field-hint { margin: .3rem 0 0; color: var(--muted); font-size: .8rem; }
.field-error { margin: .3rem 0 0; color: var(--danger); font-size: .82rem; min-height: 1em; font-weight: 500; }

/* ---- Records table ---- */
.table-scroll { overflow-x: auto; border-radius: var(--radius); }
.records-table { width: 100%; border-collapse: collapse; background: var(--surface); }
.records-table thead { display: none; } /* hidden on mobile; cards take over */
.records-table th, .records-table td { text-align: left; padding: .7rem .8rem; }

/* Mobile: each row is a card */
.records-table tbody tr {
  display: grid; grid-template-columns: 1fr auto; gap: .25rem .75rem;
  padding: .9rem 1rem; margin-bottom: .65rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  transition: box-shadow .15s ease, transform .15s ease;
}
.records-table tbody tr:hover { box-shadow: var(--shadow-lift); }
.records-table td { padding: 0; border: 0; }
.records-table td[data-label]::before {
  content: attr(data-label); display: block;
  font-size: .68rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 600;
}
.cell-title { grid-column: 1 / -1; font-weight: 600; font-size: 1.02rem; }
.cell-title mark, .cell-tag mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 .1em; }
.cell-duration { font-family: var(--font-mono); }
.cell-tag .tag-chip {
  display: inline-block; padding: .15rem .55rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-ink); font-size: .78rem; font-weight: 600;
}
.cell-actions { grid-column: 1 / -1; display: flex; gap: .5rem; margin-top: .35rem; }
.icon-btn {
  font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-soft);
  border-radius: var(--radius-sm); padding: .35rem .7rem;
  transition: border-color .15s ease, color .15s ease;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent-ink); }
.icon-btn.delete:hover { border-color: var(--danger); color: var(--danger); }

.empty-state {
  text-align: center; color: var(--muted); background: var(--surface);
  border: 1px dashed var(--line); border-radius: var(--radius); padding: 2rem 1rem;
}

/* ---- Form ---- */
.record-form {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow);
}
.form-row { margin-bottom: 1rem; }
.form-row label, .panel label, .radio-set legend { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .35rem; }
.form-row.inline { display: flex; flex-direction: column; gap: .35rem; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 1rem; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-top: .5rem; }
.edit-indicator { color: var(--accent-ink); font-size: .85rem; font-weight: 600; }

/* ---- Settings ---- */
.settings-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); }
.panel h3 { font-size: 1.05rem; margin-bottom: .25rem; }
.panel-sub { margin: 0 0 .8rem; color: var(--muted); font-size: .85rem; }
.radio-set { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .5rem; }
.button-cluster { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ---- About ---- */
.about-body { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.about-body p { margin: 0 0 .9rem; max-width: none; color: var(--ink-soft); }
.contact { display: flex; flex-wrap: wrap; gap: 1.5rem; margin: .5rem 0 0; }
.contact dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.contact dd { margin: .1rem 0 0; }

/* ---- Footer ---- */
.app-footer { border-top: 1px solid var(--line); padding-block: 1.25rem; color: var(--muted); font-size: .82rem; }

/* ---- Dialog ---- */
.confirm-dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; max-width: 380px; box-shadow: var(--shadow-lift); color: var(--ink); background: var(--surface); }
.confirm-dialog::backdrop { background: rgba(12,18,26,.45); backdrop-filter: blur(2px); }
.confirm-dialog h2 { font-size: 1.2rem; margin-bottom: .4rem; }
.confirm-dialog p { margin: 0 0 1.1rem; color: var(--ink-soft); }

/* =========================================================================
   Breakpoint: tablet (≥768px)
   ========================================================================= */
@media (min-width: 768px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 1rem; }
  .form-grid { grid-template-columns: repeat(3, 1fr); }
  .settings-grid { grid-template-columns: repeat(2, 1fr); }
  .toolbar { flex-direction: row; align-items: flex-end; justify-content: space-between; }
  .search-field { flex: 1; max-width: 460px; }
  .week-ribbon { height: 150px; }
}

/* =========================================================================
   Breakpoint: desktop (≥1024px) — table reverts to a real table
   ========================================================================= */
@media (min-width: 1024px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }

  .records-table { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
  .records-table thead { display: table-header-group; background: var(--surface-2); }
  .records-table th { font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border-bottom: 1px solid var(--line); }
  .records-table tbody tr {
    display: table-row; box-shadow: none; border: 0; border-bottom: 1px solid var(--line);
    border-radius: 0; padding: 0; margin: 0; background: var(--surface);
  }
  .records-table tbody tr:last-child { border-bottom: 0; }
  .records-table tbody tr:hover { box-shadow: none; background: var(--surface-2); transform: none; }
  .records-table td { display: table-cell; padding: .7rem .8rem; vertical-align: middle; }
  .records-table td[data-label]::before { content: none; }
  .cell-title { font-size: inherit; }
  .cell-actions { grid-column: auto; margin: 0; justify-content: flex-end; }
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
