:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --border: #e1e4ec;
  --text: #1c2030;
  --muted: #646b80;
  --accent: #3b5bdb;
  --accent-hover: #2f4bc0;
  --accent-soft: #e7ecff;
  --success: #2b8a3e;
  --success-soft: #e6f4ea;
  --warn: #b35c00;
  --warn-soft: #fff3e0;
  --danger: #c92a2a;
  --danger-soft: #fdeaea;
  --sidebar: #161a2b;
  --sidebar-2: #20253a;
  --sidebar-text: #c5cae0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 4px 16px rgba(20, 24, 40, .06);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; font-weight: 650; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 650; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; padding: 18px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.brand-text { color: #fff; font-weight: 700; font-size: 14px; line-height: 1.2; letter-spacing: .2px; }
.brand-text span { color: var(--sidebar-text); font-weight: 500; }
.nav-create {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--accent); color: #fff; text-decoration: none; font-weight: 600;
  padding: 11px 12px; border-radius: 9px; margin-bottom: 16px;
}
.nav-create:hover, .nav-create.active { background: var(--accent-hover); }
.nav-create.active { box-shadow: 0 0 0 2px rgba(255,255,255,.25) inset; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; color: var(--sidebar-text);
  text-decoration: none; padding: 10px 10px; border-radius: 8px; font-weight: 500;
}
.nav a:hover { background: var(--sidebar-2); color: #fff; }
.nav a.active { background: var(--sidebar-2); color: #fff; }
.nav a.active { box-shadow: inset 3px 0 0 var(--accent); }
.badge { margin-left: auto; background: #f59f00; color: #1c1c1c; font-size: 11px; font-weight: 700; border-radius: 99px; padding: 1px 7px; }
.sidebar-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.profile-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; font: inherit; color: var(--sidebar-text);
  background: transparent; border: 1px solid #2c3250; border-radius: 9px; padding: 8px 10px; cursor: pointer; text-align: left;
}
.profile-btn:hover, .profile-btn.open { background: var(--sidebar-2); color: #fff; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.who { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.2; }
.who > span:first-child { color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .role { font-size: 11.5px; opacity: .75; }
.caret { font-size: 11px; transition: transform .15s; transform: rotate(180deg); }
.profile-btn.open .caret { transform: none; }
.profile-menu { display: flex; flex-direction: column; gap: 2px; background: #1b2034; border-radius: 9px; padding: 4px; }
.profile-menu a, .profile-menu button {
  display: flex; align-items: center; gap: 10px; color: var(--sidebar-text); text-decoration: none; font: inherit;
  font-weight: 500; padding: 9px 10px; border-radius: 7px; background: none; border: 0; cursor: pointer; text-align: left;
}
.profile-menu a:hover, .profile-menu button:hover, .profile-menu a.active { background: var(--sidebar-2); color: #fff; }
.profile-menu #sign-out { border-top: 1px solid #2c3250; border-radius: 0 0 7px 7px; margin-top: 2px; }

/* Sign-in screen */
.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #161a2b, #2a3152); }
.auth-card { background: var(--surface); border-radius: 14px; padding: 28px; width: min(420px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.auth-card h1 { margin: 18px 0 8px; }
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-title { font-weight: 700; font-size: 16px; }
.cost-pill { font-size: 12px; color: var(--sidebar-text); border-radius: 8px; padding: 8px 10px; background: var(--sidebar-2); }
.cost-pill b { color: #fff; }
.cost-pill b { color: #ffd43b; }

.main { padding: 28px 36px 60px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer;
  border-radius: 8px; padding: 8px 14px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.lg { padding: 11px 20px; font-size: 15px; }
.btn .cost { font-weight: 500; opacity: .85; font-size: 12px; }

label.field { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 12.5px; color: #3a4055; }
label.field .hint { font-weight: 400; color: var(--muted); }
label.field > .chip { align-self: flex-start; }
input[type=text], input[type=search], input[type=email], input[type=date], input[type=time], input[type=number], input[type=password], select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: #fff;
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input[type=date]::-webkit-calendar-picker-indicator { cursor: pointer; padding: 4px; border-radius: 5px; transition: background-color .12s; }
input[type=date]::-webkit-calendar-picker-indicator:hover { background-color: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
.check { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; }
.check input { margin-top: 3px; }

.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.chip.blue { background: var(--accent-soft); color: var(--accent); }
.chip.green { background: var(--success-soft); color: var(--success); }
.chip.orange { background: var(--warn-soft); color: var(--warn); }
.chip.red { background: var(--danger-soft); color: var(--danger); }

.notice { border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.notice.warn { background: var(--warn-soft); color: #7a3f00; }
.notice.error { background: var(--danger-soft); color: #8a1c1c; }
.notice.info { background: var(--accent-soft); color: #22379a; }
.notice.success { background: var(--success-soft); color: #1e5e2c; }

/* ---------- Create page ---------- */
.stage {
  aspect-ratio: 16 / 9; width: 100%; border-radius: var(--radius);
  background: repeating-linear-gradient(45deg, #eceef4 0 12px, #e6e9f0 12px 24px);
  border: 1px dashed #c9cede; display: grid; place-items: center; overflow: hidden; position: relative;
}
.stage img { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.stage .empty { text-align: center; color: var(--muted); padding: 20px; }
.stage .empty svg { opacity: .45; }
.stage.loading::after {
  content: ""; position: absolute; inset: 0; background: rgba(255,255,255,.55);
}
.spinner { width: 36px; height: 36px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .9s linear infinite; }
.stage .spinner-wrap { position: absolute; inset: 0; display: grid; place-items: center; z-index: 2; text-align: center; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
.stage.generating { border-style: solid; border-color: var(--accent); background: linear-gradient(110deg, #eef1fb 30%, #f8f9fe 50%, #eef1fb 70%); background-size: 200% 100%; animation: shimmer 1.6s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.compare-warning { border: 1px solid #f5c27a; font-size: 13.5px; }
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.compare-item { border: 2px solid transparent; border-radius: var(--radius); cursor: pointer; padding: 4px; background: var(--surface); }
.compare-item.selected { border-color: var(--accent); }
.compare-item .stage { border-style: solid; }
.compare-item .label { padding: 6px 4px 2px; font-size: 12.5px; font-weight: 600; display: flex; justify-content: space-between; }
.image-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.prompt-box textarea { min-height: 130px; font-size: 14.5px; line-height: 1.5; }
details.details-panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
details.details-panel > summary { cursor: pointer; padding: 12px 16px; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
details.details-panel > summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
details.details-panel[open] > summary::before { transform: rotate(90deg); }
details.details-panel > .body { padding: 0 16px 16px; }

/* Orange dot on the profile button when something needs doing (e.g. no email yet) */
.profile-btn { position: relative; }
.profile-btn.needs-attention::after { content: ""; position: absolute; top: 6px; left: 30px; width: 10px; height: 10px; border-radius: 50%; background: #e8590c; border: 2px solid var(--surface); }

/* ---------- Library ---------- */
.lib-page { position: relative; min-height: 60vh; }
/* 4 across on a normal screen, 3 on a smaller one */
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(235px, 1fr)); gap: 14px; }
.lib-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; transition: border-color .1s, box-shadow .1s; }
.lib-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.lib-thumb { position: relative; cursor: pointer; }
.lib-thumb img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: #000; }
.lib-thumb::after { content: ""; position: absolute; inset: 0; background: rgba(20, 24, 40, 0); transition: background .12s; pointer-events: none; }
.lib-thumb:hover::after { background: rgba(20, 24, 40, .28); }
.lib-card.selected .lib-thumb::after { background: rgba(59, 91, 219, .18); }
.thumb-hover { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(255,255,255,.95); color: var(--text); font-weight: 650; font-size: 12.5px; padding: 5px 12px; border-radius: 99px; opacity: 0; transition: opacity .12s; pointer-events: none; z-index: 1; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.lib-thumb:hover .thumb-hover { opacity: 1; }
.lib-check { position: absolute; top: 8px; left: 8px; z-index: 2; display: flex; cursor: pointer; }
.lib-check input { width: 18px; height: 18px; margin: 0; cursor: pointer; accent-color: var(--accent); filter: drop-shadow(0 1px 2px rgba(0,0,0,.45)); }
.thumb-tag.imported { background: rgba(231, 236, 255, .95); color: var(--accent); }
.sel-bar { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 10px; margin-bottom: 12px; border-radius: var(--radius); border: 1px solid transparent; flex-wrap: wrap; }
.sel-bar.active { position: sticky; top: 8px; z-index: 5; background: var(--accent-soft); border-color: #c5d0fa; box-shadow: var(--shadow); }
.more-btn { padding: 4px 5px !important; }
.pop-menu { position: absolute; z-index: 80; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: 4px; min-width: 200px; display: flex; flex-direction: column; }
.pop-menu button { background: none; border: 0; text-align: left; padding: 8px 10px; border-radius: 5px; font: inherit; font-size: 13.5px; cursor: pointer; color: var(--text); }
.pop-menu button:hover { background: var(--surface-2); }
.pop-menu button.danger { color: var(--danger); }
.drop-overlay { position: absolute; inset: 0; z-index: 20; border: 3px dashed var(--accent); border-radius: var(--radius); background: rgba(231, 236, 255, .85); display: grid; place-items: center; font-size: 18px; font-weight: 700; color: var(--accent); pointer-events: none; }
.sched-preview { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.sched-preview img { width: 200px; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; background: #000; cursor: zoom-in; flex: none; }
.sched-preview .title { font-weight: 650; margin-bottom: 2px; }
.thumb-tag { position: absolute; top: 8px; right: 8px; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; }
.thumb-sundays { position: absolute; left: 8px; bottom: 8px; right: 8px; display: flex; gap: 4px; flex-wrap: wrap; pointer-events: none; }
.thumb-sundays span { background: rgba(20, 24, 40, .78); color: #fff; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; backdrop-filter: blur(2px); }
.thumb-sundays span.unscheduled { background: rgba(20, 24, 40, .5); font-weight: 500; }
.lib-foot { display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 10px; }
.lib-text { flex: 1; min-width: 0; }
.lib-text .title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-text .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-foot .btn.sm { padding: 4px 8px; font-size: 12px; flex: none; }
.edit-preview img { width: 100%; max-height: 260px; object-fit: contain; background: #000; border-radius: 8px; display: block; }
.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty-state h2 { color: var(--text); }

/* ---------- Week list ---------- */
.week-nav { display: flex; align-items: center; gap: 6px; }
.week-nav .date { font-weight: 650; min-width: 190px; text-align: center; }
.q-list { display: flex; flex-direction: column; gap: 10px; position: relative; }
.q-item { display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow); }
.q-item[draggable=true] { cursor: grab; }
.q-item.dragging { opacity: .4; }
/* Where a dragged graphic will land */
.drop-line { position: absolute; left: 0; right: 0; height: 4px; margin-top: -2px; background: var(--accent); border-radius: 4px; pointer-events: none; z-index: 3; box-shadow: 0 0 0 3px var(--accent-soft); }
.drop-line::before, .drop-line::after { content: ""; position: absolute; top: 50%; width: 12px; height: 12px; margin-top: -6px; border-radius: 50%; background: var(--accent); }
.drop-line::before { left: -6px; }
.drop-line::after { right: -6px; }
.q-item .num { width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-weight: 700; font-size: 12px; color: var(--muted); flex: none; }
.q-item .handle { cursor: grab; color: #9aa0b4; padding: 4px; }
.q-item img { width: 200px; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; background: #000; cursor: zoom-in; flex: none; }
.q-item .info { flex: 1; min-width: 0; }
.q-item .info .title { font-weight: 650; }
.q-item .info { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.details-line { font-size: 13px; color: #3a4055; font-weight: 500; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; font-weight: 600; }
.link-btn:hover { text-decoration: underline; }

/* Attention-grabbing "something needs doing" alert */
.action-alert {
  display: flex; align-items: center; gap: 14px; margin-bottom: 18px;
  background: #fff4e5; border: 1px solid #f0a541; border-left: 6px solid #e8590c;
  border-radius: var(--radius); padding: 14px 16px; color: #6b2e00;
  box-shadow: 0 2px 10px rgba(232, 89, 12, .12);
}
.action-alert-icon { width: 30px; height: 30px; border-radius: 50%; background: #e8590c; color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 17px; flex: none; }
.action-alert-body { flex: 1; font-size: 13.5px; }
.action-alert-title { font-weight: 700; font-size: 15px; color: #8a3200; margin-bottom: 2px; }
.btn.alert-btn { background: #e8590c; border-color: #e8590c; color: #fff; }
.btn.alert-btn:hover { background: #c94a06; }
.q-item .ctrl { display: flex; gap: 4px; }

/* ---------- Calendar ---------- */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.cal-head .month { font-weight: 700; font-size: 16px; min-width: 160px; text-align: center; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--border); gap: 1px; }
.cal .dow { background: var(--surface-2); padding: 6px; font-size: 11.5px; font-weight: 700; color: var(--muted); text-align: center; text-transform: uppercase; letter-spacing: .5px; }
.cal .day { background: var(--surface); min-height: 92px; padding: 6px; font-size: 12px; display: flex; flex-direction: column; gap: 3px; min-width: 0; overflow: hidden; }
.cal .day.other { background: #fafbfd; color: #b0b5c4; }
.cal .day.today .dnum { background: var(--accent); color: #fff; border-radius: 99px; padding: 0 6px; }
.cal .day.sunday { background: #fbfcff; cursor: pointer; }
.cal .day.sunday:hover { background: var(--accent-soft); }
.cal .dnum { font-weight: 700; align-self: flex-start; }
.cal .thumbs { display: flex; flex-wrap: wrap; gap: 2px; }
.cal .thumbs img { width: 36px; aspect-ratio: 16/9; object-fit: cover; border-radius: 2px; }
.cal .ev { font: inherit; font-size: 11px; background: var(--warn-soft); color: var(--warn); border: 1px solid transparent; border-radius: 4px; padding: 1px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; text-align: left; cursor: pointer; width: 100%; }
.cal .ev:hover { border-color: var(--warn); background: #ffe8c2; }
.cal .count { font-size: 11px; line-height: 1.3; color: var(--accent); font-weight: 700; text-decoration: none; background: var(--accent-soft); border-radius: 4px; padding: 2px 5px; align-self: stretch; white-space: normal; overflow-wrap: anywhere; }
.cal .count:hover { text-decoration: underline; }

.pending-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.pending-card { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); display: flex; flex-direction: column; }
.pending-card .img-wrap { aspect-ratio: 16/9; background: var(--surface-2); display: grid; place-items: center; }
.pending-card .img-wrap img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.pending-card .meta { padding: 10px 12px; flex: 1; }
.pending-card .actions { display: flex; gap: 6px; padding: 0 12px 12px; flex-wrap: wrap; }
.event-list { display: flex; flex-direction: column; }
.event-row { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-top: 1px solid var(--border); cursor: pointer; border-radius: 6px; }
.event-row:hover { background: var(--surface-2); }
.event-row:first-child { border-top: 0; }
.event-row .date-box { width: 52px; text-align: center; border-radius: 8px; background: var(--surface-2); padding: 4px 0; flex: none; }
.event-row .date-box .m { font-size: 10.5px; font-weight: 700; color: var(--accent); text-transform: uppercase; }
.event-row .date-box .d { font-size: 18px; font-weight: 700; line-height: 1.1; }
.event-row .info { flex: 1; min-width: 0; }
.upcoming-layout { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; align-items: start; }

/* ---------- Settings ---------- */
.settings-section { display: grid; grid-template-columns: 240px 1fr; gap: 24px; padding: 20px 0; border-top: 1px solid var(--border); }
.settings-section:first-of-type { border-top: 0; padding-top: 0; }
.settings-section .desc { color: var(--muted); font-size: 13px; }
.settings-section .desc h2 { color: var(--text); margin-bottom: 6px; }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #c9cede; border-radius: 99px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::before { transform: translateX(18px); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 700; }
table.tbl td.num, table.tbl th.num { text-align: right; }
table.tbl input[type=number] { width: 90px; padding: 5px 8px; }
.meter { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.meter > div { height: 100%; background: var(--success); }
.meter.high > div { background: #f59f00; }
.meter.full > div { background: var(--danger); }
.key-row { display: flex; gap: 8px; align-items: center; }
.key-row input { flex: 1; }
code.inline { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; font-size: 12.5px; user-select: all; }
fieldset.cap-field { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
fieldset.cap-field legend { font-weight: 600; font-size: 12.5px; color: #3a4055; padding: 0 4px; }
fieldset.cap-field .check { align-items: center; }
fieldset.cap-field .check input[type=radio] { margin-top: 0; }
ol.steps { padding-left: 20px; margin: 6px 0; }
ol.steps li { margin-bottom: 4px; }

/* ---------- Modal & toasts ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 18, 30, .55); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--surface); border-radius: 12px; width: min(560px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: min(900px, 100%); }
.modal .m-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal .m-head h2 { margin: 0; flex: 1; }
.modal .m-body { padding: 18px 20px; overflow: auto; }
.modal .m-foot { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.m-foot .foot-hint { margin-right: auto; line-height: 1; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.88); z-index: 60; display: grid; place-items: center; cursor: zoom-out; padding: 30px; }
.lightbox img { max-width: calc(100vw - 60px); max-height: calc(100vh - 60px); object-fit: contain; display: block; box-shadow: 0 10px 50px rgba(0,0,0,.5); }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.picker-item { border: 2px solid var(--border); border-radius: 8px; overflow: hidden; cursor: pointer; background: var(--surface); text-align: left; padding: 0; font: inherit; }
.picker-item img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; }
.picker-item .t { padding: 5px 8px; font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.picker-item.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.picker-item.disabled { opacity: .45; cursor: not-allowed; }
.sunday-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.sunday-opt { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; cursor: pointer; display: flex; gap: 8px; align-items: center; user-select: none; }
.sunday-opt.auto { cursor: default; opacity: .75; }
.every-sunday { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); cursor: pointer; }
.every-sunday input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.every-sunday select { width: auto; display: inline-block; margin-left: 4px; padding: 4px 8px; }
.chip.every { background: var(--accent-soft); color: var(--accent); }
.sunday-opt:hover { background: var(--surface-2); }
.sunday-opt.on { border-color: var(--accent); background: var(--accent-soft); }
.sunday-opt .n { font-size: 11px; color: var(--muted); }
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 70; }
.toast { background: #1c2030; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 420px; font-size: 13.5px; animation: toastIn .2s ease; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .main { padding: 20px 16px; }
  .upcoming-layout, .settings-section, .grid-2, .grid-3, .compare-grid { grid-template-columns: 1fr; }
  .q-item img { width: 120px; }
  .lib-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .action-alert { flex-wrap: wrap; }
}

/* Rename: label and box side by side */
.inline-field { display: flex; align-items: center; gap: 14px; }
.inline-field > span { font-weight: 700; font-size: 16px; flex: none; }
.inline-field input { flex: 1; font-size: 15px; }

/* Schedule popup */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 3px; background: var(--surface-2); margin-bottom: 10px; }
.seg button { border: 0; background: none; font: inherit; font-weight: 600; font-size: 13px; padding: 5px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.picked { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.pick-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 12.5px; padding: 3px 4px 3px 10px; border-radius: 99px; }
.pick-chip button { border: 0; background: none; color: inherit; cursor: pointer; font-size: 15px; line-height: 1; width: 20px; height: 20px; border-radius: 50%; }
.pick-chip button:hover { background: rgba(59, 91, 219, .15); }

/* Whole-page drop target */
.drop-overlay.page { position: fixed; inset: 12px 12px 12px calc(var(--sidebar-w, 260px) + 12px); z-index: 45; }

/* My Profile: read-only values with an Edit button */
.view-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.view-row .value { font-size: 15px; font-weight: 600; }

/* Schedule popup: Sunday calendar */
.sched-body { display: grid; grid-template-columns: 250px 1fr; gap: 18px; align-items: start; }
.mini-cal { border: 1px solid var(--border); border-radius: 10px; padding: 8px; width: 250px; box-sizing: border-box; }
.mc-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.mc-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.mc-dow { font-size: 11px; font-weight: 700; color: var(--muted); padding: 2px 0; }
.mc-dow.sun { color: var(--accent); }
.mc-day { font-size: 12px; padding: 4px 0; border-radius: 6px; color: #b6bbc9; }
.mc-day.out { opacity: .45; }
button.mc-day { border: 1px solid transparent; background: var(--accent-soft); color: var(--accent); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; }
button.mc-day:hover { border-color: var(--accent); }
button.mc-day.on { background: var(--accent); color: #fff; }
button.mc-day.in-range, button.mc-day.auto { background: #c9d4ff; color: #1f3aa8; }
.sched-side { display: flex; flex-direction: column; gap: 10px; }
.sv { display: flex; flex-direction: column; gap: 2px; }
.sv span { font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 700; }
.sv b { font-size: 14.5px; }
@media (max-width: 700px) { .sched-body { grid-template-columns: 1fr; } }

/* Small pencil button next to a title */
.icon-btn { display: inline-grid; place-items: center; width: 26px; height: 26px; margin-left: 4px; vertical-align: middle; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--accent); }

/* Schedule popup: compact top row, month chooser, Date Range boxes */
.sched-top { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.sched-top img { width: 120px; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; background: #000; cursor: zoom-in; flex: none; }
.sched-title { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.sched-title:has(.t) { flex-direction: row; align-items: center; justify-content: flex-start; }
.sched-title .t { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sched-title input { font-size: 15px; }
.sched-summary { margin-top: 10px; font-size: 12.5px; color: #22379a; background: var(--accent-soft); border-radius: 8px; padding: 7px 10px; }
.mc-title { border: 0; background: none; font: inherit; font-weight: 700; font-size: 13.5px; padding: 3px 8px; border-radius: 6px; cursor: pointer; color: var(--text); }
.mc-title:hover { background: var(--accent-soft); color: var(--accent); }
.mc-months { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 4px 2px; }
.mc-months button { border: 1px solid var(--border); background: var(--surface); border-radius: 7px; padding: 9px 0; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.mc-months button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.mc-months button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.mc-months button:disabled { opacity: .35; cursor: default; }
.range-boxes { display: flex; align-items: stretch; gap: 10px; }
.range-arrow { align-self: center; color: var(--muted); font-size: 18px; }
.date-box { flex: 1; text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: 9px; padding: 8px 12px; cursor: pointer; font: inherit; display: flex; flex-direction: column; gap: 2px; }
.date-box:hover { border-color: var(--accent); }
.date-box.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.date-box span { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 700; }
.date-box b { font-size: 14px; }
.range-cal { margin-top: 8px; }
.range-cal.last { margin-left: auto; }

.lib-foot .btn.icon-only { padding: 4px 6px; }

/* My Library: outlined Delete button */
.lib-foot .btn.danger { border-color: #e8a5a5; }
.lib-foot .btn.danger:hover { border-color: var(--danger); }

/* Non-Consecutive Sundays: one box listing the chosen days */
.pick-box { position: relative; padding-right: 130px; min-height: 56px; }
.pick-box .picked { margin-top: 4px; }
.pick-toggle { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-style: normal; font-size: 12.5px; font-weight: 700; color: var(--accent); }

/* Schedule popup: outlined "Remove from all Sundays" (matches My Library's Delete) */
.m-foot [data-clear-all] { border-color: #e8a5a5; }
.m-foot [data-clear-all]:hover { border-color: var(--danger); }

/* Sign-in: authenticator setup and codes */
.auth-card.wide { width: min(520px, 100%); }
.auth-card.in-modal { box-shadow: none; padding: 0; width: auto; }
.auth-card.in-modal .auth-brand { display: none; }
.code-input { font-size: 22px; letter-spacing: 6px; text-align: center; font-family: ui-monospace, Consolas, monospace; }
.enroll-qr { display: flex; gap: 16px; align-items: center; margin: 4px 0 8px 20px; flex-wrap: wrap; }
.enroll-qr img { border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.secret-key { display: inline-block; margin: 4px 0; font-size: 13px; letter-spacing: 1px; word-break: break-all; }
.recovery-codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 16px; background: var(--surface-2); border-radius: 8px; padding: 12px 16px; }
.recovery-codes code { font-family: ui-monospace, Consolas, monospace; font-size: 15px; letter-spacing: 1px; user-select: all; }
/* Security log */
.log-scroll { max-height: 420px; overflow: auto; }
tr.log-bad td { background: #fff5f5; }

/* Sidebar: Manage group (admins) */
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; color: var(--sidebar-text); font: inherit; font-weight: 500;
  padding: 10px 10px; border-radius: 8px; background: none; border: 0; cursor: pointer; text-align: left;
}
.nav-group-btn:hover, .nav-group-btn.open { background: var(--sidebar-2); color: #fff; }
.nav-group-btn .caret { margin-left: auto; }
.nav-group-btn.open .caret { transform: none; }
.nav-sub { display: flex; flex-direction: column; gap: 2px; padding-left: 28px; }
.nav .nav-sub a { padding: 8px 10px; font-size: 13.5px; }

/* Roles and logs */
.chip.purple { background: #f1e8ff; color: #6a35c2; }
.role-legend { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.log-filters { gap: 8px; flex-wrap: wrap; }
.log-filters select { width: auto; }
td.nowrap { white-space: nowrap; }

/* Sign-in: secondary links sit apart from the main button */
.auth-links { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 18px !important; }
.auth-links.end { justify-content: flex-end; }

/* Sign-in fields with an icon inside on the left; placeholder text disappears as you type, the icon stays */
.icon-input { position: relative; display: block; }
.icon-input > svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #8a90a6; pointer-events: none; }
.icon-input > input { padding-left: 40px; width: 100%; }
.icon-input > input::placeholder { color: #9aa0b4; }
/* Wide, centered LOGIN button */
.btn.auth-submit { display: flex; margin-left: auto; margin-right: auto; align-self: center; width: 70%; min-width: 220px; justify-content: center; letter-spacing: 1.5px; font-weight: 700; }
.auth-links.center { justify-content: center; }

/* Sign-in errors: plain red text above the fields */
.login-error { color: var(--danger); font-size: 13.5px; font-weight: 600; }

/* Users: inline-editable name/email, role help, roles popup */
.edit-inline-label { display: flex; align-items: center; gap: 4px; font-size: 13px; color: #3a4055; }
.edit-inline-label .icon-btn { width: 24px; height: 24px; margin-left: 2px; }
.edit-inline-value { font-size: 15px; padding: 4px 0; }
.edit-inline input { margin-top: 4px; }
.role-help { display: block; margin-top: 4px; margin-bottom: 8px; line-height: 1.4; }
.roles-list { display: flex; flex-direction: column; gap: 14px; }
#roles-help { margin-top: 4px; }

/* Sidebar spending box opens the Spending page */
a.cost-pill { display: block; text-decoration: none; cursor: pointer; border: 1px solid transparent; transition: border-color .12s; }
a.cost-pill:hover, a.cost-pill.active { border-color: #4a5280; color: #fff; }

.custom-dates { display: inline-flex; align-items: center; gap: 6px; }
.custom-dates input { width: auto; }

/* Scheduler: section headers, read-only form fields, event thumbnails */
.section-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
div.field { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 12.5px; color: #3a4055; }
div.field .hint { font-weight: 400; color: var(--muted); }
.field-static { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 38px; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); font-weight: 400; color: var(--text); }
.event-thumb { width: 72px; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); flex: none; cursor: zoom-in; }

/* Create page: progress while generating, clickable result */
.gen-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 22px 20px; aspect-ratio: 16/9; display: flex; flex-direction: column; justify-content: center; gap: 12px; }
.gen-progress { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.gen-bar { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .25s linear; }
.gen-label { text-align: center; }
.gen-label b { font-size: 22px; margin-right: 6px; }
.stage.result { cursor: pointer; }
.stage.result:hover { box-shadow: 0 0 0 3px var(--accent-soft); }
.result-bar { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.pop-menu button:disabled { color: var(--muted); cursor: default; background: none; }

/* Event form: editable display dates */
.display-dates { flex-wrap: wrap; gap: 6px; }
.pick-chip.past { opacity: .55; }
.add-date-row { gap: 8px; margin-top: 8px; align-items: center; }
.add-date-row input[type=date] { width: auto; }

/* "+ Add Date" opens the browser's calendar; the date box itself stays out of sight under the button */
.date-launch { position: relative; display: inline-block; }
.date-launch input[type=date] { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }

/* Event list thumbnails are just previews (clicking the row opens the event) */
.event-thumb.list-thumb { cursor: inherit; pointer-events: none; }

/* All Events page */
.back-link { font-size: 13px; text-decoration: none; display: inline-block; margin-bottom: 4px; }
.back-link:hover { text-decoration: underline; }
.events-toolbar { gap: 10px; flex-wrap: wrap; }
.events-toolbar input[type=search] { flex: 1; min-width: 240px; }

.sort-by { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.sort-by select { width: auto; }

/* Small "i" info icon with a hover/focus tooltip (text in data-tip). */
.info-tip { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--muted, #888); color: var(--muted, #888); font: italic 700 12px/1 Georgia, serif; cursor: help; flex: none; }
.info-tip:hover, .info-tip:focus { color: var(--text, #222); border-color: var(--text, #222); outline: none; }
.info-tip::after { content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%); width: 260px; padding: 8px 10px; border-radius: 6px; background: #222; color: #fff; font: 400 12.5px/1.4 system-ui, sans-serif; text-align: left; white-space: normal; box-shadow: 0 4px 14px rgba(0,0,0,.2); opacity: 0; visibility: hidden; transition: opacity .12s; pointer-events: none; z-index: 50; }
.info-tip:hover::after, .info-tip:focus::after { opacity: 1; visibility: visible; }

/* Settings: each setting shown as text with a pencil; editing opens a box with Save / Cancel. */
.set-field .edit-inline-value { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 30px; overflow-wrap: anywhere; }
.set-field .edit-inline-label .hint { font-weight: 400; }
.set-edit { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.set-edit > input, .set-edit > select { width: 100%; }
.info-tip::after { white-space: pre-line; }
/* Tip opens to the right of the icon (for icons near the left edge). */
.info-tip.tip-left::after { left: -6px; transform: none; width: 300px; top: calc(100% + 8px); bottom: auto; }
/* Event rows: the Edit button needs its own hover (the row's hover is the same grey as a ghost button's). */
.event-row [data-act=edit]:hover { background: var(--accent-soft); border-color: #c5d0fa; color: var(--accent); }
/* Sunday lineup popup (from the Scheduler's calendar): more compact rows. */
.sunday-lineup .q-item { padding-top: 6px; padding-bottom: 6px; }
.sunday-lineup .q-item img { width: 96px; height: 54px; }
/* My Library: a graphic shown larger with its title (pencil to rename). */
.view-graphic { display: flex; flex-direction: column; gap: 12px; }
.view-graphic img { width: 100%; max-height: calc(100vh - 230px); aspect-ratio: 16/9; object-fit: contain; background: #000; border-radius: 8px; cursor: zoom-in; display: block; }
/* My Library's larger-graphic popup: no heading or divider line, just the close button. */
.modal.view-modal .m-head h2 { display: none; }
/* Scheduler calendar: days you can't click (weekdays, past Sundays) get faint diagonal stripes and a
   "not allowed" cursor. Upcoming Sundays stay plain and clickable. */
.cal .day.disabled { background: repeating-linear-gradient(135deg, #f7f8fb 0 6px, #eef0f5 6px 12px); cursor: not-allowed; }
.cal .day.disabled .dnum { color: #9aa0b2; }
/* Next month's days: a plain gray box (no stripes), whether or not they can be clicked. */
.cal .day.other, .cal .day.other.disabled { background: #eef0f4; }
.cal .day.other .dnum { color: #a9aebd; }
.cal .day.disabled .ev { cursor: pointer; }
/* Schedule labels in the Scheduler's Sunday popup can be long (many dates): let them wrap. */
.sunday-lineup .q-item .title .chip { white-space: normal; line-height: 1.35; }
/* My Library selection bar: "Clear selection" stands out (white, blue outline) against the blue bar. */
.sel-bar .btn.clear-sel { background: #fff; border-color: var(--accent); color: var(--accent); font-weight: 700; }
.sel-bar .btn.clear-sel:hover { background: var(--accent); color: #fff; }
.sel-bar b { margin: 0 4px; }
/* Schedule pills in the Scheduler's Sunday popup: a color for each kind. */
.chip.sched-every { background: #e7ecff; color: #2f4ac0; }   /* Every Sunday: blue */
.chip.sched-range { background: #e3f6e8; color: #1f7a3a; }   /* back-to-back range: green */
.chip.sched-dates { background: #fff1e0; color: #a35a00; }   /* specific dates: orange */
/* My Library's larger-graphic popup: the title is the heading, on the top bar beside the close button. */
.modal.view-modal .m-head { border-bottom: 0; padding: 14px 16px 10px 20px; gap: 8px; align-items: flex-start; }
.modal.view-modal .m-body { padding-top: 0; }
.view-modal .view-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 20px; font-weight: 700; line-height: 1.3; min-height: 32px; }
.view-modal .view-title b { font-weight: 700; }
.view-modal .view-title input { flex: 1; font-size: 18px; font-weight: 600; }
.view-modal .view-title .notice { flex-basis: 100%; font-size: 13px; font-weight: 400; }
