@import url('/static/fonts.css');

/* Expo Lead — design system v1 (tokens, components, shared helpers).
   Reference: docs/design/expo-lead-design-v1.html, artboards 1a/1b. */

/* ---------- Tokens ---------- */

:root {
  --paper: #FAF9F5;
  --surface: #FFFFFF;
  --ink: #141413;
  --muted: #73726C;
  --line: #E8E6DC;
  --border: #D9D6CB;
  --accent: #C96442;
  --accent-bg: #F5E6DF;
  --ok: #3D7A4A;
  --ok-bg: #E6F0E4;
  --err: #B5412E;
  --err-bg: #F7E3DE;
  --warn: #A86B12;
  --chip-bg: #EFEDE6;
  --radius-btn: 12px;
  --radius-field: 10px;
  --radius-card: 14px;
}

/* Dark theme follows the OS unless JS pins data-theme on <html>. */
:root[data-theme="dark"] {
  --paper: #1F1E1D;
  --surface: #2A2927;
  --ink: #FAF9F5;
  --muted: #A3A19A;
  --line: #3A3936;
  --border: #3A3936;
  --accent: #D97757;
  --accent-bg: #3B2A24;
  --ok: #8FC79A;
  --ok-bg: #22351F;
  --err: #E08A78;
  --err-bg: #3A211D;
  --warn: #E0A458;
  --chip-bg: #2E2D2B;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1F1E1D;
    --surface: #2A2927;
    --ink: #FAF9F5;
    --muted: #A3A19A;
    --line: #3A3936;
    --border: #3A3936;
    --accent: #D97757;
    --accent-bg: #3B2A24;
    --ok: #8FC79A;
    --ok-bg: #22351F;
    --err: #E08A78;
    --err-bg: #3A211D;
    --warn: #E0A458;
    --chip-bg: #2E2D2B;
  }
}

/* ---------- Base ---------- */

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

[hidden] {
  display: none !important;
}

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

html,
body {
  font: 400 15px/1.45 Geist, system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
}

