/* ═══════════════════════════════════════════════════════════════
   Screen Auckland — Film Permit Triage Tool
   main.css — BEM, CSS custom properties, desktop-first
   Breakpoint: 1024px → single column
   ═══════════════════════════════════════════════════════════════ */

/* ── Tokens ──────────────────────────────────────────────────── */
:root {
  --color-primary:     #1a3a5c;
  --color-primary-h:   #15304e;
  --color-accent:      #0070c0;
  --color-accent-h:    #005fa3;
  --color-success:     #1a7a4a;
  --color-success-bg:  #eaf6f0;
  --color-warning:     #7a4a00;
  --color-warning-bg:  #fff8e6;
  --color-danger:      #c0392b;
  --color-danger-bg:   #fdf0ef;
  --color-surface:     #ffffff;
  --color-bg:          #f4f5f7;
  --color-border:      #d0d5dd;
  --color-border-l:    #e8ebf0;
  --color-text:        #1a1f2e;
  --color-text-muted:  #6b7280;
  --color-text-light:  #9ca3af;
  --color-iwi:         #6d28d9;
  --color-iwi-bg:      #f5f3ff;

  --radius-sm: 4px;
  --radius:    6px;
  --radius-lg: 10px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.08);
  --shadow:    0 2px 8px rgba(0,0,0,.10);
  --shadow-lg: 0 4px 20px rgba(0,0,0,.14);

  --header-h: 60px;
  --actionbar-h: 80px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  padding-bottom: calc(var(--actionbar-h) + 1rem);
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ── Banners ────────────────────────────────────────────────── */
.banner {
  padding: .75rem 1.5rem;
  border-bottom: 2px solid transparent;
  position: sticky; top: 0; z-index: 100;
}
.banner--warning { background: var(--color-warning-bg); border-color: #f6a623; }
.banner--success { background: var(--color-success-bg); border-color: #34c77b; }
.banner__content {
  max-width: 1400px; margin: 0 auto;
  display: flex; align-items: center; gap: 1rem;
}
.banner__icon { font-size: 1.25rem; flex-shrink: 0; }
.banner__content > div:nth-child(2) { flex: 1; }
.banner__actions { display: flex; gap: .5rem; flex-shrink: 0; }

/* ── Header ─────────────────────────────────────────────────── */
.app-header {
  background: var(--color-primary);
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem; gap: 1.5rem; position: sticky; top: 0; z-index: 90;
  box-shadow: var(--shadow);
}
.app-header__brand { display: flex; align-items: center; gap: .625rem; flex-shrink: 0; }
.app-header__logo { font-size: 1.375rem; }
.app-header__title { color: #fff; font-size: 1.05rem; font-weight: 700; }
.app-header__sub { color: rgba(255,255,255,.6); font-size: .8rem; }

.app-header__lookup { flex: 1; max-width: 480px; }
.lookup-field { display: flex; gap: .375rem; }
.lookup-field__input {
  flex: 1; padding: .4rem .75rem;
  border: 1px solid rgba(255,255,255,.3);
  border-radius: var(--radius);
  background: rgba(255,255,255,.12);
  color: #fff; font-size: .85rem;
}
.lookup-field__input::placeholder { color: rgba(255,255,255,.5); }
.lookup-field__input:focus {
  outline: none; border-color: rgba(255,255,255,.6);
  background: rgba(255,255,255,.18);
}
.lookup-result {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); margin-top: .375rem; padding: .875rem 1rem;
  font-size: .875rem; box-shadow: var(--shadow-lg); position: absolute; width: 460px; z-index: 200;
}

/* ── App ID Gate ────────────────────────────────────────────── */
.app-id-gate {
  display: flex; align-items: center; justify-content: center;
  padding: 3rem 1.5rem;
}
.app-id-gate__inner { text-align: center; max-width: 520px; width: 100%; }
.app-id-field {
  display: flex; gap: .5rem; margin-top: .875rem; justify-content: center;
}

/* ── Asana status inline ───────────────────────────────────── */
.asana-status {
  margin-top: .625rem; font-size: .85rem; padding: .5rem .75rem;
  border-radius: var(--radius); display: inline-flex; align-items: center; gap: .375rem;
}
.asana-status--found { background: var(--color-success-bg); color: var(--color-success); }
.asana-status--notfound { background: var(--color-warning-bg); color: var(--color-warning); }
.asana-status--error { background: var(--color-danger-bg); color: var(--color-danger); }

/* ── Two-column layout ──────────────────────────────────────── */
.triage-layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 0;
  max-width: 1400px; margin: 0 auto;
  min-height: calc(100vh - var(--header-h) - var(--actionbar-h));
}

/* ── Checklist Panel (left) ─────────────────────────────────── */
.checklist-panel {
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h) - var(--actionbar-h));
}

.checklist-panel__header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border-l);
  background: #fafbfc;
  position: sticky; top: 0; z-index: 10;
}

