/* HouseDutyBot — admin UI
   Aesthetic: warm editorial minimalism. Aged-paper background, terracotta
   accent, Fraunces italic for display, Bricolage Grotesque for body, IBM Plex
   Mono for numbers and usernames. Hand-kept-ledger feel for a small household. */

:root {
  /* palette */
  --bg:           #F2EBDB;
  --bg-deep:      #E8DDC4;
  --surface:      #FAF5E6;
  --surface-2:    #ECE2CC;
  --ink:          #1A1410;
  --ink-2:        #3F362B;
  --muted:        #786A56;
  --muted-2:      #9D8E78;
  --line:         #C9BFA5;
  --line-soft:    #DDD2B6;
  --accent:       #B5552A;
  --accent-deep:  #8A3D1B;
  --accent-soft:  #F0D5BD;
  --accent-glow:  rgba(181, 85, 42, .12);
  --success:      #5C7245;
  --danger:       #9C2A1C;
  --danger-soft:  #F2C8BF;

  /* shadows */
  --shadow-1: 0 1px 0 rgba(26,20,16,.04), 0 1px 2px rgba(26,20,16,.05);
  --shadow-2: 0 1px 0 rgba(26,20,16,.04), 0 6px 24px -8px rgba(26,20,16,.16);
  --shadow-modal: 0 12px 48px -8px rgba(26,20,16,.28);

  /* radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 18px;
  --r-pill: 999px;

  /* fonts */
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-body:    "Bricolage Grotesque", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono:    "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 900px 600px at 85% -10%, rgba(181,85,42,.07), transparent 60%),
    radial-gradient(ellipse 700px 500px at -15% 110%, rgba(60,40,20,.05), transparent 60%);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* paper grain overlay */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .65;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 .045 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

main, header.topbar { position: relative; z-index: 1; }

::selection { background: var(--accent-soft); color: var(--ink); }

/* ────────── Display typography ────────── */
.display {
  font-family: var(--font-display);
  font-weight: 600;
  font-variation-settings: "opsz" 96, "SOFT" 50;
  letter-spacing: -0.018em;
  margin: 0;
  color: var(--ink);
}
h1.display { font-size: clamp(2rem, 4vw, 2.75rem); line-height: 1.04; }
h2.display { font-size: 1.5rem; line-height: 1.2; }
.display em {
  font-style: italic;
  color: var(--accent);
  font-weight: 600;
}

/* ────────── Topbar ────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 32px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(250, 245, 230, .72);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-style: italic;
  font-size: 1.2rem;
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 11px;
  letter-spacing: -0.01em;
}
.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.nav { display: flex; align-items: center; gap: 24px; }
.nav a, .nav .link {
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--ink-2);
  text-decoration: none;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  position: relative;
  transition: color .15s;
}
.nav a:hover, .nav .link:hover { color: var(--accent); }
.nav a::after, .nav .link::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -5px;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: right;
  transition: transform .25s ease;
}
.nav a:hover::after, .nav .link:hover::after {
  transform: scaleX(1);
  transform-origin: left;
}

/* ────────── Page shell ────────── */
.content {
  max-width: 760px;
  margin: 0 auto;
  padding: 56px 32px 96px;
  animation: page-in .45s cubic-bezier(.2,.7,.3,1);
}
@keyframes page-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.page-head { margin-bottom: 36px; }
.lede {
  font-size: 1rem;
  color: var(--muted);
  margin: 12px 0 0;
  max-width: 56ch;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: 8px;
  margin-bottom: 22px;
  box-shadow: var(--shadow-1);
  position: relative;
}
.section-title {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 600;
  font-size: 1.125rem;
  margin: 16px 16px 14px;
  display: flex;
  align-items: baseline;
  gap: 12px;
  color: var(--ink);
}
.section-meta {
  font-family: var(--font-body);
  font-style: normal;
  font-weight: 400;
  font-size: 0.8125rem;
  color: var(--muted);
  letter-spacing: 0;
}

/* ────────── Residents ────────── */
.residents-list { list-style: none; margin: 0; padding: 0; }

.resident {
  display: grid;
  grid-template-columns: 28px 56px 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border-radius: var(--r-md);
  transition: background .15s;
}
.resident + .resident { border-top: 1px solid var(--line-soft); }
.resident:hover { background: var(--bg-deep); }

.resident.sortable-ghost {
  opacity: .35;
  background: var(--accent-soft);
}
.resident.sortable-chosen {
  background: var(--surface-2);
  cursor: grabbing;
}
.resident.sortable-drag {
  background: var(--surface);
  box-shadow: var(--shadow-2);
  border-radius: var(--r-md);
}

.drag-handle {
  color: var(--muted-2);
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  transition: color .15s, background .15s;
  user-select: none;
}
.resident:hover .drag-handle { color: var(--ink-2); }
.drag-handle:active { cursor: grabbing; background: var(--accent-soft); color: var(--accent-deep); }

.position-num {
  font-family: var(--font-display);
  font-feature-settings: "tnum";
  font-weight: 400;
  font-size: 1.75rem;
  line-height: 1;
  color: var(--muted);
  letter-spacing: -0.02em;
}

.resident-info {
  display: flex;
  align-items: baseline;
  gap: 14px;
  min-width: 0;
}
.resident-name {
  font-weight: 600;
  font-size: 1.0625rem;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.resident-username {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--muted);
  white-space: nowrap;
}

.icon-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted-2);
  cursor: pointer;
  transition: color .15s, background .15s, border-color .15s;
}
.icon-btn:hover {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-soft);
}
.icon-btn-danger:hover {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger-soft);
}
.resident-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.icon-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* dashed add button */
.btn-ghost.dashed {
  display: block;
  width: calc(100% - 16px);
  margin: 8px;
  padding: 14px;
  background: transparent;
  border: 1px dashed var(--line);
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
  letter-spacing: .005em;
}
.btn-ghost.dashed:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(181, 85, 42, .04);
}

