:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-elev2: #1c232d;
  --border: #2a313c;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --primary: #4f8cff;
  --primary-hi: #6ba0ff;
  --green: #3fb950;
  --amber: #d29922;
  --red: #f85149;
  --purple: #a371f7;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 600; }

/* ---------- Login ---------- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2740 0%, var(--bg) 60%);
}
.login-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 14px; padding: 2.5rem; width: 360px; box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: .6rem; }
.login-brand h1 { margin: 0; font-size: 1.8rem; letter-spacing: -.5px; }
.logo-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  box-shadow: 0 0 16px var(--primary);
}
.login-sub { color: var(--text-dim); margin-top: 0; margin-bottom: 1.5rem; }
.login-card label { display: block; margin-bottom: 1rem; font-size: .85rem; color: var(--text-dim); }
.login-card input {
  width: 100%; margin-top: .35rem; padding: .65rem .75rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: .95rem;
}
.login-error { color: var(--red); margin-top: .8rem; font-size: .85rem; min-height: 1rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
  padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-elev2); color: var(--text); cursor: pointer; font-size: .85rem;
  transition: .12s; font-weight: 500;
}
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hi); }
.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: var(--red); background: rgba(248,81,73,.1); }
.btn-block { width: 100%; margin-top: .5rem; }
.btn-sm { padding: .3rem .6rem; font-size: .78rem; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; background: var(--bg-elev); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0;
}
.sidebar .brand { display: flex; align-items: center; gap: .55rem; padding: 1.2rem 1.2rem; border-bottom: 1px solid var(--border); }
.sidebar .brand h1 { font-size: 1.35rem; margin: 0; }
.nav { flex: 1; padding: .75rem .5rem; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: .65rem; padding: .55rem .75rem; border-radius: 8px;
  color: var(--text-dim); margin-bottom: 2px; font-weight: 500;
}
.nav a:hover { background: var(--bg-elev2); color: var(--text); }
.nav a.active { background: rgba(79,140,255,.14); color: var(--primary-hi); }
.nav a .ic { width: 18px; text-align: center; }
.sidebar .userbox { padding: .9rem 1rem; border-top: 1px solid var(--border); font-size: .82rem; }
.sidebar .userbox .uname { font-weight: 600; }
.sidebar .userbox .urole { color: var(--text-dim); text-transform: capitalize; }

.main { flex: 1; margin-left: 230px; display: flex; flex-direction: column; }
.topbar {
  height: 56px; border-bottom: 1px solid var(--border); display: flex; align-items: center;
  justify-content: space-between; padding: 0 1.4rem; background: var(--bg-elev);
  position: sticky; top: 0; z-index: 20;
}
.topbar .title { font-size: 1.05rem; font-weight: 600; }
.content { padding: 1.4rem; }

/* ---------- Presence pill ---------- */
.status-pill {
  display: inline-flex; align-items: center; gap: .45rem; padding: .3rem .7rem;
  border-radius: 999px; border: 1px solid var(--border); font-size: .8rem; cursor: pointer;
  background: var(--bg-elev2);
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-dim); }
.dot.available { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.busy { background: var(--red); }
.dot.wrap_up { background: var(--amber); }
.dot.break { background: var(--purple); }
.dot.offline { background: var(--text-dim); }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 1rem; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px){ .grid.cols-4 { grid-template-columns: repeat(2,1fr);} }
.card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}
.stat .label { color: var(--text-dim); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 2rem; font-weight: 700; margin-top: .2rem; }
.stat .value.green { color: var(--green); }
.stat .value.amber { color: var(--amber); }
.stat .value.red { color: var(--red); }
.stat .value.blue { color: var(--primary-hi); }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: var(--bg-elev2); }
.badge {
  display: inline-block; padding: .15rem .5rem; border-radius: 6px; font-size: .74rem;
  background: var(--bg-elev2); border: 1px solid var(--border);
}
.badge.green { color: var(--green); border-color: rgba(63,185,80,.4); }
.badge.red { color: var(--red); border-color: rgba(248,81,73,.4); }
.badge.amber { color: var(--amber); border-color: rgba(210,153,34,.4); }
.badge.blue { color: var(--primary-hi); border-color: rgba(79,140,255,.4); }

