:root {
    color-scheme: light;
    --paper: #f7f1e6;
    --surface: #fffaf0;
    --surface-strong: #fffdf8;
    --ink: #27231f;
    --muted: #6e675e;
    --line: #d8cdbc;
    --line-strong: #b9aa95;
    --accent: #d95f3a;
    --accent-dark: #b94729;
    --accent-soft: #f6dfd4;
    --danger: #a93f35;
    --danger-soft: #f7e3df;
    --success: #477948;
    --success-soft: #e5eddf;
    --shadow: rgba(69, 51, 34, .10);
    --radius: 14px;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    min-height: 100dvh;
    color: var(--ink);
    background:
        radial-gradient(circle at 92% 0%, rgba(217, 95, 58, .07), transparent 32rem),
        linear-gradient(145deg, rgba(255, 255, 255, .28), transparent 48%),
        var(--paper);
    line-height: 1.55;
}
body::before {
    position: fixed;
    inset: 0;
    z-index: -1;
    content: "";
    pointer-events: none;
    opacity: .18;
    background-image: repeating-radial-gradient(circle at 0 0, rgba(39, 35, 31, .09) 0 .45px, transparent .6px 4px);
    background-size: 6px 6px;
}

a { color: inherit; }
button, input, textarea, select { font: inherit; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }

