:root {
    --bg: #eef1f6;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --muted: #64748b;
    --accent: #4f46e5;
    --accent-dark: #4338ca;
    --accent-soft: #eef2ff;
    --danger: #dc2626;
    --danger-dark: #b91c1c;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --radius: 12px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
}

a {
    color: inherit;
}

/* ---------- Topbar ---------- */
.topbar {
    height: 62px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    background: linear-gradient(180deg, #1e293b 0%, #111827 100%);
    color: #fff;
    box-shadow: 0 2px 16px rgba(15, 23, 42, 0.22);
}

.brand {
    text-decoration: none;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.01em;
    display: inline-flex;
    align-items: center;
    gap: 9px;
}

.brand::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 3px;
    background: var(--accent);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.25);
}

.topbar nav {
    display: flex;
    align-items: center;
    gap: 6px;
}

.topbar nav a {
    color: #cbd5e1;
    text-decoration: none;
    font-size: 0.9rem;
    padding: 7px 12px;
    border-radius: 8px;
    transition: background 0.15s, color 0.15s;
}

.topbar nav a:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.topbar form {
    margin: 0 0 0 6px;
}

.topbar button {
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.06);
    color: #e5e7eb;
    cursor: pointer;
    padding: 7px 13px;
    border-radius: 8px;
    font-size: 0.9rem;
    transition: background 0.15s;
}

.topbar button:hover {
    background: rgba(255, 255, 255, 0.14);
}

/* ---------- Layout ---------- */
.container {
    width: calc(100% - 48px);
    margin: 30px auto 64px;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 4px;
    font-size: 1.6rem;
    letter-spacing: 0.01em;
}

h2 {
    margin-bottom: 6px;
    font-size: 1.1rem;
}

.page-head p,
.danger-panel p,
.section-head p {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 0.92rem;
}

/* ---------- Flash ---------- */
.flash-list {
    display: grid;
    gap: 10px;
    margin-bottom: 20px;
}

.flash {
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    box-shadow: var(--shadow);
    border-left-width: 4px;
}

.flash.success {
    border-color: #bbf7d0;
    border-left-color: #16a34a;
    background: #f0fdf4;
}

.flash.error {
    border-color: #fecdd3;
    border-left-color: var(--danger);
    background: #fff1f2;
}

/* ---------- Metrics ---------- */
.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}

.metric,
.table-panel,
.form-panel,
.auth-panel,
.danger-panel,
.deploy-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.metric {
    padding: 18px 20px;
    position: relative;
    overflow: hidden;
}

.metric::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--accent);
}

.metric.is-warn::before {
    background: #f59e0b;
}

.metric.is-muted::before {
    background: var(--muted);
}

.metric span {
    display: block;
    color: var(--muted);
    font-size: 0.82rem;
    margin-bottom: 6px;
}

.metric strong {
    font-size: 1.9rem;
    font-weight: 700;
}

/* ---------- Tables ---------- */
.table-panel {
    overflow-x: auto;
}

.panel-head,
.section-head {
    padding: 18px 20px 0;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 900px;
}

th,
td {
    padding: 13px 18px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--surface-muted);
    border-bottom: 1px solid var(--border-strong);
    position: sticky;
    top: 0;
}

tbody tr {
    transition: background 0.12s;
}

tbody tr:hover {
    background: var(--accent-soft);
}

tbody tr:last-child td {
    border-bottom: 0;
}

td strong {
    font-weight: 600;
}

td span {
    display: block;
    color: var(--muted);
    font-size: 0.83rem;
    margin-top: 2px;
}

td.num {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.muted-text {
    color: var(--muted);
}

.nowrap {
    white-space: nowrap;
}

code {
    font-family: Consolas, "Liberation Mono", monospace;
    font-size: 0.85rem;
    overflow-wrap: anywhere;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 2px 6px;
}

/* ---------- Pills / badges ---------- */
.pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 10px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.77rem;
    white-space: nowrap;
}

.pill.active {
    color: #166534;
    background: #dcfce7;
}

.pill.expired {
    color: #92400e;
    background: #fef3c7;
}

.pill.suspended {
    color: #334155;
    background: #e2e8f0;
}

.pill.revoked {
    color: #991b1b;
    background: #fee2e2;
}

.badge-latest {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    padding: 1px 9px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--accent-dark);
    background: var(--accent-soft);
    border: 1px solid #c7d2fe;
    vertical-align: middle;
    white-space: nowrap;
}

.badge-latest::before {
    content: "★";
    font-size: 0.65rem;
}

.device-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.device-tag::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
}

.device-tag.is-zero {
    color: var(--muted);
}

.device-tag.is-zero::before {
    background: var(--border-strong);
}

.version-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.version-tag {
    display: inline-flex;
    align-items: center;
    margin: 0;
    padding: 1px 9px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: #166534;
    background: #dcfce7;
    white-space: nowrap;
}

