:root {
  --purple: #662e8f; --purple-d: #4e2270; --purple-l: #f1e9f7; --gold: #ffca08; --gold-l: #fff6d1; --grey: #737373;
  --ink: #23182b; --muted: #6f6878; --line: #e3dde8; --bg: #f6f3f9; --card: #fff;
  --good: #1f8a4c; --good-l: #e3f4ea; --bad: #b42318; --bad-l: #fde8e6; --blue-l: #e7f0fb;
  --r: 10px; --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.4 var(--font); }
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: 0; }
.muted { color: var(--muted); } .small { font-size: 12px; } .mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.error { color: var(--bad); min-height: 1em; margin: 6px 0 0; }
kbd { font: 11px ui-monospace, Consolas, monospace; background: rgba(255,255,255,.25); border-radius: 4px; padding: 0 4px; margin-right: 4px; }

/* buttons and fields */
.btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 8px; padding: 8px 14px; cursor: pointer; }
.btn:hover { border-color: var(--purple); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .tab:focus-visible, tr:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.btn.primary { background: var(--purple); border-color: var(--purple); color: #fff; } .btn.primary:hover { background: var(--purple-d); }
.btn.primary kbd { background: rgba(255,255,255,.2); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--ink); font-weight: 600; }
.btn.ghost { background: transparent; border-color: transparent; } .btn.ghost:hover { background: var(--purple-l); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--purple); cursor: pointer; font: inherit; text-decoration: underline; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
input, select, textarea { font: inherit; font-size: 14px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; }
input:disabled { background: #f3f1f5; color: var(--muted); }
label.req input { border-color: #d8b8ee; }

/* sign in */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--purple-l), #fff 60%); }
.login-card { width: min(380px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 10px 30px rgba(102,46,143,.12); }
.login-logo { width: 150px; align-self: center; }
.login-card h1 { text-align: center; color: var(--purple); font-size: 22px; }
.login-card p { text-align: center; margin: 0; }

/* layout */
.app { display: flex; flex-direction: column; gap: 12px; padding: 0 16px 16px; min-height: 100%; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 10px 0; border-bottom: 3px solid var(--purple); flex-wrap: wrap; }
.logo { height: 38px; }
.brand { display: flex; flex-direction: column; } .brand strong { font-size: 16px; }
.tag { font-size: 11px; font-weight: 700; letter-spacing: .08em; color: var(--purple); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ext { flex-direction: row; align-items: center; gap: 6px; } .ext input { width: 80px; padding: 6px 8px; }
.clock { font-weight: 700; font-size: 16px; min-width: 48px; }
.chip { border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 600; background: #eee; color: var(--muted); }
.chip.good { background: var(--good-l); color: var(--good); } .chip.bad { background: var(--bad-l); color: var(--bad); }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h2 { font-size: 15px; color: var(--purple); }
.keys { margin-left: auto; display: flex; gap: 8px; }
.top { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 12px; }

/* the screen pop */
.pop { display: flex; align-items: center; gap: 14px; background: var(--purple); color: #fff; border-radius: var(--r); padding: 12px 16px; border-left: 8px solid var(--gold); animation: in .25s ease-out; }
.pop.test { background: #3d3d3d; }
.pop.ended { background: #8a7b96; border-left-color: #cfc6d6; }
.pop-icon { font-size: 26px; }
.pop-title { font-size: 18px; font-weight: 700; } .pop-detail { opacity: .9; font-size: 13px; }
.pop-actions { margin-left: auto; display: flex; gap: 6px; } .pop .btn.ghost { color: #fff; } .pop .btn.ghost:hover { background: rgba(255,255,255,.15); }
@keyframes in { from { transform: translateY(-6px); opacity: 0; } to { transform: none; opacity: 1; } }

/* booker */
.booker .grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding: 14px; }
.span2 { grid-column: span 2; } .span3 { grid-column: span 3; }
.when { display: flex; gap: 6px; flex-wrap: wrap; } .when select { width: 140px; flex: none; } .when input { flex: 1 1 160px; }
.booker .error { padding: 0 14px 12px; margin: 0; }
.call-tag { background: var(--gold-l); color: #6b5300; border: 1px solid var(--gold); border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; }

/* side */
.side { display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; gap: 4px; padding: 8px 10px 0; border-bottom: 1px solid var(--line); align-items: flex-end; flex-wrap: wrap; }
.tab { font: inherit; background: none; border: 0; border-bottom: 3px solid transparent; padding: 8px 12px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tab.on { color: var(--purple); border-bottom-color: var(--purple); }
.side-body { padding: 14px; overflow: auto; max-height: 420px; }
.cust-name { font-size: 16px; font-weight: 700; }
.history { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 10px; }
.history li { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.job-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; } .job-head .btn { margin-left: auto; }
.dl { display: grid; grid-template-columns: 96px 1fr; gap: 4px 10px; margin: 0 0 12px; } .dl dt { color: var(--muted); font-size: 12px; font-weight: 600; } .dl dd { margin: 0; }
h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 12px 0 6px; }
.mini { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.pre { background: #faf8fc; border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-size: 12px; white-space: pre-wrap; max-height: 220px; overflow: auto; margin: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

/* lists */
.lists { flex: 1; display: flex; flex-direction: column; min-height: 260px; }
.list-tabs .spacer { flex: 1; } .filter { flex-direction: row; align-items: center; gap: 6px; padding-bottom: 6px; } .filter select { width: auto; padding: 4px 8px; }
.count { background: var(--purple); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 11px; margin-left: 4px; } .count:empty { display: none; }
.table-wrap { overflow: auto; flex: 1; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { position: sticky; top: 0; background: #faf8fc; text-align: left; font-size: 12px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td.clip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
#jobsBody tr { cursor: pointer; }
#jobsBody tr:hover td { background: #faf6fd; }
#jobsBody tr.sel td { box-shadow: inset 0 2px 0 var(--purple), inset 0 -2px 0 var(--purple); }
tr.r-allocated td { background: var(--blue-l); } tr.r-arrived td { background: var(--gold-l); } tr.r-pob td { background: var(--good-l); }
tr.r-completed td { color: var(--muted); } tr.r-cancelled td { color: var(--muted); text-decoration: line-through; }
.empty { padding: 24px; text-align: center; color: var(--muted); margin: 0; }
.rec-bar { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }

.pill { display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: 12px; font-weight: 600; background: #eee; color: #444; }
.s-booked { background: var(--purple-l); color: var(--purple); } .s-allocated { background: #d3e3f8; color: #1d4e89; } .s-arrived { background: var(--gold); color: #3b2f00; }
.s-pob { background: #c8ecd6; color: #145c33; } .s-completed { background: #e8e8e8; color: #555; } .s-cancelled { background: var(--bad-l); color: var(--bad); }
.c-requested, .c-ringing_agent, .c-ringing_customer { background: var(--gold-l); color: #6b5300; } .c-connected { background: var(--good-l); color: var(--good); }
.c-ended { background: #e8e8e8; color: #555; } .c-failed { background: var(--bad-l); color: var(--bad); }

.events { list-style: none; margin: 0; padding: 0; }
.ev { display: flex; gap: 10px; padding: 6px 12px; border-bottom: 1px solid var(--line); align-items: baseline; }
.ev-kind { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--purple); min-width: 70px; }
.ev-error .ev-kind { color: var(--bad); } .ev-pop .ev-kind { color: #8a6a00; }

/* menu, dialog, toast, player */
.menu { position: fixed; z-index: 50; min-width: 220px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 30px rgba(35,24,43,.18); padding: 6px; display: flex; flex-direction: column; }
.menu button { font: inherit; text-align: left; background: none; border: 0; padding: 7px 12px; border-radius: 6px; cursor: pointer; color: var(--ink); }
.menu button:hover:not(:disabled), .menu button:focus-visible { background: var(--purple-l); outline: none; }
.menu button:disabled { color: #b8b2be; cursor: default; }
.menu hr { margin: 4px 6px; }
.dlg { border: 0; border-radius: 14px; padding: 0; width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.dlg::backdrop { background: rgba(35,24,43,.35); }
.dlg > form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dlg h3 { color: var(--purple); } .dlg p { margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 60; max-width: calc(100vw - 32px); }
.toast.bad { background: var(--bad); }
#player { position: fixed; right: 16px; bottom: 16px; z-index: 40; width: min(340px, calc(100vw - 32px)); }

@media (max-width: 1000px) { .top { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 640px) {
  .booker .grid { grid-template-columns: 1fr; } .span2, .span3 { grid-column: auto; }
  .topbar .logo { height: 30px; } .pop { flex-wrap: wrap; } .pop-actions { margin-left: 0; }
}

/* 1.1: accounts and settings */
.note { background: var(--gold-l); border: 1px solid var(--gold); border-radius: 8px; padding: 8px 10px; font-size: 13px; color: #4d3d00; text-align: left !important; }
code { font: 12px ui-monospace, Consolas, monospace; background: #f3eef7; padding: 0 4px; border-radius: 4px; }
.who { font-size: 13px; color: var(--muted); }
.dlg.wide { width: min(1000px, calc(100vw - 32px)); max-height: calc(100vh - 40px); }
.settings { display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
.settings-head { display: flex; align-items: center; padding: 16px 20px 4px; } .settings-head h3 { color: var(--purple); } .settings-head .btn { margin-left: auto; }
.set-body { padding: 16px 20px 20px; overflow: auto; }
.add-user { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)) auto; gap: 10px; align-items: end; }
.row-actions { display: flex; gap: 8px; margin-top: 12px; }
.narrow { max-width: 420px; }
.wide-dl { grid-template-columns: 200px 1fr; }
.table td input, .table td select { padding: 5px 8px; font-size: 13px; }
.table td select { width: auto; min-width: 110px; }
.table td input { min-width: 70px; }
#usersBody input[data-f=name] { min-width: 150px; }
#usersBody td:last-child { white-space: normal; min-width: 260px; }
.add-user + p { margin: 10px 0 4px; }
.badge-off { color: var(--bad); font-weight: 600; } .badge-new { color: #8a6a00; font-weight: 600; }
@media (max-width: 760px) { .add-user { grid-template-columns: 1fr 1fr; } .wide-dl { grid-template-columns: 1fr; } }
