:root {
    color-scheme: dark;
    --background: #0c1523;
    --panel: #131f2f;
    --field: #0d1826;
    --border: #2b3e52;
    --text: #f0f7fb;
    --muted: #a9bbcc;
    --accent: #66e5cd;
    --accent-ink: #052e29;
    --error: #ffb4bb;
    --warning: #ffcf8e;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    min-width: 280px;
    color: var(--text);
    background: radial-gradient(ellipse at 13% 18%, #15313d, transparent 48rem), var(--background);
}

a { color: inherit; }

button, input, textarea { font: inherit; }

.shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: min(100% - 48px, 1060px);
    margin-inline: auto;
}

.site-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-height: 84px;
    border-bottom: 1px solid var(--border);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    color: var(--text);
    font-size: 19px;
    font-weight: 650;
    text-decoration: none;
}

.brand strong { color: var(--accent); }

.brand-mark, .device-icon {
    display: grid;
    flex: none;
    place-items: center;
    width: 39px;
    height: 39px;
    color: var(--accent);
    background: #173637;
    border: 1px solid #305450;
    border-radius: 10px;
}

.brand-mark svg, .device-icon svg { width: 23px; height: 23px; }

main { flex: 1; padding-block: 44px; }

footer {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-block: 20px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 13px;
}

h1, h2, h3, p { margin: 0; }
h1, h2, h3 { line-height: 1.15; overflow-wrap: anywhere; }
h1 { font-size: clamp(34px, 4vw, 54px); letter-spacing: -.045em; }
h2 { font-size: clamp(22px, 3vw, 28px); letter-spacing: -.022em; }
h3 { font-size: 17px; }

.eyebrow {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .035em;
}

.signal {
    width: 8px;
    height: 8px;
    border-radius: 100%;
    background: currentColor;
    box-shadow: 0 0 0 4px #66e5cd20;
}

.panel {
    min-width: 0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 26px;
}

.login-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, .78fr);
    align-items: center;
    gap: clamp(40px, 9vw, 112px);
    min-height: min(580px, 72vh);
}

.login-intro h1 { max-width: 12ch; font-size: clamp(38px, 5.6vw, 68px); }
.login-intro p:last-child { max-width: 34ch; margin-top: 18px; color: var(--muted); font-size: 18px; }
.login-panel p { color: var(--muted); margin-top: 12px; }
.login-panel .notice { margin-block: 16px 0; }
.login-panel form { margin-top: 22px; }
.centered { max-width: 600px; margin: 32px auto; text-align: center; }
.centered h1 { font-size: clamp(25px, 4vw, 38px); }
.centered p { color: var(--muted); margin-block: 12px 22px; }

.field-stack {
    display: grid;
    gap: 7px;
}

label { display: block; font-size: 14px; font-weight: 650; }
.field-stack label:not(:first-of-type) { margin-top: 9px; }
.field-stack .button { margin-top: 12px; }

input, textarea {
    display: block;
    width: 100%;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 10px 12px;
    background: var(--field);
    color: var(--text);
    font-size: 16px;
}