.version-tag.is-old {
    color: #92400e;
    background: #fef3c7;
}

/* ---------- Deployment overview ---------- */
.deploy-panel {
    padding: 20px;
    margin-bottom: 22px;
}

.deploy-list {
    display: grid;
    gap: 12px;
    margin-top: 16px;
}

.deploy-row {
    display: grid;
    grid-template-columns: 200px 1fr 70px;
    align-items: center;
    gap: 14px;
}

.deploy-label {
    font-size: 0.9rem;
}

.deploy-label small {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
}

.deploy-bar {
    height: 12px;
    border-radius: 999px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    overflow: hidden;
}

.deploy-bar > span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #6366f1);
    border-radius: 999px;
}

.deploy-count {
    text-align: right;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.deploy-count small {
    color: var(--muted);
    font-weight: 400;
}

/* ---------- Actions ---------- */
.actions {
    text-align: right;
    white-space: nowrap;
}

.actions a.row-link {
    display: inline-block;
    color: var(--accent-dark);
    font-weight: 600;
    text-decoration: none;
    padding: 5px 10px;
    border-radius: 7px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    transition: background 0.12s, border-color 0.12s;
    white-space: nowrap;
}

.actions a.row-link:hover {
    background: var(--accent-soft);
    border-color: #c7d2fe;
}

.actions a.row-link + a.row-link {
    margin-left: 6px;
}

.actions form {
    margin: 0;
}

.text-danger {
    color: var(--danger);
    font-weight: 600;
    text-decoration: none;
    border: 0;
    background: transparent;
    cursor: pointer;
    padding: 0;
}

.text-danger:hover {
    text-decoration: underline;
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 36px;
}

/* ---------- Copy note ---------- */
.copy-note {
    margin-bottom: 18px;
    padding: 11px 16px;
    border-radius: 10px;
    border: 1px solid #c7d2fe;
    background: var(--accent-soft);
    color: #3730a3;
    font-size: 0.88rem;
}

.copy-note a {
    color: var(--accent-dark);
    font-weight: 600;
    margin-left: 6px;
}

/* ---------- Auth / forms ---------- */
.auth-panel {
    width: min(100%, 420px);
    margin: 80px auto;
    padding: 30px;
}

.form-panel {
    padding: 24px;
}

.form-stack,
.license-grid {
    display: grid;
    gap: 16px;
}

.license-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.span-2 {
    grid-column: span 2;
}

label {
    display: grid;
    gap: 7px;
    color: #334155;
    font-weight: 600;
    font-size: 0.88rem;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
    color: var(--text);
    background: #fff;
    transition: border-color 0.12s, box-shadow 0.12s;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

input:disabled {
    color: #94a3b8;
    background: #f1f5f9;
    cursor: not-allowed;
}

label.is-disabled {
    color: var(--muted);
}

.checkbox-field {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--surface-muted);
    cursor: pointer;
}

.checkbox-field input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 1px 0 0;
    padding: 0;
    accent-color: var(--accent);
}

.checkbox-copy {
    display: grid;
    gap: 2px;
}

.checkbox-title {
    color: #334155;
    font-weight: 700;
}

.field-hint {
    font-weight: 400;
    font-size: 0.82rem;
    color: var(--muted);
}

.field-hint strong {
    color: var(--accent-dark);
    font-weight: 700;
}

/* ---------- Buttons ---------- */
.primary,
.secondary,
.danger {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0 18px;
    font-weight: 600;
    font-size: 0.92rem;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.14s, box-shadow 0.14s, transform 0.05s;
}

.primary:active,
.secondary:active,
.danger:active {
    transform: translateY(1px);
}

.primary {
    color: #fff;
    background: var(--accent);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.28);
}

.primary:hover {
    background: var(--accent-dark);
}

.secondary {
    color: #334155;
    background: #fff;
    border-color: var(--border-strong);
}

.secondary:hover {
    background: var(--surface-muted);
}

.danger {
    color: #fff;
    background: var(--danger);
}

.danger:hover {
    background: var(--danger-dark);
}

.link-button {
    white-space: nowrap;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
}

/* ---------- Danger panel ---------- */
.danger-panel {
    margin: 22px 0;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    border-color: #fecdd3;
    background: #fff7f7;
}

.section-gap {
    margin-top: 22px;
}

/* ---------- Responsive ---------- */
@media (max-width: 780px) {
    .topbar,
    .page-head,
    .danger-panel {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar {
        height: auto;
        padding: 14px 16px;
        gap: 10px;
    }

    .topbar nav {
        flex-wrap: wrap;
    }

    .metric-grid,
    .license-grid {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: span 1;
    }

    .deploy-row {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .deploy-count {
        text-align: left;
    }
}
