/* ============================================================
   FAENA v4 — Base styles + components. Mobile-first.
   ============================================================ */

* { box-sizing: border-box; }
html, body {
  background: var(--bg); color: var(--ink); margin: 0; padding: 0;
  -webkit-text-size-adjust: 100%;
}
body {
  font-family: var(--t-sans); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
  /* Reserve room for bottom nav on phones; desktop overrides */
  padding-bottom: var(--bottomnav-h-safe, var(--bottomnav-h));
}

/* ---------- Type ---------- */
.serif    { font-family: var(--t-serif); font-weight: 400; letter-spacing: -0.01em; }
.display  { font-family: var(--t-display); font-style: italic; letter-spacing: -0.005em; }
.mono     { font-family: var(--t-mono); }
.upper    { text-transform: uppercase; letter-spacing: 0.14em; font-size: 11px; color: var(--muted); font-weight: 500; }
.upper-sm { text-transform: uppercase; letter-spacing: 0.16em; font-size: 10px; color: var(--muted-2); }

h1, h2, h3, h4 { font-family: var(--t-serif); font-weight: 400; letter-spacing: -0.015em; line-height: 1.1; margin: 0; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }

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

p { margin: 0; }

/* ---------- Layout helpers ---------- */
.wrap { width: 100%; max-width: var(--max-w); margin: 0 auto; padding: 0 16px; }
main { padding: 16px 0 24px; min-height: calc(100vh - var(--topbar-h) - var(--bottomnav-h)); }
.page { display: block; }
.stack > * + * { margin-top: var(--gap-3); }
.stack-sm > * + * { margin-top: var(--gap-2); }
.stack-lg > * + * { margin-top: var(--gap-4); }

.grid { display: grid; gap: var(--gap-3); }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: 1fr 1fr; }

.flex     { display: flex; gap: var(--gap-2); }
.flex-col { flex-direction: column; }
.flex-1   { flex: 1; min-width: 0; }
.items-center { align-items: center; }
.items-start  { align-items: flex-start; }
.items-end    { align-items: flex-end; }
.items-baseline { align-items: baseline; }
.justify-between { justify-content: space-between; }
.justify-end     { justify-content: flex-end; }
.justify-center  { justify-content: center; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: var(--gap-1); }
.gap-2 { gap: var(--gap-2); }
.gap-3 { gap: var(--gap-3); }
.gap-4 { gap: var(--gap-4); }

.hide-desktop { }
.hide-mobile  { display: none; }

.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

.text-sm    { font-size: 13px; }
.text-xs    { font-size: 12px; }
.text-lg    { font-size: 16px; }
.text-xl    { font-size: 20px; }
.text-muted { color: var(--muted); }
.text-accent{ color: var(--accent); }
.text-right { text-align: right; }
.text-center{ text-align: center; }

