/* ============================================================================
   Design tokens
   ----------------------------------------------------------------------------
   Concept: a "registration desk / ticket board" for community event rosters.
   Dark ink-navy surfaces (a corkboard at night), a brass ticket-stub accent
   for primary actions and capacity, teal for "open / available", rose for
   "full / danger". Roster numbers are rendered like a real carbon-copy
   sign-up sheet since the content genuinely is an ordered list.
============================================================================ */

:root {
  --ink: #12151b;
  --panel: #1b212b;
  --panel-raised: #232a36;
  --panel-border: #2e3644;
  --paper: #f3efe4;
  --paper-dim: #cfc9b8;

  --brass: #d8a13a;
  --brass-dim: #a97c2c;
  --teal: #3fa796;
  --teal-dim: #2c7a6d;
  --rose: #e0596b;
  --rose-dim: #a8394a;

  --text-primary: #f1efe8;
  --text-muted: #9aa1ac;
  --text-faint: #6b7280;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 8px 24px rgba(0, 0, 0, 0.35);

  --font-display: "Vazirmatn", "Tahoma", sans-serif;
  --font-body: "Vazirmatn", "Tahoma", sans-serif;
  --font-mono: "JetBrains Mono", "Vazirmatn", ui-monospace, monospace;

  --sidebar-w: 248px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--ink);
  background-image: radial-gradient(circle at 12% 8%, rgba(216, 161, 58, 0.06), transparent 45%),
    radial-gradient(circle at 92% 82%, rgba(63, 167, 150, 0.06), transparent 40%);
  color: var(--text-primary);
  font-family: var(--font-body);
  direction: rtl;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--brass);
  color: #221a0a;
}

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

a {
  color: inherit;
}

button {
  font-family: inherit;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---- layout shell -------------------------------------------------------- */

#app-shell {
  display: grid;
  grid-template-columns: 1fr var(--sidebar-w);
  min-height: 100vh;
}

.sidebar {
  grid-column: 2;
  background: linear-gradient(180deg, var(--panel), var(--ink) 85%);
  border-inline-start: 1px solid var(--panel-border);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 22px;
  margin-bottom: 6px;
  border-bottom: 1px dashed var(--panel-border);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--brass), var(--brass-dim));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  color: #221a0a;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.brand-text strong {
  font-size: 14.5px;
  font-weight: 700;
}

.brand-text span {
  font-size: 11.5px;
  color: var(--text-faint);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item:hover {
  background: var(--panel-raised);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--panel-raised);
  color: var(--brass);
  box-shadow: inset 3px 0 0 var(--brass);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: inline-flex;
}
.nav-icon svg { width: 100%; height: 100%; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px dashed var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.logout-btn {
  background: none;
  border: 1px solid var(--panel-border);
  color: var(--text-muted);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.logout-btn:hover {
  border-color: var(--rose-dim);
  color: var(--rose);
}

main.content {
  grid-column: 1;
  padding: 28px 32px 60px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.page-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  margin: 0 0 4px;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 13.5px;
  margin: 0;
}

/* ---- buttons --------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(145deg, var(--brass), var(--brass-dim));
  color: #221a0a;
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-secondary {
  background: var(--panel-raised);
  color: var(--text-primary);
  border-color: var(--panel-border);
}
.btn-secondary:hover { border-color: var(--brass-dim); }

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

.btn-danger {
  background: transparent;
  color: var(--rose);
  border-color: var(--rose-dim);
}
.btn-danger:hover { background: rgba(224, 89, 107, 0.12); }

.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- cards & panels ---------------------------------------------------- */

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 20px;
}

.card + .card { margin-top: 16px; }

details.card summary {
  list-style: none;
}
details.card summary::-webkit-details-marker { display: none; }
details.card summary::before {
  content: "▸";
  display: inline-block;
  margin-left: 8px;
  color: var(--brass);
  transition: transform 0.15s ease;
}
details.card[open] summary::before { transform: rotate(90deg); }

.section-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---- stat tiles (dashboard) --------------------------------------------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}

.stat-tile {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
}

.stat-tile::after {
  content: "";
  position: absolute;
  inset-inline-end: -20px;
  top: -20px;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--tile-accent, var(--brass)) 0%, transparent 70%);
  opacity: 0.18;
}

.stat-tile .stat-icon { font-size: 20px; margin-bottom: 10px; display: block; }
.stat-tile .stat-value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 6px;
}
.stat-tile .stat-label { color: var(--text-muted); font-size: 12.5px; }

/* ---- ticket-stub event cards (dashboard "today's events") ---------------- */

.ticket-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}

.ticket {
  position: relative;
  background: linear-gradient(160deg, var(--panel-raised), var(--panel));
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 16px 16px 14px;
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.ticket:hover { transform: translateY(-2px); border-color: var(--brass-dim); }

.ticket::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 44px;
  bottom: 44px;
  width: 0;
  border-inline-start: 2px dashed var(--panel-border);
}

.ticket-eyebrow {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--brass);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.ticket-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 10px;
}

.ticket-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.ticket-meta b { color: var(--text-primary); font-family: var(--font-mono); font-weight: 600; }

.ticket-capacity {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(63, 167, 150, 0.14);
  color: var(--teal);
}
.ticket-capacity.full {
  background: rgba(224, 89, 107, 0.14);
  color: var(--rose);
}

