/* Admin dashboard */

:root {
  --bg: #f6f2ea;
  --surface: #ffffff;
  --ink: #23202b;
  --muted: #6c6676;
  --line: #e6dfd2;
  --navy: #15204a;
  --navy-2: #22306a;
  --gold: #f4ab3e;
  --gold-soft: #ffe2a6;
  --green: #2f7a4e;
  --green-bg: #e3f3e8;
  --red: #b13b3b;
  --red-bg: #fbe6e4;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 40, 0.06), 0 6px 20px rgba(20, 20, 40, 0.06);
  --font-display: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --font-ui: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

h1, h2 { font-family: var(--font-display); font-weight: 600; }
h1 { font-size: clamp(1.6rem, 3vw, 2.1rem); margin: 0 0 0.25rem; }
h2 { font-size: 1.4rem; margin: 0 0 1rem; }
.muted { color: var(--muted); margin: 0; }
code {
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 0.92em;
  background: #f1ebdf;
  padding: 0.08em 0.4em;
  border-radius: 6px;
}

/* ---------------------------------------------------------------- Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.05rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 150ms, border-color 150ms, box-shadow 150ms, transform 80ms;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-block { width: 100%; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { border-color: #cfc5b2; background: #fdfbf7; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #962f2f; }
.btn-ghost-light { background: transparent; color: #dfe4ff; border-color: rgba(255, 255, 255, 0.25); }
.btn-ghost-light:hover { background: rgba(255, 255, 255, 0.08); }
.btn-small { padding: 0.38rem 0.7rem; font-size: 0.85rem; border-radius: 8px; }
.btn-link {
  font: inherit;
  font-size: 0.9em;
  color: var(--navy-2);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}

:focus-visible { outline: 3px solid rgba(244, 171, 62, 0.7); outline-offset: 2px; }

/* ----------------------------------------------------------------- Forms */

label { display: block; font-weight: 600; font-size: 0.92rem; margin: 1rem 0 0.35rem; }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  width: 100%;
  transition: border-color 150ms, box-shadow 150ms;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(244, 171, 62, 0.22);
}
.field-error { color: var(--red); font-size: 0.86rem; margin: 0.35rem 0 0; min-height: 0; }
.field-error:empty { display: none; }
.hint { color: var(--muted); font-size: 0.82rem; margin: 0.35rem 0 0; }

.input-prefix {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}
.input-prefix span {
  display: flex;
  align-items: center;
  padding: 0 0.6rem;
  background: #f4efe5;
  color: var(--muted);
  font-size: 0.9rem;
  border-right: 1px solid var(--line);
}
.input-prefix input { border: 0; border-radius: 0; }
.input-prefix:focus-within { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(244, 171, 62, 0.22); }
.input-prefix input:focus { box-shadow: none; }

.input-action { display: flex; gap: 0.5rem; }

.notice { padding: 0.75rem 0.9rem; border-radius: 10px; font-size: 0.92rem; margin: 1rem 0 0; text-align: left; }
.notice-warn { background: #fff3d6; color: #6a4a07; }

/* ----------------------------------------------------------------- Login */

.login {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse at 70% 10%, rgba(255, 210, 130, 0.18), transparent 50%),
    linear-gradient(180deg, #0b1430, #22306a);
}
.login-card {
  width: min(24rem, 100%);
  padding: 2.25rem 2rem 1.75rem;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
  text-align: center;
}
.login-card label { text-align: left; }
.login-card .btn { margin-top: 1.25rem; }
.login-icon {
  width: 3.2rem; height: 3.2rem; margin: 0 auto 0.75rem;
  display: grid; place-items: center;
  font-size: 1.6rem; color: var(--gold);
  background: var(--navy); border-radius: 50%;
}
.login-back { display: inline-block; margin-top: 1rem; font-size: 0.88rem; color: var(--muted); }

/* ------------------------------------------------------------------ App */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem clamp(1rem, 3vw, 2rem);
  background: linear-gradient(90deg, var(--navy), var(--navy-2));
  color: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}
.brand {
  color: #fff;
  text-decoration: none;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
}
.brand-star { color: var(--gold); }
.brand-sub {
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold-soft);
  margin-left: 0.4rem;
}

.content {
  max-width: 1240px;
  margin: 0 auto;
  padding: clamp(1.25rem, 3vw, 2.25rem) clamp(1rem, 3vw, 2rem) 4rem;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem 2rem;
  margin-bottom: 1.5rem;
}

