/* Personal assistant control panel.
   Instrument-panel language: hairline rules, tabular data, restrained brass
   accent. Three type roles — serif for identity, grotesk for UI, mono for
   anything numeric. */

:root {
  --ink: #0b0f11;
  --surface: #121a1d;
  --surface-2: #192328;
  --line: #223034;
  --line-soft: #1a2529;
  --text: #e9eff1;
  --text-2: #91a3aa;
  --text-3: #5c6f76;
  --brass: #c2a878;
  --brass-dim: #3a3225;
  --brass-ink: #1a1408;
  --jade: #6fbf9b;
  --jade-dim: #16302a;
  --coral: #e0796b;
  --coral-dim: #33201d;
  --amber: #d4a548;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Consolas, monospace;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.25);
}

@media (prefers-color-scheme: light) {
  :root {
    --ink: #f4f4f2;
    --surface: #ffffff;
    --surface-2: #f7f7f5;
    --line: #e0e0dc;
    --line-soft: #ebebe7;
    --text: #161c1f;
    --text-2: #56656b;
    --text-3: #8b989d;
    --brass: #8a6d33;
    --brass-dim: #f0e6d4;
    --brass-ink: #ffffff;
    --jade: #2f7d5e;
    --jade-dim: #e2f2eb;
    --coral: #b4483a;
    --coral-dim: #fae7e4;
    --amber: #96701c;
    --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.06);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.screen[hidden], [hidden] { display: none !important; }

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

/* ---------- buttons ---------- */
.btn {
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

.btn-primary {
  background: var(--brass);
  border-color: var(--brass);
  color: var(--brass-ink);
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.07); }

.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { color: var(--text); border-color: var(--text-3); }

.btn-danger { background: var(--coral); border-color: var(--coral); color: #fff; font-weight: 600; }

.btn-switch { width: 100%; padding: 0.8rem 1rem; font-weight: 600; letter-spacing: .01em; }
.btn-switch.is-on { background: var(--coral-dim); border-color: var(--coral); color: var(--coral); }
.btn-switch.is-off { background: var(--jade-dim); border-color: var(--jade); color: var(--jade); }

.btn-send { flex: none; width: 42px; padding: 0; font-size: 1.1rem; line-height: 1; }

/* ---------- login ---------- */
.login-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: 100%;
  max-width: 330px;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.login-mark {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border: 1px solid var(--brass);
  border-radius: 50%;
  color: var(--brass);
  font-family: var(--serif);
  font-size: 1rem;
  letter-spacing: .04em;
  margin-bottom: 0.4rem;
}
.login-card h1 {
  font-family: var(--serif);
  font-size: 1.55rem;
  font-weight: 400;
  letter-spacing: -.01em;
  margin: 0;
}
.dek { color: var(--text-2); font-size: 0.88rem; margin: 0 0 0.5rem; }

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-3);
}
input[type="password"], input[type="text"], input[type="search"], textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s ease;
}
input:focus, textarea:focus { outline: none; border-color: var(--brass); }
input::placeholder, textarea::placeholder { color: var(--text-3); }

.error { color: var(--coral); font-size: 0.85rem; margin: 0; }

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--ink) 92%, transparent);
  backdrop-filter: blur(8px);
  z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 0.7rem; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 0.6rem; }
.wordmark {
  font-family: var(--serif);
  font-size: 1.02rem;
  letter-spacing: -.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.worker-dots { display: flex; gap: 4px; flex: none; }
.wdot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-3);
}
.wdot.alive { background: var(--jade); box-shadow: 0 0 0 3px color-mix(in srgb, var(--jade) 18%, transparent); }
.wdot.dead { background: var(--coral); box-shadow: 0 0 0 3px color-mix(in srgb, var(--coral) 18%, transparent); }

.pill {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: .02em;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--text-2);
  white-space: nowrap;
}
.pill.on { color: var(--jade); border-color: color-mix(in srgb, var(--jade) 45%, transparent); background: var(--jade-dim); }
.pill.off { color: var(--coral); border-color: color-mix(in srgb, var(--coral) 45%, transparent); background: var(--coral-dim); }

/* ---------- layout ---------- */
main {
  max-width: 760px;
  margin: 0 auto;
  padding: 1.15rem 1.1rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

/* ---------- instrument row ---------- */
.instruments {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
}
@media (min-width: 620px) { .instruments { grid-template-columns: repeat(4, 1fr); } }

.metric {
  background: var(--surface);
  padding: 0.85rem 0.95rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-height: 88px;
}
.metric .m-label {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-3);
}
.metric .m-value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.32rem;
  font-weight: 600;
  letter-spacing: -.02em;
  line-height: 1.1;
}
.metric .m-sub { font-family: var(--mono); font-size: 0.68rem; color: var(--text-3); }
.meter { height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; margin-top: auto; }
.meter > i {
  display: block; height: 100%;
  background: var(--brass);
  transition: width .5s cubic-bezier(.2,.7,.3,1);
}
.meter.warn > i { background: var(--amber); }
.meter.crit > i { background: var(--coral); }

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  flex: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-2);
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s ease;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  background: var(--brass-dim);
  color: var(--brass);
  border-color: color-mix(in srgb, var(--brass) 45%, transparent);
}
.tab-panel { display: flex; flex-direction: column; gap: 1.15rem; }

