:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --ink: #1c2230;
  --muted: #6a7080;
  --line: #e3e1da;
  --line-strong: #cfccc3;
  --accent: #0f6e63;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1ee;
  --green: #18794e;
  --red: #b42318;
  --red-soft: #fdecea;
  --amber: #8a5a00;
  --amber-soft: #fff4d6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 33, .06);
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.5; }
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: .2rem 0 .8rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
.hint { color: var(--muted); font-size: .86rem; margin: .2rem 0; }
.warn { color: var(--amber); font-weight: 600; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
[hidden] { display: none !important; }

/* Shell */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem; height: 56px; padding: 0 20px; background: var(--ink); color: #fff; }
.brand { color: #fff; text-decoration: none; font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--accent); }
.logo.big { width: 64px; height: 64px; font-size: 32px; border-radius: 16px; color: #fff; margin: 0 auto 1rem; }
.who { margin-left: auto; font-size: .9rem; }
.who .muted { color: #aab0bf; }
.who a { color: #fff; margin-left: .8rem; }
.navtoggle { display: none; background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; }
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: calc(100vh - 56px); }
.side { padding: 18px 12px; border-right: 1px solid var(--line); background: #efede7; }
.side a { display: flex; align-items: center; gap: .6rem; padding: .5rem .7rem; border-radius: 8px; color: var(--ink); text-decoration: none; }
.side a:hover { background: #e6e3db; }
.side a.active { background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }
.side .ic { width: 1.2rem; text-align: center; color: var(--accent); }
.navhead { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.2rem .7rem .3rem; }
.main { padding: 24px 32px 60px; max-width: 1100px; width: 100%; min-width: 0; }
.card:has(> .tbl), .card:has(> form > .tbl) { overflow-x: auto; }
.main.solo { margin: 0 auto; max-width: 440px; }

/* Cards & layout */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow-x: auto; }
.card.empty { color: var(--muted); text-align: center; padding: 32px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2.tight { gap: 10px 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack.tight { gap: 4px; }
.headrow { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.crumbs { margin: 0; font-size: .88rem; color: var(--muted); }
.stat { text-decoration: none; color: var(--ink); }
.stat .label, .label { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stat .big { font-size: 1.9rem; font-weight: 700; margin: .1rem 0; }
.links { margin: 0; padding-left: 1.1rem; }

/* Forms */
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: .92rem; }
label.check, label.radio { flex-direction: row; align-items: flex-start; gap: .5rem; font-weight: 400; }
label.check input, label.radio input { margin-top: .25rem; }
label.disabled { color: var(--muted); }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line-strong); border-radius: 8px; padding: .5rem .65rem; min-width: 0; }
input[type=checkbox], input[type=radio] { width: auto; padding: 0; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; resize: vertical; }
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; margin: .6rem 0; }
.inline-form label.grow { flex: 1; min-width: 220px; }
form.inline { display: inline; }
.searchbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.searchbar input[type=search] { flex: 1; min-width: 200px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600; padding: .5rem 1rem; border-radius: 8px; border: 1px solid var(--line-strong); background: #fff; color: var(--ink); text-decoration: none; cursor: pointer; }
.btn:hover { background: #f3f2ee; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.red { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #ecebe6; color: var(--ink); }
.btn.small { padding: .3rem .7rem; font-size: .86rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.red-text { color: var(--red) !important; }
.danger-zone { margin-top: 8px; }

/* Prompt editor */
fieldset.prompt { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0; background: #fbfaf8; }
fieldset.prompt legend { font-weight: 600; padding: 0 .35rem; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; margin-bottom: 8px; }
.seg label { flex-direction: row; align-items: center; gap: .35rem; padding: .3rem .8rem; font-weight: 500; cursor: pointer; background: #fff; }
.seg label:has(input:checked) { background: var(--accent-soft); color: var(--accent); }
.seg input { margin: 0; }
fieldset.prompt[data-kind=tts] .when-audio, fieldset.prompt[data-kind=audio] .when-tts { display: none; }
fieldset.prompt audio { width: 100%; max-width: 420px; display: block; margin-bottom: 6px; }

/* Tables */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: .55rem .75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #faf9f6; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.dim td { color: var(--muted); }
.tbl.hours th { font-weight: 500; width: 110px; }
.tbl.hours td { padding: .3rem .4rem; }
.tbl .trail { font-size: .86rem; color: var(--muted); max-width: 380px; }
.keycap { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; background: var(--ink); color: #fff; font-weight: 700; }

/* Pills, badges, flashes, tabs */
.pill { display: inline-block; font-size: .74rem; font-weight: 600; padding: .05rem .5rem; border-radius: 99px; background: var(--accent-soft); color: var(--accent); vertical-align: middle; }
.pill.grey { background: #ecebe6; color: var(--muted); }
.badge { margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 99px; background: var(--red); color: #fff; font-size: .75rem; text-align: center; }
.tabs .badge { margin-left: .3rem; }
.flash { padding: .65rem .9rem; border-radius: 8px; margin-bottom: 12px; background: var(--accent-soft); color: #0a4d45; border: 1px solid #bfe0da; }
.flash.err { background: var(--red-soft); color: #7a1a12; border-color: #f4c7c2; }
.flash.info { background: var(--amber-soft); color: #5c3c00; border-color: #f1dd9e; }
.flash ul { margin: .3rem 0; padding-left: 1.2rem; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.tabs a { padding: .5rem .9rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; align-items: center; }
.tabs a.active { color: var(--ink); border-color: var(--accent); font-weight: 600; }
.preview { margin-top: 14px; padding: 12px 14px; background: #faf9f6; border-radius: 8px; border: 1px dashed var(--line-strong); }
.preview p { font-style: italic; margin: .2rem 0 0; }

/* Ring set picker */
.picklist { max-height: 420px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; }
.pick { flex-direction: row; align-items: center; gap: .6rem; padding: .45rem .7rem; border-bottom: 1px solid var(--line); font-weight: 400; }
.pick:last-child { border-bottom: 0; }
.pick:has(input:checked) { background: var(--accent-soft); }
.pick .order { width: 64px; padding: .25rem .4rem; }

/* Voicemail */
.vm.new { border-left: 4px solid var(--accent); }
.vmhead { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 8px; }
.vm audio { width: 100%; }
.transcript { background: #faf9f6; padding: .5rem .7rem; border-radius: 8px; font-style: italic; }

/* Web phone */
.phone-wrap { display: grid; grid-template-columns: 360px 1fr; gap: 16px; align-items: start; }
.phone .status { display: flex; align-items: center; gap: .5rem; margin-bottom: 12px; font-size: .9rem; color: var(--muted); }
.status .dot { width: 10px; height: 10px; border-radius: 50%; background: #b9b6ad; }
.status[data-kind=ready] .dot { background: var(--green); box-shadow: 0 0 0 4px #d4ecdf; }
.status[data-kind=connecting] .dot { background: var(--amber); }
.status[data-kind=err] .dot { background: var(--red); }
.status[data-kind=err] { color: var(--red); }
.number { width: 100%; font-size: 1.5rem; text-align: center; letter-spacing: .05em; padding: .6rem; margin: 12px 0; }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.key { font: inherit; font-size: 1.35rem; font-weight: 600; padding: .7rem 0; border-radius: 12px; border: 1px solid var(--line); background: #faf9f6; cursor: pointer; }
.key:hover { background: #efede7; }
.key:active { transform: scale(.97); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.incoming, .active { text-align: center; padding: 14px; border-radius: var(--radius); margin: 10px 0; }
.incoming { background: var(--accent-soft); animation: pulse 1.4s ease-in-out infinite; }
.active { background: #f1f0eb; }
.caller { font-size: 1.25rem; font-weight: 700; margin: .2rem 0; }
.timer { font-variant-numeric: tabular-nums; color: var(--muted); }
.phone[data-state=ringing] .dialer, .phone[data-state=ringing] #startBtn { display: none; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(15, 110, 99, .15); } }
@media (prefers-reduced-motion: reduce) { .incoming { animation: none; } }
.dirlist { list-style: none; margin: 10px 0 0; padding: 0; max-height: 540px; overflow-y: auto; }
.dirlist li { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .55rem .2rem; border-bottom: 1px solid var(--line); }
#dirSearch { width: 100%; }

/* Login */
.login { text-align: center; margin-top: 12vh; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 36px 28px; box-shadow: var(--shadow); }
.login h1 { margin-bottom: .2rem; }
.login .btn { margin-top: 1.2rem; padding: .75rem; }
.devlogin { margin-top: 1.5rem; display: flex; gap: 8px; align-items: flex-end; justify-content: center; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; position: fixed; inset: 56px 0 auto 0; z-index: 9; border-bottom: 1px solid var(--line); }
  body.navopen .side { display: block; }
  .navtoggle { display: block; }
  .who { display: none; }
  .main { padding: 18px 16px 48px; }
  .grid2, .grid3, .phone-wrap { grid-template-columns: 1fr; }
}

/* ---------- App shell + phone dock ---------- */
.shell-body { margin: 0; height: 100vh; overflow: hidden; background: var(--bg); }
#appframe { position: fixed; inset: 0; width: 100%; height: 100%; border: 0; display: block; }
.dock { position: fixed; right: 16px; bottom: 16px; z-index: 50; width: 340px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 14px;
  box-shadow: 0 10px 30px rgba(20, 24, 33, .18); overflow: hidden; }
.dock-bar { display: flex; align-items: center; gap: .55rem; width: 100%; padding: .65rem .9rem; border: 0; background: var(--ink);
  color: #fff; font: inherit; cursor: pointer; text-align: left; }
.dock-bar .dot { width: 10px; height: 10px; border-radius: 50%; background: #9aa0ad; flex: none; }
.dock-bar .dot[data-kind=ready] { background: #3ecf8e; }
.dock-bar .dot[data-kind=connecting] { background: #f0b429; }
.dock-bar .dot[data-kind=err], .dock-bar .dot[data-kind=off] { background: #f06a5d; }
.dock-bar .dot[data-kind=ringing] { background: #3ecf8e; animation: blink 1s steps(2) infinite; }
.dock-bar .dot[data-kind=oncall] { background: #5bb8ff; }
.dock-title { font-weight: 700; }
.dock-sub { color: #c6cad3; font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.dock-badge { font-size: .74rem; font-weight: 700; background: #f0b429; color: #3b2a00; border-radius: 99px; padding: .05rem .5rem; }
.dock .chev { transition: transform .15s; color: #c6cad3; }
.dock[data-open="1"] .chev { transform: rotate(180deg); }
.dock-panel { display: none; padding: 12px; max-height: calc(100vh - 110px); overflow-y: auto; }
.dock[data-open="1"] .dock-panel { display: block; }
.dock.busy .dock-bar { background: var(--accent); }
.dock-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; text-align: center; }
.dock-card.incoming { background: var(--accent-soft); border-color: #bfe0da; animation: pulse 1.4s ease-in-out infinite; }
.dock-card .caller { font-size: 1.1rem; font-weight: 700; margin: .1rem 0; word-break: break-word; }
.dock-card .row2 { margin-bottom: 0; }
.active-card { background: #f4f3ef; }
.ctl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 8px 0; }
.small-keys { grid-template-columns: repeat(3, 1fr); gap: 5px; }
.small-keys .key { font-size: 1rem; padding: .4rem 0; border-radius: 8px; }
.xfer, .dial { display: flex; gap: 6px; margin: 8px 0; }
.xfer input, .dial input { flex: 1; min-width: 0; }
.held-row { padding: 6px 0; border-bottom: 1px solid var(--line); text-align: left; }
.held-top { display: flex; align-items: center; gap: 6px; }
.held-row .xfer { margin: 6px 0 0; }
.held-row:last-child { border-bottom: 0; }
#heldWrap { border: 1px solid #f1dd9e; background: var(--amber-soft); border-radius: 10px; padding: 8px 10px; margin-bottom: 10px; }
.dock-msg { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; margin-bottom: 10px; }
.dock-msg.err { color: var(--red); font-size: .88rem; }
.dock-foot { margin: 0; font-size: .76rem; }
.small { font-size: .84rem; }
@keyframes blink { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .dock-card.incoming, .dock-bar .dot[data-kind=ringing] { animation: none; } }
/* keep page content clear of the collapsed dock */
.main { padding-bottom: 90px; }
@media (max-width: 560px) { .dock { right: 8px; left: 8px; bottom: 8px; width: auto; max-width: none; } }

/* Ringtone picker */
.tones { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.tone { flex-direction: row; align-items: center; gap: .5rem; border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; font-weight: 400; }
.tone:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.tone .grow { display: flex; flex-direction: column; }
.tone .grp { font-size: .76rem; color: var(--muted); }

/* Mailbox usage */
.usage { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; }
.usage-bar { flex: 0 0 180px; height: 8px; background: #e6e3db; border-radius: 99px; overflow: hidden; }
.usage-bar span { display: block; height: 100%; background: var(--accent); }
.usage.full .usage-bar span { background: var(--red); }

/* 911 location strip in the phone dock */
.loc-strip { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px; font-size: .84rem;
  background: var(--amber-soft); color: #5c3c00; border-bottom: 1px solid #f1dd9e; }
.loc-strip[data-state=ok] { background: #f4f3ef; color: var(--muted); border-bottom-color: var(--line); }
.loc-strip .loc-text { flex: 1; min-width: 160px; }
.loc-strip .loc-btns { display: flex; gap: 6px; }

/* My 911 location page */
.loc-now .big-line { font-size: 1.25rem; font-weight: 700; margin: .2rem 0 .4rem; }
.loc-now.ok { border-left: 4px solid var(--green); }
.loc-now.warn { border-left: 4px solid #d99a00; }
.loc-now.err { border-left: 4px solid var(--red); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.red { background: var(--red-soft); color: var(--red); }
.addr-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 12px; }
.addr-grid > label { min-width: 0; }
.addr-grid input { width: 100%; box-sizing: border-box; }
.addr-grid .wide { grid-column: span 2; }
@media (max-width: 700px) { .addr-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
@media (max-width: 420px) { .addr-grid { grid-template-columns: minmax(0, 1fr); } .addr-grid .wide { grid-column: auto; } }
details.loc { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; }
details.loc > summary { cursor: pointer; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
details.loc[open] > summary { margin-bottom: 8px; }
.row-actions { display: flex; gap: 6px; margin-top: 8px; }
.numpick { border: 1px solid var(--line); border-radius: 8px; max-height: 320px; overflow-y: auto; }
