:root {
  --bg: #fbfcfe;
  --panel: #ffffff;
  --line: #e3e7ee;
  --line-strong: #d4dae5;
  --text: #111827;
  --muted: #6b7280;
  --soft: #f6f8fb;
  --accent: #246bfe;
  --accent-dark: #0f56e8;
  --accent-soft: #edf4ff;
  --danger: #d33c3c;
  --ok: #16a34a;
  --warn: #d9a400;
  --off: #8b95a1;
}

* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 14px; }
button, input, select { font: inherit; }
button { border: 1px solid var(--line); background: var(--panel); color: var(--text); min-height: 36px; padding: 0 12px; border-radius: 6px; cursor: pointer; font-weight: 550; }
button:hover { border-color: #b7c1d1; background: #fafcff; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 650; }
button.primary:hover { background: var(--accent-dark); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
input, select { min-height: 36px; border: 1px solid var(--line); border-radius: 6px; padding: 0 10px; background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus, button:focus { outline: 2px solid rgba(36, 107, 254, .18); outline-offset: 1px; border-color: var(--accent); }
label { display: grid; gap: 6px; color: var(--muted); font-weight: 600; }
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 24px; font-weight: 760; }
h2 { font-size: 16px; margin: 22px 0 12px; }

.login-body { min-height: 100vh; display: grid; place-items: center; }
.login-panel { width: min(380px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 28px; box-shadow: 0 14px 40px rgba(20, 30, 40, .08); }
.login-panel h1 { margin-bottom: 24px; }
.stack { display: grid; gap: 16px; }
.error { color: var(--danger); min-height: 20px; }

.sidebar { position: fixed; inset: 0 auto 0 0; width: 232px; background: var(--panel); color: var(--text); display: grid; grid-template-rows: auto 1fr auto; padding: 20px 8px 14px; border-right: 1px solid var(--line); }
.brand { display: grid; grid-template-columns: 44px 1fr; gap: 14px; align-items: center; font-weight: 800; letter-spacing: .04em; padding: 0 12px 32px; font-size: 24px; }
.brand small { display: block; letter-spacing: 0; color: var(--muted); font-size: 13px; font-weight: 600; margin-top: 2px; }
.brand-mark { width: 44px; height: 44px; display: grid; place-items: center; color: #fff; background: #0647ad; border-radius: 8px; box-shadow: 0 8px 20px rgba(36, 107, 254, .2); }
.brand-mark img { width: 22px; height: 22px; filter: brightness(0) invert(1); }
.sidebar nav { display: grid; gap: 8px; align-content: start; }
.sidebar nav button, .sidebar footer button { border-color: transparent; background: transparent; color: #374151; text-align: left; display: grid; grid-template-columns: 32px 1fr; align-items: center; justify-content: flex-start; min-height: 48px; padding: 0 14px; }
.nav-icon, .logout-icon { width: 20px; height: 20px; color: #526074; opacity: .92; }
.sidebar nav button.active, .sidebar nav button:hover { background: var(--accent-soft); color: #0b55de; }
.sidebar nav button.active .nav-icon, .sidebar nav button:hover .nav-icon { filter: invert(30%) sepia(90%) saturate(2398%) hue-rotate(213deg) brightness(97%) contrast(96%); }
.sidebar footer { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; color: #374151; background: #fcfdff; }
.user-chip { display: grid; grid-template-columns: 38px 1fr; gap: 10px; align-items: center; }
.user-chip::before { content: "AB"; width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; color: #111827; background: #f1f4f8; font-weight: 750; }
.user-chip span { font-weight: 700; }
.user-chip small { color: var(--muted); font-size: 12px; }

.workspace { margin-left: 232px; padding: 22px 26px 28px; min-height: 100vh; }
.view { display: none; }
.view.active { display: block; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin-bottom: 18px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.page-head p { margin: 0; color: var(--muted); }
.head-actions { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }

.dialer { max-width: 620px; margin: 6vh auto 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 28px; display: grid; gap: 16px; box-shadow: 0 1px 2px rgba(15, 23, 42, .04); }
.dialer input { min-height: 48px; font-size: 22px; }
.dialer button { min-height: 46px; }
.call-state { border: 1px solid var(--line); border-radius: 8px; padding: 18px; display: grid; gap: 8px; background: var(--soft); }
.call-state span { color: var(--muted); }
.call-state strong { font-size: 24px; }
.call-state time { font-variant-numeric: tabular-nums; font-size: 28px; }
.sip-connection { display: grid; grid-template-columns: auto auto 1fr; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 7px; padding: 10px 12px; background: #fbfdff; }
.sip-connection span { color: var(--muted); font-size: 12px; font-weight: 700; }
.sip-connection strong { font-variant-numeric: tabular-nums; }
.sip-connection strong.connected { color: #15803d; }
.sip-connection small { color: var(--muted); }
.sip-connection code { grid-column: 1 / -1; color: #334155; overflow-wrap: anywhere; font-size: 12px; }
.softphone-download { grid-column: 1 / -1; color: #2563eb; font-size: 13px; font-weight: 700; text-decoration: none; }
.softphone-download:hover { text-decoration: underline; }
.detail audio { width: min(460px, 100%); margin: 2px 0 12px; }

.filters, .periods, .tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.periods button.active, .tabs button.active { background: var(--accent-soft); border-color: var(--accent); color: #0b55de; box-shadow: inset 0 0 0 1px rgba(36, 107, 254, .12); }
.admin-controlbar { display: grid; grid-template-columns: 260px 1fr 210px; gap: 18px; align-items: end; margin-bottom: 20px; }
.admin-controlbar label { color: var(--muted); font-size: 12px; }
.date-range { min-height: 44px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); display: grid; align-items: center; padding: 0 12px; font-size: 14px; font-weight: 700; margin-top: 6px; }
.admin-controlbar .periods { margin: 0; align-self: end; justify-content: center; }
.admin-controlbar .periods button { min-width: 76px; min-height: 44px; }
.team-select select { margin-top: 6px; min-height: 44px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 22px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 14px; min-height: 82px; box-shadow: 0 1px 2px rgba(15, 23, 42, .035); }
.card span { display: flex; justify-content: space-between; align-items: center; color: #374151; font-size: 13px; margin-bottom: 8px; }
.card span b { color: var(--accent); font-size: 22px; font-weight: 800; }
.card strong { font-size: 22px; font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.metric-card small { display: flex; align-items: center; gap: 4px; color: var(--ok); margin-top: 10px; font-weight: 650; }
.metric-icon { width: 20px; height: 20px; filter: invert(30%) sepia(90%) saturate(2398%) hue-rotate(213deg) brightness(97%) contrast(96%); }
.trend-icon { width: 14px; height: 14px; filter: invert(48%) sepia(83%) saturate(564%) hue-rotate(88deg) brightness(93%) contrast(87%); }
.table-icon { width: 17px; height: 17px; display: block; color: #526074; }
.section-toolbar { display: flex; justify-content: space-between; align-items: end; gap: 18px; margin: 22px 0 10px; }
.section-toolbar h2 { margin: 0 0 6px; }
.section-toolbar p { margin: 0; color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.table-actions { display: flex; gap: 12px; align-items: center; }
.table-actions input { width: 300px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); box-shadow: 0 1px 2px rgba(15, 23, 42, .025); }
table { border-collapse: collapse; width: 100%; min-width: 760px; }
th, td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); text-align: left; padding: 11px 12px; white-space: nowrap; }
th:last-child, td:last-child { border-right: 0; }
th { background: #f8fafc; color: #374151; font-size: 12px; font-weight: 760; }
tbody tr { cursor: default; }
tbody tr:hover { background: #fbfdff; }
tr:last-child td { border-bottom: 0; }
.split { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, .8fr); gap: 18px; align-items: start; }
.split > div, .detail { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 16px; }
canvas { width: 100%; max-width: 100%; height: 260px; }
.timeline { margin: 0; padding-left: 20px; display: grid; gap: 10px; }
.timeline .idle { color: var(--muted); }
.tab { display: none; }
.tab.active { display: block; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; align-items: end; margin-bottom: 16px; }
.manager-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin: 22px 0 12px; }
.manager-toolbar h2 { margin: 0 0 5px; }
.manager-toolbar p { margin: 0; color: var(--muted); font-size: 13px; }
.button-icon { width: 18px; height: 18px; filter: brightness(0) invert(1); }
.primary .button-icon { vertical-align: -4px; margin-right: 7px; }
.status-ok { color: var(--ok); font-weight: 700; }
.status-bad { color: var(--danger); font-weight: 700; }
.status-badge { display: inline-flex; align-items: center; min-height: 25px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.status-badge.active { color: #157a38; background: #dcfce7; }
.status-badge.blocked { color: #b42318; background: #fef0ef; }
.row-actions { display: flex; gap: 6px; }
.icon-button { width: 36px; min-height: 36px; padding: 0; display: inline-grid; place-items: center; border-radius: 6px; }
.icon-button img { width: 17px; height: 17px; }
.icon-button:hover { background: var(--accent-soft); border-color: var(--accent); }
.manager-cell { display: grid; grid-template-columns: 34px auto; grid-template-rows: auto auto; align-items: center; column-gap: 10px; }
.manager-cell span { grid-row: 1 / span 2; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: #dcfce7; color: #157a38; font-weight: 760; font-size: 12px; }
.manager-cell strong { font-size: 13px; }
.manager-cell small, td small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.status-dot, .legend-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; vertical-align: middle; }
.status-dot.ok, .legend-dot.ok { background: var(--ok); }
.status-dot.warn, .legend-dot.warn { background: var(--warn); }
.status-dot.off, .legend-dot.off { background: var(--off); }
pre { margin: 0; max-width: 420px; white-space: pre-wrap; font-size: 12px; color: #394554; }
.empty { color: var(--muted); padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.heatmap { overflow: auto; margin-bottom: 18px; }
.heatmap-grid { display: grid; gap: 4px; min-width: 520px; align-items: stretch; }
.heatmap-grid b, .heatmap-grid span { font-size: 12px; color: var(--muted); min-height: 28px; display: grid; align-items: center; }
.heatmap-grid i { min-height: 28px; border: 1px solid #dbe4e2; border-radius: 4px; background: rgba(47, 111, 115, calc(.08 + var(--intensity) * .78)); color: #123b3e; font-style: normal; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.team-heatmap { min-width: 1060px; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: var(--panel); }
.hm-head, .hm-row { display: grid; grid-template-columns: 120px repeat(24, minmax(34px, 1fr)) 58px; }
.hm-head > *, .hm-row > * { min-height: 44px; display: grid; place-items: center; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: 12px; }
.hm-head > * { background: #f8fafc; font-weight: 760; color: #374151; }
.hm-head > span, .hm-row > span { justify-content: start; padding-left: 12px; font-weight: 700; }
.hm-row i { background: rgba(36, 107, 254, calc(.04 + var(--intensity) * .72)); color: #1f2937; font-style: normal; font-weight: 650; }
.hm-row strong { font-size: 12px; }
.hm-row:last-child > * { border-bottom: 0; }
.modal-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(15, 23, 42, .28); display: grid; place-items: center; padding: 20px; }
.modal-backdrop[hidden] { display: none; }
.modal { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line-strong); border-radius: 8px; padding: 22px; box-shadow: 0 24px 80px rgba(15, 23, 42, .18); }
.modal h2 { margin: 0 0 8px; font-size: 20px; }
.modal p { margin: 0 0 16px; color: var(--muted); }
.modal-call { display: flex; justify-content: space-between; align-items: center; gap: 14px; background: var(--soft); border: 1px solid var(--line); border-radius: 7px; padding: 14px; margin-bottom: 18px; }
.modal-call span { font-weight: 760; font-size: 18px; }
.modal-call time { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 760; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-actions button { min-height: 44px; }
.modal-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 18px; }
.modal-header h2 { margin-bottom: 7px; }
.modal-header p { margin: 0; }
.manager-modal { width: min(620px, 100%); max-height: min(720px, calc(100dvh - 32px)); overflow: auto; }
.sip-wizard-modal { width: min(720px, 100%); max-height: min(760px, calc(100dvh - 32px)); overflow: auto; }
.manager-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.manager-form label { font-size: 13px; }
.manager-sip-field, .manager-form-actions, .form-error { grid-column: 1 / -1; }
.manager-sip-field select { min-height: 108px; padding: 7px 10px; }
.manager-sip-field small { color: var(--muted); font-size: 12px; font-weight: 500; }
.form-error { min-height: 0; margin: -2px 0 0; }
.form-error:not(:empty) { min-height: 20px; }
.manager-form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 4px; }
.manager-form-actions button { min-height: 42px; }
.wizard-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 0; margin: 0 0 20px; list-style: none; counter-reset: wizard; }
.wizard-steps li { min-height: 34px; display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.wizard-steps li::before { counter-increment: wizard; content: counter(wizard); width: 21px; height: 21px; display: grid; place-items: center; border: 1px solid var(--line-strong); border-radius: 50%; background: var(--panel); }
.wizard-steps li.active { color: #0b55de; }
.wizard-steps li.active::before { color: #fff; border-color: var(--accent); background: var(--accent); }
.sip-wizard-result { grid-column: 1 / -1; display: grid; gap: 4px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--soft); }
.sip-wizard-result strong { font-size: 13px; }
.sip-wizard-result span, .sip-wizard-result small { color: var(--muted); overflow-wrap: anywhere; }
.sip-wizard-result small { font-size: 12px; }
.sip-wizard-result.success { border-color: #b7e4c3; background: #f0fdf4; }
.sip-wizard-result.success strong { color: #157a38; }
.sip-wizard-result.failure { border-color: #fecaca; background: #fff7f7; }
.sip-wizard-result.failure strong { color: #b42318; }
.telephony-error { max-width: 280px; white-space: normal; color: var(--muted); font-size: 12px; }

@media (max-width: 840px) {
  html { scroll-padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  button, input, select { min-height: 44px; }
  button, input, select, textarea { scroll-margin-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .sidebar { position: fixed; z-index: 30; inset: auto 0 0; width: auto; height: calc(68px + env(safe-area-inset-bottom)); min-height: 0; display: block; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); border-right: 0; box-shadow: 0 -8px 24px rgba(15, 23, 42, .08); }
  .brand { display: none; }
  .sidebar nav { height: 100%; grid-template-columns: repeat(var(--nav-items, 5), minmax(0, 1fr)); gap: 2px; align-items: stretch; }
  .sidebar nav button { min-width: 0; min-height: 56px; padding: 0; display: grid; grid-template-columns: 1fr; place-items: center; border-radius: 7px; font-size: 0; }
  .sidebar nav .nav-icon { width: 22px; height: 22px; }
  .sidebar footer { position: fixed; z-index: 31; top: 10px; right: 10px; display: block; padding: 0; border: 0; background: transparent; }
  .user-chip { display: none; }
  .sidebar footer button { width: 44px; min-height: 44px; padding: 0; display: grid; grid-template-columns: 1fr; place-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); font-size: 0; box-shadow: 0 1px 2px rgba(15, 23, 42, .05); }
  .sidebar footer button .logout-icon { width: 21px; height: 21px; }
  .workspace { margin-left: 0; padding: 16px 14px 24px; min-height: calc(100vh - 76px); }
  .page-head { display: block; padding: 4px 52px 14px 0; margin-bottom: 14px; }
  .page-head p { display: none; }
  .head-actions { margin-top: 10px; justify-content: space-between; }
  .split { grid-template-columns: 1fr; gap: 14px; }
  .admin-controlbar { grid-template-columns: 1fr; gap: 10px; margin-bottom: 16px; }
  .admin-controlbar .periods { justify-content: flex-start; }
  .admin-controlbar .periods button { flex: 1 1 72px; min-width: 0; }
  .team-select { max-width: none; }
  .date-range, .team-select select { min-height: 44px; }
  .dialer { max-width: none; margin: 0; padding: 18px; gap: 14px; }
  .dialer input { min-height: 52px; font-size: 20px; }
  .dialer button { min-height: 50px; }
  .call-state { padding: 16px; }
  .call-state strong { font-size: 22px; overflow-wrap: anywhere; }
  .call-state time { font-size: 26px; }
  .sip-connection { grid-template-columns: 1fr auto; gap: 6px 10px; }
  .sip-connection small { grid-column: 1 / -1; }
  .filters { display: grid; grid-template-columns: 1fr; gap: 10px; }
  .filters button { width: 100%; }
  .periods, .tabs { gap: 6px; }
  .periods button, .tabs button { flex: 1 1 auto; min-width: 0; padding: 0 9px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
  .card { min-height: 76px; padding: 12px; }
  .card strong { font-size: 19px; overflow-wrap: anywhere; }
  .metric-card small { margin-top: 7px; font-size: 11px; }
  .section-toolbar { display: grid; gap: 12px; align-items: stretch; margin: 18px 0 10px; }
  .section-toolbar p { display: none; }
  .table-actions { display: grid; grid-template-columns: 1fr; gap: 8px; }
  .table-actions input { width: 100%; }
  .table-wrap { margin-inline: -14px; border-radius: 0; border-left: 0; border-right: 0; -webkit-overflow-scrolling: touch; }
  table { min-width: 680px; }
  th, td { padding: 10px; }
  .detail { margin-inline: -2px; padding: 14px; overflow: hidden; }
  .detail .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-form { grid-template-columns: 1fr; gap: 10px; }
  .grid-form select[multiple] { min-height: 116px; }
  .row-actions { flex-wrap: wrap; }
  .row-actions button { flex: 0 0 40px; }
  canvas { height: 220px; }
  .heatmap { margin-inline: -14px; padding-inline: 14px; }
  .modal-backdrop { padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); align-items: end; }
  .modal { width: 100%; padding: 20px; }
  .manager-modal { max-height: calc(100dvh - 28px); }
  .sip-wizard-modal { max-height: calc(100dvh - 28px); }
  .modal-actions button { min-height: 50px; }
  .manager-toolbar { align-items: stretch; display: grid; gap: 12px; }
  .manager-toolbar button { width: 100%; }
  .manager-form { grid-template-columns: 1fr; gap: 12px; }
  .manager-sip-field, .manager-form-actions, .form-error { grid-column: auto; }
  .manager-form-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .manager-form-actions button { min-height: 48px; }
  .sip-wizard-modal .manager-form-actions { grid-template-columns: 1fr; }
  .wizard-steps { gap: 4px; }
  .wizard-steps li { font-size: 11px; }
}

@media (max-width: 390px) {
  .workspace { padding-inline: 12px; }
  .sidebar { padding-inline: 4px; }
  .sidebar nav .nav-icon { width: 20px; height: 20px; }
  .tabs button { flex-basis: calc(50% - 4px); }
  .table-wrap { margin-inline: -12px; }
  .heatmap { margin-inline: -12px; padding-inline: 12px; }
}
