:root {
  --bg: #0b0610;
  --bg-2: #140a1c;
  --surface: #1b0f26;
  --surface-2: #241433;
  --border: #3a2150;
  --text: #f1e9f7;
  --muted: #b29fc2;
  --accent: #b44be0;
  --accent-2: #7d2aa8;
  --accent-soft: rgba(180, 75, 224, 0.15);
  --good: #5fd39a;
  --bad: #ff6b8b;
  --warn: #ffc65c;
  --info: #6cb6ff;
  --radius: 12px;
  --font-display: "Syne", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font-body); }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--font-display); margin: 0; line-height: 1.2; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .65em 1.2em; border-radius: 999px; border: 1px solid transparent;
  font: 600 .95rem var(--font-body); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--accent); }
.btn-danger { background: transparent; color: var(--bad); border-color: rgba(255, 107, 139, .4); }
.btn-danger:hover { background: rgba(255, 107, 139, .1); }
.btn-sm { padding: .45em .9em; font-size: .85rem; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg-2);
  border: 1px solid var(--border); border-radius: 8px; padding: .55em .75em; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; color: var(--muted); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  display: flex; flex-direction: column; gap: 1rem; align-items: center; text-align: center;
  max-width: 380px; padding: 2.4rem; background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
}
.login-card p { margin: 0; color: var(--muted); }

/* Top bar */
.top {
  display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap;
  padding: .8rem 20px; border-bottom: 1px solid var(--border); background: var(--bg-2);
  position: sticky; top: 0; z-index: 5;
}
.top h1 { font-size: 1.3rem; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }
.who { color: var(--muted); font-size: .85rem; }

.switch { flex-direction: row; align-items: center; gap: .6rem; cursor: pointer; color: var(--text); font-weight: 600; font-size: .9rem; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { width: 42px; height: 24px; border-radius: 999px; background: var(--bad); position: relative; transition: background .2s; }
.switch-thumb { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + .switch-track { background: var(--good); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--accent-soft); }

/* Toolbar */
.toolbar { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; padding: .8rem 20px; }
.tabs { display: flex; gap: .4rem; flex-wrap: wrap; }
.tab {
  padding: .4em .9em; border-radius: 999px; border: 1px solid var(--border); background: transparent;
  color: var(--muted); font: 500 .85rem var(--font-body); cursor: pointer;
}
.tab.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.tab b { margin-left: .3rem; color: var(--text); }
#search { max-width: 280px; margin-left: auto; }

/* Layout */
.layout { display: grid; grid-template-columns: 360px 1fr; gap: 16px; padding: 0 20px 20px; align-items: start; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; max-height: calc(100vh - 140px); overflow-y: auto; }
.list .none { color: var(--muted); padding: 1rem; }
.card {
  padding: .8rem 1rem; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border); cursor: pointer; display: grid; gap: .2rem;
}
.card:hover { border-color: var(--accent-2); }
.card.on { border-color: var(--accent); background: var(--surface-2); }
.card-top { display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.card-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { color: var(--muted); font-size: .82rem; }

.pill { font-size: .72rem; font-weight: 600; padding: .15em .65em; border-radius: 999px; white-space: nowrap; border: 1px solid currentColor; }
.s-new { color: var(--info); }
.s-accepted { color: var(--warn); }
.s-in-progress { color: var(--accent); }
.s-done { color: var(--good); }
.s-declined { color: var(--muted); }

/* Detail */
.detail {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.5rem; min-height: 300px; position: sticky; top: 76px;
  max-height: calc(100vh - 140px); overflow-y: auto;
}
.detail .empty { color: var(--muted); text-align: center; margin-top: 4rem; }
.d-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; flex-wrap: wrap; margin-bottom: 1rem; }
.d-head h2 { font-size: 1.5rem; }
.d-sub { color: var(--muted); font-size: .85rem; }
.d-close { display: none; }