.mt-0 { margin-top: 0; } .mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; } .mt-8 { margin-top: 32px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 0.6rem 0.95rem; font: inherit; font-weight: 500; font-size: 14px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--r);
  cursor: pointer; transition: background .12s ease, border-color .12s ease, color .12s ease;
  text-decoration: none; line-height: 1; white-space: nowrap;
  min-height: 44px;                 /* iOS tap target */
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-2); }
.btn:active { transform: translateY(0.5px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #FFF; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: #FFF; }

.btn-soft  { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.btn-soft:hover { background: #EFD2CB; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); }

.btn-danger { background: transparent; color: var(--accent); border-color: transparent; }
.btn-danger:hover { background: var(--accent-soft); color: var(--accent-2); }

.btn-sm    { padding: .4rem .7rem; font-size: 13px; min-height: 36px; }
.btn-xs    { padding: .25rem .5rem; font-size: 12px; min-height: 28px; }
.btn-lg    { padding: .85rem 1.3rem; font-size: 15px; min-height: 48px; }
.btn-icon  { width: 44px; height: 44px; padding: 0; }
.btn-icon.btn-sm { width: 36px; height: 36px; }
.btn-block { width: 100%; }

/* ---------- Inputs ---------- */
input, textarea, select {
  font: inherit; color: var(--ink); width: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 0.65rem 0.75rem;
  transition: border-color .12s ease, box-shadow .12s ease;
  min-height: 44px;
  font-size: 16px;                  /* prevents iOS zoom-on-focus */
  appearance: none; -webkit-appearance: none;
}
input[type="checkbox"], input[type="radio"] { width: auto; height: auto; min-height: 0; }
textarea { min-height: 80px; resize: vertical; line-height: 1.45; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
::placeholder { color: var(--muted-2); opacity: 1; }

.fld { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.fld-row { display: flex; flex-direction: column; }
.fld-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.fld-error { font-size: 12px; color: var(--accent); margin-top: 4px; }

.inline-input {
  background: transparent; border: 1px solid transparent;
  padding: 6px 8px; border-radius: 4px; min-height: 36px;
  font-size: 15px;
}
.inline-input:hover { background: var(--surface-2); }
.inline-input:focus { background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.card-hover { cursor: pointer; }
.card-hover:hover { border-color: var(--border-2); box-shadow: var(--shadow-md); }
.card-pad    { padding: 16px; }
.card-pad-lg { padding: 20px; }
.card-accent { border-top: 3px solid var(--accent); }
.card-divider { border-top: 1px solid var(--border); margin: 14px 0; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.section-head h2 { font-size: 1.3rem; }
.section-head .upper { margin: 0; }

/* ---------- Chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; font-size: 11px; font-weight: 500;
  background: var(--surface-2); color: var(--ink-2);
  border: 1px solid var(--border); border-radius: 100px; line-height: 1.4;
  white-space: nowrap;
}
.chip-red     { background: var(--accent); color: #FFF; border-color: var(--accent); }
.chip-soft    { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.chip-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.chip-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.chip-outline { background: transparent; border-color: var(--border-2); color: var(--ink-2); }

.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; background: currentColor; }

/* ---------- Empty states ---------- */
.empty {
  text-align: center; padding: 36px 20px;
  background: var(--surface); border: 1px dashed var(--border-2); border-radius: var(--r-lg);
}
.empty-title { font-family: var(--t-serif); font-size: 1.5rem; margin-bottom: 4px; color: var(--ink); }
.empty-body  { color: var(--muted); font-size: 14px; max-width: 380px; margin: 0 auto 16px; }

/* ---------- Tables (used on desktop; collapse on mobile) ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 500; padding: 10px 12px; border-bottom: 1px solid var(--border); }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.table-card tr.row-hover:hover { background: var(--surface-2); cursor: pointer; }

/* ---------- KPI ---------- */
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 14px 16px;
}
.kpi-label { font-size: 10px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); margin-bottom: 4px; }
.kpi-value { font-family: var(--t-mono); font-size: 22px; color: var(--ink); line-height: 1.15; }
.kpi-meta  { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ---------- Progress ---------- */
.progress { background: var(--surface-3); border-radius: 100px; height: 8px; overflow: hidden; }
.progress-fill { background: var(--accent); height: 100%; transition: width .25s ease; }

.progress-ring-svg { transform: rotate(-90deg); }
.progress-ring-track { stroke: var(--surface-3); }
.progress-ring-fill  { stroke: var(--accent); transition: stroke-dashoffset .3s ease; }

/* ---------- Checklist rows ---------- */
.check-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 8px; border-radius: 6px;
  transition: background .12s ease;
}
.check-row:hover { background: var(--surface-2); }
.check-row .check-text { flex: 1; outline: none; min-height: 24px; line-height: 1.4; padding: 2px 0; }
.check-row.done .check-text { color: var(--muted); text-decoration: line-through; }
.check-row .check-remove {
  background: transparent; border: 0; color: var(--muted); cursor: pointer;
  padding: 4px 8px; font-size: 18px; line-height: 1;
}

/* ---------- Media ---------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.media-thumb { position: relative; aspect-ratio: 1; background: var(--surface-2); border-radius: 6px; overflow: hidden; cursor: pointer; border: 1px solid var(--border); }
.media-thumb img, .media-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-thumb .rm { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.55); color: #FFF; border: 0; border-radius: 100px; width: 24px; height: 24px; cursor: pointer; font-size: 14px; line-height: 1; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.88); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 24px; }
.lightbox img, .lightbox video { max-width: 100%; max-height: 100%; }
.lightbox .close { position: absolute; top: env(safe-area-inset-top, 12px); right: 12px; background: rgba(255,255,255,.15); color: #FFF; border: 0; padding: 10px 14px; border-radius: 6px; cursor: pointer; }

/* ---------- Login screen ---------- */
.login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #FAFAF7 0%, #F4EFE5 60%, #ECE3D2 100%);
  padding: 24px;
  padding-bottom: env(safe-area-inset-bottom);
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 32px 24px; box-shadow: var(--shadow-lg);
}
.login-mascot   { display: block; width: 96px; height: auto; margin: 0 auto 12px; }
.login-wordmark { display: block; max-width: 180px; height: auto; margin: 0 auto 8px; }
.login-sub      { text-align: center; font-size: 11px; text-transform: uppercase; letter-spacing: .22em; color: var(--muted); margin-bottom: 22px; }
.login-error    { color: var(--accent); font-size: 13px; padding: 10px 12px; background: var(--accent-soft); border-radius: 6px; margin-top: 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(var(--bottomnav-h-safe, var(--bottomnav-h)) + 16px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #FFF;
  padding: 10px 18px; border-radius: 100px; font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2); z-index: 250;
  animation: toastIn .2s ease;
  max-width: calc(100% - 24px);
}
.toast.toast-success { background: var(--success); }
.toast.toast-warning { background: var(--warning); }
.toast.toast-error   { background: var(--accent); }
@keyframes toastIn { from { transform: translate(-50%, 8px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ---------- Sheet / modal (mobile-first: sheet from bottom) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(20,18,14,.42); backdrop-filter: blur(2px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn .15s ease;
}
.sheet {
  width: 100%; max-width: 720px;
  background: var(--surface); border-radius: var(--r-lg) var(--r-lg) 0 0;
  max-height: 92vh; display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  animation: slideUp .2s ease;
}
.sheet-handle { width: 36px; height: 4px; background: var(--surface-4); border-radius: 100px; margin: 10px auto 4px; }
.sheet-head   { padding: 8px 20px 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-head h3{ font-size: 1.25rem; }
.sheet-body   { padding: 4px 20px 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.sheet-foot   { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------- Item rows ---------- */
.item-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 12px; border-bottom: 1px solid var(--border);
  min-height: 60px;
}
.item-row:last-child { border-bottom: 0; }
.item-row .item-grow { flex: 1; min-width: 0; }
.item-row .item-meta { color: var(--muted); font-size: 12px; }
.item-row.tap { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.item-row.tap:active { background: var(--surface-2); }

/* ---------- Tab pill row (event detail sub-nav) ---------- */
.pillrow {
  display: flex; gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch;
  padding: 8px 0 10px; margin: 0 -4px; scrollbar-width: none;
}
.pillrow::-webkit-scrollbar { display: none; }
.pillrow .pill {
  flex: 0 0 auto; padding: 8px 14px; font-size: 13px; font-weight: 500;
  background: var(--surface); color: var(--ink-2);
  border: 1px solid var(--border); border-radius: 100px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.pillrow .pill.active { background: var(--ink); color: #FFF; border-color: var(--ink); }

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.spacer  { flex: 1; }

/* Hide elements meant only for print */
.print-only { display: none; }
