/* Tools — mobile-first, light/dark via prefers-color-scheme */

:root {
  --bg: #ffffff;
  --fg: #111114;
  --muted: #6b7280;
  --card: #f5f5f6;
  --border: #e4e4e7;
  --accent: #0a84ff;
  --accent-fg: #ffffff;
  --danger: #d92d20;
  --ok: #12805c;
  --warn: #b54708;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0c;
    --fg: #f2f2f4;
    --muted: #9aa0aa;
    --card: #151517;
    --border: #26262b;
    --accent: #0a84ff;
    --accent-fg: #ffffff;
    --danger: #f04438;
    --ok: #47cd89;
    --warn: #f79009;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
}
#app { height: 100dvh; display: flex; flex-direction: column; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- header ---------- */
#topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--fg);
  text-decoration: none;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.top-actions { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  position: relative;
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  font-size: 20px;
  background: transparent;
  border: none;
  border-radius: 10px;
  color: var(--fg);
  cursor: pointer;
}
.icon-btn:active { background: var(--card); }
.icon-btn.has-key { color: var(--accent); }
.icon-btn kbd {
  position: absolute;
  bottom: 2px;
  right: 2px;
  font-size: 9px;
  line-height: 1;
  padding: 2px 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card);
  color: var(--muted);
  font-family: var(--mono);
}
@media (max-width: 767px) { .icon-btn kbd { display: none; } }

.badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 12px;
  font-weight: 700;
  display: inline-grid;
  place-items: center;
  line-height: 1;
}

/* ---------- offline banner ---------- */
#offline-banner {
  flex: 0 0 auto;
  padding: 10px 16px;
  text-align: center;
  font-size: 14px;
  background: #fff7e6;
  color: var(--warn);
  border-bottom: 1px solid var(--border);
}
@media (prefers-color-scheme: dark) { #offline-banner { background: #2a1f08; } }

/* ---------- main view ---------- */
#view {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
}

/* ---------- home ---------- */
.home-intro { margin: 4px 0 20px; font-size: 15px; }
.cat-section { margin-bottom: 28px; }
.cat-section h2 { font-size: 15px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 10px; }
.tool-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 768px) { .tool-grid { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); } }

.tool-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  min-height: 76px;
  color: var(--fg);
  cursor: pointer;
  font: inherit;
}
.tool-card:active { transform: scale(0.99); border-color: var(--accent); }
.t-icon { font-size: 28px; line-height: 1.2; flex: 0 0 auto; }
.t-body { flex: 1 1 auto; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.t-title { font-weight: 600; font-size: 16px; }
.t-blurb { font-size: 13px; }
.home-foot { margin: 24px 0 12px; text-align: center; font-size: 13px; }

.mode {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  white-space: nowrap;
}
.mode-instant { color: var(--ok); border-color: var(--ok); }
.mode-queued { color: var(--warn); border-color: var(--warn); }
.mode-llm-assisted { color: var(--accent); border-color: var(--accent); }

/* ---------- tool view ---------- */
.tool-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.tool-head h1 { font-size: 21px; margin: 0; flex: 1 1 auto; min-width: 0; }
.tool-head .btn { flex: 0 0 auto; }

/* ---------- archetype layouts ---------- */
/* two-pane */
.tp-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tp-tab {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
}
.tp-tab.active { background: var(--accent); border-color: transparent; color: var(--accent-fg); font-weight: 600; }
.arch-two-pane[data-tab="in"] .tp-out { display: none; }
.arch-two-pane[data-tab="out"] .tp-in { display: none; }
.tp-pane { min-width: 0; }
@media (min-width: 768px) {
  .tp-tabs { display: none; }
  .arch-two-pane .tp-panes { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
  .arch-two-pane[data-tab="in"] .tp-out,
  .arch-two-pane[data-tab="out"] .tp-in { display: block; }
}

/* canvas-media */
.cm-preview img, .cm-preview video, .job-preview img, .job-preview video {
  max-width: 100%;
  border-radius: 10px;
  display: block;
}
.cm-controls { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 768px) {
  .arch-canvas-media { display: grid; grid-template-columns: 1.25fr 1fr; gap: 20px; align-items: start; }
  .cm-controls { margin-top: 0; }
}

/* form-calculator */
.arch-form-calculator { display: flex; flex-direction: column; gap: 16px; }
.result-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.result-card h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.result-value { font-family: var(--mono); font-size: 26px; font-weight: 700; word-break: break-all; }
.result-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
@media (min-width: 768px) {
  .arch-form-calculator { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
  .result-card { position: sticky; top: 16px; }
}

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > label, .slider-head label { font-size: 14px; font-weight: 600; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }

input[type="text"], input[type="number"], input[type="search"], input[type="password"],
textarea, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font-size: 16px; /* prevents iOS auto-zoom */
  font-family: var(--mono);
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
select { font-family: inherit; }
input[type="range"] { width: 100%; min-height: 44px; accent-color: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-fg); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn:disabled { opacity: 0.5; cursor: default; }

.slider-row { margin-bottom: 12px; }
.slider-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 2px; }
.slider-val { font-size: 14px; color: var(--muted); }
.slider-body { display: flex; gap: 10px; align-items: center; }
.slider-body input[type="range"] { flex: 1 1 auto; }
.slider-num { flex: 0 0 96px; width: 96px; }

.file-btn { display: inline-block; }
.file-btn input[type="file"] { display: none; }

/* ---------- drawer ---------- */
#drawer-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 40;
}
#drawer {
  position: fixed;
  z-index: 41;
  left: 0; right: 0; bottom: 0;
  max-height: 82dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  animation: sheet-up 0.22s ease-out;
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0.6; } to { transform: none; opacity: 1; } }
@media (min-width: 768px) {
  #drawer {
    left: auto; top: 72px; right: 16px; bottom: 16px;
    width: 400px; max-height: none;
    border: 1px solid var(--border);
    border-radius: 16px;
    animation: none;
  }
}
.drawer-head {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 8px 8px 16px;
  border-bottom: 1px solid var(--border);
}
.drawer-head h2 { margin: 0; font-size: 17px; }
#job-list { flex: 1 1 auto; overflow-y: auto; padding: 12px; }
.drawer-foot { flex: 0 0 auto; padding: 12px; border-top: 1px solid var(--border); }
.drawer-foot .btn { width: 100%; }

