/* =====================================================================
   Events — Calm Card design system
   Single source of truth for tokens + components. Dark-only.
   ===================================================================== */

:root {
  /* Surfaces */
  --bg:           #0f0f10;
  --surface:      #18181b;
  --surface-2:    #1e1e22;
  --surface-3:    #26262b;
  --border:       #2a2a2e;
  --border-hover: #3a3a40;

  /* Text */
  --text:   #fafafa;
  --text-2: #a1a1aa;
  --text-3: #71717a;

  /* Accent (rose-400) */
  --accent:        #fb7185;
  --accent-hover:  #f43f5e;
  --accent-soft:   rgba(251, 113, 133, 0.12);
  --accent-ink:    #1a0a0d;

  /* Semantic */
  --danger: #f87171;
  --warn:   #fbbf24;
  --ok:     #34d399;

  /* Spacing */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;

  /* Radius */
  --r-1: 6px;
  --r-2: 10px;
  --r-3: 16px;
  --r-pill: 999px;

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Consolas, monospace;

  /* Motion */
  --t-fast: 150ms;
  --t-base: 220ms;
  --t-slow: 320ms;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);

  /* Layout */
  --content-max: 720px;
  --header-h:    56px;
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

/* Reset & base ---------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-1);
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; }
h1 { font-size: 28px; letter-spacing: -0.01em; }
h2 { font-size: 20px; }
h3 { font-size: 16px; color: var(--text-2); font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; }

p { margin: 0; }

/* Layout ---------------------------------------------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(15, 15, 16, 0.85);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  padding: 0 var(--s-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}

.app-header .brand {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
}

.app-header .brand:hover { color: var(--text); }

.app-header .brand .logo {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
}

.app-header .actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.app-main {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s-5) var(--s-4) calc(var(--s-7) + var(--safe-bottom));
}

.section { margin-top: var(--s-6); }
.section:first-child { margin-top: 0; }
.section .section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--s-3);
}

/* Centered single-column layout (auth pages) */
.center-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: var(--s-5);
}
.center-card {
  width: 100%;
  max-width: 380px;
}

/* Card ------------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  padding: var(--s-5);
}

/* Buttons --------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: 10px 16px;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--r-2);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); color: var(--accent-ink); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-2);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-hover); }

.btn-danger {
  background: transparent;
  border-color: var(--border);
  color: var(--danger);
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.08); border-color: var(--danger); }

.btn-block { width: 100%; }
.btn-sm { min-height: 32px; padding: 6px 12px; font-size: 13px; }
.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--r-pill);
}

/* Form fields ----------------------------------------------------------- */

.field {
  display: block;
  margin-bottom: var(--s-4);
}
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: var(--s-1);
}
.field-hint {
  display: block;
  font-size: 12px;
  color: var(--text-3);
  margin-top: var(--s-1);
}
.field-error {
  display: block;
  font-size: 13px;
  color: var(--danger);
  margin-top: var(--s-1);
}
.input,
.field input[type="text"],
.field input[type="password"],
.field input[type="tel"],
.field input[type="date"],
.field input[type="email"],
.field input[type="number"],
.field select,
.field textarea {
  display: block;
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  font: inherit;
  font-size: 16px; /* 16px prevents iOS zoom-on-focus */
  transition: border-color var(--t-fast) var(--ease);
}
.input:hover,
.field input:hover, .field select:hover, .field textarea:hover {
  border-color: var(--border-hover);
}
.input:focus,
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* Password show/hide */
.input-with-button {
  position: relative;
}
.input-with-button .input { padding-right: 44px; }
.input-with-button .toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  border-radius: var(--r-1);
  display: flex;
  align-items: center;
  justify-content: center;
}
.input-with-button .toggle:hover { color: var(--text); }

/* Chips ----------------------------------------------------------------- */

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-bottom: var(--s-3);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 6px 12px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid transparent;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.chip:hover { background: var(--surface-3); color: var(--text); }
.chip[aria-pressed="true"], .chip.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(251,113,133,0.4);
}

/* Event card ------------------------------------------------------------ */

.event-card {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  padding: var(--s-4) var(--s-5);
  margin-bottom: var(--s-3);
  transition: border-color var(--t-fast) var(--ease);
}
.event-card:hover { border-color: var(--border-hover); }
.event-card.is-today {
  border-color: rgba(251,191,36,0.45);
  background: linear-gradient(180deg, rgba(251,191,36,0.05), var(--surface) 60%);
}

.event-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-3);
}
.event-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  word-break: break-word;
}
.event-meta {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 2px;
}
.event-tag {
  flex: 0 0 auto;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.event-tag.tag-yearly {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(251,113,133,0.3);
}
.event-tag.tag-once {
  color: var(--text-2);
}
.event-tag.tag-today {
  color: var(--warn);
  background: rgba(251,191,36,0.1);
  border-color: rgba(251,191,36,0.4);
}

.event-hero {
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
  flex-wrap: wrap;
}
.event-hero .num {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1;
}
.event-hero .num.is-today { color: var(--warn); }
.event-hero .num-label { font-size: 13px; color: var(--text-3); }
.event-hero .num-sub { font-size: 13px; color: var(--text-2); }

.event-actions {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
}

/* Reminder cards (form) ------------------------------------------------- */

.reminder-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  padding: var(--s-3) var(--s-4);
  margin-bottom: var(--s-3);
}
.reminder-card .section-title {
  display: block;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}
