:root {
  color-scheme: light;
  --page: #f3f5fb;
  --surface: #ffffff;
  --ink: #10162b;
  --ink-2: #4c556f;
  --muted: #8a90a5;
  --hairline: #e3e6f0;
  --border: rgba(16, 22, 43, 0.08);
  --royal: #1e3fa8;
  --royal-bright: #2d55d4;
  --royal-deep: #16307f;
  --royal-soft: #dfe7fb;
  --on-royal: #ffffff;
  --gold: #e8b93c;
  --gold-deep: #b98d1c;
  --danger: #d03b3b;
  --shadow: 0 10px 30px -12px rgba(22, 48, 127, 0.25);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0c1020;
    --surface: #161b30;
    --ink: #f2f4fb;
    --ink-2: #b8bed3;
    --muted: #8a90a5;
    --hairline: #272e4a;
    --border: rgba(255, 255, 255, 0.09);
    --royal: #3b62d9;
    --royal-bright: #5d82f0;
    --royal-deep: #16307f;
    --royal-soft: #1d2b5c;
    --on-royal: #ffffff;
    --gold: #e8b93c;
    --gold-deep: #f0ca62;
    --shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  line-height: 1.45;
}

/* ---------- animated background blobs ---------- */
.bg-blobs { position: fixed; inset: 0; overflow: hidden; z-index: -1; pointer-events: none; }
.bg-blobs span {
  position: absolute;
  width: 46vmax; height: 46vmax;
  border-radius: 50%;
  filter: blur(70px);
  opacity: .16;
  animation: drift 26s ease-in-out infinite alternate;
}
.bg-blobs span:nth-child(1) { background: var(--royal-bright); top: -18vmax; left: -10vmax; }
.bg-blobs span:nth-child(2) { background: var(--gold); bottom: -20vmax; right: -12vmax; animation-delay: -8s; }
.bg-blobs span:nth-child(3) { background: var(--royal); bottom: -10vmax; left: 30vw; opacity: .10; animation-delay: -16s; }
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(6vmax, 4vmax) scale(1.15); }
}

/* ---------- entrance animations ---------- */
@keyframes riseIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
.rise { animation: riseIn .5s cubic-bezier(.2, .7, .3, 1) both; animation-delay: calc(var(--d, 0) * 90ms); }
@keyframes popIn {
  0% { opacity: 0; transform: scale(.92) translateY(10px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* ---------- auth ---------- */
#auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 34px 34px 24px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: popIn .55s cubic-bezier(.2, .7, .3, 1) both;
}
.auth-crest { display: inline-block; animation: crestFloat 5s ease-in-out infinite; }
@keyframes crestFloat {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-7px) rotate(-2deg); }
}
.auth-school {
  margin: 14px 0 2px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--royal-bright);
}
.auth-title { margin: 0; font-size: 28px; letter-spacing: -.01em; }
.auth-sub { margin: 6px 0 20px; color: var(--ink-2); font-size: 14px; }

.auth-tabs {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--page);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 18px;
}
.auth-tab {
  position: relative;
  z-index: 1;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  padding: 8px 0;
  color: var(--ink-2);
  cursor: pointer;
  transition: color .25s;
}
.auth-tab.active { color: var(--on-royal); }
.auth-tab-glider {
  position: absolute;
  top: 4px; bottom: 4px; left: 4px;
  width: calc(50% - 4px);
  border-radius: 8px;
  background: var(--royal);
  transition: transform .3s cubic-bezier(.3, .8, .3, 1);
}
.auth-tabs.signup .auth-tab-glider { transform: translateX(100%); }
#auth-form { text-align: left; }
.auth-note { font-size: 12px; color: var(--muted); margin: 16px 0 0; }
.disclaimer {
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
  margin: 14px 0 0;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 28px;
  padding-top: calc(18px + env(safe-area-inset-top, 0px));
  background: linear-gradient(120deg, var(--royal-deep), var(--royal) 55%, var(--royal-bright));
  color: #fff;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 44px; height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.16);
  animation: crestFloat 6s ease-in-out infinite;
}
.brand h1 { margin: 0; font-size: 19px; color: #fff; }
.subtitle { margin: 0; font-size: 12.5px; color: rgba(255, 255, 255, 0.75); }
.topbar-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.user-chip {
  font-size: 13px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.16);
  padding: 6px 12px;
  border-radius: 999px;
}

main { max-width: 1100px; margin: 0 auto; padding: 22px 28px 56px; }
.greeting { font-size: 15px; color: var(--ink-2); margin: 2px 0 14px; }
.greeting strong { color: var(--ink); }

