/* =========================================================================
   Twin Cities Top Down Photography — brand tokens and base styles
   Source of truth: /brand.md. No hex value belongs anywhere but this file.
   ========================================================================= */

:root {
  /* Primary */
  --tctd-deep-purple:  #490d60;
  --tctd-mid-purple:   #7b1a7d;
  --tctd-bright-pink:  #b92f8b;
  --tctd-soft-pink:    #da7ab5;

  /* Neutrals */
  --tctd-white:        #ffffff;
  --tctd-black:        #000000;
  --tctd-warm-gray:    #dbdcd7;

  /* Gradient */
  --tctd-gradient: linear-gradient(135deg, var(--tctd-mid-purple), var(--tctd-bright-pink));

  /* Type */
  --tctd-font-head: 'Oswald', 'Arial Narrow', sans-serif;
  --tctd-font-body: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --tctd-head-lh: 1.1;
  --tctd-head-ls: 0.02em;
  --tctd-body-lh: 1.75;

  /* Semantic aliases — use these in components, not the raw colors above */
  --tctd-bg-anchor:  var(--tctd-deep-purple);
  --tctd-bg-section: var(--tctd-mid-purple);
  --tctd-action:     var(--tctd-bright-pink);
  --tctd-whisper:    var(--tctd-soft-pink);
  --tctd-divider:    var(--tctd-warm-gray);

  /* Derived neutrals. Warm gray is the only gray: these are tints of it,
     never blue-toned. */
  --tctd-surface:     #ffffff;
  --tctd-surface-alt: #f6f6f4;
  --tctd-ink:         #1c1218;
  --tctd-ink-muted:   #5f5560;
  --tctd-border:      #e4e4e0;

  /* Status. Kept outside the brand palette on purpose: these must read as
     system feedback, not decoration. */
  --tctd-ok:    #1f7a48;
  --tctd-warn:  #9a6212;
  --tctd-error: #a41f2e;

  /* Scale */
  --tctd-radius:    6px;
  --tctd-radius-lg: 12px;
  --tctd-shadow:    0 1px 2px rgba(28, 18, 24, 0.06), 0 4px 12px rgba(28, 18, 24, 0.05);
  --tctd-shadow-lg: 0 12px 32px rgba(28, 18, 24, 0.14);

  --tctd-space-1: 4px;
  --tctd-space-2: 8px;
  --tctd-space-3: 12px;
  --tctd-space-4: 16px;
  --tctd-space-5: 24px;
  --tctd-space-6: 32px;
  --tctd-space-7: 48px;
  --tctd-space-8: 64px;
}

/* ---- reset ------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

/* The `hidden` attribute must actually hide things.
 *
 * Browsers implement `hidden` as a UA-stylesheet rule (`[hidden]{display:none}`),
 * and ANY author `display` declaration outranks it — author styles beat UA
 * styles regardless of specificity. So `.thing { display: grid }` silently
 * defeats `el.hidden = true`, and the element stays on screen while the
 * JavaScript is convinced it is gone.
 *
 * This cost real debugging time: the portal's loading gate is `display: grid`
 * for centring, so `gate.hidden = true` did nothing and a full-viewport
 * "Loading your portal…" panel sat on top of a portal that had loaded fine.
 * `!important` is the point — it has to win against author rules, which is the
 * whole problem being solved.
 */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--tctd-font-body);
  font-weight: 400;
  line-height: var(--tctd-body-lh);
  color: var(--tctd-ink);
  background: var(--tctd-surface);
  -webkit-font-smoothing: antialiased;
}

img, video, canvas { max-width: 100%; height: auto; display: block; }

/* ---- type -------------------------------------------------------------- */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--tctd-font-head);
  font-weight: 700;
  line-height: var(--tctd-head-lh);
  letter-spacing: var(--tctd-head-ls);
  text-transform: uppercase;
  margin: 0 0 var(--tctd-space-4);
}

h1 { font-size: clamp(2.6rem, 5vw, 4.6rem); }
h2 { font-size: clamp(1.7rem, 3vw, 2.5rem); }
h3 { font-size: 1.4rem; }
h4 { font-size: 1.15rem; }

