:root {
  --brand: #1F4E79;
  --brand-ink: #ffffff;
  --brand-soft: #D3E4F5;
  --brand-soft-ink: #0b2a45;
  --bg: #F6F8FB;
  --surface: #FFFFFF;
  --surface-2: #EEF2F7;
  --ink: #16202B;
  --ink-2: #4B5867;
  --line: #DCE3EC;
  --green: #2E7D32;
  --red: #C62828;
  --orange: #E65100;
  --focus: #2F7BD0;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 4px 16px rgba(16, 32, 48, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #A1C9F2;
    --brand-ink: #062440;
    --brand-soft: #1F3B57;
    --brand-soft-ink: #D3E4F5;
    --bg: #0F141A;
    --surface: #171E26;
    --surface-2: #1F2832;
    --ink: #E6EDF4;
    --ink-2: #9FB0C2;
    --line: #2A3542;
    --green: #66BB6A;
    --red: #EF5350;
    --orange: #FFA726;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.hidden { display: none !important; }

.boot { display: grid; place-items: center; height: 100vh; }
.boot-logo { font-size: 42px; font-weight: 700; color: var(--brand); letter-spacing: -1px; }

/* ---------- Kirjautuminen ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(400px, 100%); background: var(--surface); border-radius: 20px; padding: 32px 28px;
  box-shadow: var(--shadow); }
.auth-card h1 { margin: 0 0 4px; font-size: 30px; color: var(--brand); letter-spacing: -.5px; }
.auth-card p.lead { margin: 0 0 22px; color: var(--ink-2); }
.qr { display: grid; place-items: center; padding: 12px; background: #fff; border-radius: 12px; margin: 12px 0; }
.qr svg, .qr img { width: 200px; height: 200px; }
.secret { font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all;
  background: var(--surface-2); padding: 8px 10px; border-radius: 8px; user-select: all; }

/* ---------- Lomakkeet ---------- */
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 5px; }
.input, select.input, textarea.input {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); outline: none; transition: border-color .15s;
}
.input:focus { border-color: var(--brand); }
textarea.input { min-height: 80px; resize: vertical; }
.code-input { font-size: 26px; letter-spacing: 8px; text-align: center; font-variant-numeric: tabular-nums; }
.error { color: var(--red); font-size: 14px; min-height: 20px; margin: 6px 0; }
.hint { color: var(--ink-2); font-size: 13px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; cursor: pointer;
  padding: 10px 18px; border-radius: 999px; background: var(--brand); color: var(--brand-ink); font-weight: 600;
  transition: filter .15s, transform .05s; white-space: nowrap; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; padding: 13px; }
