:root {
  --bg: #f7f6fb;
  --surface: #ffffff;
  --text: #1c1a24;
  --muted: #6e6980;
  --border: #e4e0ee;
  --accent: #7a0c8e;
  --accent-grad: linear-gradient(135deg, #00188f 0%, #ec008c 100%);
  --accent-text: #ffffff;
  --accent-soft: #f6e8f7;
  --danger: #b91c1c;
  --radius: 10px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131118;
    --surface: #1d1a24;
    --text: #efedf4;
    --muted: #a39eb2;
    --border: #353042;
    --accent: #f07ac4;
    --accent-grad: linear-gradient(135deg, #1f3bd1 0%, #ec008c 100%);
    --accent-soft: #2e1830;
    --text-grad: linear-gradient(135deg, #7d93ff 0%, #ff5cb8 100%);
    --danger: #f87171;
  }
}

/* Lighter in dark mode so the brand name stays readable. */
.grad-text {
  background: var(--text-grad, var(--accent-grad));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.35rem; }

input, select, button { font: inherit; color: inherit; }

input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

select {
  appearance: none;
  cursor: pointer;
  padding-right: 34px;
  text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23888' stroke-width='1.6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
}

button {
  cursor: pointer;
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  background: var(--accent-grad);
  color: var(--accent-text);
  font-weight: 600;
}
button:disabled { opacity: .6; cursor: default; }
button.link { background: none; color: var(--accent); padding: 0; font-weight: 500; }
button.icon {
  background: none;
  color: var(--muted);
  padding: 4px 10px;
  font-size: 1.4rem;
  line-height: 1;
}
button.icon:hover { color: var(--text); background: var(--accent-soft); }
button.danger:hover { color: var(--danger); }

.error { color: var(--danger); margin: 8px 0 0; min-height: 0; font-size: .9rem; }
.error:empty { display: none; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%;
  max-width: 340px;
  display: grid;
  gap: 14px;
  padding: 28px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.login-card h1 { display: flex; align-items: center; gap: 10px; font-size: 1.6rem; margin-bottom: 6px; }
.login-card label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
.login-card .hint, .login-card .switch { margin: 0; color: var(--muted); font-size: .9rem; }
.notice { margin: 0; color: var(--text); background: var(--accent-soft); padding: 10px 12px; border-radius: 8px; font-size: .9rem; }
.notice:empty { display: none; }

/* Shell */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
nav { display: flex; gap: 4px; }
nav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
}
nav a.active { background: var(--accent-soft); color: var(--accent); }
.who { margin-left: auto; color: var(--muted); font-size: .9rem; white-space: nowrap; }

main { max-width: 760px; margin: 0 auto; padding: 24px 16px 48px; }

/* Movies */
.add-row { display: flex; gap: 8px; margin-top: 16px; }

.list { list-style: none; margin: 16px 0 0; padding: 0; }
.list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 6px 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 6px;
}
.movie-check { width: 18px; height: 18px; accent-color: var(--accent); flex: none; margin: 0 2px 0 0; cursor: pointer; }
.title { overflow-wrap: anywhere; }
.done .title { text-decoration: line-through; color: var(--muted); }
/* The title is a button: clicking it renames the movie. */
.title-btn {
  flex: 1;
  min-width: 0;
  padding: 2px 0;
  background: none;
  color: var(--text);
  font-weight: 400;
  text-align: left;
  border-radius: 4px;
  cursor: text;
}
.title-btn:hover { text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
.title-edit { flex: 1; padding: 4px 8px; }
.list li.downloading { border-color: var(--accent); background: var(--accent-soft); }
button.dl-btn { font-size: 1.05rem; }
button.dl-btn.active, button.dl-btn.active:hover { background: var(--accent-grad); color: #fff; }
.meta { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.empty { color: var(--muted); margin-top: 20px; }

details { margin-top: 24px; }
summary { cursor: pointer; color: var(--muted); font-weight: 500; }

/* Meals */
.week-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: center; }
.week-head .link { font-size: .85rem; margin-top: 2px; }

.days { display: grid; gap: 10px; margin-top: 18px; }
.day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}
.day.today {
  border: 2px solid transparent;
  background: linear-gradient(var(--surface), var(--surface)) padding-box, var(--accent-grad) border-box;
}
.day.past { opacity: .6; }
.day h3::first-letter { text-transform: uppercase; }
.range { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }
.day header { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 8px; }
.day h3 { font-size: 1rem; }
.date { color: var(--muted); font-size: .9rem; }
.badge {
  background: var(--accent-grad);
  color: var(--accent-text);
  font-size: .7rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.status { margin-left: auto; color: var(--muted); font-size: .8rem; }
.status.error { color: var(--danger); }
.meal { display: grid; gap: 6px; align-content: start; }
.meal h4 {
  margin: 4px 0 0;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--accent);
}
.slot { display: grid; gap: 3px; font-size: .78rem; color: var(--muted); font-weight: 500; }
.slot select { font-size: .95rem; color: var(--text); font-weight: 400; padding-top: 8px; padding-bottom: 8px; }
.slot select option { background: var(--surface); color: var(--text); }
.hint { color: var(--muted); margin: 6px 0 0; }
.notice a { color: var(--accent); font-weight: 600; }

.dish-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; margin-top: 4px; }
.dish-col .sub { margin-top: 20px; }
.col-count { font-weight: 400; }
.dish-col .add-row { margin-top: 10px; }
.dish-col .add-row button { padding-left: 14px; padding-right: 14px; }

/* Dish rows: the whole row opens the details dialog. */
.list li.dish-row { padding: 0; }
.row-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: none;
  color: var(--text);
  font-weight: 400;
  text-align: left;
  border-radius: var(--radius);
}
.row-btn:hover { background: var(--accent-soft); }
.row-text { flex: 1; min-width: 0; display: grid; gap: 1px; }
.preview { color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--muted); font-size: 1.3rem; line-height: 1; }

