:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-soft: #eef0f3;
  --head: #f3f4f6;
  --primary: #0b1220;
  --link: #2563eb;
  --danger: #dc2626;
  --ok-bg: #e7f6ec; --ok: #166534;
  --warn-bg: #fff4e0; --warn: #9a5b00;
  --bad-bg: #fde8e8; --bad: #b42318;
  --info-bg: #e8f0fe; --info: #1e40af;
  --grey-bg: #f1f2f4; --grey: #4b5563;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); font-size: 15px; line-height: 1.45; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 44px; padding: 0 18px; border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-size: 15px; font-weight: 500; cursor: pointer; white-space: nowrap;
  text-decoration: none !important;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1f2937; }
.btn-outline { background: #fff; border-color: #d1d5db; color: var(--text); }
.btn-outline:hover:not(:disabled) { background: #f9fafb; }
.btn-danger { background: #fff; border-color: #f3c2c2; color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #fef2f2; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--link); cursor: pointer; }
.link:hover { text-decoration: underline; }
.link-danger { color: var(--danger); }
.link:disabled { color: var(--muted); cursor: default; text-decoration: none; }
.icon-btn { border: 0; background: none; font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--head); color: var(--text); }

.input, input:not([type=checkbox]), textarea, select {
  width: 100%; height: 44px; padding: 0 14px; border: 1px solid #d1d5db; border-radius: 8px;
  font: inherit; color: var(--text); background: #fff;
}
textarea { height: auto; min-height: 84px; padding: 10px 14px; resize: vertical; }
.input:focus, input:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: #93c5fd; }
label { display: block; font-size: 13px; font-weight: 600; color: #374151; }
label > input:not([type=checkbox]), label > textarea { margin-top: 6px; font-weight: 400; font-size: 15px; }
.hint { font-size: 12.5px; color: var(--muted); font-weight: 400; margin-top: 4px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 400; color: #374151; white-space: nowrap; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; }
.form-error { color: var(--bad); background: var(--bad-bg); padding: 10px 12px; border-radius: 8px; font-size: 14px; margin: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 32px; display: grid; gap: 16px; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.login-card h1 { font-size: 24px; }
.login-card p { margin: -8px 0 4px; }
.login-logo { border-radius: 10px; }

/* ---------- page ---------- */
.page { max-width: 1440px; margin: 0 auto; padding: 32px 28px 24px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin-bottom: 24px; }
.page-head h1 { font-size: 34px; font-weight: 750; }
.lead { color: var(--muted); font-size: 17px; margin: 8px 0 0; max-width: 820px; }
.head-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.pill { display: inline-flex; align-items: center; height: 28px; padding: 0 10px; border-radius: 6px; font-size: 13px; font-weight: 500; border: 0; white-space: nowrap; }
.pill-user { background: #e0ecff; color: #1e3a8a; }
.pill-quota { background: #fff; border: 1px solid var(--line); color: #374151; cursor: pointer; font: inherit; font-size: 13px; }
.pill-quota:hover { background: #f9fafb; }
.pill-quota.warn { background: var(--warn-bg); color: var(--warn); border-color: #f5d9a8; }
.pill-quota.bad { background: var(--bad-bg); color: var(--bad); border-color: #f3c2c2; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px 28px; box-shadow: 0 1px 2px rgba(16,24,40,.04); margin-bottom: 20px; }
.card-title { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.card-title h2 { font-size: 18px; }

.banner { border-radius: 10px; padding: 12px 16px; margin-bottom: 16px; font-size: 14px; border: 1px solid; }
.banner.warn { background: var(--warn-bg); color: #7a4a00; border-color: #f5d9a8; }
.banner.bad { background: var(--bad-bg); color: var(--bad); border-color: #f3c2c2; }

.toolbar { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.toolbar .search { flex: 1 1 360px; height: 48px; font-size: 16px; }
.toolbar .btn { height: 48px; font-size: 16px; padding: 0 20px; }
.meta-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin: 20px 0 10px; color: var(--muted); font-size: 15px; }
.meta-actions { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 14px; }

/* ---------- table ---------- */
.table-wrap { border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th { background: #f7f8fa; text-align: left; font-weight: 600; color: #374151; padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover td { background: #fafbfc; }
.table tr.archived td { color: var(--muted); }
.cell-name strong { font-weight: 500; display: block; }
.cell-name .sub { font-size: 12.5px; color: var(--muted); }
.cell-trade { max-width: 260px; }
.cell-trade .clip { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions-col { width: 1%; }
.nowrap { white-space: nowrap; }
.row-actions { display: flex; gap: 14px; justify-content: flex-end; white-space: nowrap; font-size: 14px; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }

.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.grey { background: var(--grey-bg); color: var(--grey); }

/* ---------- pending ---------- */
.pending-card { border-color: #f5d9a8; background: #fffdf7; }
.pending-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.pending-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.pending-list .who { font-size: 13px; color: var(--muted); }

/* ---------- dialogs ---------- */
.dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 20px 50px rgba(16,24,40,.25); color: var(--text); }
.dialog-wide { width: min(980px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(17,24,39,.45); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 22px 26px 14px; border-bottom: 1px solid var(--line-soft); position: sticky; top: 0; background: #fff; z-index: 2; }
.dialog-head h2 { font-size: 22px; }
.dialog-body { padding: 20px 26px 26px; display: grid; gap: 18px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; padding-top: 4px; }
.dialog-foot .spacer { flex: 1; }

.steps { display: flex; flex-wrap: wrap; gap: 6px 8px; list-style: none; margin: 0; padding: 14px 26px 0; counter-reset: s; }
.steps li { counter-increment: s; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.steps li::before { content: counter(s); width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--head); font-weight: 600; font-size: 12px; }
.steps li:not(:last-child)::after { content: ""; width: 28px; height: 1px; background: var(--line); margin-left: 6px; }
.steps li.active { color: var(--text); font-weight: 600; }
.steps li.active::before { background: var(--primary); color: #fff; }
.steps li.done::before { background: var(--ok-bg); color: var(--ok); content: "✓"; }

.callout { border-radius: 10px; padding: 12px 14px; font-size: 14px; border: 1px solid var(--line); background: #f9fafb; }
.callout.info { background: var(--info-bg); border-color: #c7d7fb; color: #1e3a8a; }
.callout.warn { background: var(--warn-bg); border-color: #f5d9a8; color: #7a4a00; }
.callout.bad { background: var(--bad-bg); border-color: #f3c2c2; color: var(--bad); }
.callout.ok { background: var(--ok-bg); border-color: #bfe5cb; color: var(--ok); }
.callout strong { font-weight: 600; }

.candidate { border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; display: grid; gap: 6px; }
.candidate .name { font-size: 18px; font-weight: 600; }

.search-results { display: grid; gap: 6px; max-height: 300px; overflow: auto; }
.result { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.result .r-name { font-weight: 500; }
.result .r-sub { font-size: 12.5px; color: var(--muted); }
.inline-search { display: flex; gap: 8px; }
.inline-search input { flex: 1; }
details.helper { border: 1px dashed #d1d5db; border-radius: 10px; padding: 10px 14px; }
details.helper summary { cursor: pointer; color: var(--link); font-size: 14px; }
details.helper[open] summary { margin-bottom: 10px; }

/* data sections */
.sections { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.section { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.section.full { grid-column: 1 / -1; }
.section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 10px; font-weight: 600; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.licenses { display: grid; gap: 8px; }
.license { border: 1px solid var(--line-soft); border-radius: 10px; padding: 10px 12px; font-size: 14px; background: #fcfcfd; }
.license.main { border-color: #c7d7fb; background: #f5f8ff; }
.license .l-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.license .l-meta { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

.changes { border: 1px solid #f5d9a8; background: #fffaf0; border-radius: 12px; padding: 14px 16px; display: grid; gap: 10px; }
.changes h3 { font-size: 15px; }
.change-table { width: 100%; border-collapse: collapse; font-size: 14px; background: #fff; border-radius: 8px; overflow: hidden; }
.change-table th, .change-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.change-table th { font-size: 12.5px; color: var(--muted); font-weight: 600; background: #fff; }
.change-table tr.critical td:first-child { color: var(--bad); font-weight: 600; }
.change-table .old { color: var(--muted); text-decoration: line-through; }
.change-table .new { font-weight: 500; }
.change-actions { display: flex; gap: 10px; white-space: nowrap; }
.history { font-size: 13px; }
.history summary { cursor: pointer; color: var(--muted); }
.history ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }

.usage-bar { height: 10px; background: var(--head); border-radius: 999px; overflow: hidden; }
.usage-bar > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.stat-row { display: flex; gap: 28px; flex-wrap: wrap; }
.stat strong { display: block; font-size: 24px; }
.stat span { color: var(--muted); font-size: 13px; }
.calls-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.calls-table th, .calls-table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line-soft); }
.calls-table th { color: var(--muted); font-weight: 600; }

.toasts { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 50; }
.toast { background: var(--primary); color: #fff; padding: 12px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 8px 24px rgba(16,24,40,.2); max-width: 420px; }
.toast.error { background: var(--bad); }
.foot { text-align: center; font-size: 12.5px; padding: 8px 0 16px; }

.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; display: inline-block; animation: spin .7s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .page { padding: 20px 14px; }
  .page-head { flex-direction: column; }
  .page-head h1 { font-size: 28px; }
  .card { padding: 18px 16px; }
  .sections, .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 120px 1fr; }
  .steps li:not(.active) { font-size: 0; gap: 0; }
  .steps li::before { font-size: 12px; }
  .steps li:not(:last-child)::after { width: 14px; }
}
