/* Component layer. Page layout utilities come from Tailwind.
   Tokens are shared so light/dark and Tamil text stay consistent. */

:root {
  --bg: #f4f0e6;
  --surface: #fffcf7;
  --surface-2: #f3eee4;
  --text: #1c1917;
  --muted: #57534e;
  --line: #e6dfd2;
  --brand: #1e3a5f;
  --on-brand: #ffffff;
  --gold: #b45309;
  --danger: #9f1239;
  --ok: #047857;
  --shadow: 0 10px 30px rgb(28 25 23 / 0.06);
  color-scheme: light;
}

html.dark {
  --bg: #0b1220;
  --surface: #141c2f;
  --surface-2: #1c2740;
  --text: #f5f5f4;
  --muted: #a8a29e;
  --line: #2c3b58;
  --brand: #93c5fd;
  --on-brand: #0b1220;
  --gold: #fbbf24;
  --danger: #fda4af;
  --ok: #6ee7b7;
  --shadow: 0 12px 32px rgb(0 0 0 / 0.35);
  color-scheme: dark;
}

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Nirmala UI", "Noto Sans Tamil", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; }

[hidden] { display: none !important; }

.btn:disabled, .icon-btn:disabled { opacity: 0.45; cursor: not-allowed; }

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.shell {
  width: min(72rem, 100%);
  margin-inline: auto;
  padding: 0.85rem 0.85rem 1.25rem;
}

.top-row {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

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

.meta-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;
}

#chips {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.2rem;
}

#list { display: grid; gap: 0.75rem; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar-line {
  height: 3px;
  background: linear-gradient(90deg, var(--brand), var(--gold), var(--brand));
}

.brand-mark {
  width: 2.75rem;
  height: 2.75rem;
  flex: none;
  border-radius: 0.9rem;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
}

html.dark .brand-mark { color: #0b1220; background: var(--brand); }

.kicker {
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field {
  width: 100%;
  min-height: 48px;
  border-radius: 0.85rem;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  padding: 0.55rem 0.8rem;
  font-size: 1rem;
  line-height: 1.45;
}

textarea.field {
  height: auto;
  min-height: 4.5rem;
  resize: vertical;
}

.field:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  border-color: var(--brand);
}

.label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--muted);
}