.skip-link {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 100;
    padding: 9px 13px;
    color: #fff;
    background: var(--ink);
    border-radius: 7px;
    transform: translateY(-160%);
    transition: transform .2s ease;
}
.skip-link:focus { transform: translateY(0); }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 72px;
    padding: 12px max(24px, calc((100vw - 1280px) / 2));
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
    align-items: center;
    gap: 26px;
    background: rgba(247, 241, 230, .88);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(18px) saturate(120%);
}
.brand, .login-brand {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    font-family: "Songti SC", STSong, serif;
    font-size: 21px;
    font-weight: 700;
    text-decoration: none;
    letter-spacing: -.02em;
}
.brand-mark {
    width: 34px;
    height: 34px;
    display: inline-grid;
    place-items: center;
    color: var(--surface-strong);
    background: var(--accent);
    border-radius: 11px 11px 11px 4px;
    font-family: "Songti SC", STSong, serif;
    font-size: 16px;
    box-shadow: 0 8px 18px rgba(185, 71, 41, .17);
}
.primary-nav { display: flex; align-items: center; gap: 8px; }
.primary-nav a {
    position: relative;
    padding: 9px 14px;
    color: var(--muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: color .2s ease, transform .2s ease;
}
.primary-nav a:first-child, .primary-nav a:hover { color: var(--accent-dark); }
.primary-nav a:first-child::after {
    position: absolute;
    right: 14px;
    bottom: 2px;
    left: 14px;
    height: 2px;
    content: "";
    background: var(--accent);
}
.primary-nav a:active { transform: translateY(1px); }
.topbar form { justify-self: end; }

.layout {
    width: min(1280px, calc(100% - 48px));
    margin: 0 auto;
    padding: 26px 0 68px;
    display: grid;
    grid-template-columns: minmax(0, 1.85fr) minmax(330px, .95fr);
    grid-template-areas:
        "flash flash"
        "stats stats"
        "global announcements"
        "devices announcements"
        "audit audit";
    gap: 18px;
    align-items: start;
}
.flash { grid-area: flash; }
.stats { grid-area: stats; }
.global-card { grid-area: global; }
.devices-card { grid-area: devices; }
.announcements-card { grid-area: announcements; }
.audit-card { grid-area: audit; }

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: rgba(255, 250, 240, .62);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.stats article {
    position: relative;
    min-height: 102px;
    padding: 20px 24px;
    display: grid;
    align-content: center;
    gap: 4px;
}
.stats article + article::before {
    position: absolute;
    top: 22px;
    bottom: 22px;
    left: 0;
    width: 1px;
    content: "";
    background: var(--line);
}
.stats span { color: var(--muted); font-size: 13px; font-weight: 600; }
.stats strong {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: clamp(25px, 3vw, 34px);
    font-variant-numeric: tabular-nums;
    letter-spacing: -.04em;
}
.stats article:last-child strong { color: var(--accent-dark); font-family: "Songti SC", STSong, serif; }

.card {
    padding: 22px;
    background: rgba(255, 250, 240, .68);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.section-title {
    margin-bottom: 18px;
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 20px;
    padding-bottom: 13px;
    border-bottom: 1px solid var(--line);
}
.section-title h2 {
    margin: 0 0 4px;
    font-family: "Songti SC", STSong, serif;
    font-size: 23px;
    line-height: 1.2;
    letter-spacing: -.02em;
}
.section-title p { max-width: 62ch; margin: 0; color: var(--muted); font-size: 13px; }
.muted, small { color: var(--muted); }

button {
    min-height: 40px;
    padding: 9px 15px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: #fff;
    background: var(--accent);
    cursor: pointer;
    font-weight: 700;
    white-space: nowrap;
    box-shadow: 0 7px 14px rgba(185, 71, 41, .13);
    transition: background-color .2s ease, border-color .2s ease, color .2s ease, transform .2s ease, box-shadow .2s ease;
}
button:hover { background: var(--accent-dark); box-shadow: 0 9px 18px rgba(185, 71, 41, .18); transform: translateY(-1px); }
button:active { transform: translateY(1px) scale(.985); box-shadow: none; }
button.secondary { color: var(--ink); background: transparent; border-color: var(--line-strong); box-shadow: none; }
button.secondary:hover { color: var(--accent-dark); background: var(--accent-soft); border-color: var(--accent); }
button.danger { color: var(--danger); background: transparent; border-color: transparent; box-shadow: none; }
button.danger:hover { background: var(--danger-soft); }

input, textarea, select {
    width: 100%;
    min-width: 0;
    min-height: 42px;
    padding: 9px 11px;
    color: var(--ink);
    background: rgba(255, 253, 248, .82);
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    transition: background-color .2s ease, border-color .2s ease, box-shadow .2s ease;
}
textarea { min-height: 96px; resize: vertical; }
input:hover, textarea:hover, select:hover { background: var(--surface-strong); border-color: #a99780; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
    outline: 3px solid rgba(217, 95, 58, .26);
    outline-offset: 2px;
}
input:focus, textarea:focus, select:focus { background: var(--surface-strong); border-color: var(--accent); box-shadow: 0 0 0 3px rgba(217, 95, 58, .10); }
label { display: grid; gap: 7px; color: var(--ink); font-size: 13px; font-weight: 650; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: end; }
.form-grid > * { min-width: 0; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-grid > button { justify-self: start; }
.switch-row { display: flex; align-items: center; gap: 10px; min-height: 42px; }
.switch-row input { width: 19px; height: 19px; accent-color: var(--accent); }
.search { min-width: min(410px, 100%); display: flex; gap: 8px; }
.search input { min-width: 0; }

.device-list, .announcement-list { display: grid; gap: 12px; }
.device-card {
    padding: 16px;
    background: rgba(255, 253, 248, .52);
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: 10px;
}
.device-heading, .row-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.device-heading { margin-bottom: 14px; }
.device-heading strong, .device-heading small { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }
.device-heading small { display: block; margin-top: 4px; font-size: 11px; }
.badge {
    padding: 4px 8px;
    border: 1px solid currentColor;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 750;
    white-space: nowrap;
}
.badge.on { color: var(--success); background: var(--success-soft); }
.badge.off { color: var(--danger); background: var(--danger-soft); }

.announcement-list { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.announcement-list article {
    padding: 15px 0;
    display: grid;
    gap: 14px;
    border-bottom: 1px solid var(--line);
}
.announcement-list article:first-child { padding-top: 0; }
.announcement-list p { margin: 9px 0; color: #514a42; white-space: normal; }
.actions { display: flex; align-items: start; gap: 8px; }
.actions form { display: inline-flex; }

.alert { padding: 12px 14px; border: 1px solid currentColor; border-radius: 9px; }
.alert.success { color: #315f33; background: var(--success-soft); }
.alert.error { color: #8b2c24; background: var(--danger-soft); }
.empty { margin: 0; padding: 30px; color: var(--muted); text-align: center; }

.table-wrap { overflow-x: auto; }
.layout > *, .stats article, .table-wrap { min-width: 0; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 9px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-size: 12px; font-weight: 750; letter-spacing: .03em; }
td:first-child { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }
tbody tr { transition: background-color .18s ease; }
tbody tr:hover { background: rgba(217, 95, 58, .045); }

.login-page { display: grid; place-items: center; padding: 24px; }
.login-card {
    width: min(430px, 100%);
    padding: 34px;
    background: rgba(255, 250, 240, .82);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 22px 60px var(--shadow);
}
.login-brand { margin-bottom: 28px; color: var(--muted); font-size: 17px; }
.login-card h1 { margin: 0; font-family: "Songti SC", STSong, serif; font-size: 34px; letter-spacing: -.04em; }
.login-card > p { margin: 7px 0 0; }
.login-card .alert { margin-top: 18px; }
.login-card form { display: grid; gap: 15px; margin-top: 24px; }
.login-card button { margin-top: 3px; }

@media (max-width: 980px) {
    .topbar { grid-template-columns: 1fr auto; }
    .primary-nav { grid-column: 1 / -1; grid-row: 2; overflow-x: auto; justify-content: center; }
    .layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "flash" "stats" "global" "devices" "announcements" "audit";
    }
}

@media (max-width: 700px) {
    .topbar { padding: 11px 16px; gap: 10px; }
    .brand { font-size: 18px; }
    .brand-mark { width: 31px; height: 31px; }
    .topbar button { min-height: 36px; padding: 7px 10px; font-size: 12px; }
    .primary-nav { justify-content: start; gap: 0; }
    .primary-nav a { flex: 0 0 auto; padding-inline: 12px; }
    .layout { width: min(100% - 28px, 1280px); padding-top: 16px; gap: 14px; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stats article { min-height: 84px; padding: 15px; }
    .stats article + article::before { top: 15px; bottom: 15px; }
    .stats article:nth-child(3)::after, .stats article:nth-child(4)::after {
        position: absolute;
        top: 0;
        right: 15px;
        left: 15px;
        height: 1px;
        content: "";
        background: var(--line);
    }
    .card { padding: 17px; }
    .section-title { align-items: stretch; flex-direction: column; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .span-2 { grid-column: auto; }
    .search { width: 100%; min-width: 0; }
    .device-heading { align-items: flex-start; }
    .actions { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