.meta-row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.meta-field { display: flex; flex-direction: column; gap: .25rem; }
.meta-field--wide { flex: 1; min-width: 140px; }
.meta-value--appid {
  font-size: 1rem; font-weight: 700; color: var(--color-accent);
  font-family: var(--font-mono); letter-spacing: .04em;
}

/* Checklist categories */
.checklist-category { border-bottom: 1px solid var(--color-border-l); }

.checklist-category__header {
  width: 100%; background: none; border: none; cursor: pointer;
  display: flex; align-items: center; gap: .5rem;
  padding: .875rem 1.25rem; text-align: left;
  font-size: .875rem; font-weight: 600; color: var(--color-primary);
  transition: background .15s;
}
.checklist-category__header:hover { background: #f4f5f7; }

.checklist-category__name { flex: 1; }
.checklist-category__badge {
  background: var(--color-accent); color: #fff;
  font-size: .7rem; font-weight: 700; border-radius: 99px;
  padding: .1rem .45rem; min-width: 1.25rem; text-align: center;
  transition: opacity .2s;
}
.checklist-category__badge[data-count="0"] { opacity: 0; }
.checklist-category__chevron {
  font-size: .75rem; color: var(--color-text-muted);
  transition: transform .2s;
}
.checklist-category--collapsed .checklist-category__chevron { transform: rotate(-90deg); }
.checklist-category--collapsed .checklist-category__body { display: none; }

.checklist-category__body { padding: .25rem 0 .5rem; }

/* Checklist items */
.checklist-item { padding: .25rem 1.25rem .25rem 1rem; }
.checklist-item__label {
  display: flex; align-items: flex-start; gap: .625rem; cursor: pointer;
  padding: .4rem .25rem; border-radius: var(--radius-sm);
  transition: background .1s;
}
.checklist-item__label:hover { background: #f4f5f7; }
.checklist-item__checkbox {
  width: 16px; height: 16px; flex-shrink: 0; margin-top: 2px; cursor: pointer;
  accent-color: var(--color-accent);
}
.checklist-item__text { font-size: .875rem; line-height: 1.45; }

.badge--iwi {
  font-size: .65rem; font-weight: 700; padding: .1rem .35rem;
  border-radius: var(--radius-sm); background: var(--color-iwi-bg);
  color: var(--color-iwi); border: 1px solid #c4b5fd; flex-shrink: 0;
}

/* Sub-fields */
.checklist-item__subfields {
  margin: .375rem 0 .25rem 1.625rem; padding: .75rem;
  background: #f8f9fb; border-left: 3px solid var(--color-accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  animation: slide-in .15s ease;
}
@keyframes slide-in { from { opacity: 0; transform: translateY(-4px); } }

.sub-field + .sub-field { margin-top: .5rem; }

/* IWI Panel */
.iwi-panel {
  margin: .75rem 1.25rem;
  padding: 1rem;
  background: var(--color-iwi-bg);
  border: 1px solid #c4b5fd;
  border-radius: var(--radius);
  animation: slide-in .2s ease;
}
.iwi-panel__title { font-size: .9rem; font-weight: 700; color: var(--color-iwi); margin-bottom: .25rem; }
.iwi-panel__hint { font-size: .8rem; color: var(--color-text-muted); margin-bottom: .625rem; }

.iwi-match-row {
  display: grid; grid-template-columns: auto 1fr auto;
  gap: .5rem; align-items: start; padding: .4rem 0;
  border-bottom: 1px solid #ede9fe; font-size: .8rem;
}
.iwi-match-row:last-child { border-bottom: none; }
.iwi-match-row__status { font-size: .875rem; }
.iwi-match-row__name { font-weight: 600; }
.iwi-match-row__emails { color: var(--color-text-muted); font-size: .75rem; }
.iwi-match-row--unmatched .iwi-match-row__name { color: #b45309; }

/* ── Email Panel (right) ─────────────────────────────────────── */
.email-panel {
  display: flex; flex-direction: column;
  height: calc(100vh - var(--header-h) - var(--actionbar-h));
  position: sticky; top: var(--header-h);
}

.email-panel__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .875rem 1.25rem; border-bottom: 1px solid var(--color-border-l);
  background: #fafbfc;
}
.email-panel__title { font-size: .95rem; font-weight: 700; }
.email-panel__controls { display: flex; align-items: center; gap: .75rem; }

.save-indicator { font-size: .78rem; color: var(--color-text-muted); }
.save-indicator--saving { color: var(--color-accent); }
.save-indicator--saved  { color: var(--color-success); }
.save-indicator--error  { color: var(--color-danger); }

.email-panel__body { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.email-readonly-banner {
  padding: .5rem 1.25rem; background: #eff6ff;
  border-bottom: 1px solid #bfdbfe; display: flex;
  align-items: center; justify-content: space-between;
  font-size: .8rem; color: #1d4ed8;
}

.email-preview {
  flex: 1; resize: none; border: none; outline: none;
  padding: 1.25rem; font-family: var(--font-mono); font-size: .82rem;
  line-height: 1.65; color: var(--color-text);
  background: var(--color-surface); width: 100%;
}
.email-preview:read-only { background: #fafbfc; color: #4b5563; cursor: default; }

/* ── Action Bar (sticky bottom) ─────────────────────────────── */
.action-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--color-primary);
  border-top: 2px solid rgba(255,255,255,.12);
  box-shadow: 0 -4px 20px rgba(0,0,0,.2);
}
.action-bar__inner {
  max-width: 1400px; margin: 0 auto;
  padding: .75rem 1.5rem;
  display: flex; align-items: flex-end; gap: 1.25rem;
}
.action-bar__asana { flex: 1; }
.action-bar__asana .form-label { color: rgba(255,255,255,.8); }
.action-bar__asana .input {
  background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.25); color: #fff;
  margin-top: .25rem;
}
.action-bar__asana .input::placeholder { color: rgba(255,255,255,.4); }
.action-bar__asana .input:focus { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.55); outline: none; }
.action-bar__buttons { display: flex; gap: .625rem; flex-shrink: 0; }

