/* DSH Pocket — mobile-first design system.
   Dark, calm, high-contrast, thumb-friendly. */

:root {
  color-scheme: dark;

  --bg: #0b0d12;
  --bg-elevated: #12151d;
  --panel: #161a24;
  --panel-2: #1c2130;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.13);

  --text: #e9ecf5;
  --text-dim: #9aa2b6;
  --text-faint: #6c7488;

  --accent: #5b8cff;
  --accent-2: #8b5cf6;
  --accent-soft: rgba(91, 140, 255, 0.14);
  --ok: #35d39a;
  --warn: #f5b544;
  --danger: #ff5d6c;

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-height: 62px;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "SF Pro Text", system-ui, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(91, 140, 255, 0.16), transparent 60%),
    radial-gradient(80% 40% at 100% 0%, rgba(139, 92, 246, 0.10), transparent 55%),
    var(--bg);
}

button, input, textarea {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

a { color: var(--accent); text-decoration: none; }

::-webkit-scrollbar { width: 0; height: 0; }

/* ---------- app frame ---------- */

#app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  animation: view-in 220ms ease both;
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px calc(20px + var(--safe-bottom));
  scrollbar-width: none;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: linear-gradient(180deg, rgba(11, 13, 18, 0.96) 60%, rgba(11, 13, 18, 0.72));
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .sub {
  display: block;
  font-size: 12px;
  font-weight: 450;
  color: var(--text-faint);
  margin-top: 2px;
}

.topbar > .chip { flex: 0 0 auto; }

.icon-btn {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--text-dim);
  background: var(--panel);
  border: 1px solid var(--line);
  transition: transform 120ms ease, background 120ms ease;
}

.icon-btn:active { transform: scale(0.94); background: var(--panel-2); }
.icon-btn.accent { color: #fff; background: linear-gradient(145deg, var(--accent), var(--accent-2)); border-color: transparent; }
.icon-btn svg { width: 19px; height: 19px; }

/* ---------- cards ---------- */

.card {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.015));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 16px;
  margin-top: 12px;
  transition: transform 140ms ease, border-color 140ms ease;
}

.card.tappable:active { transform: scale(0.985); border-color: var(--line-strong); }

.card.compact { padding: 12px 14px; }
.card.compact .card-head { margin-bottom: 0; }
.card.compact .meta-row { margin-top: 8px; }

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.card-title {
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.35;
  flex: 1;
  min-width: 0;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: 0 0 7px;
}

.dot.live { background: var(--ok); box-shadow: 0 0 0 4px rgba(53, 211, 154, 0.15); animation: pulse 2s infinite; }
.dot.err { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  font-size: 11.5px;
  font-weight: 550;
  border-radius: 999px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  white-space: nowrap;
}

