* { box-sizing: border-box; }
/* The HTML [hidden] attribute must always win — otherwise rules like
   `.modal { display: flex }` cause the modal to flash on load. */
[hidden] { display: none !important; }
html, body { margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; background:#0c1018; color:#dfe6f0; font-size: 13px; }
code { font-family: Menlo, monospace; font-size: 11px; background: rgba(255,255,255,0.04); padding: 1px 4px; border-radius: 3px; color: #7ad6ff; }
h2, h3, h4 { color: #fff; }
h3 { margin: 0 0 12px; font-size: 14px; color: #7ad6ff; font-weight: 600; }
h4 { margin: 14px 0 8px; font-size: 12px; color: #b0c0d4; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.hint { color: #7c8aa0; font-size: 11px; margin: 8px 0; }
.msg { font-size: 11px; align-self: center; color: var(--text-muted); }

.bar { display:flex; justify-content:space-between; align-items:center; padding:12px 22px; background:#0a0e1a; border-bottom:1px solid #1d2433; }
.bar-right { display: flex; align-items: center; gap: 12px; }
.brand { font-weight:600; color:#7ad6ff; letter-spacing:.5px; font-size: 14px; }
.product-pill { font-size: 11px; color: #9fb0c5; }
.product-pill select { background:#19273b; color:#dfe6f0; border:1px solid #2a3852; padding: 3px 8px; border-radius: 4px; font-size: 11px; }
.user { display:flex; gap:8px; align-items:center; font-size: 11px; color: #9fb0c5; }
.role-tag { padding: 2px 8px; background: rgba(122, 214, 255, 0.1); color: #7ad6ff; border-radius: 8px; font-size: 10px; font-weight: 600; }
.user button { background:#19273b; color:#dfe6f0; border:1px solid #2a3852; padding:5px 10px; border-radius:4px; cursor:pointer; font-size: 11px; }
.user button:hover { background: #243650; }

.tabs { display:flex; gap:2px; padding:14px 22px 0; background:#0c1018; flex-wrap: wrap; }
.tabs button { background:#141a25; color:#9fb0c5; border:1px solid #1d2433; padding:8px 14px; cursor:pointer; border-radius:6px 6px 0 0; font-size: 12px; }
.tabs button.active { background:#19273b; color:#7ad6ff; border-bottom-color:#19273b; }
.tabs button:hover { color: #fff; }
.tabs button[hidden] { display: none; }

.tab { padding: 0 22px 22px; }
.card { background:#11161f; border:1px solid #1d2433; border-radius:6px; padding:16px 18px; margin:14px 0; }
.row { display:flex; gap:8px; flex-wrap:wrap; margin:6px 0; align-items: center; }
.form-row { display:flex; gap:8px; flex-wrap: wrap; margin:10px 0; align-items: center; }
.form-row label { min-width: 200px; color: #9fb0c5; font-size: 12px; }

input, select, textarea {
    background:#0d1320; color:#dfe6f0; border:1px solid #2a3852;
    padding:7px 10px; border-radius:4px; font-size:12px; min-width:140px; flex:1;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: #7ad6ff; }

button {
    background:#1da57a; color:#fff; border:0; padding:8px 16px;
    border-radius:4px; cursor:pointer; font-weight:600; font-size: 12px;
}
button:hover { background:#168660; }
button.secondary { background: #243650; }
button.secondary:hover { background: #34486a; }
button.danger { background: #a43030; }
button.danger:hover { background: #871d1d; }
button.warn { background: #a37500; }
button.warn:hover { background: #7e5b00; }
button.link { background: transparent; color: #7ad6ff; padding: 4px 10px; font-weight: normal; font-size: 11px; }

.err { color:#ff7a7a; margin-top:8px; font-size:12px; min-height:18px; }

table { width:100%; border-collapse:collapse; font-size:12px; }
th, td { padding:8px 6px; text-align:left; border-bottom:1px solid #1d2433; }
th { color:#7ad6ff; font-weight:600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
td button { padding: 4px 10px; font-size: 11px; margin-right: 4px; }

.token-out { background:#070b14; color:#7ad6ff; padding:10px; border-radius:4px; font-family:Menlo,monospace; font-size:11px; word-break:break-all; margin-top:10px; white-space:pre-wrap; min-height:24px; }

.login { max-width:420px; margin:60px auto; padding:24px; }
.login-version { color:#7f8ea3; font-size:11px; margin-top:-8px; margin-bottom:14px; }
.login label { display:block; margin:10px 0; color:#9fb0c5; font-size:12px; }
.login input { width:100%; margin-top:4px; }
.login button { width:100%; margin-top:10px; }
.login-footer { font-size: 10px; color: #5a6878; margin-top: 14px; padding-top: 12px; border-top: 1px solid #1d2433; }

.tag, .status-tag { padding:2px 8px; border-radius:8px; font-size:10px; display:inline-block; font-weight: 600; }
.tag.active   { background:#0b3b27; color:#7ad6a0; }
.tag.suspended{ background:#3b1f00; color:#ffb070; }
.tag.revoked  { background:#3b1010; color:#ff7a7a; }
.tag.expired  { background:#2a2a3b; color:#a0a0c0; }
.tag.warn     { background:#3b2510; color:#ffb070; }
.tag.ok       { background:#0b3b27; color:#7ad6a0; }

/* KPI grid for dashboard */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin: 14px 0; }
.kpi { background: #11161f; border: 1px solid #1d2433; border-radius: 6px; padding: 14px 16px; }
.kpi-label { font-size: 10px; color: #7c8aa0; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.kpi-value { font-size: 26px; font-weight: 700; color: #fff; }
.kpi-value.warn  { color: #ffb070; }
.kpi-value.muted { color: #5a6878; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.toggle-section {
    background: rgba(255,255,255,0.02);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 5px;
    padding: 10px;
    margin-bottom: 12px;
}
.toggle-section-head {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 8px; font-size: 12px; font-weight: 600; color: #7ad6ff;
}
.toggle-section-head button {
    padding: 2px 8px; font-size: 10px; background: #19273b;
}
.toggle-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 5px;
}
.toggle-grid label {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 8px; background: rgba(255,255,255,0.02);
    border: 1px solid rgba(255,255,255,0.04); border-radius: 3px;
    cursor: pointer; font-size: 11px;
}
.toggle-grid label:hover { background: rgba(255,255,255,0.04); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 9999; }
.modal-body { background: #0c1018; border: 1px solid #2a3852; border-radius: 8px; padding: 24px; min-width: 420px; max-width: 600px; }

.chart { background: #0a0e1a; border-radius: 4px; padding: 12px; min-height: 220px; }
.chart svg { width: 100%; height: 200px; }

.btn-secondary-link { display: inline-block; padding: 5px 12px; background: #243650; color: #dfe6f0; text-decoration: none; border-radius: 4px; font-size: 11px; font-weight: 600; }
.btn-secondary-link:hover { background: #34486a; }

/* ───── Clients tab — competitor-parity layout ───── */
.page-head {
    display: flex; justify-content: space-between; align-items: flex-end;
    padding: 16px 0 6px;
}
.page-head h2 { font-size: 22px; }
button.primary { background: #1e88e5; }
button.primary:hover { background: #1565c0; }

.stat-cards {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 12px; margin: 12px 0;
}
@media (max-width: 800px) { .stat-cards { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
    background: #11161f; border: 1px solid #1d2433; border-radius: 6px;
    padding: 18px 20px; text-align: center;
}
.stat-num { font-size: 32px; font-weight: 700; color: #dfe6f0; line-height: 1; }
.stat-num.green  { color: #7ad6a0; }
.stat-num.yellow { color: #ffb070; }
.stat-num.red    { color: #ff7a7a; }
.stat-label { font-size: 10px; color: #7c8aa0; text-transform: uppercase; letter-spacing: 1px; margin-top: 8px; font-weight: 600; }

.filter-bar { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.filter-bar input { flex: 1; min-width: 250px; }
.pill-row { display: flex; gap: 6px; }
.pill {
    background: transparent; padding: 6px 14px; border-radius: 18px;
    font-size: 11px; font-weight: 600; color: #9fb0c5;
    border: 1px solid #2a3852; cursor: pointer;
}
.pill:hover { background: rgba(255,255,255,0.04); }
.pill.active.pill-blue   { background: #1e88e5; color: #fff; border-color: #1e88e5; }
.pill.active.pill-green  { background: #1da57a; color: #fff; border-color: #1da57a; }
.pill.active.pill-yellow { background: #a37500; color: #fff; border-color: #a37500; }
.pill.active.pill-red    { background: #a43030; color: #fff; border-color: #a43030; }
.pill span {
    background: rgba(0,0,0,0.3); padding: 1px 6px; border-radius: 8px;
    margin-left: 4px; font-size: 10px;
}

.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.icon-btn {
    background: transparent; border: 1px solid #2a3852;
    color: #9fb0c5; padding: 4px 8px; border-radius: 4px; cursor: pointer; font-size: 13px;
}
.icon-btn:hover { background: rgba(255,255,255,0.06); color: #fff; }
.icon-btn.edit:hover { color: #7ad6ff; border-color: #7ad6ff; }
.icon-btn.del:hover  { color: #ff7a7a; border-color: #ff7a7a; }

.modal-wide { min-width: 540px; max-width: 720px; }
.modal-xl { min-width: 920px; max-width: 1100px; width: 90vw; max-height: 90vh; overflow-y: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid #1d2433; }
.modal-head h2 { margin: 0; font-size: 20px; }

.form-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
}
.form-grid label.stack, label.stack { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: #9fb0c5; }
label.stack input, label.stack textarea, label.stack select { font-size: 12px; flex: 0 0 auto; }
label.check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #dfe6f0; }
textarea { font-family: inherit; resize: vertical; }

.kv-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.kv-grid > div label { display: block; font-size: 10px; color: #7c8aa0; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 2px; }
.kv-grid > div > div { color: #dfe6f0; font-size: 13px; word-break: break-word; }
.kv-grid > div > div.muted { color: #5a6878; font-style: italic; }
.kv-grid a { color: #7ad6ff; text-decoration: none; }
.kv-grid a:hover { text-decoration: underline; }

/* Dynamic settings editor */
.ds-row { display: grid; grid-template-columns: 200px 1fr 32px; gap: 8px; padding: 4px 0; align-items: center; }
.ds-row code { font-size: 11px; color: #7ad6ff; }
.ds-row .ds-del { background: transparent; color: #ff7a7a; border: 0; padding: 4px 8px; cursor: pointer; }