.asana-task-status { font-size: .78rem; margin-top: .3rem; min-height: 1.1rem; color: rgba(255,255,255,.7); }
.asana-task-status--found { color: #6ee7b7; }
.asana-task-status--notfound { color: #fcd34d; }

.asana-post-status {
  padding: .5rem 1.5rem; font-size: .82rem;
  text-align: center;
}
.asana-post-status--success { color: #6ee7b7; }
.asana-post-status--error   { color: #fca5a5; }

/* ── Form primitives ─────────────────────────────────────────── */
.form-label { font-size: .8rem; font-weight: 600; color: var(--color-text-muted); }
.form-label--lg { font-size: 1rem; color: var(--color-text); }
.form-label--sm { font-size: .75rem; }
.form-hint { font-size: .8rem; color: var(--color-text-muted); margin-top: .25rem; }
.required { color: var(--color-danger); }

.input {
  padding: .45rem .75rem; border: 1px solid var(--color-border);
  border-radius: var(--radius); font-size: .875rem; color: var(--color-text);
  background: var(--color-surface); width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.input--sm { padding: .35rem .6rem; font-size: .8rem; }
.input--lg { padding: .625rem 1rem; font-size: 1.05rem; max-width: 280px; }
.input:focus { outline: none; border-color: var(--color-accent); box-shadow: 0 0 0 3px rgba(0,112,192,.15); }

.select {
  padding: .45rem .75rem; border: 1px solid var(--color-border);
  border-radius: var(--radius); font-size: .875rem; color: var(--color-text);
  background: var(--color-surface); width: 100%;
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7280'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .625rem center;
  padding-right: 2rem;
}
.select--sm { padding: .3rem .5rem; font-size: .8rem; padding-right: 1.75rem; }
.select:focus { outline: none; border-color: var(--color-accent); box-shadow: 0 0 0 3px rgba(0,112,192,.15); }

.textarea {
  padding: .5rem .75rem; border: 1px solid var(--color-border);
  border-radius: var(--radius); font-size: .875rem;
  color: var(--color-text); background: var(--color-surface); width: 100%;
  resize: vertical; font-family: var(--font);
  transition: border-color .15s;
}
.textarea--sm { font-size: .8rem; padding: .35rem .6rem; }
.textarea:focus { outline: none; border-color: var(--color-accent); box-shadow: 0 0 0 3px rgba(0,112,192,.15); }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .375rem; padding: .525rem 1rem; border-radius: var(--radius);
  font-size: .875rem; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap; min-height: 36px; min-width: 36px;
  text-decoration: none;
}
.btn--sm  { padding: .35rem .75rem; font-size: .8rem; min-height: 30px; }
.btn--lg  { padding: .625rem 1.375rem; font-size: 1rem; min-height: 44px; }

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

.btn--outline  { background: transparent; color: #fff; border-color: rgba(255,255,255,.5); }
.btn--outline:hover { background: rgba(255,255,255,.12); }

.btn--ghost    { background: transparent; color: var(--color-text-muted); border-color: transparent; }
.btn--ghost:hover { background: #f4f5f7; color: var(--color-text); }

.btn:disabled  { opacity: .5; cursor: not-allowed; pointer-events: none; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .triage-layout { grid-template-columns: 1fr; }
  .checklist-panel {
    position: static; height: auto; overflow: visible;
    border-right: none; border-bottom: 2px solid var(--color-border);
  }
  .email-panel { position: static; height: 75vh; }
  .action-bar__inner { flex-wrap: wrap; }
  .action-bar__asana { flex-basis: 100%; }
  .app-id-field { flex-direction: column; align-items: center; }
  .input--lg { max-width: 100%; }
}

@media (max-width: 768px) {
  .app-header { padding: 0 1rem; }
  .app-header__sub { display: none; }
  .meta-row { gap: .5rem; }
  .lookup-result { width: calc(100vw - 2rem); }
}
