:root {
    --ink: #17211f;
    --muted: #66736f;
    --line: #dbe4df;
    --paper: #f7f5ef;
    --panel: #ffffff;
    --teal: #0f766e;
    --teal-dark: #115e59;
    --rose: #be123c;
    --amber: #d97706;
    --blue: #2563eb;
    --shadow: 0 18px 45px rgba(23, 33, 31, .12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--ink);
    background: var(--paper);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: inherit;
    text-decoration: none;
}

main {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto 64px;
}

.topbar {
    width: min(1180px, calc(100% - 32px));
    height: 76px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.brand,
.nav,
.hero-actions,
.button-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand {
    font-weight: 800;
    font-size: 1.1rem;
}

.brand-mark {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    color: white;
    background: var(--ink);
    font-size: .78rem;
    letter-spacing: 0;
}

.nav {
    color: var(--muted);
    font-weight: 700;
    font-size: .94rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.nav-cta,
.button,
.mini-button,
.command-button {
    border: 0;
    border-radius: 8px;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.nav-cta,
.button {
    min-height: 44px;
    padding: 0 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.nav-cta,
.button.primary {
    color: white;
    background: var(--teal);
}

.button.danger {
    color: white;
    background: var(--rose);
}

.button.ghost {
    color: var(--ink);
    background: #e7eee9;
}

.link-button {
    color: var(--muted);
    border: 0;
    background: transparent;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.flash {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto 18px;
    padding: 14px 16px;
    border: 1px solid #b5d6cf;
    border-radius: 8px;
    color: var(--teal-dark);
    background: #ecfdf5;
    font-weight: 700;
}

.flash-error {
    color: #991b1b;
    border-color: #fecaca;
    background: #fff1f2;
}

.impersonation-bar {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto 18px;
    padding: 12px 16px;
    border-radius: 8px;
    color: #7c2d12;
    background: #ffedd5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    font-weight: 800;
}

.impersonation-bar button {
    min-height: 34px;
    border: 0;
    border-radius: 8px;
    color: white;
    background: var(--amber);
    font: inherit;
    font-weight: 800;
    padding: 0 12px;
    cursor: pointer;
}

.hero {
    min-height: calc(100vh - 132px);
    display: grid;
    grid-template-columns: minmax(0, .82fr) minmax(380px, 1fr);
    gap: 36px;
    align-items: center;
    padding-bottom: 44px;
}

.hero-copy {
    padding: 24px 0;
}

.eyebrow {
    margin: 0 0 12px;
    color: var(--teal-dark);
    text-transform: uppercase;
    font-size: .78rem;
    font-weight: 900;
    letter-spacing: 0;
}

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

h1 {
    margin-bottom: 18px;
    font-size: clamp(2.7rem, 6vw, 5.8rem);
    line-height: .95;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 8px;
    font-size: 1.15rem;
}

h3 {
    margin-bottom: 4px;
    font-size: 1rem;
}

.hero-text,
.muted {
    color: var(--muted);
    line-height: 1.7;
}

.hero-text {
    max-width: 620px;
    font-size: 1.1rem;
}

.hero-media {
    min-height: 540px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
    background: #111;
}

.hero-media img {
    width: 100%;
    height: 100%;
    min-height: 540px;
    object-fit: cover;
    display: block;
}

.section-grid,
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    margin-top: 24px;
}

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

.feature,
.panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 8px 22px rgba(23, 33, 31, .06);
}

.feature {
    padding: 22px;
}

.feature-icon,
.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 0 10px;
    border-radius: 8px;
    color: var(--teal-dark);
    background: #d9f3ed;
    font-size: .78rem;
    font-weight: 900;
}

.status-stack {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.status-ok {
    color: #14532d;
    background: #dcfce7;
}

.status-danger {
    color: #991b1b;
    background: #fee2e2;
}

.panel {
    padding: 20px;
}

.panel-heading,
.page-header.split {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
}

.panel-heading {
    margin-bottom: 16px;
}

.panel-heading span,
small {
    color: var(--muted);
    font-size: .82rem;
    font-weight: 700;
}

.page-header {
    padding: 44px 0 12px;
}

.page-header h1,
.auth-shell h1 {
    max-width: 760px;
    font-size: clamp(2.3rem, 5vw, 4.2rem);
}

.auth-shell {
    min-height: calc(100vh - 140px);
    display: grid;
    grid-template-columns: .85fr minmax(320px, 460px);
    gap: 36px;
    align-items: center;
}

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

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

label {
    display: grid;
    gap: 7px;
    color: var(--ink);
    font-weight: 800;
    font-size: .9rem;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 13px;
    color: var(--ink);
    background: #fbfcfa;
    font: inherit;
}

textarea {
    min-height: 116px;
    resize: vertical;
}

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

.check-row input {
    width: auto;
}

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

.device-row,
.request-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 0;
    border-top: 1px solid var(--line);
}

.device-row {
    justify-content: flex-start;
    opacity: 0;
    transform: translateY(8px);
}

.device-row.is-visible {
    opacity: 1;
    transform: translateY(0);
    transition: .28s ease;
}

.device-row p,
.request-row p {
    margin-bottom: 0;
    color: var(--muted);
}

.pulse {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    background: var(--amber);
    box-shadow: 0 0 0 6px rgba(217, 119, 6, .12);
    flex: 0 0 auto;
}

.pulse.is-live {
    background: var(--teal);
    box-shadow: 0 0 0 6px rgba(15, 118, 110, .14);
}

.mini-button {
    min-height: 34px;
    padding: 0 12px;
    color: white;
    background: var(--blue);
    white-space: nowrap;
}

.mini-button.danger {
    background: var(--rose);
}

.mini-button.neutral {
    color: var(--ink);
    background: #e7eee9;
}

.admin-table {
    display: grid;
    gap: 0;
}

.admin-row {
    display: grid;
    grid-template-columns: minmax(260px, 1.6fr) .7fr .8fr minmax(180px, .9fr);
    gap: 16px;
    align-items: center;
    padding: 14px 0;
    border-top: 1px solid var(--line);
}

.admin-row p {
    margin-bottom: 0;
    color: var(--muted);
}

.admin-head {
    border-top: 0;
    color: var(--muted);
    font-size: .78rem;
    font-weight: 900;
    text-transform: uppercase;
}

.admin-actions,
.form-actions,
.compact-form {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.compact-form select {
    width: auto;
    min-height: 34px;
    padding: 6px 9px;
}

.control-panel {
    background: #17211f;
    color: white;
}

.control-panel .panel-heading span {
    color: #bdd7d1;
}

.lock-state {
    margin-bottom: 16px;
    padding: 18px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 16px;
    border: 1px solid rgba(255, 255, 255, .16);
}

.lock-state img {
    width: 96px;
    height: 96px;
    border-radius: 8px;
    object-fit: cover;
    background: rgba(255, 255, 255, .08);
    flex: 0 0 auto;
}

.lock-state span {
    font-size: 1.55rem;
    font-weight: 900;
}

.lock-state small {
    color: rgba(255, 255, 255, .78);
    font-weight: 800;
}

.lock-state-locked {
    background: rgba(190, 18, 60, .34);
}

.lock-state-unlocked {
    background: rgba(15, 118, 110, .38);
}

.command-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.command-input {
    color: #dce8e4;
}

.command-input input {
    color: white;
    border-color: rgba(255, 255, 255, .16);
    background: rgba(255, 255, 255, .1);
}

.command-button {
    min-height: 88px;
    color: white;
    background: rgba(255, 255, 255, .12);
    border: 1px solid rgba(255, 255, 255, .16);
}

.command-button:hover {
    background: var(--teal);
}

.command-button:disabled {
    opacity: .45;
    cursor: not-allowed;
}

.panel-note {
    margin: 14px 0 0;
    color: #ffedd5;
    line-height: 1.6;
}

.warning-check {
    padding: 12px;
    border: 1px solid #fed7aa;
    border-radius: 8px;
    color: #7c2d12;
    background: #fffbeb;
}

.compact-check {
    font-size: .8rem;
    padding: 8px;
}

.emergency-panel {
    margin-top: 24px;
    display: grid;
    grid-template-columns: minmax(0, .8fr) minmax(320px, 1fr);
    gap: 20px;
    border-color: #fecaca;
}

.audit-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 13px 0;
    border-top: 1px solid var(--line);
}

.audit-row p {
    margin-bottom: 0;
    color: var(--muted);
}

.audit-row span {
    color: var(--muted);
    font-size: .82rem;
    font-weight: 800;
    white-space: nowrap;
}

.warning-modal {
    width: min(520px, calc(100% - 32px));
    border: 0;
    border-radius: 8px;
    padding: 0;
    color: var(--ink);
    background: transparent;
}

.warning-modal::backdrop {
    background: rgba(23, 33, 31, .52);
}

.warning-modal-box {
    padding: 22px;
    border: 1px solid #fed7aa;
    border-radius: 8px;
    background: #fffbeb;
    box-shadow: var(--shadow);
}

.warning-modal-box h2 {
    color: #7c2d12;
}

.warning-modal-box p {
    color: #7c2d12;
    line-height: 1.6;
}

@media (max-width: 820px) {
    .topbar {
        height: auto;
        padding: 18px 0;
        align-items: flex-start;
        flex-direction: column;
    }

    .nav {
        justify-content: flex-start;
    }

    .hero,
    .auth-shell,
    .section-grid,
    .dashboard-grid,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .hero {
        min-height: auto;
    }

    .hero-media,
    .hero-media img {
        min-height: 340px;
    }

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

    .page-header.split,
    .panel-heading,
    .request-row,
    .impersonation-bar,
    .emergency-panel,
    .audit-row {
        align-items: stretch;
        flex-direction: column;
        grid-template-columns: 1fr;
    }

    .admin-row {
        grid-template-columns: 1fr;
    }
}
