:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  color: #102d3d;
  background: #e8f3f4;
  --ink: #102d3d;
  --muted: #607984;
  --line: rgba(39, 103, 119, 0.18);
  --surface: rgba(250, 254, 253, 0.9);
  --surface-solid: #f8fcfb;
  --surface-soft: rgba(218, 239, 239, 0.7);
  --deep: #071d31;
  --navy: #0b2a43;
  --ocean: #126178;
  --teal: #1a8290;
  --foam: #dff5f2;
  --star: #f3c969;
  --star-soft: #fff1bd;
  --blue: #176a8a;
  --rust: #ae513d;
  --radius: 14px;
  --shadow: 0 18px 48px rgba(6, 36, 54, 0.1);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 8% 12%, rgba(255, 255, 255, 0.9) 0 1px, transparent 2px),
    radial-gradient(circle at 27% 7%, rgba(243, 201, 105, 0.45) 0 1px, transparent 2px),
    radial-gradient(circle at 70% 15%, rgba(255, 255, 255, 0.8) 0 1px, transparent 2px),
    radial-gradient(circle at 92% 5%, rgba(243, 201, 105, 0.4) 0 1px, transparent 2px),
    linear-gradient(180deg, #d8ecf0 0%, #edf7f5 42%, #d7eceb 100%);
  background-size: 180px 180px, 240px 240px, 210px 210px, 270px 270px, auto;
}
body::before {
  position: fixed;
  z-index: -1;
  inset: 58px 0 auto;
  height: 230px;
  content: "";
  pointer-events: none;
  opacity: 0.7;
  background:
    radial-gradient(110% 65% at 25% 0%, transparent 68%, rgba(22, 111, 132, 0.13) 69%, transparent 71%),
    radial-gradient(100% 55% at 75% 0%, transparent 70%, rgba(255, 255, 255, 0.6) 71%, transparent 73%);
}
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
svg { width: 18px; height: 18px; stroke-width: 1.8; }
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  color: #f5fbfa;
  background:
    radial-gradient(circle at 14% 24%, rgba(255,255,255,.8) 0 1px, transparent 1.5px),
    radial-gradient(circle at 31% 70%, rgba(243,201,105,.7) 0 1px, transparent 1.5px),
    radial-gradient(circle at 76% 30%, rgba(255,255,255,.7) 0 1px, transparent 1.5px),
    linear-gradient(105deg, #061a2e, #0b304a 62%, #0d4558);
  background-size: 130px 64px, 190px 64px, 220px 64px, auto;
  border-bottom: 1px solid rgba(164, 223, 224, 0.2);
  box-shadow: 0 5px 24px rgba(2, 20, 35, 0.2);
}
.brand { display: flex; align-items: center; gap: 11px; font-size: 17px; font-weight: 760; letter-spacing: .04em; }
.brand img { width: 36px; height: 36px; filter: drop-shadow(0 3px 9px rgba(0,0,0,.24)); }
.top-actions { display: flex; align-items: center; gap: 12px; }
.top-actions form { margin: 0; }
.user-name { color: #bcd8df; font-size: 12px; letter-spacing: .05em; text-transform: uppercase; }

.app-layout {
  min-height: calc(100vh - 64px);
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
}
.sidebar {
  position: relative;
  overflow: hidden;
  padding: 24px 15px;
  color: #d7eaec;
  background: linear-gradient(180deg, rgba(7, 32, 52, .97), rgba(10, 60, 74, .94));
  border-right: 1px solid rgba(155, 218, 220, .28);
}
.sidebar::after {
  position: absolute;
  right: -55px;
  bottom: -28px;
  width: 220px;
  height: 140px;
  content: "";
  opacity: .45;
  border: 1px solid rgba(197, 238, 235, .35);
  border-radius: 50%;
  box-shadow: 0 -18px 0 -17px rgba(197,238,235,.35), 0 -38px 0 -37px rgba(197,238,235,.25);
  transform: rotate(-9deg);
}
.section-heading {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.section-heading h2 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: .01em; }
.sidebar .section-heading h2 { color: #f2d584; }
.space-nav { position: relative; z-index: 1; display: grid; gap: 5px; margin-top: 9px; }
.space-nav a {
  min-width: 0;
  height: 42px;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: #c9e0e3;
  transition: 150ms ease;
}
.space-nav a:hover, .space-nav a.active {
  color: #fff;
  background: rgba(141, 213, 213, 0.14);
  border-color: rgba(167, 224, 222, 0.2);
  transform: translateX(2px);
}
.space-nav a.active svg { color: var(--star); }
.space-nav span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.space-nav small { color: #82aeb6; font-size: 10px; }

.workspace { min-width: 0; padding: 36px clamp(20px, 4vw, 62px) 78px; }
.workspace-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 28px;
}
.workspace-heading h1 {
  margin: 5px 0 0;
  color: #0b3047;
  font-size: clamp(30px, 4vw, 42px);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -.025em;
}
.workspace-heading h1::after {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 0 16px 10px;
  content: "";
  border-radius: 50%;
  background: var(--star);
  box-shadow: 0 0 0 4px rgba(243, 201, 105, .16), 0 0 18px rgba(243, 201, 105, .7);
}
.eyebrow { margin: 0; color: var(--ocean); font-size: 11px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
.revision { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--blue); font-size: 13px; font-weight: 650; }

.icon-button, .check-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: 150ms ease;
}
.icon-button:hover, .check-button:hover { background: rgba(14, 101, 119, 0.1); border-color: rgba(14,101,119,.15); }
.topbar .icon-button:hover { background: rgba(255, 255, 255, 0.12); border-color: rgba(255,255,255,.12); }
.primary-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 17px;
  border: 1px solid #0d6577;
  border-radius: 22px;
  background: linear-gradient(135deg, #17778a, #0d586f);
  color: #fff;
  font-weight: 750;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(8, 77, 96, .2);
  transition: 160ms ease;
}
.primary-button:hover { transform: translateY(-1px); background: linear-gradient(135deg, #1d8998, #0b4c66); box-shadow: 0 10px 24px rgba(8,77,96,.27); }
.primary-button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.filter-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid rgba(52, 118, 132, .16);
  border-radius: var(--radius);
  background: rgba(248, 253, 252, .65);
  box-shadow: 0 10px 30px rgba(9, 51, 68, .06);
  backdrop-filter: blur(14px);
}
label { min-width: 0; display: grid; gap: 6px; }
label > span { color: #4e6e79; font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
input, select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid #b8d2d4;
  border-radius: 9px;
  background: rgba(252, 255, 254, .9);
  color: var(--ink);
  outline: none;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #2b8993; box-shadow: 0 0 0 3px rgba(31, 133, 145, 0.14); }

.items-panel {
  overflow: hidden;
  border: 1px solid rgba(42, 106, 122, .17);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.list-header, .item-row {
  display: grid;
  grid-template-columns: minmax(230px, 2fr) minmax(150px, 1fr) 110px 74px;
  gap: 16px;
  align-items: center;
}
.list-header {
  min-height: 42px;
  padding: 0 14px 0 56px;
  color: #64808a;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  background: rgba(209, 235, 234, .45);
  border-bottom: 1px solid var(--line);
}
.item-row {
  position: relative;
  min-height: 72px;
  padding: 10px 14px 10px 56px;
  background: rgba(255,255,255,.48);
  border-bottom: 1px solid rgba(47, 109, 121, .12);
  transition: background 150ms ease;
}
.item-row:last-child { border-bottom: 0; }
.item-row:hover { background: rgba(228, 245, 243, .65); }
.item-check { position: absolute; left: 11px; top: 18px; }
.check-button { color: #66828a; }
.check-button.is-done { color: #0e7480; background: #d9f0ec; border-color: #b9dfda; }
.item-main, .item-source { min-width: 0; display: grid; gap: 5px; }
.item-main strong, .item-source span { overflow-wrap: anywhere; }
.item-source small { color: var(--muted); }
.item-quantity { color: #365966; }
.tag-line, .tag-cloud { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tag, .type-label, .status-label {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  width: fit-content;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 750;
  line-height: 1.2;
  letter-spacing: .04em;
}
.tag { background: #dcedef; color: #145b72; border: 1px solid #c8e0e3; }
.type-label { background: #f7edcc; color: #795e18; }
.status-label { justify-content: center; text-transform: capitalize; }
.status-open { background: #eaf2f1; color: #4e6970; }
.status-done { background: #d9efea; color: #0d665f; }
.empty-state {
  min-height: 190px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 9px;
  color: var(--muted);
  background: rgba(250,254,253,.7);
}
.empty-state svg { width: 30px; height: 30px; color: #5d97a3; }
.empty-copy { color: var(--muted); font-size: 13px; }

.content-section {
  margin-bottom: 18px;
  padding: 20px 22px 23px;
  border: 1px solid rgba(42, 106, 122, .15);
  border-radius: var(--radius);
  background: rgba(249, 254, 253, .72);
  box-shadow: 0 12px 34px rgba(8, 50, 66, .06);
  backdrop-filter: blur(12px);
}
.content-section + .content-section { margin-top: 0; }
.compact-list, .source-lists, .notes-list { display: grid; margin-top: 9px; }
.compact-row, .source-list {
  min-height: 50px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border-bottom: 1px solid rgba(43, 110, 122, .12);
}
.compact-row:last-child, .source-list:last-child { border-bottom: 0; }
.compact-row > span { color: var(--muted); font-size: 11px; }
.source-list { justify-content: space-between; border-radius: 8px; }
.source-list > div { min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.source-list h3 { margin: 0; color: #123b50; font-family: inherit; font-size: 14px; overflow-wrap: anywhere; }
.source-list > span { color: var(--muted); font-size: 11px; }
.source-list:hover, .compact-row:hover { background: rgba(212, 239, 238, .5); }

.inline-item-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 120px 120px auto;
  align-items: end;
  gap: 12px;
}
.list-detail { padding: 0; overflow: hidden; }
.list-detail-item {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 36px;
  align-items: center;
  gap: 10px;
  min-height: 62px;
  padding: 9px 15px;
  border-bottom: 1px solid var(--line);
}
.list-detail-item:last-child { border-bottom: 0; }
.list-detail-item > div { display: flex; justify-content: space-between; gap: 16px; }
.list-detail-item > div span { color: var(--muted); }
.list-detail-item.is-done strong { color: var(--muted); text-decoration: line-through; }
.danger-button { color: #a2463b; }
.danger-button:hover { color: #7c2d26; background: #fae6e1; border-color: #efc7bf; }
.note-entry { padding: 14px 7px; border-bottom: 1px solid var(--line); }
.note-entry:last-child { border-bottom: 0; }
.note-entry p { margin: 8px 0 0; white-space: pre-wrap; line-height: 1.6; overflow-wrap: anywhere; }
.note-meta { display: flex; flex-wrap: wrap; gap: 5px; }

dialog {
  width: min(520px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  padding: 0;
  border: 1px solid rgba(144, 202, 205, .55);
  border-radius: 16px;
  background: #f6fbfa;
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(1, 22, 37, .38);
}
dialog::backdrop { background: rgba(3, 22, 38, 0.68); backdrop-filter: blur(3px); }
.dialog-form { display: grid; gap: 15px; padding: 22px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; }
.dialog-heading h2 { margin: 0; color: #103b50; font-size: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 15% 18%, #fff 0 1px, transparent 1.5px),
    radial-gradient(circle at 78% 13%, #f3c969 0 1.5px, transparent 2px),
    radial-gradient(circle at 62% 35%, #fff 0 1px, transparent 1.5px),
    linear-gradient(165deg, #06192b 0%, #0a3c55 55%, #147384 100%);
  background-size: 150px 150px, 230px 230px, 180px 180px, auto;
}
.login-panel {
  width: min(390px, 100%);
  padding: 30px;
  border: 1px solid rgba(184, 229, 226, .4);
  border-radius: 18px;
  background: rgba(242, 251, 249, .92);
  box-shadow: 0 24px 80px rgba(0, 15, 30, .38);
  backdrop-filter: blur(16px);
}
.login-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 25px; }
.login-brand img { width: 48px; height: 48px; filter: drop-shadow(0 5px 10px rgba(3,39,55,.22)); }
.login-brand h1 { margin: 0; color: #0b3047; font-size: 30px; font-weight: 600; }
.stack-form { display: grid; gap: 16px; }
.form-error { margin-bottom: 16px; padding: 11px; border-left: 3px solid var(--rust); border-radius: 6px; background: #fae7e1; color: #7c3420; font-size: 13px; }
.flash { padding: 10px 24px; border-bottom: 1px solid; font-size: 13px; }
.flash-success { background: #dff2ec; color: #145c54; border-color: #b5dbd2; }
.flash-error { background: #f8e7e2; color: #813a24; border-color: #ddb9ab; }
.mobile-nav { display: none; }

@media (max-width: 820px) {
  .topbar { height: 60px; padding: 0 14px; }
  .user-name { display: none; }
  .app-layout { display: block; }
  .sidebar { display: none; }
  .workspace { padding: 24px 14px 90px; }
  .workspace-heading { align-items: center; }
  .workspace-heading h1 { font-size: 30px; }
  .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .list-header { display: none; }
  .item-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 12px;
    min-height: 84px;
    padding: 12px 10px 12px 50px;
  }
  .inline-item-form { grid-template-columns: 1fr 1fr; }
  .inline-item-form label:first-of-type { grid-column: 1 / -1; }
  .inline-item-form .primary-button { width: 100%; }
  .item-source { grid-column: 1; }
  .item-quantity { grid-column: 2; grid-row: 1; text-align: right; }
  .status-label { grid-column: 2; grid-row: 2; justify-self: end; }
  .item-check { left: 6px; top: 21px; }
  .mobile-nav {
    position: fixed;
    z-index: 30;
    bottom: 0;
    left: 0;
    right: 0;
    height: 66px;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    color: #d9ecee;
    background: rgba(5, 30, 49, .96);
    border-top: 1px solid rgba(146, 213, 216, .28);
    backdrop-filter: blur(14px);
  }
  .mobile-nav a { display: grid; place-content: center; justify-items: center; gap: 3px; color: #c5dfe2; font-size: 11px; }
}

@media (max-width: 520px) {
  .primary-button span { display: none; }
  .primary-button { width: 42px; padding: 0; }
  .dialog-form .primary-button, .inline-item-form .primary-button { width: 100%; }
  .dialog-form .primary-button span, .inline-item-form .primary-button span { display: inline; }
  .filter-bar { grid-template-columns: 1fr; gap: 9px; }
  .form-grid { grid-template-columns: 1fr; }
  .workspace-heading { margin-bottom: 20px; }
  .content-section { padding: 17px 15px 20px; }
  .list-detail-item > div { display: grid; gap: 3px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    color: #d9ecee;
    background: #061522;
    --ink: #d9ecee;
    --muted: #87a9b2;
    --line: rgba(143, 203, 205, .18);
    --surface: rgba(9, 37, 53, .88);
    --surface-solid: #0a2638;
    --surface-soft: rgba(16, 63, 76, .72);
    --ocean: #55b7c0;
    --teal: #67c6c8;
    --foam: #c7eeea;
    --star: #f1cf76;
    --star-soft: #f8e6a8;
    --blue: #71c4d5;
    --rust: #e6816d;
    --shadow: 0 20px 52px rgba(0, 8, 18, .34);
  }
  body {
    background:
      radial-gradient(circle at 8% 12%, rgba(222, 244, 243, .58) 0 1px, transparent 2px),
      radial-gradient(circle at 27% 7%, rgba(241, 207, 118, .52) 0 1px, transparent 2px),
      radial-gradient(circle at 70% 15%, rgba(220, 243, 242, .5) 0 1px, transparent 2px),
      radial-gradient(circle at 92% 5%, rgba(241, 207, 118, .42) 0 1px, transparent 2px),
      linear-gradient(180deg, #061522 0%, #082536 45%, #0a3441 100%);
    background-size: 180px 180px, 240px 240px, 210px 210px, 270px 270px, auto;
  }
  body::before {
    opacity: .4;
    background:
      radial-gradient(110% 65% at 25% 0%, transparent 68%, rgba(73, 173, 190, .16) 69%, transparent 71%),
      radial-gradient(100% 55% at 75% 0%, transparent 70%, rgba(190, 235, 232, .09) 71%, transparent 73%);
  }
  .topbar {
    background:
      radial-gradient(circle at 14% 24%, rgba(255,255,255,.7) 0 1px, transparent 1.5px),
      radial-gradient(circle at 31% 70%, rgba(241,207,118,.75) 0 1px, transparent 1.5px),
      radial-gradient(circle at 76% 30%, rgba(255,255,255,.6) 0 1px, transparent 1.5px),
      linear-gradient(105deg, #020b15, #061b2b 62%, #082c3a);
    background-size: 130px 64px, 190px 64px, 220px 64px, auto;
    border-bottom-color: rgba(143, 203, 205, .17);
  }
  .sidebar {
    color: #d1e7e9;
    background: linear-gradient(180deg, rgba(3, 16, 28, .98), rgba(5, 38, 50, .98));
    border-right-color: rgba(126, 194, 198, .19);
  }
  .space-nav a { color: #afd0d4; }
  .space-nav a:hover, .space-nav a.active {
    color: #effafa;
    background: rgba(87, 177, 184, .13);
    border-color: rgba(116, 199, 201, .18);
  }
  .space-nav small { color: #638e99; }
  .workspace-heading h1, .source-list h3, .dialog-heading h2, .login-brand h1 { color: #dff3f2; }
  .eyebrow { color: #66bdc4; }
  .filter-bar, .content-section {
    border-color: rgba(107, 178, 184, .18);
    background: rgba(9, 38, 53, .7);
    box-shadow: var(--shadow);
  }
  label > span { color: #8fb0b7; }
  input, select, textarea {
    border-color: #285969;
    background: rgba(5, 27, 41, .9);
    color: #e0f0f0;
  }
  input:focus, select:focus, textarea:focus {
    border-color: #55afb8;
    box-shadow: 0 0 0 3px rgba(85, 175, 184, .16);
  }
  .items-panel {
    border-color: rgba(103, 177, 184, .19);
    background: var(--surface);
  }
  .list-header { color: #84a6ae; background: rgba(22, 67, 80, .56); }
  .item-row { background: rgba(8, 33, 48, .56); border-bottom-color: rgba(114, 184, 188, .12); }
  .item-row:hover { background: rgba(16, 59, 70, .72); }
  .item-quantity { color: #a8c6ca; }
  .check-button { color: #749ba3; }
  .check-button.is-done { color: #7ad3cc; background: rgba(24, 106, 105, .34); border-color: rgba(93,190,184,.26); }
  .tag { color: #9dd7df; background: rgba(35, 105, 124, .35); border-color: rgba(87, 166, 181, .25); }
  .type-label { color: #efd787; background: rgba(113, 88, 25, .35); }
  .status-open { color: #a9c1c4; background: rgba(56, 87, 92, .42); }
  .status-done { color: #8ed4c9; background: rgba(26, 99, 90, .4); }
  .empty-state { background: rgba(7, 31, 45, .55); }
  .empty-state svg { color: #5cabb6; }
  .compact-row, .source-list, .note-entry, .list-detail-item { border-bottom-color: rgba(109, 179, 184, .14); }
  .source-list:hover, .compact-row:hover { background: rgba(33, 100, 111, .32); }
  .danger-button { color: #e38776; }
  .danger-button:hover { color: #ffab99; background: rgba(133, 50, 43, .3); border-color: rgba(218, 105, 88, .28); }
  dialog {
    border-color: rgba(103, 174, 181, .4);
    background: #092638;
    color: #dceeee;
  }
  dialog::backdrop { background: rgba(0, 7, 14, .78); }
  .login-panel {
    border-color: rgba(113, 191, 194, .3);
    background: rgba(6, 29, 43, .92);
  }
  .form-error { color: #ffc3b5; background: rgba(125, 43, 35, .4); }
  .flash-success { color: #a6e2d6; background: #0c3c3b; border-color: #235c58; }
  .flash-error { color: #ffc0ad; background: #48251f; border-color: #704034; }
}

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