:root {
  --bg: #f3efe8;
  --bg-elev: #fffdf9;
  --bg-card: #ffffff;
  --sidebar: #fffdf9;
  --line: #e4ddd2;
  --line-strong: #d4cbbd;
  --text: #2a241e;
  --muted: #6f675f;
  --faint: #8f867c;
  --orange: #e56b12;
  --orange-2: #f1842e;
  --orange-deep: #c2570c;
  --orange-dim: rgba(229, 107, 18, 0.12);
  --gray: #8d8d8d;
  --green: #1f8a4c;
  --green-dim: rgba(31, 138, 76, 0.12);
  --red: #c2414a;
  --red-dim: rgba(194, 65, 74, 0.12);
  --yellow: #b58108;
  --yellow-dim: rgba(181, 129, 8, 0.14);
  --blue: #2d6a9f;
  --shadow: 0 10px 30px rgba(60, 42, 22, 0.08);
  --radius: 14px;
  --sidebar-w: 240px;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sans);
  background:
    linear-gradient(180deg, #f7f3ed 0%, var(--bg) 180px);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--orange-deep); text-decoration: none; }
button, input, select, textarea { font-family: inherit; }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  background:
    radial-gradient(900px 420px at 50% -8%, rgba(229, 107, 18, 0.16), transparent 58%),
    linear-gradient(180deg, #fbf7f1, #efe8de);
}

.login-card {
  width: min(420px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-top: 4px solid var(--orange);
  border-radius: 18px;
  padding: 36px 32px 28px;
  box-shadow: var(--shadow);
}

.login-logo {
  width: 240px;
  display: block;
  margin: 0 auto 14px;
}

.login-card h1 {
  margin: 0;
  text-align: center;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.login-card p.lead {
  margin: 8px 0 26px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 8px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="file"] {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 15px;
  outline: none;
}

input:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px var(--orange-dim);
}

.field { margin-bottom: 16px; }

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .12s ease, background .12s ease, opacity .12s ease, box-shadow .12s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(180deg, var(--orange-2), var(--orange));
  color: #fff;
  width: 100%;
  box-shadow: 0 6px 16px rgba(229, 107, 18, 0.28);
}

.btn-ghost {
  background: #fff;
  color: var(--muted);
  border: 1px solid var(--line-strong);
}

.btn-danger {
  background: var(--red-dim);
  color: var(--red);
}

.btn-small { padding: 7px 12px; font-size: 13px; width: auto; }

.error {
  color: var(--red);
  font-size: 13px;
  min-height: 18px;
  margin: 4px 0 12px;
}

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  box-shadow: inset -1px 0 0 rgba(229, 107, 18, 0.08);
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 10px 20px;
}

.brand img { width: 168px; height: auto; }
.brand span {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--orange-deep);
  font-weight: 700;
  background: var(--orange-dim);
  border: 1px solid rgba(229, 107, 18, 0.22);
  border-radius: 999px;
  padding: 4px 9px;
}

nav { display: flex; flex-direction: column; gap: 3px; }
nav button {
  all: unset;
  cursor: pointer;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 550;
  border-left: 3px solid transparent;
}
nav button.active {
  background: var(--orange-dim);
  color: var(--orange-deep);
  border-left-color: var(--orange);
  font-weight: 650;
}
nav button:hover { background: rgba(229, 107, 18, 0.08); color: var(--text); }
nav svg { width: 18px; height: 18px; opacity: .85; }

.sidebar-foot {
  margin-top: auto;
  padding: 12px 10px 4px;
  color: var(--faint);
  font-size: 12px;
}

.main { padding: 24px 32px 48px; min-width: 0; }

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 18px;
}

.top h2 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.04em;
  font-weight: 650;
}

.top .sub { color: var(--muted); font-size: 14px; margin-top: 6px; }

.top-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.pbx-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.pbx-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 550;
}

.grid-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px 14px;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--orange);
}

.stat .k { color: var(--muted); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; font-weight: 650; }
.stat .v { font-size: 28px; font-weight: 700; letter-spacing: -0.04em; margin-top: 8px; font-variant-numeric: tabular-nums; }
.stat .d { color: var(--faint); font-size: 12px; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.card-h {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fffdf9, #faf6f0);
}

.card-h h3 { margin: 0; font-size: 15px; font-weight: 650; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--line); }
th {
  color: var(--faint);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 700;
  background: #faf6f0;
}
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(229, 107, 18, 0.04); }
td.mono, .mono { font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12.5px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 650;
}
.pill::before {
  content: "";
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 18%, transparent);
}
.pill-online { background: var(--green-dim); color: var(--green); }
.pill-offline { background: #f0ece6; color: var(--faint); }
.pill-busy { background: var(--red-dim); color: var(--red); }
.pill-ringing { background: var(--yellow-dim); color: var(--yellow); }

.muted { color: var(--muted); }
.hidden { display: none !important; }

.toolbar { display: flex; gap: 10px; align-items: center; }

.modal-back {
  position: fixed; inset: 0;
  background: rgba(42, 36, 30, .38);
  display: grid; place-items: center;
  padding: 20px;
  z-index: 40;
}

.modal {
  width: min(520px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--line-strong);
  border-top: 4px solid var(--orange);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 24px 60px rgba(42, 36, 30, 0.18);
}

.modal h3 { margin: 0 0 6px; }
.modal p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

.qr-wrap {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 16px;
  align-items: start;
  margin: 8px 0 4px;
}
.qr-wrap img {
  width: 196px;
  min-height: 196px;
  height: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  object-fit: contain;
}
.qr-wrap img.qr-loading { opacity: 0.55; }
.qr-wrap img.qr-fail {
  outline: 1px dashed var(--line);
  background: #faf6f0;
}
@media (max-width: 640px) {
  .qr-wrap { grid-template-columns: 1fr; justify-items: start; }
}

.cred-box {
  background: #faf6f0;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #2a241e;
  color: #fffdf9;
  border: 0;
  padding: 12px 14px;
  border-radius: 12px;
  z-index: 50;
  font-size: 13px;
  box-shadow: var(--shadow);
}

.ami-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block;
  margin-right: 2px;
}
.ami-on { background: var(--green); box-shadow: 0 0 0 4px var(--green-dim); }
.ami-off { background: var(--red); box-shadow: 0 0 0 4px var(--red-dim); }

.view { display: none; }
.view.active { display: block; }

.row-actions { display: flex; gap: 6px; }

.modal-lg { width: min(740px, 100%); max-height: calc(100vh - 40px); overflow: auto; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
}
.form-grid .span-2 { grid-column: 1 / -1; }

select {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 14px;
  outline: none;
}
select:focus, textarea:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px var(--orange-dim);
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
  margin: 0;
  cursor: pointer;
}
.check input { width: 16px; height: 16px; accent-color: var(--orange); }

.preset-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.preset {
  background: var(--orange-dim);
  color: var(--orange-deep);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}
.preset:hover { border-color: var(--orange); }

.map-row {
  display: grid;
  grid-template-columns: 1fr 150px 40px;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}
.key-row {
  display: grid;
  grid-template-columns: 72px 150px 1fr 40px;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

.hint {
  color: var(--faint);
  font-size: 12px;
  line-height: 1.5;
  margin: 0 0 16px;
}

@media (max-width: 980px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { height: auto; position: relative; flex-direction: row; flex-wrap: wrap; align-items: center; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { display: none; }
  .grid-stats { grid-template-columns: 1fr 1fr; }
  .main { padding: 20px 16px 40px; }
}