.reminder-card .section-help {
  display: block;
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
  margin-bottom: var(--s-3);
}
.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-bottom: var(--s-3);
}
.checkbox-group label {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  min-height: 36px;
  -webkit-tap-highlight-color: transparent;
}
.checkbox-group label:hover { border-color: var(--border-hover); }
.checkbox-group input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border-hover);
  border-radius: 4px;
  background: var(--bg);
  cursor: pointer;
  display: inline-grid;
  place-content: center;
}
.checkbox-group input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.checkbox-group input[type="checkbox"]:checked::before {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--accent-ink);
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0, 43% 62%);
}
.checkbox-group label:has(input:checked) {
  background: var(--accent-soft);
  border-color: rgba(251,113,133,0.45);
}

/* FAB ------------------------------------------------------------------- */

.fab {
  position: fixed;
  right: max(var(--s-4), env(safe-area-inset-right));
  bottom: calc(var(--s-5) + env(safe-area-inset-bottom));
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 14px 20px;
  border: none;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45), 0 2px 6px rgba(0,0,0,0.3);
  transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.fab:hover { background: var(--accent-hover); }
.fab:active { transform: scale(0.96); }

/* Bottom sheet ---------------------------------------------------------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
}
.sheet[hidden] { display: none !important; }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  opacity: 0;
  transition: opacity var(--t-base) var(--ease);
  pointer-events: auto;
}
.sheet[data-open="true"] .sheet-backdrop { opacity: 1; }

.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 90dvh;
  background: var(--surface);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  border: 1px solid var(--border);
  border-bottom: none;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform var(--t-slow) var(--ease);
  pointer-events: auto;
  padding-bottom: var(--safe-bottom);
}
.sheet[data-open="true"] .sheet-panel { transform: translateY(0); }

@media (min-width: 720px) {
  .sheet { align-items: center; }
  .sheet-panel {
    border-radius: var(--r-3);
    border: 1px solid var(--border);
    margin: 0 var(--s-4);
  }
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border-hover);
  border-radius: 2px;
  margin: 8px auto 0;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-5) var(--s-2);
}
.sheet-head h2 { font-size: 18px; }
.sheet-body {
  padding: var(--s-2) var(--s-5) var(--s-5);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.sheet-body form .btn-primary { margin-top: var(--s-3); }

/* Toast ----------------------------------------------------------------- */

.toast-region {
  position: fixed;
  top: calc(var(--header-h) + 8px);
  left: 0;
  right: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  pointer-events: none;
  padding: 0 var(--s-3);
}
.toast {
  pointer-events: auto;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  padding: 10px 16px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toast-in var(--t-base) var(--ease);
  max-width: 90vw;
}
.toast.toast-ok { border-color: rgba(52,211,153,0.4); }
.toast.toast-err { border-color: rgba(248,113,113,0.5); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* HTMX loading spinner -------------------------------------------------- */

.htmx-indicator {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline-block; }
.htmx-request { opacity: 0.7; }
@keyframes spin { to { transform: rotate(360deg); } }

/* List link rows -------------------------------------------------------- */

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  margin-bottom: var(--s-2);
  color: var(--text);
  text-decoration: none;
  transition: border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.list-row:hover { color: var(--text); border-color: var(--border-hover); }
.list-row:active { transform: scale(0.99); }
.list-row .name { font-weight: 500; }
.list-row .count { color: var(--text-3); font-size: 13px; }
.list-row .arrow { color: var(--text-3); }

/* Empty state ----------------------------------------------------------- */

.empty {
  text-align: center;
  padding: var(--s-7) var(--s-4);
  color: var(--text-3);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--r-3);
}
.empty .empty-title {
  display: block;
  color: var(--text-2);
  font-weight: 500;
  margin-bottom: var(--s-1);
}

/* Footer ---------------------------------------------------------------- */

.app-footer {
  margin-top: var(--s-7);
  padding-top: var(--s-4);
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
}

/* Utilities ------------------------------------------------------------- */

.muted   { color: var(--text-3); }
.text-2  { color: var(--text-2); }
.text-accent { color: var(--accent); }
.row     { display: flex; gap: var(--s-3); align-items: center; }
.row-between { display: flex; gap: var(--s-3); align-items: center; justify-content: space-between; }
.stack-2 > * + * { margin-top: var(--s-2); }
.stack-3 > * + * { margin-top: var(--s-3); }
.stack-4 > * + * { margin-top: var(--s-4); }
.hide-mobile { }
@media (max-width: 540px) {
  .hide-mobile { display: none !important; }
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

/* Reduced motion -------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