.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1.4rem; }
.actions select { width: auto; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.4rem; }
.box { background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; }
.box h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-family: var(--font-body); margin-bottom: .6rem; }
.box ul { margin: 0; padding-left: 1.1rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .3rem .8rem; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.desc { white-space: pre-wrap; word-break: break-word; margin: 0; }
.money { font: 800 1.6rem var(--font-display); }

.checks { display: flex; flex-direction: column; gap: .4rem; }
.checks label { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); font-size: .92rem; }
.checks input { width: auto; accent-color: var(--accent); }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; }
.thumbs a { display: block; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--surface); border: 1px solid var(--border); position: relative; }
.thumbs img { width: 100%; height: 100%; object-fit: cover; }
.thumbs span { position: absolute; inset: 0; display: grid; place-items: center; padding: .4rem; font-size: .7rem; color: var(--muted); word-break: break-all; text-align: center; }

.order-no { color: var(--accent); font-variant-numeric: tabular-nums; }
.emails { margin-bottom: 1.4rem; }
.btn[aria-disabled="true"] { opacity: .4; cursor: not-allowed; }

.char-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: .5rem; }
.char-card { margin: 0; text-align: center; font-size: .82rem; font-weight: 600; line-height: 1.3; }
.char-card figcaption { margin-top: .3rem; word-break: break-word; }
.char-card a { font-weight: 400; }
.char-pic {
  display: grid; place-items: center; aspect-ratio: 1; border-radius: 8px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); color: var(--muted); font: 700 1.5rem var(--font-display);
}
.char-pic img { width: 100%; height: 100%; object-fit: cover; object-position: top; }

.gold { color: #f0c75e; font-weight: 600; }
.gold-box { border-color: #d4a73a; background: rgba(212, 167, 58, .08); }
.gold-box h3 { color: #f0c75e; }

.saved { color: var(--good); font-size: .82rem; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.form .full { grid-column: 1 / -1; }
.msg { font-size: .88rem; margin: 0; }
.msg.err { color: var(--bad); }

/* Phones and small tablets */
@media (max-width: 860px) {
  /* Top bar: title + open switch on one line, buttons on the next */
  .top { gap: .6rem 1rem; padding: .7rem 16px; }
  .top h1 { font-size: 1.15rem; }
  .switch { font-size: .82rem; margin-left: auto; }
  .top-right { margin-left: 0; width: 100%; gap: .5rem; }
  .top-right #new-btn { flex: 1; }
  .who { display: none; }

  /* Search first, tabs as one scrollable row */
  .toolbar { flex-direction: column; align-items: stretch; gap: .6rem; padding: .7rem 16px; }
  #search { max-width: none; margin-left: 0; order: -1; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex-shrink: 0; padding: .5em 1em; }

  .layout { grid-template-columns: 1fr; padding: 0 16px calc(16px + env(safe-area-inset-bottom)); }
  .list { max-height: none; overflow: visible; }
  .card { padding: .9rem 1rem; }

  /* Detail opens full screen over the list */
  .detail {
    position: fixed; inset: 0; z-index: 20; border: 0; border-radius: 0;
    max-height: none; min-height: 0; padding: 0 16px calc(24px + env(safe-area-inset-bottom));
    overscroll-behavior: contain;
  }
  .detail.idle { display: none; }
  body:has(.detail:not(.idle)) { overflow: hidden; }
  .d-head {
    position: sticky; top: 0; z-index: 2; margin: 0 -16px 1rem; padding: .8rem 16px;
    background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: nowrap;
  }
  .d-head h2 { font-size: 1.2rem; }
  .d-head > div:first-child { min-width: 0; }
  .d-head .d-sub { overflow-wrap: anywhere; }
  .d-close { display: inline-flex; }

  .actions .btn, .actions select { flex: 1 1 auto; }
  .grid2 { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }
  .char-cards { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
  .thumbs { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }

  /* Bigger touch targets; 16px inputs stop iPhones zooming in */
  .btn { min-height: 42px; }
  .btn-sm { min-height: 38px; }
  input, select, textarea { font-size: 16px; }
  .checks label { min-height: 36px; }
}