.chip.blue { color: #a8c0ff; background: var(--accent-soft); border-color: rgba(91, 140, 255, 0.25); }
.chip.green { color: #86e9c4; background: rgba(53, 211, 154, 0.12); border-color: rgba(53, 211, 154, 0.25); }
.chip.red { color: #ffabb4; background: rgba(255, 93, 108, 0.12); border-color: rgba(255, 93, 108, 0.25); }
.chip.amber { color: #f7d08a; background: rgba(245, 181, 68, 0.12); border-color: rgba(245, 181, 68, 0.25); }

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.mono { font-family: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace; }

.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.section-label {
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 22px 4px 6px;
}

/* ---------- bottom nav ---------- */

.tabbar {
  position: sticky;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 6px 10px calc(6px + var(--safe-bottom));
  background: rgba(12, 14, 20, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0 4px;
  border-radius: 12px;
  color: var(--text-faint);
  font-size: 10.5px;
  font-weight: 550;
  transition: color 150ms ease;
}

.tab svg { width: 21px; height: 21px; }
.tab.active { color: var(--text); }
.tab.active svg { color: var(--accent); filter: drop-shadow(0 0 10px rgba(91, 140, 255, 0.45)); }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 18px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  background: var(--panel-2);
  border: 1px solid var(--line);
  transition: transform 120ms ease, opacity 120ms ease;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; }
.btn.primary {
  color: #fff;
  background: linear-gradient(140deg, #5b8cff, #7c5cff);
  border-color: transparent;
  box-shadow: 0 10px 26px rgba(91, 140, 255, 0.28);
}
.btn.ghost { background: transparent; }
.btn.danger { color: #ffb3ba; background: rgba(255, 93, 108, 0.1); border-color: rgba(255, 93, 108, 0.25); }
.btn.sm { width: auto; padding: 9px 14px; font-size: 13px; border-radius: 11px; }

.field {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 14px 15px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.field:focus { border-color: rgba(91, 140, 255, 0.55); box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.14); }
.field::placeholder { color: var(--text-faint); }

/* ---------- empty / loading ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 56px 24px;
  color: var(--text-dim);
}

.empty svg { width: 44px; height: 44px; opacity: 0.5; }
.empty h3 { margin: 0; font-size: 16px; font-weight: 600; color: var(--text); }
.empty p { margin: 0; font-size: 13.5px; line-height: 1.5; max-width: 280px; }

.skeleton {
  height: 86px;
  border-radius: var(--radius);
  margin-top: 12px;
  background: linear-gradient(100deg, var(--panel) 20%, var(--panel-2) 40%, var(--panel) 60%);
  background-size: 300% 100%;
  animation: shimmer 1.4s infinite linear;
}

@keyframes shimmer { to { background-position: -300% 0; } }

.spinner {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-top-color: #fff;
  animation: spin 700ms linear infinite;
}

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

/* ---------- chat ---------- */

.chat-scroll {
  padding: 12px 14px calc(16px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  max-width: 88%;
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  animation: bubble-in 180ms ease both;
}

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.bubble.user {
  align-self: flex-end;
  color: #fff;
  background: linear-gradient(140deg, #4b7dfa, #6d54e8);
  border-bottom-right-radius: 6px;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.bubble.assistant.streaming::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--accent);
  border-radius: 2px;
  animation: caret 1s steps(2) infinite;
}

@keyframes caret { 50% { opacity: 0; } }

.bubble .md-code {
  display: block;
  margin: 8px 0 2px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.42);
  border: 1px solid var(--line);
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.45;
  overflow-x: auto;
  white-space: pre;
}

.bubble code.inline {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.09);
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 0.92em;
}

.tool-row {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 92%;
  padding: 7px 11px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--text-dim);
  animation: bubble-in 180ms ease both;
}

.tool-row .name { color: #b9c6e6; font-weight: 600; font-family: ui-monospace, "SF Mono", Consolas, monospace; }
.tool-row .status { margin-left: auto; font-size: 10.5px; font-weight: 650; letter-spacing: 0.04em; }
.tool-row .status.ok { color: var(--ok); }
.tool-row .status.fail { color: var(--danger); }
.tool-row .status.run { color: var(--warn); animation: pulse 1.6s infinite; }

.reasoning {
  align-self: flex-start;
  max-width: 92%;
  font-size: 12.5px;
  color: var(--text-faint);
}

.reasoning summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px 4px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--text-faint);
  transition: color 140ms ease;
}

.reasoning summary::-webkit-details-marker { display: none; }
.reasoning .chev {
  display: inline-block;
  font-size: 14px;
  line-height: 1;
  transition: transform 160ms ease;
}
.reasoning[open] .chev { transform: rotate(90deg); }
.reasoning[open] summary { color: var(--text-dim); }

.reasoning .body {
  white-space: pre-wrap;
  padding: 8px 12px;
  margin-top: 6px;
  border-left: 2px solid var(--line-strong);
  line-height: 1.5;
  color: var(--text-dim);
  max-height: 220px;
  overflow-y: auto;
}

.day-sep {
  align-self: center;
  font-size: 11px;
  color: var(--text-faint);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  margin: 8px 0;
}

/* ---------- composer ---------- */

.composer {
  position: sticky;
  bottom: 0;
  z-index: 35;
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 10px 14px calc(10px + var(--safe-bottom));
  background: linear-gradient(180deg, rgba(11, 13, 18, 0.72), rgba(11, 13, 18, 0.98) 40%);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}

.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  padding: 12px 14px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  resize: none;
  outline: none;
  font-size: 15.5px;
  line-height: 1.35;
  transition: border-color 140ms ease;
}

.composer textarea:focus { border-color: rgba(91, 140, 255, 0.5); }

.send-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(140deg, #5b8cff, #7c5cff);
  box-shadow: 0 8px 22px rgba(91, 140, 255, 0.3);
  transition: transform 120ms ease, opacity 120ms ease;
}

.send-btn:active { transform: scale(0.92); }
.send-btn:disabled { opacity: 0.4; box-shadow: none; }
.send-btn.stop { background: linear-gradient(140deg, #ff6b78, #e0455a); }
.send-btn svg { width: 20px; height: 20px; }

/* ---------- reports ---------- */

.report-ask {
  font-size: 13.5px;
  color: var(--text-dim);
  padding-left: 10px;
  border-left: 2px solid rgba(91, 140, 255, 0.4);
  margin: 8px 0;
  line-height: 1.45;
}

.report-answer {
  font-size: 14px;
  line-height: 1.5;
  margin: 8px 0 0;
  color: var(--text);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.stat {
  padding: 9px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line);
}

.stat .k { font-size: 10.5px; color: var(--text-faint); letter-spacing: 0.03em; text-transform: uppercase; }
.stat .v { font-size: 15px; font-weight: 650; margin-top: 2px; letter-spacing: -0.01em; }

.files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

/* ---------- plugins ---------- */

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 15px;
  margin-top: 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.032);
  border: 1px solid var(--line);
}

.row .grow { flex: 1; min-width: 0; }
.row .name { font-size: 14.5px; font-weight: 600; letter-spacing: -0.01em; }
.row .desc { font-size: 12px; color: var(--text-faint); margin-top: 3px; line-height: 1.4; }

.row .desc {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.switch {
  position: relative;
  width: 46px;
  height: 27px;
  flex: 0 0 46px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  transition: background 180ms ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #fff;
  transition: transform 180ms cubic-bezier(0.3, 0.9, 0.4, 1);
}

.switch.on { background: linear-gradient(140deg, #5b8cff, #7c5cff); }
.switch.on::after { transform: translateX(19px); }

/* ---------- pairing ---------- */

.pair-wrap {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  max-width: 100%;
  min-height: 100dvh;
  padding: calc(28px + var(--safe-top)) 24px calc(28px + var(--safe-bottom));
  gap: 6px;
}

.pair-logo {
  width: 62px;
  height: 62px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, #5b8cff, #7c5cff);
  box-shadow: 0 16px 40px rgba(91, 140, 255, 0.32);
  margin-bottom: 18px;
}

.pair-logo svg { width: 32px; height: 32px; color: #fff; }

.pair-wrap h1 { font-size: 27px; letter-spacing: -0.03em; margin: 0 0 6px; font-weight: 700; }
.pair-wrap p { color: var(--text-dim); margin: 0 0 22px; font-size: 14.5px; line-height: 1.5; }

.pin-field {
  text-align: center;
  font-size: 30px;
  font-weight: 650;
  letter-spacing: 0.42em;
  padding: 16px;
  font-variant-numeric: tabular-nums;
  text-indent: 0.42em;
}
.pair-err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; text-align: center; }

/* ---------- toast ---------- */

.toast-host {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(84px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 100;
}

.toast {
  max-width: 86vw;
  padding: 11px 16px;
  border-radius: 13px;
  background: rgba(28, 33, 48, 0.97);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  font-size: 13.5px;
  animation: toast-in 200ms ease both;
}

.toast.err { border-color: rgba(255, 93, 108, 0.4); color: #ffc4c9; }
.toast.ok { border-color: rgba(53, 211, 154, 0.4); color: #b9f5df; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* ---------- misc ---------- */

.offline-banner {
  padding: 7px 16px;
  background: rgba(245, 181, 68, 0.12);
  border-bottom: 1px solid rgba(245, 181, 68, 0.25);
  color: #f7d08a;
  font-size: 12px;
  text-align: center;
}

.spacer { flex: 1; }

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