/* ────────── Schedule ────────── */
.schedule-list { list-style: none; margin: 0; padding: 0; }

.schedule-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 14px 16px;
  border-radius: var(--r-md);
  position: relative;
}
.schedule-row + .schedule-row { border-top: 1px solid var(--line-soft); }

.schedule-row.is-current {
  background: linear-gradient(90deg, var(--accent-glow) 0, transparent 28%);
}
.schedule-row.is-current::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.date-chip {
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
  padding: 7px 11px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--ink-2);
  letter-spacing: 0.02em;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.schedule-row.is-current .date-chip {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--surface);
}

.schedule-name {
  font-weight: 500;
  color: var(--ink);
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
.schedule-name .empty-name {
  color: var(--muted-2);
  font-style: italic;
  font-weight: 400;
  font-family: var(--font-display);
}

.now-tag {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 0.9375rem;
  color: var(--accent);
  letter-spacing: -.005em;
}

.override-badge {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-deep);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: var(--r-pill);
}

.select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 8px 32px 8px 12px;
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%23786A56' stroke-width='1.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color .15s, box-shadow .15s;
  min-width: 160px;
}
.select:hover { border-color: var(--accent); }
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.select:disabled { color: var(--muted); cursor: not-allowed; }

.hint {
  margin: 12px 16px;
  font-size: 0.8125rem;
  color: var(--muted);
  font-style: italic;
  font-family: var(--font-display);
}

/* ────────── Forms ────────── */
.form { display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ink-2);
  letter-spacing: 0.01em;
}

.input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--muted-2); }
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input-with-prefix {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
}
.input-with-prefix:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input-with-prefix .prefix {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  font-family: var(--font-mono);
  color: var(--muted);
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  font-size: 0.9375rem;
  user-select: none;
}
.input-with-prefix .input {
  border: 0;
  border-radius: 0;
  background: transparent;
  flex: 1;
  font-family: var(--font-mono);
}
.input-with-prefix .input:focus { box-shadow: none; }

.field .hint {
  margin: 0;
  font-size: 0.75rem;
  font-style: normal;
  font-family: var(--font-body);
  color: var(--muted);
}

/* ────────── Buttons ────────── */
.btn {
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 500;
  padding: 11px 22px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background .15s, transform .05s ease-out, box-shadow .15s;
  letter-spacing: 0.005em;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primary {
  background: var(--accent);
  color: var(--surface);
  box-shadow: 0 1px 0 rgba(26,20,16,.05), inset 0 1px 0 rgba(255,255,255,.12);
}
.btn-primary:hover {
  background: var(--accent-deep);
  box-shadow: 0 4px 12px -4px rgba(181,85,42,.45), inset 0 1px 0 rgba(255,255,255,.12);
}
.btn-primary:disabled {
  opacity: .55;
  cursor: not-allowed;
  background: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 500;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--ink);
}

/* ────────── Error notice ────────── */
.error {
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.875rem;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  border: 1px solid #e0a59a;
  font-weight: 500;
  animation: error-in .25s ease-out;
}
@keyframes error-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ────────── Modal ────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 20, 16, .42);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in .2s;
}
.modal-backdrop[hidden] { display: none; }
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  width: min(440px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: 28px;
  box-shadow: var(--shadow-modal);
  animation: modal-in .25s cubic-bezier(.2,.7,.3,1);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal h2 { margin: 0 0 18px; font-size: 1.375rem; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

/* ────────── Login ────────── */
.login-stage {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  position: relative;
}
.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: 40px 36px 32px;
  box-shadow: var(--shadow-2);
  position: relative;
  animation: modal-in .35s cubic-bezier(.2,.7,.3,1);
}
.login-header {
  text-align: center;
  margin-bottom: 26px;
}
.login-mark {
  margin: 0 auto 14px;
  display: block;
}
.login-header h1 {
  font-size: 1.875rem;
  margin: 0;
  letter-spacing: -0.02em;
}
.login-header .subtle {
  font-size: 0.875rem;
  color: var(--muted);
  margin: 6px 0 0;
  font-style: italic;
  font-family: var(--font-display);
}
.login-footer {
  margin-top: 24px;
  font-size: 0.75rem;
  color: var(--muted-2);
  letter-spacing: 0.02em;
  font-style: italic;
  font-family: var(--font-display);
}

/* ────────── Empty state ────────── */
.empty {
  text-align: center;
  padding: 28px 24px;
  color: var(--muted);
  font-style: italic;
  font-family: var(--font-display);
  font-size: 1rem;
  margin: 0;
}

/* ────────── Mobile ────────── */
@media (max-width: 640px) {
  .topbar { padding: 14px 18px; }
  .nav { gap: 16px; }
  .content { padding: 32px 18px 64px; }
  .resident {
    grid-template-columns: 24px 32px 1fr auto;
    gap: 10px;
    padding: 12px 10px;
  }
  .position-num { font-size: 1.375rem; }
  .resident-info { flex-direction: column; align-items: flex-start; gap: 0; }
  .schedule-row {
    grid-template-columns: auto 1fr;
    row-gap: 10px;
  }
  .schedule-row > .select,
  .schedule-row > .now-tag {
    grid-column: 1 / -1;
    justify-self: start;
  }
  .login-card { padding: 32px 22px 24px; }
  .modal { padding: 22px; }
}