p { margin: 0 0 var(--tctd-space-4); }

/* Oswald has no usable italic — taglines and quotes use DM Sans italic. */
blockquote, .tctd-tagline {
  font-family: var(--tctd-font-body);
  font-style: italic;
  font-weight: 300;
}

.tctd-eyebrow {
  font-family: var(--tctd-font-body);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--tctd-mid-purple);
  margin: 0 0 var(--tctd-space-2);
}

/* Soft pink fails contrast on white. On light backgrounds a whisper is mid
   purple; soft pink is reserved for dark ones. */
.tctd-on-dark .tctd-eyebrow { color: var(--tctd-whisper); }

.tctd-caption {
  font-size: 0.85rem;
  font-weight: 300;
  color: var(--tctd-ink-muted);
}

a { color: var(--tctd-mid-purple); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--tctd-bright-pink); }

/* Property addresses are headline material. */
.tctd-address {
  font-family: var(--tctd-font-head);
  font-weight: 700;
  text-transform: uppercase;
  line-height: var(--tctd-head-lh);
  letter-spacing: var(--tctd-head-ls);
}
.tctd-address small {
  display: block;
  font-family: var(--tctd-font-body);
  font-weight: 400;
  font-size: 0.5em;
  letter-spacing: 0;
  text-transform: none;
  color: var(--tctd-ink-muted);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--tctd-space-2);
  font-family: var(--tctd-font-body);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1;
  padding: 12px 20px;
  border: 1px solid transparent;
  border-radius: var(--tctd-radius);
  cursor: pointer;
  text-decoration: none;
  transition: filter 120ms ease, background-color 120ms ease, border-color 120ms ease;
  white-space: nowrap;
}

.btn:disabled, .btn[aria-disabled='true'] { opacity: 0.5; cursor: not-allowed; }

/* Primary carries the signature gradient — the main action, per brand.md. */
.btn-primary {
  background: var(--tctd-gradient);
  color: var(--tctd-white);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); color: var(--tctd-white); }

.btn-secondary {
  background: transparent;
  color: var(--tctd-mid-purple);
  border-color: var(--tctd-mid-purple);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--tctd-mid-purple);
  color: var(--tctd-white);
}

.btn-ghost {
  background: transparent;
  color: var(--tctd-ink-muted);
  border-color: var(--tctd-border);
}
.btn-ghost:hover:not(:disabled) { color: var(--tctd-ink); border-color: var(--tctd-ink-muted); }

.btn-danger { background: var(--tctd-error); color: var(--tctd-white); }
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); color: var(--tctd-white); }

.btn-sm { padding: 8px 14px; font-size: 13px; }

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

label, .label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--tctd-ink-muted);
  margin-bottom: var(--tctd-space-2);
}

input[type='text'], input[type='email'], input[type='password'], input[type='tel'],
input[type='number'], input[type='url'], input[type='date'], input[type='datetime-local'],
input[type='search'], select, textarea {
  width: 100%;
  font-family: var(--tctd-font-body);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.4;
  color: var(--tctd-ink);
  background: var(--tctd-white);
  border: 1px solid var(--tctd-border);
  border-radius: var(--tctd-radius);
  padding: 10px 12px;
}

textarea { min-height: 110px; resize: vertical; line-height: 1.6; }

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--tctd-bright-pink);
  outline-offset: 1px;
  border-color: var(--tctd-bright-pink);
}

/* Visible focus for keyboard users everywhere, not just form fields. */
:focus-visible { outline: 2px solid var(--tctd-bright-pink); outline-offset: 2px; }

.field { margin-bottom: var(--tctd-space-4); }
.field-hint { font-size: 12px; color: var(--tctd-ink-muted); margin-top: var(--tctd-space-1); }
.field-error { font-size: 12px; color: var(--tctd-error); margin-top: var(--tctd-space-1); }
/* A hint that has turned into a complaint — same line, same place, so the form
   does not jump when a field starts failing as it is typed into. */
.field-hint.is-error { color: var(--tctd-error); }