.back-link { display: inline-block; margin-bottom: 0.75rem; color: var(--muted); text-decoration: none; font-size: 0.92rem; }
.back-link:hover { color: var(--ink); }

.empty {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--muted);
  border: 2px dashed var(--line);
  border-radius: var(--radius);
}

/* -------------------------------------------------------- Instance cards */

.instance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr));
  gap: 1rem;
}

.instance-card {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.instance-card h2 { margin: 0; font-size: 1.3rem; }
.instance-meta { display: grid; gap: 0.3rem; font-size: 0.9rem; color: var(--muted); }
.instance-meta a { color: var(--navy-2); }
.instance-progress { display: flex; align-items: center; gap: 0.6rem; font-size: 0.86rem; color: var(--muted); }
.instance-progress .progress-bar { flex: 1; }
.instance-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: auto; }

.progress-bar {
  height: 8px;
  background: #eee6d7;
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #f4ab3e, #ffd27a);
  border-radius: inherit;
  transition: width 400ms ease;
}

/* ----------------------------------------------------------- Editor head */

.editor-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.editor-meta a { color: var(--navy-2); }

.preview-tools label { margin: 0 0 0.35rem; }
.preview-row { display: flex; gap: 0.5rem; }
.preview-row select { width: auto; min-width: 12rem; }

.progress-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  padding: 0.9rem 1.1rem;
  margin-bottom: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.progress-panel .progress-bar { flex: 1 1 10rem; }
.progress-text { font-size: 0.95rem; }

.filter-chips { display: flex; gap: 0.35rem; }
.chip {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
}
.chip.is-active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* ------------------------------------------------------ Appearance panel */

.appearance-panel {
  padding: 1.1rem 1.25rem 1.25rem;
  margin-bottom: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.appearance-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.appearance-head h2 { margin: 0 0 0.15rem; font-size: 1.25rem; }
.appearance-head .muted { font-size: 0.88rem; }
.appearance-head .save-state { font-size: 0.85rem; white-space: nowrap; padding-top: 0.3rem; }

.option-group { border: 0; padding: 0; margin: 0.5rem 0 0; min-width: 0; }
.option-group legend {
  padding: 0;
  margin-bottom: 0.45rem;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.option-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
  gap: 0.75rem 1.5rem;
  margin-top: 0.75rem;
}

/* Radio inputs are visually hidden; the label is the control. */
.view-card input,
.swatch input,
.segmented input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.view-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
  gap: 0.75rem;
}

