/* mcpkit web UI — mobile-first, theme-aware. Light is the OS default; dark applies via
   prefers-color-scheme AND an explicit [data-theme] the toggle stamps on <html>, so the toggle
   wins in both directions. No external assets: everything ships embedded. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --border: #dfe3ea;
  --text: #1a1d24;
  --muted: #626a78;
  --accent: #2f6feb;
  --accent-text: #ffffff;
  --ok: #1a7f4b;
  --warn: #b25e00;
  --err: #c23b3b;
  --err-bg: #fdecec;
  --radius: 14px;
  --gap: 14px;
  --maxw: 720px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d12;
    --surface: #151922;
    --surface-2: #1d2330;
    --border: #2a3140;
    --text: #e7eaf0;
    --muted: #97a0b0;
    --accent: #4f8cff;
    --accent-text: #ffffff;
    --ok: #4ecb83;
    --warn: #e0a24a;
    --err: #ff6b6b;
    --err-bg: #2a1618;
  }
}

/* Explicit overrides beat the media query in both directions. */
:root[data-theme="light"] {
  --bg: #f6f7f9; --surface: #fff; --surface-2: #eef0f4; --border: #dfe3ea;
  --text: #1a1d24; --muted: #626a78; --accent: #2f6feb; --err: #c23b3b; --err-bg: #fdecec;
}
:root[data-theme="dark"] {
  --bg: #0b0d12; --surface: #151922; --surface-2: #1d2330; --border: #2a3140;
  --text: #e7eaf0; --muted: #97a0b0; --accent: #4f8cff; --err: #ff6b6b; --err-bg: #2a1618;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: max(env(safe-area-inset-top), 10px) 16px 10px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; font-weight: 650; margin: 0; letter-spacing: .2px; }
.topbar-actions { display: flex; gap: 6px; }

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  width: 38px; height: 38px;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
}
.icon-btn:active { transform: scale(.94); }

.view {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 40px);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: var(--gap);
}
.card h2 { margin: 0 0 6px; font-size: 18px; }

.muted { color: var(--muted); }
.muted.center { text-align: center; margin-top: 40px; }
.error { color: var(--err); }

/* Auth */
.auth-card { margin-top: 8vh; }
#auth-form { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px; /* ≥16px so iOS Safari doesn't zoom on focus */
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button.primary, button[type="submit"].primary {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  padding: 12px 16px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
}
button.primary:disabled { opacity: .5; }
button.primary:active { transform: scale(.98); }

.link-btn {
  background: none; border: none; color: var(--accent);
  font-size: 15px; padding: 4px 0 12px; cursor: pointer;
}

/* Tool list */
.tool-group-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); margin: 18px 4px 8px;
}
.tool-item {
  display: block; width: 100%; text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  color: var(--text);
}
.tool-item:active { background: var(--surface-2); }
.tool-item .name { font-weight: 600; }
.tool-item .desc { color: var(--muted); font-size: 14px; margin-top: 2px; }

/* Tool form */
#tool-form { display: flex; flex-direction: column; gap: 14px; margin-top: 10px; }
.field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.field .hint { color: var(--muted); font-size: 13px; margin-top: 4px; }
.field-check { display: flex; align-items: center; gap: 10px; }
.field-check input { width: auto; }
.field-check label { margin: 0; }

/* Result */
#result { margin-top: 4px; }
.result-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px; overflow: hidden; }
.result-card.err { border-color: var(--err); background: var(--err-bg); }
.result-head { display:flex; justify-content: space-between; align-items:center; padding: 10px 14px; }
.result-head .status { font-size: 13px; font-weight: 600; }
.result-head .status.ok { color: var(--ok); }
.result-head .status.err { color: var(--err); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; position: sticky; top: 0; background: var(--surface-2); }
tr:last-child td { border-bottom: none; }

pre.raw { margin: 0; padding: 14px; overflow-x: auto; font-size: 13px; line-height: 1.45; white-space: pre; }

/* x-display master-detail: each row is a group with a header line + an indented detail table. */
.dtl { padding: 6px; }
.dtl-group { padding: 10px 10px 12px; border-bottom: 1px solid var(--border); }
.dtl-group:last-child { border-bottom: none; }
.dtl-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; margin-bottom: 8px; }
.dtl-title { font-weight: 650; font-size: 15px; }
.dtl-meta { color: var(--muted); font-size: 13px; }
.dtl-flags { margin-left: auto; font-size: 15px; }
.dtl-group .table-wrap { border: 1px solid var(--border); border-radius: 10px; }
.dtl-group table { font-size: 13px; }

.spinner { display:inline-block; width:16px; height:16px; border:2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%);
  background: var(--err); color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.28);
  max-width: 90vw;
}
