:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c1f24;
  --muted: #6b7280;
  --border: #dde1e6;
  --accent: #7360f2;
  --accent-text: #ffffff;
  --mine: #ece9ff;
  --ok: #16a34a;
  --busy: #d97706;
  --danger: #dc2626;
  --radius: 10px;
  color-scheme: light dark;
}

/* Dark colours: when Windows is dark (unless the operator picked Light), or when they picked Dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121418;
    --surface: #1b1e24;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --border: #2c3038;
    --mine: #2a2546;
  }
}
:root[data-theme="dark"] {
  --bg: #121418;
  --surface: #1b1e24;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --border: #2c3038;
  --mine: #2a2546;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }

/* Author display rules (e.g. .empty) would otherwise override the hidden attribute. */
[hidden] { display: none !important; }

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

h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 12px; }

button {
  font: inherit;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.link { border: 0; background: none; color: var(--accent); padding: 0 4px; }
button[aria-pressed="true"] { background: var(--busy); border-color: var(--busy); color: #fff; }

input, select {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
.prefs { display: flex; gap: 6px; }
.prefs select { width: auto; padding: 4px 8px; font-size: 13px; }
.who { color: var(--muted); }
.who strong { color: var(--text); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); margin-right: 4px; }
.dot.on { background: var(--ok); }

/* Phones and the call panel in a narrow left column; history takes the rest. */
.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 20%) 1fr;
  gap: 16px;
  padding: 16px;
  align-items: start;
}
@media (max-width: 760px) {
  .workspace { grid-template-columns: 1fr; }
}
.side {
  display: grid;
  gap: 16px;
  position: sticky;
  top: 16px;
}
@media (max-width: 760px) {
  .side { position: static; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.phone-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.phone {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.phone .info { flex: 1; min-width: 0; }
.phone .name { font-weight: 600; }
.phone .label { font-size: 13px; color: var(--muted); }
.phone .flag { font-size: 20px; }
.phone.free .label { color: var(--ok); }
.phone.taken { opacity: .6; }
.phone.offline { opacity: .4; border-style: dashed; }
.phone.low { opacity: .7; }
.phone.low .label { color: var(--danger); }
.phone .battery { color: var(--muted); white-space: nowrap; }
.phone.mine { border: 2px solid var(--accent); background: var(--mine); }

.empty { color: var(--muted); display: grid; place-items: center; min-height: 96px; text-align: center; }

.dial label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.in-call { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.call-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: baseline; }
#call-state { font-weight: 600; }
.number { color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 2px; }
.timer { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 600; }

.meter { height: 6px; border-radius: 3px; background: var(--border); margin-top: 12px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--ok); transition: width 80ms linear; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); width: min(360px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
dialog input + label { margin-top: 12px; }
.login-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.login-head h2 { margin: 0; }
.login-head select { width: auto; padding: 4px 8px; font-size: 13px; }
.login-error { color: var(--danger); font-size: 13px; margin: 10px 0 0; }

.history { min-width: 0; }
.history-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.history-bar h2 { margin: 0 8px 0 0; }
.history-bar select, .history-bar input { width: auto; flex: 1 1 160px; }
a.button {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}
.count { color: var(--muted); font-size: 13px; margin: 8px 0 12px; }

/* Staggered grid: columns filled by app.js, each card goes in the shortest column. */
.masonry { display: flex; gap: 12px; align-items: flex-start; }
.masonry-col { flex: 1 1 0; min-width: 0; display: grid; gap: 12px; }
.masonry-empty { color: var(--muted); padding: 24px 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: grid;
  gap: 4px;
}
.card.ok { border-left-color: var(--ok); }
.card.bad { border-left-color: var(--danger); }
.card.live { border-color: var(--accent); border-left-color: var(--accent); background: var(--mine); }
.card-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.card .result { font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.card.ok .result { color: var(--ok); }
.card.bad .result { color: var(--danger); }
.card.live .result { color: var(--accent); }
.card-number { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.card-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.card-meta .talk { font-variant-numeric: tabular-nums; color: var(--text); }
.card-error { font-size: 13px; color: var(--danger); overflow-wrap: anywhere; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 4px 16px rgb(0 0 0 / .2);
}
.toast.error { background: var(--danger); color: #fff; }

/* Right side: Customers and Call history tabs. */
.right { min-width: 0; display: grid; gap: 12px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); padding: 8px 14px; font-weight: 600; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.list-problem { color: var(--danger); font-size: 13px; margin: 8px 0 0; overflow-wrap: anywhere; }

.customers { min-width: 0; }
.customer-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.customer {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto minmax(180px, 1.2fr);
  gap: 6px 14px;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
@media (max-width: 1100px) { .customer { grid-template-columns: 1fr; } }
.customer .c-name { font-weight: 600; overflow-wrap: anywhere; }
.customer .c-name.none { font-weight: 400; font-style: italic; color: var(--muted); }
.customer .c-reaction { font-size: 12px; color: var(--muted); font-weight: 400; }
.customer .c-numbers { display: flex; flex-wrap: wrap; gap: 6px; }
.customer .c-numbers button { font-variant-numeric: tabular-nums; padding: 6px 10px; }
.customer .c-numbers button.bad { border-style: dashed; color: var(--muted); }
.customer .c-status { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.customer.calling { border-color: var(--busy); }
.customer.calling .c-status { color: var(--busy); font-weight: 600; }
.customer.mine { border: 2px solid var(--accent); background: var(--mine); }
.customer .c-status.ok { color: var(--ok); }
.customer .c-status.bad { color: var(--danger); }