.search-wrap { position: relative; margin-top: 0.75rem; }
.search-wrap svg {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.search-input { padding-left: 2.6rem; }

.btn, .icon-btn, .chip, .drag-handle {
  min-height: 44px;
  border-radius: 0.85rem;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 0.4rem 0.85rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.2;
}

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

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

.btn-ghost { background: var(--surface); }

.icon-btn {
  width: 44px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

.btn:hover, .icon-btn:hover, .chip:hover, .drag-handle:hover {
  border-color: var(--brand);
}

.chip {
  border-radius: 999px;
  white-space: nowrap;
  background: var(--surface);
}

.chip[aria-pressed="true"] {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 1.15rem;
  box-shadow: var(--shadow);
  padding: 0.85rem;
}

.card-row { display: flex; gap: 0.75rem; align-items: flex-start; }
.card-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 0.45rem; }

.drag-handle {
  width: 44px;
  flex: none;
  display: grid;
  place-items: center;
  cursor: grab;
  touch-action: none;
  user-select: none;
  background: var(--surface-2);
  color: var(--muted);
}

.drag-handle:active { cursor: grabbing; }
.drag-handle[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }

.card.is-dragging {
  opacity: 0.55;
  outline: 2px dashed var(--brand);
}

.card-meta, .card-actions, .people, .row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.order-input {
  width: 3.4rem;
  min-height: 44px;
  text-align: center;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  border-radius: 0.85rem;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
}

.order-input::-webkit-outer-spin-button,
.order-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.order-input { -moz-appearance: textfield; appearance: textfield; }

.time-pill {
  font-weight: 700;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
}

.cat, .flag, .person, .more {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.45;
}

.cat[data-cat="Ceremony"] { background: #e0e7ff; color: #312e81; }
.cat[data-cat="Speech"] { background: #dbeafe; color: #1e3a8a; }
.cat[data-cat="Song"] { background: #fce7f3; color: #9d174d; }
.cat[data-cat="Dance"] { background: #ffedd5; color: #9a3412; }
.cat[data-cat="Drama"] { background: #ede9fe; color: #5b21b6; }
.cat[data-cat="Poem"] { background: #d1fae5; color: #065f46; }
.cat[data-cat="Music"] { background: #cffafe; color: #155e75; }
.cat[data-cat="Honoring"] { background: #fef3c7; color: #92400e; }
.cat[data-cat="Special"] { background: #f3e8ff; color: #6b21a8; }

html.dark .cat[data-cat="Ceremony"] { background: #1e1b4b; color: #c7d2fe; }
html.dark .cat[data-cat="Speech"] { background: #172554; color: #bfdbfe; }
html.dark .cat[data-cat="Song"] { background: #500724; color: #fbcfe8; }
html.dark .cat[data-cat="Dance"] { background: #431407; color: #fed7aa; }
html.dark .cat[data-cat="Drama"] { background: #2e1065; color: #ddd6fe; }
html.dark .cat[data-cat="Poem"] { background: #022c22; color: #a7f3d0; }
html.dark .cat[data-cat="Music"] { background: #083344; color: #a5f3fc; }
html.dark .cat[data-cat="Honoring"] { background: #451a03; color: #fde68a; }
html.dark .cat[data-cat="Special"] { background: #3b0764; color: #e9d5ff; }

.flag-shawl { background: #fef3c7; color: #92400e; }
.flag-shield { background: #ccfbf1; color: #115e59; }
html.dark .flag-shawl { background: #451a03; color: #fde68a; }
html.dark .flag-shield { background: #042f2e; color: #99f6e4; }

.person, .more {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
}

.card-title {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.45;
  font-weight: 800;
}

.card-sub, .card-org, .detail-block p { margin: 0; color: var(--muted); font-size: 0.95rem; }
.card-org { color: var(--text); }

.details {
  border-top: 1px solid var(--line);
  padding-top: 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.detail-block strong {
  display: block;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  color: var(--gold);
}

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

.modal-back {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgb(0 0 0 / 0.5);
  padding: 0;
}

.modal-panel {
  width: 100%;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--text);
  border-radius: 1.4rem 1.4rem 0 0;
  box-shadow: var(--shadow);
}

#modal .modal-panel { overflow: hidden; height: 100dvh; }

#event-form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.modal-head, .modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
}

.modal-foot {
  border-bottom: 0;
  border-top: 1px solid var(--line);
  justify-content: flex-end;
  padding-bottom: max(0.9rem, env(safe-area-inset-bottom));
}

.modal-body {
  overflow: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-head h2 { margin: 0; font-size: 1.2rem; }

.form-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;
}

.stack { display: flex; flex-direction: column; gap: 0.45rem; }

.entry {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
}
.entry:last-child { border-bottom: 0; }
.entry-num {
  width: 1.85rem;
  height: 1.85rem;
  margin-top: 0.15rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  flex: none;
  font-weight: 800;
  font-size: 0.85rem;
  background: var(--brand);
  color: var(--on-brand);
}
.entry-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.entry-name { margin: 0; font-weight: 800; line-height: 1.45; }
.entry-intro { margin: 0; color: var(--muted); line-height: 1.45; }
.duration-pill {
  font-weight: 700;
  color: var(--gold);
  font-size: 0.95rem;
}
.duration-field { display: flex; align-items: center; gap: 0.5rem; }
.duration-field .field { max-width: 7.5rem; }
.minute-suffix { font-weight: 800; white-space: nowrap; }
.garland-line { display: flex; flex-direction: column; gap: 0.25rem; margin-top: 0.15rem; }
.garland-label { color: var(--gold); font-size: 0.85rem; font-weight: 800; }
.row .field { flex: 1; min-width: 0; }

.check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
  font-weight: 700;
}

.check input { width: 1.15rem; height: 1.15rem; accent-color: var(--brand); }

.section-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 800;
}

.confirm-panel { max-width: 32rem; margin: 1rem; border-radius: 1.2rem; padding: 1.1rem; }
.confirm-panel p { color: var(--muted); }

.toast {
  position: fixed;
  z-index: 70;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--brand);
  color: var(--on-brand);
  padding: 0.7rem 1rem;
  border-radius: 999px;
  font-weight: 700;
  max-width: min(92vw, 36rem);
  text-align: center;
  box-shadow: var(--shadow);
}

.program-details summary {
  cursor: pointer;
  font-weight: 700;
  min-height: 44px;
  display: flex;
  align-items: center;
  color: var(--brand);
}
.program-details[open] summary { margin-bottom: 0.65rem; }

.stat { color: var(--muted); font-size: 0.9rem; }
.hint { color: var(--muted); font-size: 0.8rem; }

#print-view[hidden] { display: none !important; }
#print-view {
  position: fixed;
  inset: 0;
  z-index: 70;
  overflow: auto;
  background: rgba(15, 23, 42, 0.78);
  padding: 4.75rem 1rem 2rem;
}
.print-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 71;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.print-page {
  display: block;
  width: min(794px, 100%);
  height: auto;
  margin: 0 auto 1rem;
  background: #fffaf3;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

@media (min-width: 640px) {
  .shell { padding: 1rem 1.5rem 1.5rem; }
  .top-row { flex-direction: row; align-items: center; justify-content: space-between; }
  .meta-grid { grid-template-columns: 1fr 1fr; }
  .card { padding: 1rem 1.05rem; }
  .modal-back { align-items: center; padding: 1.5rem; }
  .modal-panel {
    max-width: 48rem;
    max-height: 90vh;
    border-radius: 1.4rem;
  }
  #modal .modal-panel { height: min(90vh, 920px); }
  .form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .span-2 { grid-column: span 2; }
  .span-3 { grid-column: span 3; }
}

@media (min-width: 1024px) {
  .meta-grid { grid-template-columns: 1.3fr 1.3fr 0.8fr 0.8fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}

@media print {
  @page { size: A4; margin: 0; }
  .app-shell, .modal-back, .toast, .print-bar { display: none !important; }
  #print-view {
    display: block !important;
    position: static;
    overflow: visible;
    background: #fff;
    padding: 0;
  }
  .print-page {
    width: 210mm;
    height: 297mm;
    object-fit: fill;
    margin: 0;
    box-shadow: none;
    break-after: page;
    page-break-after: always;
  }
}