.job {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}
.job-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.job-title { font-weight: 600; font-size: 15px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill {
  flex: 0 0 auto;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted);
}
.st-queued { color: var(--warn); border-color: var(--warn); }
.st-processing { color: var(--accent); border-color: var(--accent); }
.st-completed { color: var(--ok); border-color: var(--ok); }
.st-failed { color: var(--danger); border-color: var(--danger); }
.st-cancelled { color: var(--muted); }

.progress { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width 0.2s; }
.job-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.job-actions .btn { min-height: 44px; font-size: 14px; padding: 0 14px; }
.job-err { color: var(--danger); font-size: 14px; margin-top: 8px; word-break: break-word; }
.job-note {
  font-size: 13px; margin-top: 8px; padding: 8px 10px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  word-break: break-all; max-height: 120px; overflow: auto;
}
.job-preview { margin-top: 8px; }

/* ---------- modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.45);
}
.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
}
.modal-card h2 { margin: 0 0 8px; font-size: 19px; }
.modal-card p { font-size: 14px; margin: 0 0 12px; }
.key-actions { margin-top: 12px; }

/* search */
#search-input { margin-bottom: 8px; }
#search-results { max-height: 52dvh; overflow-y: auto; }
.sr-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 56px;
  padding: 8px 10px;
  background: transparent; border: none; border-radius: 10px;
  color: var(--fg); font: inherit; text-align: left; cursor: pointer;
}
.sr-item.active { background: var(--card); }
.sr-icon { font-size: 24px; flex: 0 0 auto; }
.sr-text { display: flex; flex-direction: column; min-width: 0; }
.sr-title { font-weight: 600; font-size: 15px; }
.sr-cat { font-size: 12px; }
.empty { padding: 16px; text-align: center; }

/* ---------- toasts ---------- */
#toasts {
  position: fixed;
  z-index: 60;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.toast {
  background: #17171a; color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 15px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
  opacity: 1;
  transition: opacity 0.3s;
  max-width: 100%;
  word-break: break-word;
}
@media (prefers-color-scheme: dark) { .toast { background: #f2f2f4; color: #111; } }
.toast.out { opacity: 0; }

.notfound { max-width: 420px; margin: 40px auto; text-align: center; }
.stale-badge {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  color: var(--warn); border: 1px solid var(--warn); border-radius: 999px; padding: 2px 8px;
}
