/* TETRA-Gateway – gemeinsame Oberfläche (Client und Server). Kein Framework, kein CDN. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1d2430;
  --muted: #6b7380;
  --border: #d9dde3;
  --accent: #1f5fae;
  --accent-text: #ffffff;
  --ok: #1e7a3c;
  --warn: #9a6500;
  --bad: #b3261e;
  --flash: #b3261e;
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181f;
    --surface: #1d232c;
    --text: #e4e7ec;
    --muted: #98a1ad;
    --border: #323a46;
    --accent: #5b9be6;
    --accent-text: #0b0f14;
    --ok: #4fc27a;
    --warn: #e0a33a;
    --bad: #f07067;
    --flash: #f07067;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }

/* ---------------------------------------------------------------- Kopfzeile */

.topbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.site { color: var(--muted); }
.mainnav { display: flex; gap: .25rem; flex-wrap: wrap; }
.mainnav a { padding: .3rem .6rem; border-radius: var(--radius); text-decoration: none; color: var(--text); }
.mainnav a.active, .mainnav a:hover { background: var(--bg); }
.spacer { flex: 1; }
.who { color: var(--muted); }
.conn { color: var(--muted); font-size: .9rem; }
.conn.on { color: var(--ok); }
.conn.off { color: var(--bad); }

main { max-width: 1280px; margin: 0 auto; padding: 1rem; }

/* ---------------------------------------------------------------- Bausteine */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.card.narrow { max-width: 420px; margin: 2rem auto; }
.card > header { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.card > header h2 { margin: 0 0 .5rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1rem; }

.muted { color: var(--muted); font-weight: normal; }
.hint { color: var(--muted); font-size: .9rem; }
.empty { color: var(--muted); font-style: italic; }
.error { color: var(--bad); }
.nowrap { white-space: nowrap; }

.flash { padding: .6rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid var(--border); background: var(--surface); }
.flash.error { border-color: var(--bad); color: var(--bad); }
.flash.success { border-color: var(--ok); color: var(--ok); }

.toast {
  position: fixed; right: 1rem; bottom: 1rem; max-width: 380px; z-index: 10;
  padding: .7rem 1rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.flash-sds { border: 2px solid var(--flash); }

.badge {
  display: inline-block; padding: 0 .4rem; border-radius: 4px; font-size: .8rem;
  border: 1px solid var(--border); color: var(--muted);
}
.badge.flash { border-color: var(--flash); color: var(--flash); font-weight: 600; }
.opta { color: var(--muted); font-size: .85rem; white-space: pre; }

/* ---------------------------------------------------------------- Status */

dl.status { display: grid; grid-template-columns: max-content 1fr; gap: .2rem .8rem; margin: 0; }
dl.status dt { color: var(--muted); }
dl.status dd { margin: 0; }
.state { font-weight: 600; }
.state-online { color: var(--ok); }
.state-connecting { color: var(--warn); }
.state-error, .state-offline { color: var(--bad); }
.state-driver_unavailable, .state-disabled { color: var(--muted); }
.detail { color: var(--muted); font-size: .85rem; }
.radio.tx { outline: 2px solid var(--bad); }
.radio.rx { outline: 2px solid var(--ok); }

/* ---------------------------------------------------------------- Formulare */

form.inline { display: inline; margin: 0; }
.stack { display: flex; flex-direction: column; gap: .7rem; margin-bottom: .8rem; }
.stack label { display: flex; flex-direction: column; gap: .25rem; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: end; }
.filter { margin-bottom: 1rem; }
label.choice { flex-direction: row; align-items: center; gap: .4rem; display: inline-flex; margin-right: 1rem; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); }

input, select, textarea, button {
  font: inherit; color: inherit;
  padding: .45rem .6rem;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg);
}
textarea { resize: vertical; }
button { cursor: pointer; background: var(--surface); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--bad); border-color: var(--bad); }
button.link { border: none; background: none; color: var(--accent); padding: 0; }
button.link.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
.counter { font-size: .8rem; align-self: flex-end; }
.result { min-height: 1.2em; margin: 0; }
.result.ok { color: var(--ok); }
.result.err { color: var(--bad); }

