/* CTI CentralinoVoip.click: stesso linguaggio del pannello e dell'app (nero, testo
   caldo, verde per ciò che è attivo). Il telefono è il pezzo forte: numero
   grande in JetBrains Mono, tastiera a portata di mano. */

@font-face { font-family: Barlow; src: url(../admin/fonts/Barlow-Regular.ttf); font-weight: 400; }
@font-face { font-family: Barlow; src: url(../admin/fonts/Barlow-Medium.ttf); font-weight: 500; }
@font-face { font-family: Barlow; src: url(../admin/fonts/Barlow-SemiBold.ttf); font-weight: 600; }
@font-face { font-family: JBMono; src: url(../admin/fonts/JetBrainsMono-Variable.ttf); font-weight: 100 800; }

:root {
  --bg: #000000;
  --surface: #141415;
  --raise: #1b1b1c;
  --line: #232324;
  --text: #f2f2f0;
  --soft: #bdbdbb;
  --muted: #8a8a88;
  --dim: #5e5e5c;
  --green: #3ddc84;
  --red: #e23b2e;
  --amber: #f2b33d;
  --sans: Barlow, system-ui, sans-serif;
  --mono: JBMono, ui-monospace, monospace;
  --accent-text: #3ddc84;
  --amber-text: #f2b33d;
  --red-text: #ff7a70;
  --line-hover: #3a3a3b;
  --row-hover: #0d0d0e;
  --pressed: #262627;
  --on-text: #000000;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 400 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.sub { display: block; color: var(--muted); font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--raise); cursor: pointer; font-weight: 500; text-decoration: none;
}
.btn:hover { border-color: var(--line-hover); }
.btn.primary { background: var(--green); color: #000; border-color: var(--green); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: none; }
.btn:disabled { opacity: .45; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--soft); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.err { color: var(--red-text); margin: 0; }

/* ------------------------------------------------------------ accesso */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.gate form { width: min(380px, 100%); display: grid; gap: 14px; }
.gate .brand { margin-bottom: 18px; }
.gate h1 { font-size: 30px; line-height: 1.1; font-weight: 600; margin: 0; }
.gate p { margin: 0; color: var(--muted); }
.gate label { display: grid; gap: 6px; font-size: 14px; color: var(--soft); }
.gate input {
  height: 46px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  padding: 0 14px; font-size: 16px;
}
.gate input:focus { border-color: var(--green); outline: none; }
.gate .btn { height: 46px; }
.gate .row { display: flex; justify-content: space-between; align-items: center; }

.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 17px; }
.brand svg { width: 26px; height: 26px; color: var(--accent-text); }

