:root {
  color-scheme: light;
  --navy: #17324d;
  --navy-deep: #0f2538;
  --gold: #d49a45;
  --gold-soft: #f0dfc3;
  --paper: #f4f1ea;
  --surface: #ffffff;
  --ink: #18222c;
  --muted: #66727d;
  --line: #d9d6cf;
  --success: #237454;
  --danger: #a53d3d;
  --shadow: 0 14px 40px rgba(22, 42, 58, 0.1);
  --radius: 18px;
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, rgba(212, 154, 69, 0.13), transparent 28rem),
    var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; }
button, select, input[type="checkbox"] { cursor: pointer; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  color: #fff;
  background: linear-gradient(135deg, var(--navy-deep), var(--navy));
  box-shadow: 0 8px 28px rgba(15, 37, 56, 0.22);
}

.header-inner {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand-block { display: flex; align-items: center; gap: 14px; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.logout-form { margin: 0; }
.logout-button {
  min-height: 42px;
  border: 1px solid rgba(255,255,255,.46);
  border-radius: 11px;
  padding: 8px 12px;
  color: #fff;
  background: transparent;
  font-weight: 750;
}
.logout-button:hover { background: rgba(255,255,255,.1); }
.brand-mark {
  width: 48px;
  height: 48px;
  border: 2px solid rgba(255,255,255,.9);
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--navy-deep);
  background: var(--gold);
  font-family: Georgia, serif;
  font-size: 1.7rem;
  font-weight: 700;
}

.eyebrow, .section-kicker {
  margin: 0 0 2px;
  font-size: .76rem;
  font-weight: 750;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.eyebrow { color: rgba(255,255,255,.72); }
.section-kicker { color: #815c29; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Georgia, serif; font-size: clamp(1.45rem, 4vw, 2rem); font-weight: 600; }
h2 { margin-bottom: 0; font-family: Georgia, serif; font-size: clamp(1.6rem, 5vw, 2.35rem); line-height: 1.18; }
h3 { margin-bottom: 8px; font-size: 1.08rem; }

.app-shell { width: min(1080px, calc(100% - 32px)); margin: 0 auto; padding: 32px 0 110px; }
.summary-row, .detail-heading, .progress-copy, .dialog-head, .dialog-actions, .detail-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.stats-grid { display: grid; grid-template-columns: 1fr 1fr 2fr; gap: 14px; margin: 24px 0; }
.stat-card {
  min-height: 112px;
  padding: 18px;
  border: 1px solid rgba(23,50,77,.09);
  border-radius: var(--radius);
  background: rgba(255,255,255,.84);
  box-shadow: 0 8px 24px rgba(22,42,58,.06);
}
.stat-card strong { display: block; margin-top: 8px; color: var(--navy); font-size: 2rem; line-height: 1; }
.stat-label { color: var(--muted); font-weight: 700; }
.mini-progress, .progress-track { overflow: hidden; border-radius: 999px; background: #e7e3db; }
.mini-progress { height: 7px; margin-top: 15px; }
.mini-progress span, .progress-track span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), #b97927); transition: width .25s ease; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.search-field { flex: 1; }
.search-field input, .form-field input, .form-field select, .form-field textarea, .inline-form input {
  width: 100%;
  border: 1px solid #c8c6c1;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  padding: 13px 14px;
  min-height: 48px;
}
.search-field input:focus, .form-field input:focus, .form-field select:focus, .form-field textarea:focus, .inline-form input:focus {
  outline: 3px solid rgba(212,154,69,.25);
  border-color: #b97827;
}
.filter-row { display: flex; gap: 6px; padding: 4px; border-radius: 14px; background: rgba(23,50,77,.08); }
.filter-button { min-height: 42px; border: 0; border-radius: 10px; padding: 8px 13px; background: transparent; color: var(--navy); font-weight: 750; }
.filter-button.is-active { background: var(--surface); box-shadow: 0 4px 14px rgba(22,42,58,.09); }

.item-list { display: grid; gap: 14px; }
.item-card {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  padding: 20px;
  border: 1px solid rgba(23,50,77,.1);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(22,42,58,.055);
  text-align: left;
  color: inherit;
  transition: transform .15s ease, box-shadow .15s ease;
}
.item-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.item-title { margin: 8px 0 4px; font-size: 1.18rem; }
.item-meta { margin: 0; color: var(--muted); }
.item-progress { min-width: 118px; align-self: center; text-align: right; }
.item-progress strong { display: block; color: var(--navy); font-size: 1.18rem; }
.item-progress span { color: var(--muted); font-size: .86rem; }
.type-badge {
  display: inline-flex;
  align-items: center;
  min-height: 29px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: #6c4a1c;
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.is-complete .type-badge { background: #d9eee5; color: #1f6047; }

.empty-state {
  margin-top: 24px;
  padding: 44px 24px;
  border: 1px dashed #bdb8ae;
  border-radius: var(--radius);
  background: rgba(255,255,255,.58);
  text-align: center;
}
.empty-symbol { width: 58px; height: 58px; display: grid; place-items: center; margin: 0 auto 16px; border-radius: 50%; background: var(--gold-soft); color: var(--navy); font-size: 1.8rem; font-weight: 800; }
.empty-state p { max-width: 520px; margin: 0 auto 20px; color: var(--muted); }

.button {
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 800;
}
.button-primary { background: var(--gold); color: #17212b; }
.button-primary:hover { background: #e0a751; }
.button-secondary { background: #e8edf1; color: var(--navy); border-color: #cbd4db; }
.button-quiet { background: #fff; color: var(--navy); border-color: #ccd2d7; }
.button-danger { background: #fff; color: var(--danger); border-color: #e1bebe; }

.floating-button {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 18;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  color: #17212b;
  background: var(--gold);
  box-shadow: 0 14px 34px rgba(15,37,56,.28);
  font-size: 2rem;
  line-height: 1;
}

.detail-view { max-width: 850px; margin: 0 auto; }
.back-button { margin-bottom: 18px; border: 0; background: transparent; color: var(--navy); font-weight: 800; padding: 8px 0; }
.detail-card { padding: 26px; border: 1px solid rgba(23,50,77,.1); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); }
.detail-heading { align-items: flex-start; }
.detail-heading h2 { margin: 10px 0 6px; }
.detail-meta { margin-bottom: 0; color: var(--muted); }
.progress-block { margin: 24px 0; padding: 18px; border-radius: 15px; background: #f2eee6; }
.progress-copy { margin-bottom: 10px; }
.progress-copy span { color: var(--muted); font-weight: 800; }
.progress-track { height: 11px; background: #ded9cf; }
.notes-block { margin-bottom: 24px; padding: 16px; border-left: 4px solid var(--gold); background: #faf6ef; white-space: pre-wrap; }
.task-groups { display: grid; gap: 22px; }
.task-group h3 { margin-bottom: 10px; color: var(--navy); }
.task-list { display: grid; gap: 9px; }
.task-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: start;
  gap: 11px;
  min-height: 54px;
  padding: 13px 12px;
  border: 1px solid #ddd9d1;
  border-radius: 13px;
  background: #fff;
}
.task-row input { width: 24px; height: 24px; margin: 1px 0 0; accent-color: var(--success); }
.task-row label { font-size: 1rem; line-height: 1.45; cursor: pointer; }
.task-row.is-done { background: #f2f7f4; color: #557064; }
.task-row.is-done label { text-decoration: line-through; text-decoration-thickness: 1.5px; }
.task-delete { border: 0; background: transparent; color: var(--danger); min-width: 36px; min-height: 34px; font-weight: 800; }
.custom-task-form { margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--line); }
.custom-task-form > label { display: block; margin-bottom: 8px; font-weight: 800; }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.detail-actions { margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--line); }

.dialog-layer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 12px;
  background: rgba(10,24,36,.58);
  backdrop-filter: blur(3px);
}
.dialog-layer[hidden] { display: none; }
body.modal-open { overflow: hidden; }
.app-dialog {
  width: min(620px, calc(100% - 24px));
  max-height: calc(100vh - 24px);
  overflow: auto;
  border: 0;
  border-radius: 22px;
  padding: 24px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 28px 80px rgba(15,37,56,.34);
}
.compact-dialog { max-width: 500px; }
.dialog-head { align-items: flex-start; margin-bottom: 22px; }
.icon-button { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--navy); font-size: 1.6rem; line-height: 1; }
.form-field { display: grid; gap: 7px; margin-bottom: 15px; }
.form-field > span { font-weight: 800; color: #27333d; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-field textarea { resize: vertical; min-height: 104px; }
.form-help, .small-note { color: var(--muted); font-size: .88rem; }
.dialog-actions { margin-top: 22px; justify-content: flex-end; }
.backup-actions { display: grid; gap: 10px; margin: 20px 0; }
.file-button { display: grid; place-items: center; text-align: center; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 50; max-width: calc(100% - 32px); transform: translate(-50%, 120px); padding: 12px 16px; border-radius: 12px; color: #fff; background: var(--navy-deep); box-shadow: var(--shadow); opacity: 0; transition: .25s ease; }
.toast.is-visible { transform: translate(-50%, 0); opacity: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.auth-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.auth-shell { width: min(480px, 100%); }
.auth-card {
  padding: clamp(24px, 6vw, 42px);
  border: 1px solid rgba(23,50,77,.12);
  border-radius: 24px;
  background: rgba(255,255,255,.96);
  box-shadow: var(--shadow);
}
.auth-brand { margin-bottom: 22px; }
.auth-brand .brand-mark { color: var(--navy-deep); border-color: var(--navy); }
.auth-card h1 { margin-bottom: 12px; color: var(--navy); font-size: clamp(1.85rem, 8vw, 2.55rem); }
.auth-intro { margin-bottom: 24px; color: var(--muted); }
.auth-submit { width: 100%; margin-top: 4px; }
.error-message, .success-message { margin-bottom: 20px; padding: 12px 14px; border-radius: 12px; font-weight: 700; }
.error-message { border: 1px solid #e5bcbc; color: #7c2e2e; background: #fff0f0; }
.success-message { border: 1px solid #b7d9c7; color: #205e45; background: #edf8f2; }

@media (max-width: 720px) {
  .header-inner, .app-shell { width: min(100% - 24px, 1080px); }
  .header-inner { min-height: 76px; }
  .desktop-new { display: none; }
  .header-actions { gap: 0; }
  .logout-button { padding-inline: 10px; font-size: .88rem; }
  .app-shell { padding-top: 22px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-card-wide { grid-column: 1 / -1; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .filter-row { display: grid; grid-template-columns: repeat(3, 1fr); }
  .item-card { grid-template-columns: 1fr; gap: 12px; }
  .item-progress { text-align: left; }
  .detail-card { padding: 19px 14px; }
  .detail-heading { flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; gap: 0; }
  .inline-form { grid-template-columns: 1fr; }
  .detail-actions { align-items: stretch; flex-direction: column; }
  .detail-actions .button { width: 100%; }
  .app-dialog { padding: 20px 16px; }
}

@media (min-width: 721px) {
  .floating-button { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