.view-card {
  position: relative;
  display: flex;
  gap: 0.85rem;
  align-items: center;
  margin: 0;
  padding: 0.75rem;
  border: 2px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  font-weight: 400;
  transition: border-color 150ms, background 150ms;
}
.view-card:hover { border-color: #cfc5b2; }
.view-card:has(input:checked) { border-color: var(--gold); background: #fff9ee; }
.view-card:has(input:focus-visible) { outline: 3px solid rgba(244, 171, 62, 0.7); outline-offset: 2px; }
.view-card strong { display: block; font-size: 0.98rem; margin-bottom: 0.15rem; }
.view-card small { display: block; color: var(--muted); font-size: 0.84rem; line-height: 1.4; }

/* Tiny window illustrations for the two view modes */
.view-illus {
  flex: 0 0 auto;
  position: relative;
  width: 3.4rem;
  height: 4.2rem;
  border-radius: 1.7rem 1.7rem 6px 6px;
  border: 4px solid #7c6748;
  background: #1b2440;
  overflow: hidden;
}
.view-illus::before,
.view-illus::after {
  content: '';
  position: absolute;
  background: #d9c9a6;
}
.view-illus::before { left: 50%; top: 0; bottom: 0; width: 3px; margin-left: -1.5px; }
.view-illus::after { top: 55%; left: 0; right: 0; height: 3px; }
.view-illus-classic {
  background: radial-gradient(circle at 50% 65%, #fff4cf, #ffd177 35%, #f19b3c 75%, #b45f22);
  box-shadow: 0 0 14px rgba(255, 190, 90, 0.7);
}
.view-illus-peek {
  background:
    radial-gradient(circle at 70% 28%, #fff6d0 0 12%, transparent 13%),
    linear-gradient(180deg, transparent 58%, #e9eff8 58%),
    linear-gradient(160deg, #2d6a4f, #457b9d 60%, #1d3557);
  box-shadow: 0 0 14px rgba(255, 190, 90, 0.45);
}
.view-illus-peek::before,
.view-illus-peek::after { opacity: 0; }

/* House style cards with a live preview of the artwork */
.house-card {
  flex-direction: column;
  align-items: stretch;
  gap: 0.6rem;
}
.house-preview {
  display: block;
  aspect-ratio: 1200 / 860;
  overflow: hidden;
  border-radius: 8px;
  background: var(--pv-sky);
}

/* ---- Live preview variables (set via classes from the current settings) ---- */
.house-options {
  /* sky: Winternacht */
  --pv-sky: linear-gradient(180deg, #070d22 0%, #13204a 50%, #2a3a6c 80%, #3b4a7a 100%);
  /* light: Warmgold */
  --pv-l1: #fff1c4;
  --pv-l2: #ffc062;
  --pv-l3: #d9782a;
  /* house color "Standard": honey wood (cottage) / lavender (villa) */
  --pv-c1: #b98249; --pv-c2: #9c6a37; --pv-c3: #76491f;
  --pv-m1: #6d6479; --pv-m2: #5a5266; --pv-m3: #433c4f;
  --pv-g1: #c98444; --pv-g2: #ad6830; --pv-g3: #87491d;
}
.house-options.pv-theme-dusk {
  --pv-sky: linear-gradient(180deg, #120b2a 0%, #3a2155 45%, #8a4469 78%, #e48a6c 100%);
}
.house-options.pv-theme-aurora {
  --pv-sky:
    radial-gradient(ellipse 70% 28% at 38% 16%, rgba(80, 255, 170, 0.38), transparent 70%),
    radial-gradient(ellipse 50% 22% at 70% 26%, rgba(60, 220, 255, 0.26), transparent 70%),
    linear-gradient(180deg, #020c14 0%, #062433 50%, #0d3d4a 80%, #1b5a5e 100%);
}
.house-options.pv-light-candle { --pv-l1: #ffe4b8; --pv-l2: #ffa95a; --pv-l3: #c45a1c; }
.house-options.pv-light-white { --pv-l1: #ffffff; --pv-l2: #eaf0ff; --pv-l3: #a9bbe3; }
.house-options.pv-house-red {
  --pv-c1: #8e3d35; --pv-c2: #74302a; --pv-c3: #57221e;
  --pv-m1: #8e3d35; --pv-m2: #74302a; --pv-m3: #57221e;
  --pv-g1: #8e3d35; --pv-g2: #74302a; --pv-g3: #57221e;
}
.house-options.pv-house-cream {
  --pv-c1: #b6ae9f; --pv-c2: #9a9284; --pv-c3: #777064;
  --pv-m1: #b6ae9f; --pv-m2: #9a9284; --pv-m3: #777064;
  --pv-g1: #b6ae9f; --pv-g2: #9a9284; --pv-g3: #777064;
}

.house-preview stop { transition: stop-color 350ms ease; }
.house-preview .pv-l1 { stop-color: var(--pv-l1); }
.house-preview .pv-l2 { stop-color: var(--pv-l2); }
.house-preview .pv-l3 { stop-color: var(--pv-l3); }
.house-preview svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.house-preview .smoke,
.house-preview .fl-glow,
.house-preview .tower-star-glow,
.house-preview .tree-star-glow,
.house-preview .lantern-glow { display: none; }
.house-preview .lantern-light { fill: #ffd27a; }
.house-preview .tower-star { fill: #ffd87a; }
.pv-cottage .wall-1 { stop-color: var(--pv-c1); }
.pv-cottage .wall-2 { stop-color: var(--pv-c2); }
.pv-cottage .wall-3 { stop-color: var(--pv-c3); }
.pv-manor .wall-1 { stop-color: var(--pv-m1); }
.pv-manor .wall-2 { stop-color: var(--pv-m2); }
.pv-manor .wall-3 { stop-color: var(--pv-m3); }
.pv-gingerbread .wall-1 { stop-color: var(--pv-g1); }
.pv-gingerbread .wall-2 { stop-color: var(--pv-g2); }
.pv-gingerbread .wall-3 { stop-color: var(--pv-g3); }

.swatches { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.swatch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  padding: 0.35rem 0.7rem 0.35rem 0.4rem;
  border: 2px solid var(--line);
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 150ms, background 150ms;
}
.swatch:hover { border-color: #cfc5b2; }
.swatch:has(input:checked) { border-color: var(--gold); background: #fff9ee; font-weight: 700; }
.swatch:has(input:focus-visible) { outline: 3px solid rgba(244, 171, 62, 0.7); outline-offset: 2px; }
.swatch-dot {
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  background: var(--sw);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}
.segmented label {
  position: relative;
  margin: 0;
  padding: 0.45rem 0.8rem;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  border-right: 1px solid var(--line);
}
.segmented label:last-child { border-right: 0; }
.segmented label:has(input:checked) { background: var(--navy); color: #fff; font-weight: 700; }
.segmented label:has(input:focus-visible) { outline: 3px solid rgba(244, 171, 62, 0.7); outline-offset: -3px; }

.instance-tags { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tag {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  background: #f1ebdf;
  color: #5d5446;
}

/* --------------------------------------------------------------- Day grid */

.day-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 15.5rem), 1fr));
  gap: 1rem;
}

.day-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: border-color 200ms, box-shadow 200ms;
}
.day-card.is-dragover { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(244, 171, 62, 0.3); }

.day-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.7rem 0.85rem;
}
.day-num {
  display: grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  font-family: var(--font-display);
  font-weight: 700;
  color: #fff;
  background: var(--navy);
  flex: 0 0 auto;
}
.day-date { font-weight: 600; font-size: 0.95rem; }
.pill {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
}
.pill-done { color: var(--green); background: var(--green-bg); }
.pill-empty { color: #8a6d3b; background: #f7ecd5; }

.day-drop {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  margin: 0 0.85rem;
  border-radius: 10px;
  background: repeating-linear-gradient(45deg, #faf6ee 0 10px, #f4eee2 10px 20px);
  border: 2px dashed #ddd2bd;
  cursor: pointer;
  overflow: hidden;
  font-weight: 500;
}
.day-drop:hover { border-color: var(--gold); }
.day-drop.has-image { border-style: solid; border-color: transparent; background: #eee6d7; }
.day-drop img { width: 100%; height: 100%; object-fit: cover; display: block; }
.day-drop-empty { padding: 1rem; text-align: center; color: var(--muted); font-size: 0.88rem; line-height: 1.4; }
.day-drop-empty strong { display: block; color: var(--ink); font-size: 1.6rem; line-height: 1; margin-bottom: 0.35rem; }
.day-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.day-busy {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.8);
  font-size: 0.88rem;
  font-weight: 600;
}
.spinner {
  width: 1.6rem; height: 1.6rem; margin: 0 auto 0.4rem;
  border: 3px solid #e7dcc7; border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.day-actions { display: flex; gap: 0.4rem; padding: 0.6rem 0.85rem 0; }
.day-actions .btn { flex: 1; }

.day-body { padding: 0.6rem 0.85rem 0.85rem; display: flex; flex-direction: column; gap: 0.35rem; flex: 1; }
.day-body textarea { resize: vertical; min-height: 4.8rem; font-size: 0.92rem; line-height: 1.45; }
.day-foot { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--muted); }
.save-state.is-saving { color: #8a6d3b; }
.save-state.is-saved { color: var(--green); }
.save-state.is-error { color: var(--red); }

/* ---------------------------------------------------------------- Dialogs */

.dialog {
  width: min(30rem, calc(100vw - 2rem));
  border: 0;
  border-radius: 18px;
  padding: 1.6rem 1.6rem 1.3rem;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3);
  color: var(--ink);
}
.dialog-small { width: min(26rem, calc(100vw - 2rem)); }
.dialog::backdrop { background: rgba(11, 20, 48, 0.55); backdrop-filter: blur(3px); }
.dialog h2 { margin-bottom: 0.25rem; }
.dialog label:first-of-type { margin-top: 0.75rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.5rem; }

/* ----------------------------------------------------------------- Toast */

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 1.5rem;
  max-width: calc(100vw - 2rem);
  padding: 0.75rem 1.1rem;
  border-radius: 12px;
  background: var(--navy);
  color: #fff;
  font-size: 0.93rem;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity 200ms, transform 200ms;
  pointer-events: none;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--red); }

@media (max-width: 560px) {
  .preview-row { flex-wrap: wrap; }
  .preview-row select { flex: 1; min-width: 0; }
}