.field-row {
  display: grid;
  gap: var(--tctd-space-4);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.p-category-checks {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tctd-space-2) var(--tctd-space-4);
}
.p-category-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--tctd-ink);
  cursor: pointer;
}
.p-category-check input { width: auto; margin: 0; }

/* ---- surfaces ---------------------------------------------------------- */

.card {
  background: var(--tctd-white);
  border: 1px solid var(--tctd-border);
  border-radius: var(--tctd-radius-lg);
  box-shadow: var(--tctd-shadow);
  padding: var(--tctd-space-5);
}

.tctd-on-dark {
  background: var(--tctd-bg-anchor);
  color: var(--tctd-white);
}
.tctd-on-dark p { font-weight: 300; }
.tctd-on-dark a { color: var(--tctd-whisper); }

/* ---- badges ------------------------------------------------------------ */

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--tctd-surface-alt);
  color: var(--tctd-ink-muted);
  border: 1px solid var(--tctd-border);
  white-space: nowrap;
}

.badge-draft     { background: #f2f2ef; color: #5f5560; }
.badge-live      { background: #e6f3ec; color: var(--tctd-ok); border-color: #c4e3d2; }
.badge-sold      { background: #f3e9f5; color: var(--tctd-mid-purple); border-color: #e2cfe8; }
.badge-archived  { background: #f2f2ef; color: #857d86; }
.badge-booked    { background: #fdf0e2; color: var(--tctd-warn); border-color: #f2dcbd; }

/* Order lifecycle. `requested` reads as "needs your attention" on purpose —
   nothing has checked a calendar yet, so it is not a confirmed booking. */
.badge-requested { background: #fdf0e2; color: var(--tctd-warn); border-color: #f2dcbd; }
.badge-confirmed { background: #eef0fb; color: #3c4a99; border-color: #d5daf3; }
.badge-completed { background: #e6f3ec; color: var(--tctd-ok); border-color: #c4e3d2; }
.badge-cancelled { background: #f7ecee; color: var(--tctd-error); border-color: #ecd4d8; }
.badge-shot      { background: #eef0fb; color: #3c4a99; border-color: #d5daf3; }
.badge-editing   { background: #fdf0e2; color: var(--tctd-warn); border-color: #f2dcbd; }
.badge-delivered { background: #e6f3ec; color: var(--tctd-ok); border-color: #c4e3d2; }

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

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

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.data th {
  font-family: var(--tctd-font-body);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--tctd-ink-muted);
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--tctd-border);
  white-space: nowrap;
}
table.data td {
  padding: 12px;
  border-bottom: 1px solid var(--tctd-border);
  vertical-align: middle;
}
table.data tbody tr:hover { background: var(--tctd-surface-alt); }
table.data th.is-sortable { cursor: pointer; user-select: none; }
table.data th.is-sortable:hover { color: var(--tctd-ink); }
table.data th.is-sorted { color: var(--tctd-ink); }
table.data th .sort-arrow { font-size: 9px; }

/* ---- utility ----------------------------------------------------------- */

.stack > * + * { margin-top: var(--tctd-space-4); }
.row { display: flex; align-items: center; gap: var(--tctd-space-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--tctd-space-3); }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--tctd-ink-muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

.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;
}

.empty-state {
  text-align: center;
  padding: var(--tctd-space-8) var(--tctd-space-5);
  color: var(--tctd-ink-muted);
}

/* ---- toast ------------------------------------------------------------- */

#toast-host {
  position: fixed;
  bottom: var(--tctd-space-5);
  right: var(--tctd-space-5);
  display: flex;
  flex-direction: column;
  gap: var(--tctd-space-2);
  z-index: 1000;
}
.toast {
  background: var(--tctd-ink);
  color: var(--tctd-white);
  padding: 12px 16px;
  border-radius: var(--tctd-radius);
  box-shadow: var(--tctd-shadow-lg);
  font-size: 14px;
  max-width: 380px;
  animation: toast-in 160ms ease-out;
}
.toast-error { background: var(--tctd-error); }
.toast-ok { background: var(--tctd-ok); }

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

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

/* ==========================================================================
   MOBILE FOUNDATION
   Shared by the admin and the portal. Layout lives in their own stylesheets;
   this is the part that is the same wherever a finger is doing the pointing.
   ========================================================================== */

:root {
  /* Height of the fixed bottom nav, so a page can reserve space for it in one
     place instead of every scroll container guessing. */
  --tctd-tabbar: 60px;
  --tctd-safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (max-width: 860px) {
  /* iOS zooms the whole page when a focused field is under 16px, and never
     zooms back out. Every control that takes typing goes to 16px on phones —
     this is the single most common reason a form feels broken on an iPhone. */
  input[type='text'], input[type='email'], input[type='password'], input[type='tel'],
  input[type='number'], input[type='url'], input[type='date'], input[type='datetime-local'],
  input[type='time'], input[type='search'], select, textarea {
    font-size: 16px;
  }

  /* A 44px target is the smallest thing a thumb hits reliably. Buttons keep
     their own padding; this is the floor. */
  .btn, button, .p-nav a, .admin-nav a, select {
    min-height: 44px;
  }
  .btn-sm { min-height: 40px; }

  /* Icon-only controls need width too, not just height. */
  .icon-btn, .p-photo-dl, .p-photo-select { min-width: 44px; min-height: 44px; }

  /* Long addresses and emails must not force the page sideways. */
  body { overflow-x: hidden; }
  table.data { min-width: 0; }
}

/* Anything fixed to the bottom sits above the home indicator, not under it. */
.tctd-tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 60;
  display: none;
  background: var(--tctd-white);
  border-top: 1px solid var(--tctd-border);
  padding-bottom: var(--tctd-safe-bottom);
  box-shadow: 0 -2px 12px rgba(28, 18, 24, .07);
}
.tctd-tabbar-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: stretch;
  height: var(--tctd-tabbar);
}
.tctd-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: none;
  font: inherit;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--tctd-ink-muted);
  text-decoration: none;
  cursor: pointer;
  padding: 6px 2px;
  /* Kills the grey flash iOS paints over tapped elements. */
  -webkit-tap-highlight-color: transparent;
}
.tctd-tab svg { width: 21px; height: 21px; flex: none; }
.tctd-tab[aria-current], .tctd-tab.is-active { color: var(--tctd-bright-pink); }
.tctd-tab:disabled { opacity: .4; }

/* The overflow sheet the "More" tab opens. */
.tctd-sheet {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: none;
  background: rgba(28, 18, 24, .45);
}
.tctd-sheet[open] { display: block; }
.tctd-sheet-panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--tctd-white);
  border-radius: var(--tctd-radius-lg) var(--tctd-radius-lg) 0 0;
  padding: var(--tctd-space-4) var(--tctd-space-4)
           calc(var(--tctd-space-4) + var(--tctd-safe-bottom));
  max-height: 80vh;
  overflow-y: auto;
  animation: tctd-sheet-up 180ms ease;
}
@keyframes tctd-sheet-up { from { transform: translateY(100%); } to { transform: none; } }
.tctd-sheet-grip {
  width: 38px; height: 4px; border-radius: 2px;
  background: var(--tctd-border);
  margin: 0 auto var(--tctd-space-4);
}
.tctd-sheet-title {
  font-size: 11px; font-weight: 600; letter-spacing: .12em;
  text-transform: uppercase; color: var(--tctd-ink-muted);
  margin: var(--tctd-space-4) 0 var(--tctd-space-2);
}
.tctd-sheet a, .tctd-sheet button.tctd-sheet-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 0 var(--tctd-space-3);
  border: 0; border-radius: var(--tctd-radius);
  background: none;
  font: inherit; font-size: 15px; text-align: left;
  color: var(--tctd-ink); text-decoration: none;
  cursor: pointer;
}
.tctd-sheet a[aria-current='page'] { background: var(--tctd-surface-alt); font-weight: 600; }
.tctd-sheet a.soon { opacity: .45; pointer-events: none; }

@media (max-width: 860px) {
  .tctd-tabbar { display: block; }
  /* Reserve the bar's height so the last row of content is not sat on. */
  body.admin, body.portal { padding-bottom: calc(var(--tctd-tabbar) + var(--tctd-safe-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .tctd-sheet-panel { animation: none; }
}