/* ------------------------------------------------------------ guscio */
.top {
  display: flex; align-items: center; gap: 16px; padding: 14px 24px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.top .company { color: var(--muted); padding-left: 16px; border-left: 1px solid var(--line); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .spacer { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--soft); white-space: nowrap; }
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.chip.on::before { background: var(--green); }
.chip.bad::before { background: var(--red); }
.chip.wait::before { background: var(--amber); }
.who { position: relative; }
.who > button { background: none; border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; cursor: pointer; text-align: left; display: grid; line-height: 1.25; }
.who > button small { color: var(--muted); font-size: 12px; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 240px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 6px; display: grid; z-index: 10;
}
.menu button, .menu a { background: none; border: 0; text-align: left; padding: 9px 12px; border-radius: 8px; cursor: pointer; text-decoration: none; }
.menu button:hover, .menu a:hover { background: var(--raise); }

.layout { display: grid; grid-template-columns: 360px 1fr; min-height: calc(100vh - 67px); }

/* ------------------------------------------------------------ telefono */
.phone { border-right: 1px solid var(--line); padding: 22px 22px 28px; display: flex; flex-direction: column; gap: 18px; }
.me { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.me b { font-weight: 600; font-size: 17px; display: block; line-height: 1.2; }
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; color: var(--soft); }
.toggle input { appearance: none; width: 38px; height: 22px; border-radius: 11px; background: var(--raise); border: 1px solid var(--line); position: relative; cursor: pointer; margin: 0; }
.toggle input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: transform .15s; }
.toggle input:checked { background: var(--red); border-color: var(--red); }
.toggle input:checked::after { transform: translateX(16px); background: #fff; }

.display { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.display input {
  flex: 1; min-width: 0; background: none; border: 0; font: 500 34px/1.2 var(--mono); letter-spacing: -0.02em;
  padding: 4px 0; text-align: left;
}
.display input:focus { outline: none; }
.display input::placeholder { color: var(--dim); font-family: var(--sans); font-size: 20px; letter-spacing: 0; }
.display button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 8px; border-radius: 8px; }
.hint { min-height: 20px; color: var(--muted); font-size: 14px; margin-top: -10px; }

.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pad button {
  height: 58px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  display: grid; place-items: center; line-height: 1;
}
.pad button:hover { background: var(--raise); }
.pad button:active { background: var(--pressed); }
.pad b { font: 500 22px var(--mono); }
.pad small { display: block; font-size: 10px; letter-spacing: .12em; color: var(--dim); margin-top: 3px; min-height: 12px; }

.callbtn { height: 58px; border-radius: 29px; border: 0; cursor: pointer; font-weight: 600; font-size: 17px; display: flex; align-items: center; justify-content: center; gap: 10px; }
.callbtn svg { width: 22px; height: 22px; }
.callbtn.go { background: var(--green); color: #000; }
.callbtn.stop { background: var(--red); color: #fff; }
.callbtn:disabled { opacity: .4; cursor: default; }

/* chiamata in corso / in arrivo */
.call { display: grid; gap: 18px; }
.call .state { color: var(--muted); font-size: 14px; }
.call .party { font-size: 28px; font-weight: 600; line-height: 1.15; overflow-wrap: anywhere; }
.call .partynum { font: 500 20px var(--mono); color: var(--soft); }
.call .timer { font: 500 20px var(--mono); color: var(--accent-text); }
.call.ringing .party { animation: ring 1.2s ease-in-out infinite; }
@keyframes ring { 50% { color: var(--amber-text); } }
@media (prefers-reduced-motion: reduce) { .call.ringing .party, .tile.ringing .dot { animation: none !important; } }
.answer { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tools { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 8px; }
.tools button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 12px 6px; cursor: pointer;
  display: grid; justify-items: center; gap: 6px; font-size: 13px; color: var(--soft);
}
.tools button svg { width: 22px; height: 22px; color: var(--text); }
.tools button[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.tools button[aria-pressed="true"] svg { color: var(--bg); }
.xfer { display: flex; gap: 8px; }
.xfer input { flex: 1; min-width: 0; height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); padding: 0 12px; font-family: var(--mono); }
.held { border: 1px dashed var(--line); border-radius: 12px; padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 14px; }

.phone-off { border: 1px solid var(--line); border-radius: 12px; padding: 14px; color: var(--soft); font-size: 14px; display: grid; gap: 8px; }

/* ------------------------------------------------------------ contenuto */
.main { padding: 22px 28px 40px; min-width: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 22px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 10px 12px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 500; }
.tabs a[aria-current="page"] { color: var(--text); border-color: var(--green); }
.tabs .badge { display: inline-block; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--red); color: #fff; font: 600 12px/20px var(--sans); text-align: center; margin-left: 6px; }
.bar { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; }
.bar h1 { font-size: 22px; margin: 0; font-weight: 600; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { background: none; border: 0; padding: 5px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--raise); color: var(--text); }
.search { height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); padding: 0 14px; min-width: 0; width: min(320px, 100%); }

/* colleghi */
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.tile {
  border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; background: none; text-align: left;
  cursor: pointer; display: grid; gap: 2px; position: relative; min-height: 86px;
}
.tile:hover { border-color: var(--line-hover); }
.tile .n { font: 500 13px var(--mono); color: var(--muted); display: flex; align-items: center; gap: 8px; }
.tile .nm { font-weight: 600; font-size: 16px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .st { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dim); flex: none; }
.tile.online .dot { background: var(--green); }
.tile.ringing { border-color: var(--amber); }
.tile.ringing .dot { background: var(--amber); animation: blink .8s steps(2) infinite; }
.tile.ringing .st { color: var(--amber-text); }
.tile.busy .dot, .tile.held .dot { background: var(--red); }
.tile.busy .st { color: var(--red-text); }
.tile.dnd .dot { background: none; border: 2px solid var(--red); }
.tile.offline .nm { color: var(--muted); }
.tile.mine { border-style: dashed; }
@keyframes blink { 50% { opacity: .2; } }
.tile-menu { position: absolute; left: 8px; right: 8px; top: calc(100% - 6px); z-index: 4; }
.groups { margin-top: 26px; color: var(--muted); font-size: 14px; }
.groups .num { color: var(--soft); }

/* tabelle */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
td.right, th.right { text-align: right; }
tr.unheard td:first-child { font-weight: 600; }
.dial { background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
.dial:hover .num { color: var(--accent-text); }
.dir { display: inline-flex; width: 22px; height: 22px; align-items: center; justify-content: center; color: var(--muted); }
.dir.missed { color: var(--red-text); }
.dir svg { width: 16px; height: 16px; }
.play { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: none; cursor: pointer; color: var(--text); }
.play:hover { border-color: var(--green); color: var(--accent-text); }
audio.inline { height: 34px; max-width: 220px; vertical-align: middle; }
.empty { border: 1px dashed var(--line); border-radius: 14px; padding: 28px; color: var(--muted); text-align: center; }
.more { margin-top: 14px; }

/* modulo contatto */
.sheet { border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: grid; gap: 12px; margin-bottom: 18px; background: var(--surface); }
.sheet .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet label { display: grid; gap: 4px; font-size: 13px; color: var(--soft); }
.sheet input:not([type=checkbox]) { height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); padding: 0 12px; }
.sheet .actions { display: flex; gap: 10px; align-items: center; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 500; transition: .2s; z-index: 50;
  max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--red); color: #fff; }

/* ------------------------------------------------------------ telefono stretto */
@media (max-width: 860px) {
  .top { padding: 12px 16px; gap: 10px; }
  .top .company, .top .brand span { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .phone { border-right: 0; border-bottom: 1px solid var(--line); padding: 16px; min-width: 0; }
  .phone.compact .devs small { display: none; }
  .phone.compact .pad { display: none; }
  .main { padding: 16px 16px 40px; }
  .pad button { height: 52px; }
  .hide-sm { display: none; }
  .sheet .grid { grid-template-columns: 1fr; }
  .board { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
@media (min-width: 861px) { .padtoggle { display: none !important; } }

/* dispositivi del proprio interno */
.pull { border: 1px solid var(--green); border-radius: 14px; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pull > div { display: grid; line-height: 1.3; min-width: 0; }
.pull .btn { white-space: nowrap; flex: none; }
.pull b { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pull span { font-size: 13px; }
.devs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.devs .label { width: 100%; font-size: 13px; color: var(--muted); }
.dev { border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 13px; color: var(--soft); }
.devs small { width: 100%; color: var(--dim); font-size: 12px; margin-top: 2px; }
.padtoggle { justify-self: start; }
.phone { min-width: 0; }

/* trasferimenti: annuncio e trascina e lascia */
.consult { border: 1px solid var(--amber); border-radius: 14px; padding: 12px 14px; display: grid; gap: 2px; }
.consult b { font-size: 18px; line-height: 1.25; }
.consult .muted { font-size: 13px; }
.consult-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
[data-drag="call"] { cursor: grab; }
[data-drag="call"]:active { cursor: grabbing; }
body.dragging-call .tile:not(.mine) { border-style: dashed; border-color: var(--green); }
.tile.drop-on { background: rgba(61, 220, 132, .12); border-color: var(--green) !important; border-style: solid !important; }
.phone.drop-on { box-shadow: inset 0 0 0 2px var(--green); }
.xfer .btn { padding: 0 12px; }

/* con cosa chiamare */
.callwith { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 14px; color: var(--soft); }
.callwith select { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; height: 34px; padding: 0 8px; margin-left: 6px; max-width: 200px; }
.toggle.small { font-size: 13px; }
.toggle.small input { width: 32px; height: 18px; }
.toggle.small input::after { width: 12px; height: 12px; }
.toggle.small input:checked { background: var(--green); border-color: var(--green); }
.toggle.small input:checked::after { transform: translateX(14px); }
.tools button.rec[aria-pressed="true"] { background: var(--red); border-color: var(--red); color: #fff; }
.tools button.rec[aria-pressed="true"] svg { color: #fff; }
.fwdline { display: grid; gap: 6px; }
.fwdline .link { justify-self: start; font-size: 14px; }
.fwdon { border: 1px solid var(--amber, #d9a33b); color: var(--text); border-radius: 10px; padding: 8px 12px; font-size: 14px; line-height: 1.45; }
.toggles { display: flex; flex-wrap: wrap; gap: 10px 16px; }
.toggles .toggle.lit { color: var(--text); }
.toggles .toggle input:disabled { opacity: .5; cursor: not-allowed; }
.sheet .toggle { display: inline-flex; }
.twofa .qr { background: #fff; border-radius: 12px; padding: 10px; width: 200px; height: 200px; justify-self: center; }
.twofa .qr svg { width: 100%; height: 100%; display: block; }
.twofa .codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 18px; font-size: 16px; padding: 12px; border: 1px dashed var(--line); border-radius: 10px; }
.sheet.twofa { max-width: 460px; }
.btn.danger { color: var(--red-text); background: none; border-color: var(--red); }
.sec-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 8px 0 18px; }
.kpis > div { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 2px; }
.kpis b { font-size: 24px; font-weight: 600; }
.kpis small { color: var(--muted); }
table.list { width: 100%; border-collapse: collapse; margin-bottom: 18px; font-size: 14px; }
table.list th, table.list td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.list .r { text-align: right; }
.ok-text { color: var(--accent-text); }
.chat { display: grid; grid-template-columns: 260px 1fr; gap: 0; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; height: calc(100vh - 200px); min-height: 420px; }
.convs { border-right: 1px solid var(--line); overflow-y: auto; display: grid; align-content: start; }
.conv { all: unset; cursor: pointer; display: grid; gap: 2px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.conv:hover, .conv.on { background: var(--raise); }
.conv:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
.conv .t { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.conv .t .badge { margin-left: auto; }
.conv .s { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.conv .dot.on { background: var(--green); }
.thread { display: grid; grid-template-rows: auto 1fr auto; min-height: 0; }
.thread header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.msgs { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 75%; align-self: flex-start; background: var(--raise); border-radius: 14px 14px 14px 4px; padding: 8px 12px; display: grid; gap: 2px; }
.msg.me { align-self: flex-end; background: color-mix(in srgb, var(--green) 22%, var(--surface)); border-radius: 14px 14px 4px 14px; }
.msg p { margin: 0; line-height: 1.45; overflow-wrap: anywhere; }
.msg .who { font-size: 12px; color: var(--soft); font-weight: 600; }
.msg time { font-size: 11px; color: var(--muted); justify-self: end; }
.empty-chat { margin: auto; }
#chatForm { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
#chatForm textarea { flex: 1; resize: none; min-height: 40px; max-height: 120px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); padding: 9px 12px; font: inherit; }
@media (max-width: 760px) { .chat { grid-template-columns: 1fr; height: auto; } .convs { max-height: 200px; border-right: 0; border-bottom: 1px solid var(--line); } .thread { min-height: 420px; } }

/* ------------------------------------------------------------ tema chiaro */
:root[data-theme="light"] {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --raise: #ededea;
  --line: #dcdcd7;
  --line-soft: #e8e8e4;
  --text: #171716;
  --soft: #3f3f3c;
  --muted: #6a6a66;
  --dim: #9b9b97;
  --green: #2fc06f;
  --green-ink: #062a15;
  --red: #d8382b;
  --amber: #d99a1e;
  --accent-text: #137a42;
  --amber-text: #8f5f00;
  --red-text: #b8281d;
  --line-hover: #b9b9b4;
  --row-hover: #efefeb;
  --pressed: #e2e2de;
  --on-text: #ffffff;
  color-scheme: light;
}
input[type=checkbox], input[type=radio] { accent-color: var(--green); }