/* Dish details dialog */
.sheet {
  width: min(440px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
.sheet::backdrop { background: rgba(10, 8, 20, .45); }
.sheet-body { display: grid; gap: 12px; padding: 16px 18px 18px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.field { display: grid; gap: 4px; font-size: .8rem; color: var(--muted); font-weight: 500; }
.field input { font-size: 1.05rem; font-weight: 600; color: var(--text); }
.sheet-sub { margin: 4px 0 0; font-size: .8rem; color: var(--muted); font-weight: 500; }
.sheet .empty { margin: 0; font-size: .9rem; }
.sheet .add-row { margin: 0; }
.sheet .error { margin: 0; }
.sheet-note { margin: -8px 0 0; color: var(--muted); font-size: .8rem; }
.sheet-note:empty { display: none; }
.sheet h3 { font-size: 1.1rem; }

/* Ingredients: name | quantity | unit | remove */
.ing-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ing-row { display: flex; align-items: center; gap: 6px; }
.ing-label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.ing-qty, .ing-unit { padding: 7px 8px; font-size: .9rem; }
.ing-qty { width: 72px; flex: none; text-align: right; }
.ing-unit { width: 118px; flex: none; padding-right: 26px; background-position: right 8px center; }
.ing-add { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 10px; border-top: 1px solid var(--border); }
.ing-add .ing-name { flex: 1 1 100%; }
.ing-add .ing-qty { flex: 1 1 72px; }
.ing-add .ing-unit { flex: 1 1 118px; }
.ing-add button { flex: none; }

/* Shopping list */
.week-actions { display: flex; justify-content: center; margin-top: 10px; }
.shop-list { list-style: none; margin: 0; padding: 0; max-height: 55vh; overflow-y: auto; }
.shop-list li + li { border-top: 1px solid var(--border); }
.shop-list label { display: flex; align-items: center; gap: 10px; padding: 9px 2px; cursor: pointer; }
.shop-list input { width: 18px; height: 18px; flex: none; accent-color: var(--accent); }
.shop-name { flex: 1; }
.shop-qty { color: var(--muted); font-size: .9rem; white-space: nowrap; }
.shop-list input:checked ~ span { text-decoration: line-through; color: var(--muted); }
#shop-dialog .sheet-foot .status { margin: 0 auto 0 0; }
.sheet-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 4px; }
button.danger-link { color: var(--danger); }

/* Home: server stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; margin-top: 10px; }
.stat {
  display: grid;
  gap: 8px;
  align-content: start;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.stat-label { color: var(--muted); font-size: .85rem; font-weight: 500; }
.stat-value { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat-sub { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.gauge { height: 6px; border-radius: 99px; background: var(--border); overflow: hidden; }
.gauge span { display: block; height: 100%; border-radius: inherit; background: var(--accent-grad); transition: width .6s ease; }
.gauge.high span { background: var(--danger); }
#stats-off { margin-top: 10px; }

/* Home: services */
.sub-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.sub-row .link { font-size: .9rem; }
.services { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin-top: 10px; }
.svc {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font: inherit;
  text-align: left;
  transition: border-color .15s, transform .15s;
}
a.svc:hover, a.svc:focus-visible { border-color: var(--accent); transform: translateY(-1px); }
.svc-icon {
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  overflow: hidden;
}
.svc-icon img { width: 100%; height: 100%; object-fit: contain; }
.svc-letter {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background: var(--accent-grad);
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
}
.svc-text { display: grid; min-width: 0; }
.svc-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc-host { color: var(--muted); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc-wrap { position: relative; display: grid; }
.services.editing .svc { border-style: dashed; cursor: pointer; padding-right: 64px; }
.svc-tools { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); display: flex; }
.svc-tools .icon { padding: 4px 7px; }
.svc-tools .icon:disabled { opacity: .3; }
button.svc-add { background: none; color: var(--muted); cursor: pointer; font-weight: 400; }
button.svc-add:hover { color: var(--accent); border-color: var(--accent); }
.icon-field { display: flex; align-items: end; gap: 10px; }
.icon-field .field { flex: 1; }
.icon-field .svc-icon { width: 42px; height: 42px; }
.sheet-note a { color: var(--accent); }

/* Admin */
.count {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  margin-left: 2px;
  border-radius: 99px;
  background: var(--accent-grad);
  color: var(--accent-text);
  font-size: .72rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.sub { font-size: 1rem; margin-top: 28px; color: var(--muted); font-weight: 600; }
.sub + .list { margin-top: 10px; }

/* Tasks */
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.seg button { background: none; color: var(--muted); padding: 5px 12px; font-size: .85rem; font-weight: 500; border-radius: 7px; }
.seg button.active { background: var(--accent-grad); color: var(--accent-text); }
.task-add { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.task-add input[name=title] { flex: 1 1 260px; }
.task-add input[name=due] { flex: 0 1 160px; width: auto; }
.task-add select { flex: 0 1 160px; width: auto; }
.task-text { flex: 1; min-width: 0; display: grid; gap: 4px; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: .75rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 99px;
  background: var(--border);
  color: var(--muted);
}
.chip.soon { background: var(--accent-soft); color: var(--accent); }
.chip.late { background: var(--danger); color: #fff; }
.chip.assignee { background: none; border: 1px solid var(--border); font-weight: 500; }
.list li.late { border-color: var(--danger); }
#task-clear { margin: 4px 0 0 6px; font-size: .9rem; }

/* Settings */
.settings-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-top: 10px; }
.card-form {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.card-form h4 { margin: 0; font-size: .95rem; }
.card-form .field input { font-size: 1rem; font-weight: 400; }
.card-form .error, .card-form .notice { margin: 0; }
.card-form button[type=submit] { justify-self: start; }
.settings-note { margin: 8px 0 0; }
.admin-title { margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--border); color: var(--text); font-size: 1.15rem; }
.grow { flex: 1; min-width: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.list li > button:not(.icon) { padding: 6px 12px; font-size: .85rem; }
button.secondary { background: var(--accent-soft); color: var(--accent); }
.tag {
  font-size: .72rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
}
.tag.muted { background: var(--border); color: var(--muted); }
.create-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.create-row input:not([type=checkbox]) { flex: 1 1 180px; width: auto; }
.inline { display: flex; align-items: center; gap: 6px; color: var(--muted); white-space: nowrap; }
.inline input { width: 18px; height: 18px; accent-color: var(--accent); }

@media (max-width: 560px) {
  .list li { flex-wrap: wrap; }
  .topbar { flex-wrap: wrap; gap: 8px 12px; }
  .who { order: 2; }
  nav { order: 3; width: 100%; }
  nav a { flex: 1; text-align: center; padding: 6px 2px; font-size: .9rem; }
  .meta { display: none; }
  .stats, .services { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat, .svc { padding: 10px 12px; }
  .stat-value { font-size: 1.1rem; }
  .svc { gap: 10px; }
  .svc-icon { width: 30px; height: 30px; }
  .day { grid-template-columns: 1fr; }
  .dish-cols { grid-template-columns: 1fr; }
}
#meal-hint { margin-top: 14px; }
