:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --border: #e2e2de;
  --hover: #efefec;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --danger: #b42318;
  --ok: #2e7d32;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131315;
    --surface: #1c1c1f;
    --text: #ececee;
    --muted: #9b9ba1;
    --border: #2d2d32;
    --hover: #26262a;
    --accent: #7c9dff;
    --accent-text: #0c1224;
    --danger: #ff7b6f;
    --ok: #7bd389;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
}

main { max-width: 720px; margin: 0 auto; padding: 16px 16px 48px; }

[hidden] { display: none !important; }

h1 { font-size: 22px; font-weight: 600; margin: 0 0 6px; }
h2 { font-size: 13px; font-weight: 600; margin: 0; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }
.error:empty { min-height: 0; }
.notice { background: var(--hover); border-radius: 8px; padding: 8px 12px; font-size: 14px; }

.panel {
  max-width: 380px;
  margin: 12vh auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  box-shadow: var(--shadow);
}
.panel form { display: grid; gap: 14px; margin-top: 16px; }
.panel .row { margin-top: 16px; }
.panel form .row { margin-top: 0; }

label { display: grid; gap: 6px; font-size: 14px; font-weight: 500; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }

input[type="text"], input:not([type]), input[type="password"], input[type="number"], select, textarea {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
}
textarea { resize: vertical; min-height: 76px; display: block; }
input:focus, select:focus, textarea:focus, button:focus-visible, .button:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button, .button {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  background: none;
  color: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
button:disabled { opacity: 0.55; cursor: default; }
.primary { background: var(--accent); color: var(--accent-text); }
.danger { background: var(--danger); color: #fff; }
.quiet { border-color: var(--border); background: var(--surface); }
.quiet:hover:not(:disabled) { background: var(--hover); }
.link { color: var(--accent); padding-left: 4px; padding-right: 4px; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row .primary:last-child { margin-left: auto; }

.bar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.brand { font-weight: 600; font-size: 17px; }
.bar nav { margin-left: auto; display: flex; gap: 8px; }
.conn { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.conn::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.conn[data-state="live"]::before { background: var(--ok); }

.composer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 10px;
  box-shadow: var(--shadow);
}
.composer textarea { background: transparent; border: none; padding: 4px; min-height: 64px; }
.composer textarea:focus { outline: none; }

.history { margin-top: 24px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }

.clips, .devices { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.clip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: grid;
  gap: 8px;
  min-width: 0;
}
.clip-body { min-width: 0; }
.clip-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 7.5em;
  overflow: hidden;
}
.clip-thumb {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: 6px;
  background: var(--hover);
}
.clip-thumb.pending { width: 160px; height: 90px; }
.clip-file { display: flex; gap: 10px; align-items: baseline; min-width: 0; }
.clip-body > .clip-file:not(:first-child) { margin-top: 8px; }
.clip-file strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.clip-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.clip-info { font-size: 12px; color: var(--muted); margin-right: auto; overflow-wrap: anywhere; }
.clip-actions { display: flex; gap: 6px; }
.clip-actions button { padding: 4px 10px; font-size: 13px; }
.clip.bad .clip-body { color: var(--danger); font-size: 14px; }

.more { margin: 12px auto 0; display: flex; }

dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 18px;
  width: min(460px, calc(100vw - 32px));
}
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
.devices li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.devices li:first-child { border-top: none; }
.device-name { font-weight: 500; }
.device-meta { font-size: 12px; color: var(--muted); }
.devices li > div { margin-right: auto; min-width: 0; }

.settings { display: grid; gap: 6px; }
.settings .section-head { margin-bottom: 8px; }
.settings label { margin-top: 8px; }
.settings select { appearance: auto; }
.settings .notice { margin: 8px 0 0; }
.settings .row { margin-top: 12px; justify-content: flex-end; }
.settings .row .primary:last-child { margin-left: 0; }
.field-unit { display: flex; align-items: center; gap: 10px; }
.field-unit input { max-width: 160px; }
.settings input[aria-invalid="true"] { border-color: var(--danger); }

.dropzone {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(0 0 0 / 0.4);
  z-index: 10;
  pointer-events: none;
}
.dropzone span {
  background: var(--surface);
  border: 2px dashed var(--accent);
  border-radius: 14px;
  padding: 28px 40px;
  font-weight: 500;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--text);
  color: var(--bg);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 20;
}
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 520px) {
  .panel { margin-top: 24px; padding: 20px; }
  .bar { flex-wrap: wrap; }
  .conn { order: 3; width: 100%; }
}
