:root {
  --bg: #f4f5f8; --card: #fff; --text: #1d2330; --muted: #6a7282; --line: #e2e5ea; --soft: #eef1f6;
  --primary: #1f5eff; --primary-text: #fff; --danger: #c62828; --ok: #1b8a3a; --warn: #b26a00;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12151b; --card: #1b2029; --text: #e8ebf0; --muted: #98a1b0; --line: #2c3340; --soft: #232a36; --primary: #4f7dff; }
}
* { box-sizing: border-box; }
/* Anything marked hidden stays hidden, even when its own style says flex or grid. */
[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); }
header { display: flex; gap: 16px; align-items: center; padding: 0 16px; min-height: 52px; border-bottom: 1px solid var(--line); background: var(--card); flex-wrap: wrap; }
header #who { margin-left: auto; color: var(--muted); }
header a { color: var(--primary); }
.brand { font-size: 18px; letter-spacing: -.01em; }
nav { display: flex; gap: 4px; align-self: stretch; }
nav a { display: flex; align-items: center; padding: 0 14px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; font-weight: 500; }
nav a:hover { color: var(--text); }
nav a.on { color: var(--primary); border-bottom-color: var(--primary); }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 14px; }
.card.narrow { max-width: 420px; margin: 40px auto; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin: 8px 0; }
.grow { flex: 1; min-width: 200px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); width: 100%; }
input[type=checkbox], input[type=radio] { width: auto; }
input[type=range] { padding: 0; width: 220px; accent-color: var(--primary); }
button, a.button { font: inherit; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; text-decoration: none; display: inline-block; }
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
button.link { border: 0; background: none; color: var(--primary); padding: 0; }
button.big { padding: 12px 22px; font-size: 16px; font-weight: 600; }
button:disabled { opacity: .5; cursor: default; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.state { font-size: 26px; font-weight: 600; margin: 4px 0; }
.state.st-live { color: var(--ok); }
.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 13px; }
.pill.on { background: #e3f5e8; color: var(--ok); } .pill.off { background: #fbe9e9; color: var(--danger); }
.notice { color: var(--warn); min-height: 1.2em; } .error { color: var(--danger); min-height: 1.2em; }
.hint, .small, .muted { color: var(--muted); font-size: 13px; }
.hint { margin: 4px 0 10px; }
.lead { font-size: 20px; margin: 8px 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; margin-top: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
td, th { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 13px; color: var(--muted); font-weight: 600; }
tr.off td { opacity: .6; }
.nowrap { white-space: nowrap; }
.scrollX { overflow-x: auto; }
h1 { font-size: 22px; margin: 0 0 4px; } h2 { font-size: 17px; margin: 0 0 10px; } h3 { font-size: 15px; margin: 18px 0 8px; }
form.inline, .groupForm .inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
form.inline label, .groupForm .inline label { min-width: 150px; flex: 1; }
.titleRow { display: flex; justify-content: space-between; align-items: start; gap: 12px; flex-wrap: wrap; }

/* Dialer: list picker next to the big Start button */
.dialrow { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; margin: 12px 0 8px; }
.picker { position: relative; flex: 1; min-width: 260px; }
.pickerBtn { width: 100%; height: 100%; display: flex; justify-content: space-between; align-items: center; text-align: left; padding: 12px 14px; }
.caret { color: var(--muted); margin-left: 8px; }
.pickerPanel { position: absolute; z-index: 10; top: calc(100% + 6px); left: 0; right: 0; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.15); }
.pickerRows { max-height: 320px; overflow-y: auto; margin-top: 8px; }
.pickRow { display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left; border: 0; border-radius: 8px; margin: 2px 0; }
.pickRow:hover, .pickRow.on { background: var(--soft); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chips button { padding: 4px 12px; border-radius: 99px; font-size: 13px; }
.chips button.on, .seg button.on { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }

/* Dialing setup sections */
.sectionTitle { margin: 24px 0 0; }
details.fold { padding: 0; }
details.fold > summary { list-style: none; cursor: pointer; padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after { content: '\25BE'; position: absolute; right: 18px; color: var(--muted); }
details.fold { position: relative; }
details.fold[open] > summary::after { content: '\25B4'; }
details.fold > :not(summary) { margin-left: 18px; margin-right: 18px; }
details.fold[open] { padding-bottom: 14px; }
details.fold[open] > summary { border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.foldTitle { font-weight: 600; }
.foldSum { color: var(--muted); font-size: 13px; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting > div:first-child { flex: 1; }
.setting .hint { margin: 2px 0 0; }
.setTitle { font-weight: 500; }
.inlineNum { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.inlineNum input { width: 80px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 8px 16px; }
.seg.wide { display: flex; margin: 12px 0; border: 0; gap: 8px; }
.seg.wide button { border: 1px solid var(--line); border-radius: 8px; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: .15s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(20px); }
.switch input:disabled + span { opacity: .6; cursor: default; }
.tbl { margin: 8px 0 12px; }
.tbl select, .tbl input { padding: 5px 8px; }

/* Contact lists import */
.tagList { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 12px; max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 8px 0; }
.tagItem { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }

/* Logs */
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin: 12px 0; }
.logs td.notes { max-width: 280px; font-size: 13px; }
.logs audio { width: 200px; height: 32px; }

/* Call screen */
.callHead { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.callTitle { font-size: 19px; font-weight: 600; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar button { padding: 8px 12px; }
.toolbar button.on { background: var(--soft); border-color: var(--primary); }
.popWrap { position: relative; }
.popClose { position: absolute; top: 4px; right: 6px; border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; padding: 4px 6px; cursor: pointer; }
.pop > label:first-of-type, .pop > .pad { margin-right: 22px; }
.pop { position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; width: 280px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.15); display: flex; flex-direction: column; gap: 8px; }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pad button { font-size: 18px; padding: 10px; }
.lineStrip { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; padding: 10px; background: var(--soft); border-radius: 10px; min-height: 58px; align-items: center; }
.lineChip { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.badge { font-size: 12px; padding: 2px 10px; border-radius: 99px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.st-ringing .badge, .st-dialing .badge { background: #fff4e0; color: var(--warn); }
.st-answered .badge, .st-connected .badge { background: #e3f5e8; color: var(--ok); }
.transferBox { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 10px; padding: 10px 12px; border: 1px solid var(--primary); border-radius: 10px; }
.leadHead { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.leadTitle { font-size: 22px; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.liveDot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); display: inline-block; }
.timer { font-variant-numeric: tabular-nums; }
.leadGrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-top: 14px; }
.panel { border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.panel h3 { margin: 0 0 10px; }
.mt { margin-top: 12px; }
.fields { margin: 0; }
.fields > div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--soft); margin: 1px 0; }
.notesList { max-height: 320px; overflow-y: auto; }
.noteItem { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.pre { white-space: pre-wrap; }
.cbInfo { margin-top: 8px; color: var(--ok); }
.scriptPanel { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100vw); background: var(--card); border-left: 1px solid var(--line); box-shadow: -10px 0 30px rgba(0,0,0,.12); padding: 16px; z-index: 30; display: flex; flex-direction: column; }
.scriptPanel[hidden] { display: none; }
.scriptText { white-space: pre-wrap; overflow-y: auto; flex: 1; line-height: 1.6; }
dialog.card { width: min(720px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.35); }

@media (max-width: 640px) {
  nav a { padding: 0 8px; }
  .setting { flex-direction: column; align-items: start; }
  .pop { left: auto; right: 0; }
  .leadHead { flex-direction: column; }
}

/* Tabs: one section at a time instead of a long scroll */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); margin: 12px 0 0; }
.tabs button { border: 1px solid transparent; border-bottom: 0; border-radius: 8px 8px 0 0; background: transparent; padding: 8px 14px; margin-bottom: -1px; }
.tabs button.on { background: var(--card, #fff); border-color: var(--line); font-weight: 600; }
.tabPanel { border-top-left-radius: 0; margin-top: 0; }
.recorder { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; }
.recDot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #d33; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.2; } }

/* Admin inside the dialer page */
.adminFrame { display: block; width: 100%; min-height: 70vh; border: 0; background: transparent; }
body.embedded > header { display: none; }
body.embedded > main { max-width: none; padding: 0; }

/* Ring groups */
.groupForm { margin-top: 12px; }
.groupForm fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; padding: 8px 12px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.check { display: flex; align-items: center; gap: 6px; font-weight: 400; }