/* ---- tables -------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

table.data-table th {
  text-align: right;
  color: var(--text-faint);
  font-weight: 600;
  font-size: 12px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--panel-border);
  white-space: nowrap;
}

table.data-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--panel-border);
  vertical-align: middle;
}

table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: rgba(255, 255, 255, 0.015); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
}
.badge-on { background: rgba(63, 167, 150, 0.15); color: var(--teal); }
.badge-off { background: rgba(154, 161, 172, 0.15); color: var(--text-muted); }
.badge-recurring { background: rgba(216, 161, 58, 0.15); color: var(--brass); }

/* ---- roster / sign-up sheet --------------------------------------------- */

.roster-sheet {
  background-image: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent 38px,
    var(--panel-border) 39px
  );
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.roster-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  height: 39px;
}

.roster-num {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--brass);
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.roster-name { flex: 1; font-size: 14px; }
.roster-sub { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-faint); }

.roster-paid {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  flex-shrink: 0;
}
.roster-paid input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
  cursor: pointer;
}

.roster-row .drag-handle {
  cursor: grab;
  color: var(--text-faint);
  padding: 2px 6px;
}
.roster-row.dragging { opacity: 0.4; }

/* ---- forms --------------------------------------------------------------- */

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-grid.single { grid-template-columns: 1fr; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.span-2 { grid-column: 1 / -1; }

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="date"],
input[type="time"],
input[type="tel"],
select,
textarea {
  background: var(--ink);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: inherit;
  width: 100%;
  transition: border-color 0.15s ease;
}
textarea { resize: vertical; min-height: 120px; font-family: var(--font-mono); line-height: 1.7; }

input:focus, select:focus, textarea:focus {
  border-color: var(--brass-dim);
  outline: none;
}

.hint { font-size: 11.5px; color: var(--text-faint); }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  cursor: pointer;
}
.checkbox-row input { width: auto; }

.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--ink);
  color: var(--text-muted);
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
}
.chip.selected {
  background: rgba(216, 161, 58, 0.16);
  border-color: var(--brass-dim);
  color: var(--brass);
}

/* ---- preview panel --------------------------------------------------------- */

.tg-preview {
  background: #0e1621;
  border-radius: var(--radius-lg);
  padding: 18px;
  border: 1px solid var(--panel-border);
}
.tg-bubble {
  background: #1f2c38;
  border-radius: 12px 12px 12px 2px;
  padding: 12px 14px;
  color: #e8edf1;
  font-size: 13.5px;
  line-height: 1.9;
  white-space: pre-wrap;
  max-width: 100%;
}

/* ---- calendar ------------------------------------------------------------ */

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.calendar-weekday {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-faint);
  padding-bottom: 6px;
}
.calendar-cell {
  min-height: 84px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 6px;
  background: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.calendar-cell:hover { border-color: var(--brass-dim); }
.calendar-cell.empty { background: transparent; border-color: transparent; cursor: default; }
.calendar-cell.today { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass) inset; }
.calendar-day-num { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.calendar-event-pill {
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(216, 161, 58, 0.16);
  color: var(--brass);
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- login ----------------------------------------------------------------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-card);
}
.login-card .brand { border-bottom: none; justify-content: center; padding-bottom: 18px; }
.login-error {
  background: rgba(224, 89, 107, 0.12);
  color: var(--rose);
  border: 1px solid var(--rose-dim);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 12.5px;
  margin-bottom: 14px;
}

/* ---- misc ------------------------------------------------------------------ */

.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-faint);
}
.empty-state .empty-icon { font-size: 30px; margin-bottom: 10px; opacity: 0.7; }

.toast-stack {
  position: fixed;
  bottom: 20px;
  inset-inline-start: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  background: var(--panel-raised);
  border: 1px solid var(--panel-border);
  border-inline-start: 3px solid var(--brass);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  animation: toast-in 0.2s ease;
}
.toast.error { border-inline-start-color: var(--rose); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  padding: 20px;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: var(--shadow-card);
}
.modal.modal-wide { max-width: 920px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.modal-header h2 { font-family: var(--font-display); font-size: 17px; margin: 0; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 20px; cursor: pointer; line-height: 1; }

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid var(--panel-border);
  border-top-color: var(--brass);
  animation: spin 0.7s linear infinite;
  margin: 24px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }

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

@media (max-width: 880px) {
  #app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    grid-column: 1;
    flex-direction: row;
    overflow-x: auto;
    align-items: center;
    padding: 12px;
  }
  .brand, .sidebar-footer { display: none; }
  main.content { padding: 20px 16px 50px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
}

/* Print / Save-as-PDF for the export preview table */
#pdf-print-area { display: none; }
@media print {
  body * { visibility: hidden !important; }
  #pdf-print-area, #pdf-print-area * { visibility: visible !important; }
  #pdf-print-area { display: block !important; position: absolute; inset: 0; direction: rtl; font-family: Vazir, Tahoma, sans-serif; color: #000; }
  #pdf-print-area table { width: 100%; border-collapse: collapse; font-size: 11px; }
  #pdf-print-area th, #pdf-print-area td { border: 1px solid #999; padding: 5px 7px; text-align: right; }
  #pdf-print-area h2 { margin: 0 0 12px; font-size: 16px; }
}