input::placeholder { color: #8295a9; }
input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: 9px;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

.button-primary { color: var(--accent-ink); background: var(--accent); }
.button-primary:hover { background: #91f0df; }
.button-subtle { color: var(--text); background: #1b2a3d; border-color: #35495e; }
.button-subtle:hover { background: #263950; }
.button-danger { color: var(--error); background: #462a38; border-color: #714452; }
.button-danger:hover { background: #553143; }

.notice {
    margin-block: 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 13px;
    overflow-wrap: anywhere;
}

.notice-error, .login-panel .notice-error { color: var(--error); background: #382432; border-color: #663e4d; }
.notice-success { color: var(--accent); background: #163334; border-color: #305450; }

.dashboard-heading, .section-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.dashboard-heading { margin-bottom: 22px; align-items: flex-end; flex-wrap: wrap; }

.status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border);
    border-radius: 99px;
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 700;
}

.status span { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-active { color: var(--accent); background: #163334; border-color: #305450; }
.status-inactive { color: var(--warning); background: #352b2a; border-color: #5b4840; }

.subscription {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    padding-block: 19px;
    margin-bottom: 22px;
}

.subscription > div { display: grid; align-content: start; gap: 5px; }
.subscription > div + div { border-left: 1px solid var(--border); padding-left: 18px; }
.subscription span, .subscription small { color: var(--muted); font-size: 13px; }
.subscription strong { font-size: 19px; overflow-wrap: anywhere; }

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, .86fr) minmax(0, 1.14fr);
    align-items: start;
    gap: 22px;
}

.count {
    flex: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2px 8px;
    color: var(--muted);
    font-size: 13px;
}

.devices { list-style: none; padding: 0; margin-block: 18px 0; }
.devices li + li { margin-top: 8px; }

.devices a {
    display: flex;
    align-items: center;
    gap: 11px;
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 8px;
    text-decoration: none;
}

.devices a:hover, .devices a[aria-current] { background: #192c39; border-color: #427368; }
.device-name { flex: 1; min-width: 0; font-weight: 650; overflow-wrap: anywhere; }
.device-arrow { padding-right: 5px; color: var(--muted); font-size: 23px; }

.add-device, .limit-note { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 17px; }
.add-device form, .add-device p { margin-top: 12px; }
.empty { margin-top: 15px; }
.empty, .add-device p, .limit-note, .config-empty p, .qr-box p, .action-details p { color: var(--muted); }

.input-group {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
    gap: 8px;
    margin-top: 6px;
}

.config-panel { min-height: 215px; }
.config-empty .device-icon { margin-bottom: 13px; }
.config-empty p { margin-top: 8px; max-width: 37ch; }
.config-panel .section-heading { margin-bottom: 18px; }
.config-panel .eyebrow { margin-bottom: 7px; }

.qr-box {
    display: grid;
    justify-items: center;
    gap: 11px;
    margin-block: 12px 18px;
    padding: 15px;
    border-radius: 12px;
    background: var(--field);
    text-align: center;
}

.qr-box img { width: min(100%, 208px); height: auto; image-rendering: pixelated; }
.qr-box p { font-size: 14px; }
.config-link textarea { margin-block: 6px 9px; resize: vertical; font: 13px/1.45 ui-monospace, monospace; overflow-wrap: anywhere; }
.copy-status { min-height: 1.5em; margin-top: 5px; color: var(--accent); font-size: 13px; }
.device-actions { margin-top: 15px; padding-top: 16px; border-top: 1px solid var(--border); }

.action-details { margin-top: 13px; }
.action-details summary { width: fit-content; min-height: 32px; color: var(--muted); font-weight: 650; cursor: pointer; }
.action-details summary:hover { color: var(--text); }
.action-details p { margin-block: 4px 8px; font-size: 14px; }
.action-danger summary { color: var(--error); }

[data-reissue-form] button:disabled { cursor: wait; opacity: .65; }

.reissue-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    padding: 10px 13px;
    border: 1px solid #305450;
    border-radius: 10px;
    background: #163334;
    color: var(--accent);
    font-size: 14px;
}

.reissue-progress p { color: var(--muted); }

.reissue-spinner {
    flex: none;
    width: 20px;
    height: 20px;
    border: 2px solid #427368;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: reissue-spin .85s linear infinite;
}

@keyframes reissue-spin { to { transform: rotate(1turn); } }

@media (prefers-reduced-motion: reduce) {
    .reissue-spinner { animation: none; }
}

@media (max-width: 760px) {
    .login-layout, .dashboard-grid { grid-template-columns: minmax(0, 1fr); gap: 18px; }
    .login-layout { min-height: 0; gap: 30px; }
    .login-panel { width: min(100%, 460px); }
    .login-intro h1 { max-width: 16ch; }
    main { padding-block: 32px; }
}

@media (max-width: 440px) {
    .shell { width: calc(100% - 28px); }
    .site-header { min-height: 67px; }
    .panel { padding: 17px; border-radius: 13px; }
    .subscription { gap: 8px; }
    .subscription > div + div { padding-left: 9px; }
    .subscription strong { font-size: 16px; }
    .subscription span, .subscription small { font-size: 12px; }
    .input-group { grid-template-columns: minmax(0, 1fr); }
}
