:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #66737c;
  --line: #d9e0e4;
  --accent: #0f766e;
  --accent-2: #2563eb;
  --danger: #b42318;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.sidebar {
  background: #102027;
  color: #eaf2f4;
  padding: 18px 12px;
  min-height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  margin: 0 8px 22px;
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent);
}
.nav {
  width: 100%;
  display: block;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 11px 12px;
  margin: 3px 0;
  cursor: pointer;
  font-size: 15px;
}
.nav.active, .nav:hover { background: rgba(255,255,255,.12); }

.main { padding: 22px; min-width: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}
h1 { margin: 0; font-size: 28px; }
h2 { margin: 0 0 14px; font-size: 18px; }
p { margin: 6px 0 0; color: var(--muted); }
.auth { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

input, select, button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
}
button {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  cursor: pointer;
  font-weight: 650;
}
button.secondary { background: var(--accent-2); border-color: var(--accent-2); }
button.success { background: #15803d; border-color: #15803d; }
button.danger { background: var(--danger); border-color: var(--danger); }

.view { display: none; }
.view.active { display: block; }
.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.metric, .panel, .phone-shell, .table {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.metric span { display: block; font-size: 30px; font-weight: 750; }
.metric label { color: var(--muted); }
.form-grid, .phone-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.form-grid button { align-self: stretch; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { min-height: 0; }
.table { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { color: var(--muted); font-size: 13px; }
.notice {
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: #e8f5f2;
  border: 1px solid #b7ddd5;
}
.notice.error {
  color: var(--danger);
  background: #fff0ee;
  border-color: #ffc8c0;
}
.hidden { display: none; }
.phone-shell { max-width: 900px; }
.phone-display {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
  padding: 18px;
  border: 1px solid #cdd8dd;
  border-radius: 8px;
  background: #f8fbfb;
}
.phone-status {
  font-size: 24px;
  font-weight: 750;
}
.phone-caller {
  color: var(--muted);
  font-size: 15px;
}
.phone-actions {
  display: grid;
  grid-template-columns: repeat(5, minmax(96px, 1fr));
  gap: 10px;
}
.phone-page {
  display: block;
  min-height: 100vh;
  background: #edf1f3;
}
.phone-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}
.phone-login-box {
  width: min(380px, 100%);
  display: grid;
  gap: 12px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 45px rgba(23, 32, 38, .12);
}
.phone-login-box h1 { font-size: 26px; }
.phone-login-box label, .phone-grid label { display: grid; gap: 6px; color: var(--muted); }
.phone-login-error { min-height: 20px; color: var(--danger); font-weight: 650; }
.phone-console {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
}
.phone-nav {
  min-height: 100vh;
  background: #13252b;
  color: #eaf2f4;
  padding: 16px 12px;
}
.phone-brand.compact { margin: 0 6px 20px; }
.phone-brand.compact h1 { font-size: 20px; }
.phone-tab {
  width: 100%;
  display: block;
  margin: 4px 0;
  text-align: left;
  background: transparent;
  border-color: transparent;
  color: inherit;
}
.phone-tab.active, .phone-tab:hover { background: rgba(255,255,255,.12); }
.phone-tab.logout { margin-top: 22px; color: #ffd6d2; }
.phone-workspace {
  min-width: 0;
  padding: 20px;
}
.phone-topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}
.phone-topbar h2 { font-size: 26px; margin: 0; }
.phone-presence {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--panel);
  font-weight: 750;
}
.phone-panel { display: none; }
.phone-panel.active { display: grid; }
#panel-dialer {
  grid-template-columns: minmax(320px, 520px) 1fr;
  gap: 16px;
  align-items: start;
}
.phone-softphone, .phone-side, .phone-table-wrap, .contact-tools, .status-grid {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.dial-input {
  width: 100%;
  min-height: 52px;
  margin-bottom: 12px;
  font-size: 22px;
  text-align: center;
}
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.keypad button {
  min-height: 54px;
  background: #f7fafb;
  color: var(--ink);
  border-color: var(--line);
  font-size: 22px;
}
.phone-main {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}
.standalone-phone {
  width: min(760px, 100%);
  padding: 22px;
}
.phone-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}
.phone-brand h1 {
  font-size: 24px;
}
.contact-list, .contact-grid {
  display: grid;
  gap: 8px;
}
.contact-grid {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.contact-row, .contact-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f9fbfb;
}
.contact-row span, .contact-card span {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}
.contact-tools {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}
.contact-tools input { flex: 1; }
.phone-table-wrap { overflow-x: auto; }
.phone-table { min-width: 720px; }
.phone-table button, .contact-row button, .contact-card button {
  min-height: 34px;
  padding: 6px 10px;
}
.call-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 8px;
  background: #e8f5f2;
  color: #0f766e;
  font-weight: 750;
  font-size: 12px;
}
.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}
.status-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f9fbfb;
}
.status-grid span {
  display: block;
  color: var(--muted);
  margin-bottom: 6px;
}
.empty-state {
  color: var(--muted);
  padding: 12px;
}
.hidden { display: none !important; }

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; }
  .topbar { flex-direction: column; }
  .metrics, .form-grid, .phone-grid, .phone-actions { grid-template-columns: 1fr; }
  .phone-console { grid-template-columns: 1fr; }
  .phone-nav { min-height: auto; }
  #panel-dialer, .status-grid { grid-template-columns: 1fr; }
  .phone-topbar, .contact-tools { flex-direction: column; }
}