/* ---------- Forms ---------- */
.form-row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: end; margin-bottom: 1rem; }
.field { display: flex; flex-direction: column; gap: .25rem; }
.field label { font-size: .76rem; color: var(--text-dim); }
input, select, textarea {
  padding: .5rem .6rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: 7px; color: var(--text); font-size: .85rem; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none;
  align-items: center; justify-content: center; z-index: 100;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px;
  padding: 1.5rem; width: 460px; max-width: 92vw; max-height: 88vh; overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal h3 { margin-bottom: 1rem; }
.modal .field { margin-bottom: .8rem; }
.modal .field input, .modal .field select, .modal .field textarea { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }

/* ---------- Softphone ---------- */
.softphone {
  position: fixed; right: 1.4rem; bottom: 1.4rem; width: 300px; z-index: 80;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden;
}
.softphone .sp-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem 1rem; background: var(--bg-elev2); border-bottom: 1px solid var(--border);
}
.softphone .sp-body { padding: 1rem; }
.softphone .sp-status { font-size: .78rem; color: var(--text-dim); margin-bottom: .6rem; }
.softphone .sp-dial { width: 100%; text-align: center; font-size: 1.1rem; letter-spacing: 1px; }
.dialpad { display: grid; grid-template-columns: repeat(3,1fr); gap: .4rem; margin: .8rem 0; }
.dialpad button {
  padding: .6rem; background: var(--bg-elev2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 1rem; cursor: pointer;
}
.dialpad button:hover { border-color: var(--primary); }
.sp-actions { display: flex; gap: .5rem; }
.sp-actions .btn { flex: 1; }
.btn-call { background: var(--green); border-color: var(--green); color: #fff; }
.btn-hang { background: var(--red); border-color: var(--red); color: #fff; }

.toast-wrap { position: fixed; top: 1rem; right: 1rem; z-index: 200; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  background: var(--bg-elev2); border: 1px solid var(--border); border-left: 3px solid var(--primary);
  padding: .7rem 1rem; border-radius: 8px; box-shadow: var(--shadow); min-width: 240px; animation: slidein .2s;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }

.muted { color: var(--text-dim); }
.right { text-align: right; }
.flex { display: flex; align-items: center; gap: .5rem; }
.spacer { flex: 1; }
.hidden { display: none !important; }
.empty { color: var(--text-dim); text-align: center; padding: 2rem; }

/* ---------- User cards ---------- */
.user-card { display: flex; flex-direction: column; gap: .7rem; }
.uc-head { display: flex; align-items: center; gap: .7rem; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: 0 0 42px;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
  color: #fff; background: linear-gradient(135deg, var(--primary), var(--purple));
}
img.avatar { object-fit: cover; background: #222; }
.uc-id { flex: 1; min-width: 0; }
.uc-name { font-weight: 600; }
.uc-email { font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uc-rows { display: flex; flex-direction: column; gap: .35rem; }
.uc-row { display: flex; justify-content: space-between; gap: .5rem; font-size: .82rem; }
.uc-k { color: var(--text-dim); }
.uc-v { text-align: right; }
.uc-actions { display: flex; gap: .5rem; justify-content: flex-end; border-top: 1px solid var(--border); padding-top: .6rem; }

/* ---------- Scrollbars ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2f3947; border-radius: 8px; border: 2px solid var(--bg-elev); }
::-webkit-scrollbar-thumb:hover { background: #3c4858; }
.nav::-webkit-scrollbar { width: 8px; }
.nav::-webkit-scrollbar-thumb { background: #303a48; border: 2px solid var(--bg-elev); }

/* ---------- Settings tabs ---------- */
.tabs { display: flex; gap: .4rem; border-bottom: 1px solid var(--border); margin-bottom: 1.2rem; flex-wrap: wrap; }
.tab {
  padding: .55rem .9rem; cursor: pointer; color: var(--text-dim); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary-hi); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- QR ---------- */
.qr-box { background:#fff; padding: 12px; border-radius: 10px; width: max-content; margin: 0 auto; }
.qr-box svg { display:block; }

/* ---------- Internal P2P phone ---------- */
.intphone {
  position: fixed; right: 1.4rem; bottom: 360px; width: 300px; z-index: 90;
  background: var(--bg-elev); border: 1px solid var(--primary); border-radius: 14px;
  box-shadow: var(--shadow); padding: 1rem;
}
.intphone .ip-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: .4rem; }
.intphone .ip-name { font-size: 1.05rem; font-weight: 600; margin-bottom: .8rem; }
.intphone .ip-actions { display: flex; gap: .5rem; }
.intphone .ip-actions .btn { flex: 1; }
