:root {
  --bg: #14161a;
  --panel: #1e2127;
  --field: #1a1d23;
  --border: #2a2e36;
  --text: #eee;
  --muted: #9aa0aa;
  --accent: #4a7cff;
  --accent-ring: rgba(74, 124, 255, 0.35);
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* ---- form controls: one consistent dark treatment everywhere
   (cards, modals, admin forms) - inputs/selects/textareas have no
   built-in dark styling from the browser, so without this rule every
   text/password/select field renders as a stock white OS control. ---- */

input[type="text"],
input[type="password"],
input[type="date"],
textarea,
select {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--field);
  color: var(--text);
  transition: border-color 0.15s ease;
}

input[type="text"]::placeholder,
input[type="password"]::placeholder,
textarea::placeholder {
  color: var(--muted);
}

input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.75);
  cursor: pointer;
}

input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="date"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse 800px 500px at 50% 35%, rgba(74, 124, 255, 0.16), transparent 70%),
    var(--bg);
}

.login-box {
  max-width: 360px;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 2.5rem 2rem;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.login-box .login-icon { font-size: 2rem; margin-bottom: 0.7rem; }

.login-box h1 { margin: 0 0 0.4rem; font-size: 1.3rem; }

.login-box .login-subtitle { color: var(--muted); font-size: 0.85rem; margin: 0 0 1.6rem; }

a.primary, button.primary {
  display: inline-block;
  padding: 0.7rem 1.2rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  text-decoration: none;
  font-size: 1rem;
  cursor: pointer;
}

.err { color: var(--danger); font-size: 0.9rem; min-height: 1.2em; margin-bottom: 0.5rem; }

/* ---- top bar: brand + account pill switcher + profile ---- */

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1.2rem;
  border-bottom: 1px solid var(--border);
}

.topbar-brand { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }

.account-pills {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  scrollbar-width: none;
}

.account-pills::-webkit-scrollbar { display: none; }

.account-pills .pill {
  flex: 0 0 auto;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.account-pills .pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 600;
}

.account-pills .pill.pill-add {
  background: none;
  border-style: dashed;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  flex: 0 0 auto;
}

/* ---- shell: left rail + main content ---- */

.shell { display: flex; align-items: stretch; min-height: calc(100vh - 57px); }

.rail {
  width: 200px;
  flex: 0 0 200px;
  display: flex;
  flex-direction: column;
  padding: 1rem 0.8rem;
  border-right: 1px solid var(--border);
  position: sticky;
  top: 57px;
  height: calc(100vh - 57px);
  align-self: flex-start;
}

.rail-nav { display: flex; flex-direction: column; gap: 0.25rem; }

#tabbar button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-align: left;
  background: none;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
}

#tabbar button:hover { background: rgba(128, 128, 128, 0.12); }

#tabbar button.active {
  color: var(--text);
  background: rgba(74, 124, 255, 0.15);
  font-weight: 600;
}

.rail-section-label {
  margin: 0.9rem 0 0.2rem 0.7rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.rail-stats {
  margin-top: auto;
  padding: 0.8rem 0.7rem;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 0.8rem;
}

.rail-stats .rail-stats-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.rail-stats .rail-stat-row {
  display: flex;
  justify-content: space-between;
  padding: 0.15rem 0;
}

main { padding: 1.5rem 2rem 3rem; max-width: 1300px; margin: 0 auto; flex: 1; min-width: 0; }

main h1#tab-title { font-size: 1.3rem; margin: 0 0 1rem; }

/* ---- card grid (Fronta) ---- */

.queue-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
  align-items: start;
}

.card {
  background: var(--panel);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}

/* auto-fit + 1fr stretches a lone card to the full grid width - cap it so
   a queue of 1-2 posts still reads as a card, not a full-bleed poster. */
.queue-grid .card { margin-bottom: 0; max-width: 420px; }

.card img { max-width: 100%; border-radius: 8px; margin-bottom: 0.5rem; }

.card .caption { white-space: pre-wrap; margin-bottom: 0.5rem; }

.card .meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.5rem; }

.card .actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.card .actions button {
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--field);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.card .actions button:hover { border-color: var(--accent); }

.card .actions button.danger { border-color: var(--danger); color: var(--danger); }

.card .actions button.danger:hover { background: rgba(255, 107, 107, 0.1); }

.error-banner {
  background: #3a1f1f;
  color: var(--danger);
  padding: 0.8rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

/* ---- calendar: month grid ---- */

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.calendar-nav .calendar-month-label { font-weight: 600; }

.calendar-nav button {
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.calendar-nav button:hover { border-color: var(--accent); }

.calendar-weekday-labels {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.4rem;
  margin-bottom: 0.3rem;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.4rem;
}

.calendar-day {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem;
  min-height: 84px;
  cursor: default;
}

.calendar-day.outside-month { opacity: 0.35; }

.calendar-day.is-today { border-color: var(--accent); }

.calendar-day .day-label { font-size: 0.75rem; color: var(--muted); margin-bottom: 0.3rem; }

.calendar-day .post-chip {
  display: block;
  font-size: 0.7rem;
  background: var(--bg);
  border-radius: 4px;
  padding: 0.15rem 0.35rem;
  margin-bottom: 0.2rem;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- modal + toast (replaces native alert/confirm/prompt) ---- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem;
  max-width: 420px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}

.modal .modal-body { white-space: pre-wrap; margin-bottom: 1rem; font-size: 0.92rem; }

.modal input[type="text"], .modal textarea {
  width: 100%;
  margin-bottom: 1rem;
}

.modal .modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }

.modal .modal-actions button {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--field);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  transition: border-color 0.15s ease, filter 0.15s ease;
}

.modal .modal-actions button:hover { border-color: var(--accent); }

.modal .modal-actions button.primary { background: var(--accent); border-color: var(--accent); color: white; }

.modal .modal-actions button.primary:hover { filter: brightness(1.1); }

#toast-root {
  position: fixed;
  bottom: 1.2rem;
  right: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 200;
}

.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 0.7rem 1rem;
  font-size: 0.85rem;
  max-width: 320px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.toast.toast-danger { border-left-color: var(--danger); }

/* ---- narrow viewports ---- */

@media (max-width: 700px) {
  .shell { flex-direction: column; min-height: auto; }
  .rail {
    width: auto;
    flex: 0 0 auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 0.6rem 0.8rem;
    border-right: none;
    border-bottom: 1px solid var(--border);
    position: static;
    height: auto;
  }
  .rail-nav { flex-direction: row; flex-wrap: wrap; flex: 1 1 100%; gap: 0.2rem; }
  #tabbar button { flex: 1 1 auto; justify-content: center; padding: 0.5rem 0.4rem; font-size: 0.8rem; }
  .rail-section-label { flex-basis: 100%; margin: 0.4rem 0 0 0.3rem; }
  .rail-stats { margin-top: 0.5rem; flex: 1 1 100%; }
  main { padding: 1rem 1rem 3rem; }
  .queue-grid { grid-template-columns: 1fr; }
  .calendar-day { min-height: 60px; }
}