/* ---------------------------------------------------------------- Tabellen */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .35rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; }
tr.warn td { color: var(--warn); }
tr.muted td { color: var(--muted); }
td.dir { font-weight: 700; }
tr.dir-in td.dir { color: var(--ok); }
tr.dir-out td.dir { color: var(--accent); }
tr.flash td.content { font-weight: 600; }
tr.new { animation: highlight 2s ease-out; }
td.content { white-space: pre-wrap; word-break: break-word; }
td.detail .kv { margin-right: .6rem; }
.delivery-delivered { color: var(--ok); }
.delivery-failed { color: var(--bad); }
.delivery-pending { color: var(--warn); }

ul.segments { list-style: none; margin: 0; padding: 0; }
ul.segments li { display: flex; gap: .5rem; flex-wrap: wrap; }
ul.segments .t, ul.segments .d { color: var(--muted); font-variant-numeric: tabular-nums; }
ul.segments li.own .who { color: var(--accent); }
ul.segments li.open .d::after { content: "spricht …"; color: var(--bad); }
table.calls tr.open td[data-field="duration"] { color: var(--bad); }

/* ---------------------------------------------------------------- Leitstand */

.console {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: .75rem;
  align-items: start;
}
.console-col {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .75rem; display: flex; flex-direction: column; gap: .6rem; min-width: 0;
}
.console-col > header { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.console-col > header h2 { margin: 0; font-size: 1.05rem; }
.talker-panel {
  border-radius: var(--radius); padding: .6rem; background: var(--bg);
  display: grid; gap: .3rem; border: 2px solid transparent;
}
.talker-panel strong { font-size: 1.05rem; word-break: break-word; }
.talker-panel .tg-current, .talker-panel .talker { display: flex; flex-direction: column; }
.talker-panel .meta { display: flex; gap: .8rem; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.radio.rx .talker-panel { border-color: var(--ok); }
.radio.tx .talker-panel { border-color: var(--bad); }
.radio.tx, .radio.rx { outline: none; }

.ptt-wrap { display: flex; flex-direction: column; gap: .25rem; }
button.ptt {
  width: 100%; min-height: 4.2rem; font-size: 1.3rem; font-weight: 700; letter-spacing: .05em;
  border-radius: var(--radius); border: 2px solid var(--border); background: var(--bg);
  user-select: none; -webkit-user-select: none; touch-action: none;
}
button.ptt.requesting { border-color: var(--warn); color: var(--warn); }
button.ptt.sending { background: var(--bad); border-color: var(--bad); color: #fff; }
button.ptt.busy { border-color: var(--ok); color: var(--muted); cursor: not-allowed; }
button.ptt:focus-visible { outline: 3px solid var(--accent); }
.ptt-hint { margin: 0; font-size: .8rem; }

.tg-switch { position: relative; }
.tg-switch input { width: 100%; }
.tg-results {
  list-style: none; margin: .2rem 0 0; padding: 0; max-height: 16rem; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface);
}
.tg-results li button {
  display: flex; width: 100%; justify-content: space-between; gap: .5rem;
  border: none; border-radius: 0; background: none; text-align: left; padding: .4rem .6rem;
}
.tg-results li button:hover, .tg-results li button:focus { background: var(--bg); }
.tg-results .folder { color: var(--muted); font-size: .85rem; }
.tg-results .on-device { color: var(--ok); font-size: .8rem; }
.tg-results li.current button { font-weight: 700; }

.quick-sds { display: flex; flex-direction: column; gap: .4rem; }
.quick-sds .row { justify-content: space-between; align-items: center; gap: .5rem; }
.feed { list-style: none; margin: 0; padding: 0; font-size: .88rem; max-height: 14rem; overflow-y: auto; }
.feed li { display: flex; gap: .4rem; padding: .2rem 0; border-top: 1px solid var(--border); }
.feed .t { color: var(--muted); font-variant-numeric: tabular-nums; }
.feed .who { white-space: nowrap; }
.feed .txt { word-break: break-word; }
.feed li.dir-in .who { color: var(--ok); }
.feed li.dir-out .who { color: var(--accent); }
.feed li.flash .txt { font-weight: 700; color: var(--flash); }
.feed li.feed-call .who { color: var(--muted); }
form.inline-edit { gap: .4rem; flex-wrap: nowrap; }
form.inline-edit input { min-width: 0; flex: 1; }

@keyframes highlight { from { background: rgba(91, 155, 230, .25); } to { background: transparent; } }

@media (max-width: 640px) {
  .topbar { gap: .5rem; }
  table { font-size: .9rem; }
}

/* PTT gesperrt (kein Recht oder kein Ton-Weg) */
.ptt.ptt-off,
.ptt.ptt-off:hover {
  opacity: .45;
  cursor: not-allowed;
  filter: grayscale(1);
}

/* ---------------------------------------------------------------- Gruppenverzeichnis */
.page-head { display: flex; flex-wrap: wrap; gap: .75rem 1.5rem; align-items: center; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.search-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; flex: 1; }
.search-bar input[type=search] { flex: 1; min-width: 14rem; max-width: 28rem; }
.tg-page { display: grid; gap: 1rem; align-items: start; }
.tg-page.with-side { grid-template-columns: minmax(0, 1fr) 320px; }
@media (max-width: 900px) { .tg-page.with-side { grid-template-columns: 1fr; } }
.tg-list { padding: 0; overflow: hidden; }
.tg-list > .empty, .tg-list > .hint { padding: 1rem; margin: 0; }
.table-scroll { max-height: calc(100vh - 12rem); overflow: auto; }
.tg-table th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.tg-table th, .tg-table td { padding: .4rem .75rem; vertical-align: middle; }
.tg-table td.num, .tg-table th.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.tg-table tbody tr:hover { background: var(--bg); }
.tg-table tr.selected { background: var(--bg); box-shadow: inset 3px 0 0 var(--accent); }
.tg-table td.actions { text-align: right; white-space: nowrap; }
.tg-table td.actions a { visibility: hidden; }
.tg-table tr:hover td.actions a, .tg-table tr.selected td.actions a, .tg-table td.actions a:focus { visibility: visible; }
@media (hover: none) { .tg-table td.actions a { visibility: visible; } }
.tg-table .badge { font-size: .78rem; }
.src { font-size: .8rem; color: var(--muted); }
.src-device { color: var(--ok); }
.tg-side { display: flex; flex-direction: column; gap: 1rem; position: sticky; top: 1rem; }
.tg-side .card { margin: 0; }
.tg-side h2 { font-size: 1rem; }
ul.device-import { list-style: none; margin: 0 0 .5rem; padding: 0; display: flex; flex-direction: column; gap: .6rem; }
ul.device-import li { display: flex; flex-direction: column; gap: .15rem; }
.device-line { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.device-line form { margin: 0; }
details.card > summary { cursor: pointer; font-weight: 600; }
details.card[open] > summary { margin-bottom: .75rem; }

/* Gesprächsliste: Gruppenname + Nummer */
td.tg-cell .tg-name { font-weight: 600; }
td.tg-cell .tg-num { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }

/* Server: einmalige Token-Anzeige, Konfigurationsschnipsel */
.token-box code { display: block; padding: .6rem .8rem; border: 2px dashed var(--accent); border-radius: var(--radius); word-break: break-all; font-size: 1rem; user-select: all; }
pre.code { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .8rem; overflow-x: auto; }
.inline-edit { gap: .4rem; align-items: center; flex-wrap: nowrap; }
.inline-edit input { min-width: 8rem; }