/* ---------- KPIs ---------- */
.kpis {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: var(--shadow);
  transition: transform .25s, box-shadow .25s;
}
.kpi:hover { transform: translateY(-3px); }
.kpi-label { font-size: 13px; color: var(--ink-2); }
.kpi-value { font-size: 34px; font-weight: 650; }
.kpi-hero { background: linear-gradient(135deg, var(--royal-soft), var(--surface) 60%); }
.kpi-hero .kpi-value { font-size: 48px; color: var(--royal-bright); }

.goal { margin-top: 8px; }
.goal-bar {
  height: 10px;
  border-radius: 5px;
  background: var(--hairline);
  overflow: hidden;
}
.goal-fill {
  position: relative;
  height: 100%;
  width: 0;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--royal), var(--royal-bright));
  transition: width .8s cubic-bezier(.2, .7, .3, 1);
  overflow: hidden;
}
.goal-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,.45) 50%, transparent 70%);
  transform: translateX(-100%);
  animation: shimmer 2.6s ease-in-out infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
.goal-fill.done { background: linear-gradient(90deg, var(--gold-deep), var(--gold)); }
.goal-text { font-size: 12.5px; color: var(--ink-2); }

/* ---------- cards & layout ---------- */
.columns {
  display: grid;
  grid-template-columns: 370px 1fr;
  gap: 14px;
  align-items: start;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 12px; font-size: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* ---------- carpool switch ---------- */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; margin-bottom: 12px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 40px; height: 22px;
  border-radius: 999px;
  background: var(--hairline);
  position: relative;
  transition: background .25s;
  flex-shrink: 0;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.35);
  transition: transform .25s cubic-bezier(.3,.8,.3,1.2);
}
.switch input:checked + .switch-track { background: var(--gold); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--royal-bright); outline-offset: 2px; }
.switch-label { font-size: 13px; font-weight: 650; color: var(--ink-2); }
.switch input:checked ~ .switch-label { color: var(--gold-deep); }

/* ---------- export dropdown ---------- */
.export-wrap { position: relative; }
.export-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-width: 220px;
  padding: 6px;
  z-index: 40;
  animation: popIn .18s ease;
}
.export-menu a {
  display: block;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
  font-weight: 550;
}
.export-menu a:hover { background: var(--royal-soft); }

/* ---------- attachment chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--royal-soft);
  border-radius: 999px;
  padding: 2px 6px 2px 10px;
  font-size: 12px;
  max-width: 100%;
}
.chip a {
  color: var(--royal-bright);
  text-decoration: none;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}
.chip a:hover { text-decoration: underline; }
.chip-x {
  border: none; background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  padding: 2px 4px;
  border-radius: 50%;
}
.chip-x:hover { color: var(--danger); }

/* ---------- danger zone ---------- */
.danger-zone h3 { color: var(--danger); }
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover { filter: brightness(1.1); }