/* ---------- cards ---------- */
.card {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.card-head { display: flex; flex-direction: column; gap: 0.15rem; }
.eyebrow {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.76rem;
  color: var(--brass);
  letter-spacing: .01em;
}
.card-head h2 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: -.01em;
}
.card-note { margin: 0; color: var(--text-2); font-size: 0.88rem; }

/* ---------- rows ---------- */
.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.rows li {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.8rem;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  font-size: 0.9rem;
  animation: rowIn .25s ease both;
}
.rows li.done { opacity: .45; }
.rows li.done .r-text { text-decoration: line-through; }
.r-text { flex: 1; min-width: 0; word-break: break-word; }
.r-meta {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.72rem;
  color: var(--brass);
  flex: none;
}
.r-btn {
  flex: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-3);
  border-radius: var(--r-sm);
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all .15s ease;
}
.r-btn:hover { color: var(--text); border-color: var(--text-3); }
.r-btn.danger:hover { color: var(--coral); border-color: var(--coral); }

.data-rows li { flex-direction: column; align-items: stretch; gap: 0.2rem; font-family: var(--mono); font-size: 0.76rem; }
.data-row-top { display: flex; justify-content: space-between; gap: 0.6rem; }
.dim { color: var(--text-3); }

.empty { color: var(--text-3); font-size: 0.88rem; padding: 0.5rem 0; }

.kind-tag {
  font-family: var(--mono);
  font-size: 0.64rem;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  background: var(--brass-dim);
  color: var(--brass);
  flex: none;
}

/* ---------- composer ---------- */
.composer { display: flex; gap: 0.5rem; align-items: flex-end; }
.composer input, .composer textarea { flex: 1; min-width: 0; }
.input-narrow { flex: 0 0 92px !important; }
.composer textarea { resize: none; max-height: 140px; overflow-y: auto; line-height: 1.45; }
.hint { margin: 0; font-size: 0.72rem; color: var(--text-3); }

/* ---------- chat ---------- */
.chat-card { gap: 0.7rem; }
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 52dvh;
  min-height: 180px;
  overflow-y: auto;
  padding: 0.2rem;
  margin: -0.2rem;
}
.chat-msg {
  padding: 0.6rem 0.8rem;
  border-radius: var(--r-md);
  font-size: 0.9rem;
  max-width: 88%;
  white-space: pre-wrap;
  word-break: break-word;
  animation: rowIn .25s ease both;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--brass-dim);
  border: 1px solid color-mix(in srgb, var(--brass) 30%, transparent);
  border-bottom-right-radius: 3px;
}
.chat-msg.assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-bottom-left-radius: 3px;
}
.chat-msg .ts { display: block; margin-top: 0.3rem; font-family: var(--mono); font-size: 0.64rem; color: var(--text-3); }
.chat-msg code { font-family: var(--mono); font-size: .85em; background: var(--ink); padding: .05em .3em; border-radius: 3px; }
.chat-msg strong { font-weight: 650; }

.typing { display: inline-flex; gap: 3px; align-items: center; height: 1.2em; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--text-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }

/* ---------- toasts ---------- */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(1.1rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  z-index: 60;
  width: min(92vw, 380px);
}
.toast {
  padding: 0.65rem 0.9rem;
  border-radius: var(--r-sm);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 0.86rem;
  animation: toastIn .22s cubic-bezier(.2,.8,.3,1) both;
}
.toast.ok { border-left: 2px solid var(--jade); }
.toast.err { border-left: 2px solid var(--coral); }
.toast.leaving { animation: toastOut .18s ease forwards; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: grid; place-items: center;
  padding: 1.2rem;
  z-index: 70;
  animation: fadeIn .15s ease both;
}
.modal {
  width: min(90vw, 340px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 1.2rem;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 1rem;
  animation: modalIn .2s cubic-bezier(.2,.8,.3,1) both;
}
.modal p { margin: 0; font-size: 0.94rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }

/* ---------- offline ---------- */
.offline-banner {
  position: fixed; top: 0; left: 0; right: 0;
  background: var(--coral);
  color: #fff;
  font-size: 0.8rem;
  text-align: center;
  padding: 0.4rem;
  z-index: 80;
}

/* ---------- skeleton ---------- */
.skeleton-block { background: var(--surface); position: relative; overflow: hidden; }
.skeleton-block::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text-3) 10%, transparent), transparent);
  animation: shimmer 1.4s infinite;
}

/* ---------- motion ---------- */
@keyframes rowIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes blink { 0%,60%,100% { opacity: .25; } 30% { opacity: 1; } }

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