body {
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a {
  color: var(--accent);
}

/* ---------- Typography ---------- */

.title {
  margin: 0;
  font: 600 28px/1.15 Geist, system-ui, sans-serif;
  letter-spacing: -0.02em;
}

.h2 {
  margin: 0;
  font: 600 18px Geist, system-ui, sans-serif;
}

.label {
  font: 500 12px 'Geist Mono', monospace;
  color: var(--muted);
}

.mono {
  font-family: 'Geist Mono', monospace;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

/* ---------- Layout ---------- */

.page {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px calc(84px + env(safe-area-inset-bottom));
}

.page-wide {
  max-width: 1280px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stack-lg {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.row-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.grow {
  flex: 1;
}

.spacer {
  flex: 1;
}

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

/* ---------- Auth (login) ---------- */

.auth-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.auth-card {
  width: 100%;
  max-width: 480px;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 48px;
  padding: 0 16px;
  border: none;
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--ink);
  font: 500 15px Geist, system-ui, sans-serif;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  opacity: 0.9;
}

.btn:active {
  opacity: 0.78;
}

.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn:focus-visible {
  outline: none;
  border: 1px solid var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.btn-primary {
  height: 52px;
  background: var(--ink);
  color: var(--paper);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
}

.btn-text {
  background: transparent;
  color: var(--accent);
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-sm {
  height: 36px;
  padding: 0 12px;
  font-size: 14px;
}

/* ---------- Fields ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font: 500 12px 'Geist Mono', monospace;
  color: var(--muted);
}

.input {
  display: block;
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-field);
  background: var(--surface);
  color: var(--ink);
  font: 400 15px Geist, system-ui, sans-serif;
}

textarea.input {
  height: auto;
  min-height: 96px;
  padding: 12px 14px;
  resize: vertical;
}

.input:focus {
  outline: none;
  border: 1.5px solid var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.input.is-error {
  border: 1.5px solid var(--err);
}

.field-error {
  margin: 0;
  font-size: 13px;
  color: var(--err);
}

.field-hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.switch {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  width: 44px;
  height: 26px;
  flex: none;
  border: none;
  border-radius: 13px;
  background-color: var(--border);
  background-image: radial-gradient(circle at center, #fff 0 10px, transparent 10.5px);
  background-size: 20px 20px;
  background-repeat: no-repeat;
  background-position: 3px center;
  cursor: pointer;
  transition: background-color 0.15s ease, background-position 0.15s ease;
}

.switch:checked {
  background-color: var(--accent);
  background-position: 21px center;
}

.switch:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-bg);
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--chip-bg);
  color: var(--muted);
  font: 500 11px 'Geist Mono', monospace;
  white-space: nowrap;
}

.badge-ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.badge-draft {
  background: var(--chip-bg);
  color: var(--muted);
}

.badge-done {
  background: var(--chip-bg);
  color: var(--ink);
}

.badge-err {
  background: var(--err-bg);
  color: var(--err);
}

.badge-reply {
  background: var(--accent-bg);
  color: var(--accent);
}

.badge-warn {
  background: #F6EBD6;
  color: var(--warn);
}

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  padding: 10px 0;
  margin-bottom: -1px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font: 500 14px Geist, system-ui, sans-serif;
  cursor: pointer;
  white-space: nowrap;
}

.tab.is-active {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

/* ---------- Cards & lists ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 16px;
}

.card-link {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 16px;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
}

.card-link:hover {
  border-color: var(--accent);
}

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--ink);
  font: 500 13px 'Geist Mono', monospace;
}

.divider {
  height: 1px;
  margin: 0;
  border: none;
  background: var(--line);
}

/* ---------- Messages ---------- */

.toast-host {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--paper);
  font: 400 14px Geist, system-ui, sans-serif;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  animation: toast-in 0.2s ease;
}

.toast-ok::before {
  content: '✓';
  color: var(--ok);
  font-family: 'Geist Mono', monospace;
}

.toast-err {
  background: var(--err-bg);
  color: var(--err);
}

.toast-err::before {
  content: '×';
  color: var(--err);
  font-family: 'Geist Mono', monospace;
}

.banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 12px;
  border-left: 3px solid var(--muted);
  background: var(--surface);
  color: var(--ink);
  font: 400 14px/1.45 Geist, system-ui, sans-serif;
}

.banner-err {
  border-left-color: var(--err);
  background: var(--err-bg);
  color: var(--err);
}

.banner-warn {
  border-left-color: var(--warn);
  background: #F6EBD6;
  color: var(--warn);
}

.banner-ok {
  border-left-color: var(--ok);
  background: var(--ok-bg);
  color: var(--ok);
}

/* ---------- States (7a–7d) ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 48px 24px;
  text-align: center;
}

.loading {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font: 500 12px 'Geist Mono', monospace;
}

.loading::before {
  content: '✻';
  display: inline-block;
  animation: spin 2s linear infinite;
}

.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 24px;
  text-align: center;
}

.error-state::before {
  content: '×';
  padding: 8px 16px;
  border-radius: 8px;
  background: var(--err-bg);
  color: var(--err);
  font: 500 20px 'Geist Mono', monospace;
  line-height: 1;
}

.skeleton {
  background: var(--chip-bg);
  border-radius: 8px;
  animation: shimmer 1.4s ease-in-out infinite;
}

/* ---------- Action bar ---------- */

.actionbar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 1px solid var(--line);
}

/* ---------- Modal sheet ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
}

.sheet {
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--paper);
  color: var(--ink);
  border-radius: 20px 20px 0 0;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  margin: 0 auto 12px;
  border-radius: 2px;
  background: var(--line);
}

.sheet-title {
  margin: 0 0 12px;
  font: 600 18px Geist, system-ui, sans-serif;
}

@media (min-width: 700px) {
  .sheet-backdrop {
    align-items: center;
    padding: 24px;
  }

  .sheet {
    max-width: 520px;
    border-radius: 16px;
  }
}

/* ---------- Table (desktop, 5a) ---------- */

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

.table {
  width: 100%;
  border-collapse: collapse;
  font: 400 14px Geist, system-ui, sans-serif;
}

.table th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font: 500 11px 'Geist Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  text-align: left;
  white-space: nowrap;
}

.table td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.table tbody tr:hover {
  background: var(--surface);
}

@media (max-width: 699px) {
  .hide-mobile {
    display: none !important;
  }
}

@media (min-width: 700px) {
  .show-mobile {
    display: none !important;
  }
}

/* ---------- Utilities ---------- */

.accent {
  color: var(--accent);
}

.ok {
  color: var(--ok);
}

.err {
  color: var(--err);
}

.nowrap {
  white-space: nowrap;
}

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

/* ---------- Animations ---------- */

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

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes shimmer {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* ---------- Touch targets (mobile) ----------
   Interactive controls keep at least a 48×48px hit area on phones while the
   small visuals (the 14px .btn-sm label, the 44×26 switch track) stay intact. */

@media (max-width: 699px) {
  .btn-sm {
    min-height: 48px;
  }

  .tab {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
  }

  .switch {
    width: 48px;
    height: 48px;
    padding: 11px 2px;
    /* Compensate the asymmetric padding so the clipped content-box background
       still reads as the 44×26 pill: 13px radius + 2px/11px offsets. */
    border-radius: 15px / 24px;
    background-origin: content-box;
    background-clip: content-box;
  }
}

/* ---------- Legacy shims ----------
   Kept so pages not yet migrated to the design system (admin, scan, public
   form, brochures) stay usable until their own tickets restyle them. */

/* The new `.label` is a typography utility, but form.html and scan.html still
   use <label class="label"><span>Caption</span><input> as a stacked field
   container. Restore that container layout for `<label>` elements only so the
   standalone typography `<div class="label">` in the styleguide is unaffected. */
label.label {
  display: block;
  margin-bottom: 12px;
}

label.label > span {
  display: block;
  margin-bottom: 6px;
}

.hp-field {
  position: absolute !important;
  left: -10000px !important;
  top: auto !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
}

.error {
  color: var(--err);
}

.hint {
  color: var(--muted);
  font-size: 13px;
}

.btn-danger {
  color: var(--err);
  border: 1px solid var(--err);
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

.form-container {
  max-width: 560px;
}

.form-header {
  text-align: center;
  margin-bottom: 16px;
}

.form-header img {
  max-width: 180px;
  max-height: 90px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0;
}

.grid {
  display: grid;
  gap: 12px;
}

@media (min-width: 560px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }
}

.event-card {
  display: block;
  text-decoration: none;
  color: var(--ink);
}

.event-card:hover {
  border-color: var(--accent);
}

.event-card h3 {
  margin: 0 0 4px;
}

.event-card p {
  margin: 2px 0;
}

.drop {
  padding: 18px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-card);
  text-align: center;
}

.drop-active {
  border-color: var(--accent);
}

.file-list,
.sender-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.file-item,
.sender-item {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.file-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.file-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-decoration: none;
  color: var(--ink);
}

.file-link:hover {
  border-color: var(--accent);
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
}

.recording {
  border-color: var(--err);
  color: var(--err);
}

.logo-preview {
  max-width: 160px;
  max-height: 80px;
}

.photo-preview {
  max-width: 100%;
  max-height: 320px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}

input[type="color"].input {
  width: 76px;
  padding: 4px;
}

.qr-card {
  display: grid;
  gap: 10px;
}

.qr-img {
  width: 200px;
  height: 200px;
  max-width: 100%;
  background: #fff;
  border-radius: 4px;
}

.qr-url {
  word-break: break-all;
}

.qr-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filters {
  display: grid;
  gap: 10px;
}

.lead-cards {
  display: grid;
  gap: 10px;
}

.lead-card p {
  margin: 2px 0;
}

.lead-fields {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 10px 0;
}

.lead-fields dt {
  color: var(--muted);
}

.lead-row {
  cursor: pointer;
}

.table-wide {
  display: none;
}

.table-narrow {
  display: block;
}

@media (min-width: 700px) {
  .table-wide {
    display: block;
  }

  .table-narrow {
    display: none;
  }
}

.tab.active {
  color: var(--ink);
  border-bottom-color: var(--ink);
}