/* ---------- forms ---------- */
form label {
  display: block;
  font-size: 13px;
  font-weight: 550;
  color: var(--ink-2);
  margin-bottom: 12px;
}
.optional { color: var(--muted); font-size: 12px; font-weight: 400; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 11px;
  font: inherit;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--hairline);
  border-radius: 9px;
  transition: border-color .2s, box-shadow .2s, transform .15s;
}
textarea { resize: vertical; }
/* iPhones render date inputs with centered text and odd sizing — normalize */
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  min-height: 41px;
  text-align: left;
}
input[type="date"]::-webkit-date-and-time-value {
  text-align: left;
  margin: 0;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--royal-bright);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--royal-bright) 25%, transparent);
}

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: transform .15s, box-shadow .2s, filter .2s;
}
.btn:hover { transform: translateY(-1.5px); box-shadow: 0 6px 16px -8px rgba(22, 48, 127, .5); }
.btn:active { transform: translateY(0) scale(.97); }
.btn-primary { background: var(--royal); border-color: var(--royal); color: var(--on-royal); }
.btn-primary:hover { filter: brightness(1.1); }
.btn-big { width: 100%; padding: 11px; font-size: 15px; }
.btn-gold { background: var(--gold); border-color: var(--gold); color: #241a02; }
.btn-onroyal { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.25); color: #fff; }
.btn-ghost { border: none; background: none; font-size: 15px; }
.btn-ghost:hover { transform: none; box-shadow: none; }
.btn-danger-text {
  background: none; border: none;
  color: var(--danger);
  cursor: pointer;
  font: inherit; font-size: 13px;
  padding: 2px 6px;
  border-radius: 6px;
  transition: background .2s;
}
.btn-danger-text:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

.form-msg { font-size: 13px; min-height: 1.2em; margin: 8px 0 0; }
.form-msg.ok { color: var(--royal-bright); }
.form-msg.err { color: var(--danger); animation: shake .4s; }
@keyframes shake {
  25% { transform: translateX(-4px); } 50% { transform: translateX(4px); } 75% { transform: translateX(-2px); }
}

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  font-weight: 650;
  padding: 6px 8px;
  border-bottom: 1px solid var(--hairline);
}
td { padding: 9px 8px; border-bottom: 1px solid var(--hairline); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
tbody tr { animation: riseIn .35s ease both; transition: background .2s; }
tbody tr:hover { background: color-mix(in srgb, var(--royal-soft) 45%, transparent); }
.td-desc { color: var(--ink-2); font-size: 13px; }
.td-loc { color: var(--muted); font-size: 12px; }

.empty { text-align: center; color: var(--muted); font-size: 14px; padding: 26px 12px; }
.empty-art { font-size: 40px; display: inline-block; animation: crestFloat 4s ease-in-out infinite; }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  width: min(440px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
dialog[open] { animation: popIn .3s cubic-bezier(.2, .7, .3, 1); }
dialog::backdrop { background: rgba(8, 12, 30, .55); backdrop-filter: blur(3px); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.dialog-head h2 { margin: 0; font-size: 17px; }
.dialog-section { border-top: 1px solid var(--hairline); padding-top: 14px; margin-top: 14px; }
.dialog-section h3 { margin: 0 0 8px; font-size: 14px; }
.hint { font-size: 12.5px; color: var(--ink-2); margin: 6px 0 10px; font-weight: 400; }
.hint code { background: var(--page); padding: 1px 4px; border-radius: 4px; }
.row { display: flex; gap: 10px; }
.net-url {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 16px;
  font-weight: 700;
  color: var(--royal-bright);
  background: var(--page);
  border: 1px dashed var(--royal-bright);
  border-radius: 9px;
  padding: 10px 12px;
  text-align: center;
  margin: 8px 0 10px;
  user-select: all;
  -webkit-user-select: all;
  overflow-wrap: anywhere;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 80px);
  background: var(--royal);
  color: #fff;
  font-weight: 600;
  padding: 11px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: transform .4s cubic-bezier(.2, .8, .3, 1.2), opacity .3s;
  z-index: 50;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------- confetti ---------- */
#confetti-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 60; }
.confetti {
  position: absolute;
  width: 9px; height: 14px;
  top: -20px;
  border-radius: 2px;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  to { transform: translateY(105vh) rotate(720deg); opacity: .9; }
}

/* ---------- full-height desktop layout ---------- */
#app-view { min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; display: flex; flex-direction: column; width: 100%; }
.columns { flex: 1; align-items: stretch; }
.card-entries { display: flex; flex-direction: column; }
.card-entries .table-wrap { flex: 1; display: flex; flex-direction: column; }
.card-entries .empty {
  flex: 1;
  display: grid;
  place-content: center;
  gap: 6px;
}

@media (max-width: 960px) {
  .columns { grid-template-columns: 1fr; }
}
@media (min-width: 961px) {
  main { max-width: 1240px; }
}
@media (max-width: 800px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi-hero { grid-column: 1 / -1; }
  .field-grid { grid-template-columns: 1fr; }
  .topbar { padding: 14px 16px; }
  .brand h1 { font-size: 17px; }
  main { padding: 18px 16px 44px; }
  .card { padding: 16px; }
  .kpi-hero .kpi-value { font-size: 42px; }
  .kpi-value { font-size: 28px; }
}
@media (max-width: 640px) {
  /* Entries table becomes stacked cards on phones */
  #entries-table, #entries-table tbody { display: block; }
  #entries-table thead { display: none; }
  #entries-table tr {
    display: block;
    position: relative;
    border: 1px solid var(--hairline);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 10px;
    background: var(--page);
  }
  #entries-table td {
    display: block;
    border: none;
    padding: 3px 0;
    text-align: left;
  }
  #entries-table td.num {
    position: absolute;
    top: 10px;
    right: 14px;
    font-size: 20px;
    color: var(--royal-bright);
  }
  #entries-table td.num::after { content: " hrs"; font-size: 12px; color: var(--muted); font-weight: 500; }
  #entries-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    font-weight: 650;
    margin-top: 4px;
  }
  #entries-table td:first-child { padding-right: 84px; font-weight: 600; }
  #entries-table td:last-child { position: absolute; bottom: 8px; right: 8px; padding: 0; }
  .topbar-actions { width: 100%; }
  .topbar-actions .btn { flex: 1; text-align: center; padding: 9px 8px; font-size: 13.5px; }
  .user-chip { display: none; }
  .auth-card { padding: 26px 20px 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
