/* ----------------------------------------------------------------------------
   Theme: shades of white, black and gold.
   Default follows the system color scheme; an explicit choice on <html
   data-theme="light|dark"> overrides it. High-contrast in both modes.
---------------------------------------------------------------------------- */

:root {
  --gold: #c8a13a;
  --gold-strong: #b88a1f;
  --gold-soft: rgba(200, 161, 58, 0.14);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  --font-sans: "Inter", system-ui, -apple-system, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
}

/* Light palette (default + explicit light) */
:root,
:root[data-theme="light"] {
  --bg: #faf8f4;
  --surface: #ffffff;
  --surface-2: #f3efe7;
  --border: #e5ded2;
  --text: #14130f;
  --text-muted: #6b665c;
  --on-gold: #1a1a1a;
  --danger: #b23b2e;
  --shadow: 0 10px 30px rgba(20, 19, 15, 0.07);
}

/* Dark palette: follow system when no explicit choice is made */
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #0d0d0f;
    --surface: #17171a;
    --surface-2: #202024;
    --border: #2c2c31;
    --text: #f4f1ea;
    --text-muted: #a39e93;
    --on-gold: #14130f;
    --danger: #e06b5c;
    --gold: #d8b24c;
    --gold-strong: #e6c45f;
    --gold-soft: rgba(216, 178, 76, 0.16);
    --shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  }
}

/* Explicit dark choice */
:root[data-theme="dark"] {
  --bg: #0d0d0f;
  --surface: #17171a;
  --surface-2: #202024;
  --border: #2c2c31;
  --text: #f4f1ea;
  --text-muted: #a39e93;
  --on-gold: #14130f;
  --danger: #e06b5c;
  --gold: #d8b24c;
  --gold-strong: #e6c45f;
  --gold-soft: rgba(216, 178, 76, 0.16);
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  transition: background 0.2s ease, color 0.2s ease;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
}

/* ---- Top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.5rem;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.brand-mark {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold-strong), var(--gold));
  box-shadow: 0 0 0 4px var(--gold-soft);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.theme-toggle {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.theme-toggle button {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  width: 34px;
  height: 30px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.15s ease;
}

.theme-toggle button[aria-pressed="true"] {
  background: var(--gold);
  color: var(--on-gold);
  font-weight: 600;
}

.session {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.session-user {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* ---- Layout ---- */
.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.view {
  animation: fade 0.25s ease;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---- Login ---- */
.login-card {
  max-width: 440px;
  margin: 6vh auto 0;
  padding: 2.25rem;
}

.display {
  font-family: var(--font-display);
  font-size: 2rem;
  margin: 0 0 0.5rem;
  line-height: 1.1;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  margin-top: 1.25rem;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

input,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.7rem;
  width: 100%;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}

.demo-users {
  margin-top: 1.5rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  font-size: 0.85rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: ui-monospace, monospace;
}

.chip:hover {
  border-color: var(--gold);
}

/* ---- Buttons ---- */
.btn {
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, border 0.15s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--gold);
  color: var(--on-gold);
}

.btn-primary:hover {
  background: var(--gold-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--gold);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
}

.btn-sm {
  padding: 0.4rem 0.7rem;
  font-size: 0.85rem;
}

/* ---- Events ---- */
.toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
}

.page-title {
  font-family: var(--font-display);
  font-size: 1.8rem;
  margin: 0;
}

.events-grid {
  display: grid;
  gap: 1rem;
}

.event-card {
  padding: 1.25rem 1.35rem;
}

.event-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.event-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  margin: 0;
}

.event-meta {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.items {
  margin-top: 1rem;
  display: grid;
  gap: 0.6rem;
}

.item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.9rem;
  background: var(--surface-2);
}

.item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.item-name {
  font-weight: 600;
}

.item-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.progress {
  height: 7px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.55rem 0;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold-strong), var(--gold));
  border-radius: 999px;
  transition: width 0.4s ease;
}

.item-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.badge-done {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--gold-strong);
  background: var(--gold-soft);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 0;
}

/* ---- Calendar links ---- */
.cal-links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.6rem;
  font-size: 0.85rem;
}

.cal-link {
  color: var(--gold-strong);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
}

.cal-link:hover {
  border-color: var(--gold);
}

/* ---- Batch item editor ---- */
.item-rows {
  display: grid;
  gap: 0.5rem;
}

.item-row {
  display: grid;
  grid-template-columns: 1fr 88px auto;
  gap: 0.5rem;
  align-items: center;
}

.item-row .ir-qty {
  text-align: center;
}

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
  animation: fade 0.15s ease;
}

.modal {
  width: 100%;
  max-width: 480px;
  padding: 1.5rem;
  max-height: 88vh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-head h2 {
  font-family: var(--font-display);
  margin: 0;
  font-size: 1.3rem;
}

.repeater-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.contact-list {
  display: grid;
  gap: 0.75rem;
}

.contact {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.85rem;
  background: var(--surface-2);
}

.contact-name {
  font-weight: 600;
}

.contact-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.contact-actions {
  display: flex;
  flex-shrink: 0;
  gap: 0.35rem;
}

.contact-notes {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  font-style: italic;
}

.contact-lines {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.contact-lines a {
  color: var(--gold-strong);
  text-decoration: none;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 80;
  box-shadow: var(--shadow);
  animation: fade 0.2s ease;
}

.toast.error {
  background: var(--danger);
  color: #fff;
}

/* ---- Admin panel ---- */
/* The admin panel needs more room than a regular modal. */
.modal:has(.admin-panel) {
  max-width: 720px;
}

.tabs {
  display: flex;
  gap: 0.4rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.1rem;
}

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  padding: 0.5rem 0.75rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.tab:hover {
  color: var(--text);
}

.tab-active {
  color: var(--text);
  border-bottom-color: var(--gold);
}

.admin-create {
  margin-bottom: 1.2rem;
}

.admin-create h3 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
}

.create-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.create-row input {
  flex: 1 1 9rem;
  min-width: 0;
}

.role-select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.6rem;
  font: inherit;
  cursor: pointer;
}

.user-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.7rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.user-id {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.user-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge-self,
.badge-done {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--gold-strong);
}

/* RBAC matrix */
.rbac-grid {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 1rem 0 1.2rem;
}

.rbac-row {
  display: grid;
  grid-template-columns: 1fr repeat(3, 6.5rem);
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.rbac-head {
  background: transparent;
  border-color: transparent;
  font-weight: 600;
  text-transform: capitalize;
}

.rbac-cell {
  text-align: center;
  text-transform: capitalize;
}

.rbac-check {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--gold-strong);
  cursor: pointer;
}

.rbac-check:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.perm-key {
  font-weight: 600;
  font-family: var(--font-display);
}

.perm-desc {
  font-size: 0.8rem;
}

@media (max-width: 560px) {
  .display {
    font-size: 1.6rem;
  }
  .topbar {
    padding: 0.7rem 1rem;
  }
  .rbac-row {
    grid-template-columns: 1fr repeat(3, 3.4rem);
    font-size: 0.85rem;
  }
}
