:root {
  --bg: #eef1f5; --card: #fff; --fg: #1f2937; --muted: #6b7280; --line: #dde1e7;
  --accent: #2563eb; --accent-dk: #1d4ed8; --ok: #16a34a; --err: #dc2626;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 1px 4px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { font-family: system-ui, sans-serif; font-size: 15px; line-height: 1.4; margin: 0; background: var(--bg); color: var(--fg); display: flex; flex-direction: column; }

/* Header + tabs */
header { display: flex; gap: 0.75em; align-items: center; padding: 0.6em 1.25em; background: #111827; color: #fff; }
h1 { font-size: 1.05em; font-weight: 600; letter-spacing: 0.02em; margin: 0 1em 0 0; }
header button { background: transparent; color: #fff; border-color: #4b5563; }
header button.primary { background: var(--accent); border-color: var(--accent); }
#devname { font-family: var(--mono); color: #cbd5e1; }
.badge { margin-left: auto; padding: 2px 10px 2px 8px; border-radius: 999px; background: #374151; color: #d1d5db; font-size: 12px; }
.badge::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; margin-right: 6px; }
.badge.on { background: #14532d; color: #dcfce7; }
.badge.on::before { background: #4ade80; box-shadow: 0 0 6px #4ade80; }

#tabs { display: flex; gap: 2px; padding: 0.4em 1.25em 0; background: var(--card); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
#tabs button { white-space: nowrap; }
#tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 14px; color: var(--muted); font-weight: 500; }
#tabs button:hover { color: var(--fg); background: #f3f4f6; }
#tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
#tabs button.alert { color: var(--err); }

/* Controls */
button { font: inherit; padding: 5px 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--fg); cursor: pointer; transition: background .12s, border-color .12s; }
button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover:not(:disabled) { background: var(--accent-dk); color: #fff; }
input[type=text], input[type=number], select { font: inherit; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; width: 16em; max-width: 100%; background: var(--card); }
input:focus, select:focus, button:focus-visible { outline: 2px solid #93c5fd; outline-offset: 1px; border-color: var(--accent); }
label { user-select: none; }

/* Layout */
main { padding: 1.25em; flex: 1; min-height: 0; overflow: auto; }
.tab { display: none; }
.tab.active { display: block; }
#tab-image.active { display: flex; flex-direction: column; height: 100%; }
.cols { display: flex; gap: 2em; flex-wrap: wrap; align-items: flex-start; }
.cols > * { flex: 1 1 320px; max-width: 480px; }

h2 { font-size: 0.8em; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 0.6em; display: flex; align-items: center; gap: 0.75em; }
h2 .tools { margin-left: auto; font-weight: normal; text-transform: none; letter-spacing: 0; font-size: 1.15em; display: flex; gap: 0.75em; align-items: center; }
h2 ~ h2 { margin-top: 1.75em; }
form { margin-bottom: 1.75em; }
form .buttons { margin-top: 0.75em; display: flex; gap: 0.5em; }

table { border-collapse: collapse; width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; box-shadow: var(--shadow); }
td { padding: 6px 10px; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
td:first-child { color: var(--muted); width: 9em; }
td:last-child { font-family: var(--mono); }
form td { padding: 4px 10px; }

/* Panels */
.muted { color: var(--muted); font-family: var(--mono); font-size: 12px; margin-bottom: 0.4em; }
#mapwrap { flex: 3 1 400px; max-width: none; }
#map { height: 60vh; border-radius: 8px; border: 1px solid var(--line); box-shadow: var(--shadow); }
#imgwrap { flex: 1; min-height: 0; position: relative; }
#image { display: block; width: 100%; height: 100%; object-fit: contain; }
#term { height: 60vh; padding: 6px; background: #000; border-radius: 8px; box-shadow: var(--shadow); }
#log { background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 0.6em 0.8em; margin: 0; font: 12px/1.5 var(--mono); white-space: pre-wrap; word-break: break-all; max-height: 75vh; overflow-y: auto; }
.err { color: var(--err); }
dialog { border: none; border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.25); padding: 1em 1.25em; min-width: 320px; }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h2 { color: var(--err); }
#pingdlg { text-align: center; }
.spinner { width: 32px; height: 32px; margin: 0.5em auto; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
dialog pre { font: 13px/1.5 var(--mono); margin: 0 0 1em; white-space: pre-wrap; }
.warn { background: #fef2f2; color: #991b1b; border: 1px solid #fca5a5; border-left: 4px solid var(--err); border-radius: 6px; padding: 0.6em 0.9em; margin-bottom: 1.25em; font-weight: 600; }

/* Phones / portrait */
@media (max-width: 640px) {
  body { font-size: 16px; }             /* also stops iOS zooming into inputs */
  header { flex-wrap: wrap; padding: 0.6em 0.9em; gap: 0.5em; }
  h1 { margin-right: 0.5em; }
  #devname { order: 10; flex-basis: 100%; font-size: 0.85em; }
  #tabs { padding: 0.3em 0.5em 0; }
  #tabs button { padding: 10px 12px; }
  main { padding: 0.9em; }
  .cols { gap: 1.25em; }
  .cols > * { max-width: none; }
  td:first-child { width: 7em; }
  input[type=text], input[type=number], select { width: 100%; }
  button { padding: 8px 14px; }
  #map, #term { height: 50vh; }
  dialog { min-width: 0; width: 90vw; }
}