.btn.tonal { background: var(--brand-soft); color: var(--brand-soft-ink); }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.green { background: var(--green); color: #fff; }
.btn.red { background: var(--red); color: #fff; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: transparent; color: var(--ink-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.call { color: var(--brand); }
svg.i { width: 22px; height: 22px; fill: currentColor; flex: none; }

/* ---------- Pääasettelu ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; display: flex;
  flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.side .logo { font-size: 26px; font-weight: 700; color: var(--brand); padding: 4px 14px 16px; letter-spacing: -.5px; }
.nav-item { display: flex; align-items: center; gap: 14px; padding: 11px 14px; border-radius: 999px; color: var(--ink-2);
  text-decoration: none; font-weight: 500; position: relative; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--brand-soft); color: var(--brand-soft-ink); }
.nav-item .badge { margin-left: auto; }
.badge { background: var(--red); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 7px;
  min-width: 20px; text-align: center; }
.side .spacer { flex: 1; }
.phone-state { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); padding: 10px 14px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-2); flex: none; }
.dot.ok { background: var(--green); }
.dot.err { background: var(--red); }
.dot.wait { background: var(--orange); }
.who { font-size: 13px; color: var(--ink-2); padding: 0 14px 8px; }

main { min-width: 0; padding: 24px clamp(16px, 4vw, 40px) 120px; max-width: 1080px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 24px; letter-spacing: -.3px; margin-right: auto; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 20px; }
.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--line);
  cursor: pointer; }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .title.missed { color: var(--red); }
.row .sub { color: var(--ink-2); font-size: 13px; display: flex; align-items: center; gap: 6px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.row .sub svg.i { width: 15px; height: 15px; }
.row .meta { color: var(--ink-2); font-size: 13px; white-space: nowrap; text-align: right; max-width: 40%; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  font-weight: 600; flex: none; }
.section-letter { padding: 14px 16px 4px; color: var(--brand); font-weight: 700; font-size: 13px; }
.empty { padding: 48px 16px; text-align: center; color: var(--ink-2); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 6px 14px; border-radius: 999px;
  cursor: pointer; font-size: 14px; color: var(--ink-2); }
.chip.on { background: var(--brand-soft); border-color: transparent; color: var(--brand-soft-ink); font-weight: 600; }
.search { position: relative; flex: 1; min-width: 200px; max-width: 420px; }
.search .input { padding-left: 40px; border-radius: 999px; }
.search svg.i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-2); width: 20px; }

/* ---------- Soita ---------- */
.dial { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 24px; align-items: start; }
.dialpad { padding: 22px; }
.display { font-size: 32px; text-align: center; min-height: 48px; font-variant-numeric: tabular-nums;
  letter-spacing: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; }
.display-row { display: flex; align-items: center; gap: 6px; }
.display-row .display { flex: 1; min-width: 0; width: 0; background: transparent; border: 0; outline: none; padding: 4px; }
.display-row .icon-btn, .display-spacer { flex: none; width: 40px; }
.invisible { visibility: hidden; }
.contact-hint { text-align: center; color: var(--brand); font-weight: 600; min-height: 22px; }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.key { height: 64px; border-radius: 999px; border: 0; background: var(--surface-2); cursor: pointer; display: grid;
  place-items: center; line-height: 1.05; }
.key:hover { filter: brightness(.97); }
.key b { font-size: 26px; font-weight: 500; }
.key small { font-size: 10px; color: var(--ink-2); letter-spacing: 1px; }
.call-fab { width: 68px; height: 68px; border-radius: 50%; border: 0; background: var(--green); color: #fff;
  display: grid; place-items: center; margin: 4px auto 0; cursor: pointer; box-shadow: var(--shadow); }
.call-fab svg.i { width: 30px; height: 30px; }
.call-fab.red { background: var(--red); }

/* ---------- Käynnissä ---------- */
.live { display: grid; gap: 14px; }
.live-card { padding: 16px 18px; display: grid; gap: 10px; }
.live-top { display: flex; align-items: center; gap: 14px; }
.state-pill { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--surface-2);
  color: var(--ink-2); text-transform: uppercase; letter-spacing: .4px; }
.state-pill.connected { background: rgba(46, 125, 50, .14); color: var(--green); }
.state-pill.ringing, .state-pill.queue, .state-pill.dialing { background: rgba(230, 81, 0, .14); color: var(--orange); }
.state-pill.moving { background: var(--brand-soft); color: var(--brand-soft-ink); }
.devices { display: flex; gap: 8px; flex-wrap: wrap; }
.device { font-size: 13px; padding: 4px 10px; border-radius: 8px; background: var(--surface-2); color: var(--ink-2); }
.device.on { background: rgba(46, 125, 50, .14); color: var(--green); font-weight: 600; }
.live-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Puhelupalkki ---------- */
.callbar { position: fixed; z-index: 30; left: 50%; transform: translateX(-50%); bottom: 20px;
  width: min(560px, calc(100% - 24px)); background: var(--brand); color: #fff; border-radius: 20px; padding: 14px 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25); display: grid; gap: 10px; }
.callbar .who-big { font-size: 18px; font-weight: 700; }
.callbar .muted { opacity: .8; font-size: 13px; }
.callbar .controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.callbar .cbtn { width: 48px; height: 48px; border-radius: 50%; border: 0; display: grid; place-items: center;
  cursor: pointer; background: rgba(255, 255, 255, .16); color: #fff; }
.callbar .cbtn.on { background: #fff; color: var(--brand); }
.callbar .cbtn.hang { background: var(--red); margin-left: auto; width: 56px; height: 56px; }
.callbar .cbtn.answer { background: var(--green); width: 56px; height: 56px; }
.callbar .dtmf { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.callbar .dtmf button { height: 38px; border-radius: 10px; border: 0; background: rgba(255, 255, 255, .16); color: #fff;
  font-size: 17px; cursor: pointer; }
@media (prefers-color-scheme: dark) { .callbar { background: #1F4E79; } }
.ringing-anim { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px rgba(46, 125, 50, 0); } 0%, 100% { box-shadow: 0 0 0 0 rgba(46, 125, 50, .6); } }

/* ---------- Dialogit ---------- */
.scrim { position: fixed; inset: 0; background: rgba(10, 20, 30, .45); z-index: 40; display: grid; place-items: center;
  padding: 16px; }
.dialog { width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface);
  border-radius: 20px; padding: 22px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.dialog h3 { margin: 0 0 4px; font-size: 21px; }
.dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; margin: 14px 0; }
.kv dt { color: var(--ink-2); font-size: 13px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.vm-box { background: var(--surface-2); border-radius: 12px; padding: 14px; margin-top: 10px; }
.bubbles { display: grid; gap: 8px; margin-top: 10px; }
.bubble { max-width: 85%; padding: 8px 12px; border-radius: 14px; background: var(--surface-2); }
.bubble.me { justify-self: end; background: var(--brand-soft); color: var(--brand-soft-ink); }
.bubble small { display: block; opacity: .7; font-size: 11px; }
.target-list { display: grid; gap: 8px; margin-top: 12px; }
.target { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--surface); cursor: pointer; text-align: left; width: 100%; }
.target:hover { border-color: var(--brand); background: var(--surface-2); }
.target .main { flex: 1; }
.target small { color: var(--ink-2); display: block; }
.num-row { display: grid; grid-template-columns: 140px 1fr 40px; gap: 8px; margin-bottom: 8px; }

.toast { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); top: 18px; background: #26323F;
  color: #fff; padding: 11px 18px; border-radius: 12px; box-shadow: var(--shadow); max-width: calc(100% - 24px); }
.toast.err { background: var(--red); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.tbl th { color: var(--ink-2); font-weight: 600; font-size: 13px; }
.linkbox { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.linkbox .input { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }

/* ---------- Mobiili ---------- */
.bottom-nav { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  main { padding: 16px 12px 150px; }
  .bottom-nav { display: grid; grid-template-columns: repeat(6, 1fr); position: fixed; bottom: 0; left: 0; right: 0;
    z-index: 20; background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .bottom-nav a { display: grid; justify-items: center; gap: 2px; font-size: 11px; color: var(--ink-2); text-decoration: none;
    padding: 4px 0; position: relative; }
  .bottom-nav a .pill { padding: 3px 16px; border-radius: 999px; }
  .bottom-nav a.active { color: var(--ink); font-weight: 600; }
  .bottom-nav a.active .pill { background: var(--brand-soft); color: var(--brand-soft-ink); }
  .bottom-nav .badge { position: absolute; top: 0; left: calc(50% + 6px); }
  .mobile-top { display: flex !important; }
  .dial { grid-template-columns: 1fr; }
  .callbar { bottom: 76px; }
  .grid2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .num-row { grid-template-columns: 1fr 1fr 40px; }
  .row .meta { display: none; }
}
.mobile-top { display: none; align-items: center; gap: 10px; margin-bottom: 8px; }
.mobile-top .logo { font-size: 22px; font-weight: 700; color: var(--brand); margin-right: auto; }

/* ---------- Jonot ---------- */
.queues { display: grid; gap: 16px; }
.queue-card { padding: 18px; display: grid; gap: 14px; }
.queue-top { display: flex; gap: 14px; align-items: flex-start; }
.queue-top .main { flex: 1; min-width: 0; }
.queue-ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: var(--brand-soft); color: var(--brand-soft-ink); }
.queue-name { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 2px; }
.queue-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.queue-grid .label { font-size: 12px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.queue-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.queue-stats > div { background: var(--surface-2); border-radius: 12px; padding: 10px; text-align: center; display: grid; }
.queue-stats b { font-size: 22px; font-variant-numeric: tabular-nums; }
.queue-stats span { font-size: 12px; color: var(--ink-2); }
.queue-waiting { border-top: 1px solid var(--line); }
.checks { display: grid; gap: 2px; margin-bottom: 6px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
.check input { margin-top: 3px; width: 17px; height: 17px; accent-color: var(--brand); flex: none; }
.check small { display: block; color: var(--ink-2); font-size: 12px; }
.check[hidden] { display: none; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg label { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; display: grid; gap: 2px; }
.seg label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-soft-ink); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg small { font-size: 12px; color: var(--ink-2); }
.qform .num-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) 40px; }
.qform .num-row.two { grid-template-columns: minmax(0, 1fr) 40px; }
@media (max-width: 860px) {
  .queue-grid, .seg { grid-template-columns: 1fr; }
  .queue-stats { grid-template-columns: repeat(3, 1fr); }
  .queue-top .btn { padding: 6px 10px; }
}

.move-banner { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px; border-radius: 10px;
  background: var(--brand-soft); color: var(--brand-soft-ink); font-size: 14px; font-weight: 600; }
.move-banner span { flex: 1; min-width: 160px; }
.move-banner.held, .move-banner.failed { background: rgba(230, 81, 0, .14); color: var(--orange); }
.move-banner.done { background: rgba(46, 125, 50, .14); color: var(--green); }
.state-pill.hold { background: rgba(230, 81, 0, .14); color: var(--orange); }
