:root {
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    --radius: 10px;
    --radius-sm: 8px;
}

/* Default theme: dark */
:root,
[data-theme="dark"] {
    color-scheme: dark;
    --bg: #101816;
    --surface: #1a2421;
    --ink: #e6efe9;
    --muted: #9eb0a6;
    --accent: #3ecf8e;
    --accent-hover: #2fb97a;
    --accent-soft: rgba(62, 207, 142, 0.16);
    --border: #2e3f37;
    --danger: #f97066;
    --on-accent: #062a18;
    --topbar-bg: rgba(20, 28, 25, 0.92);
    --body-gradient: linear-gradient(165deg, #0c1210 0%, var(--bg) 38%, #141c19 100%);
    --input-bg: #121a17;
    --code-bg: #243029;
    --table-row-hover: rgba(62, 207, 142, 0.06);
    --media-well: #0d1210;
    --badge-off-bg: #243029;
    --scrim: rgba(0, 0, 0, 0.55);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] {
    color-scheme: light;
    --bg: #eef3ef;
    --surface: #ffffff;
    --ink: #0f1a14;
    --muted: #5a6b62;
    --accent: #1a6b4a;
    --accent-hover: #145a3d;
    --accent-soft: #dceee4;
    --border: #c8d8ce;
    --danger: #b42318;
    --on-accent: #ffffff;
    --topbar-bg: rgba(255, 255, 255, 0.92);
    --body-gradient: linear-gradient(165deg, #e4efe8 0%, var(--bg) 38%, #f6f8f6 100%);
    --input-bg: #ffffff;
    --code-bg: #eef2ef;
    --table-row-hover: #f8fbf9;
    --media-well: #f4f7f5;
    --badge-off-bg: #eef0ee;
    --scrim: rgba(15, 26, 20, 0.45);
    --shadow: 0 1px 2px rgba(15, 26, 20, 0.06), 0 8px 24px rgba(15, 26, 20, 0.05);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--body-gradient);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
}

h1 {
    margin: 0 0 0.35rem;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

h2 {
    margin: 0 0 0.5rem;
    font-size: 1rem;
    font-weight: 700;
}

.app-shell {
    min-height: 100vh;
    min-height: 100dvh;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 0.75rem 1rem;
    padding: 0.55rem 1rem;
    background: var(--topbar-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
}

.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    line-height: 1;
    flex-shrink: 0;
}

.brand-mark {
    width: 28px;
    height: 28px;
    display: block;
    flex: 0 0 auto;
}

.brand-name {
    color: var(--ink);
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    white-space: nowrap;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin-bottom: 0.65rem;
}

.auth-mark {
    width: 40px;
    height: 40px;
    display: block;
    flex: 0 0 auto;
}

.nav {
    display: flex;
    align-items: center;
    gap: 0.15rem 0.35rem;
    flex: 1;
    flex-wrap: wrap;
    min-width: 0;
}

.nav-links {
    display: contents;
}

.nav a,
.nav-admin summary {
    text-decoration: none;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.8125rem;
    padding: 0.35rem 0.55rem;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.nav a:hover,
.nav-admin summary:hover {
    color: var(--accent);
    background: var(--accent-soft);
}

.nav-admin {
    position: relative;
}

.nav-admin summary {
    list-style: none;
    cursor: pointer;
    color: var(--muted);
}

.nav-admin summary::-webkit-details-marker {
    display: none;
}

.nav-admin[open] summary {
    color: var(--accent);
    background: var(--accent-soft);
}

.nav-admin-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 10rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.35rem;
    display: grid;
    gap: 0.15rem;
    z-index: 30;
}

.nav-admin-menu a {
    display: block;
    padding: 0.4rem 0.55rem;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
}

.nav-admin-menu a:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

.account {
    display: flex;
    align-items: center;
    gap: 0.5rem 0.65rem;
    font-size: 0.8125rem;
    margin-left: auto;
}

.account a {
    font-weight: 600;
    text-decoration: none;
}

.content {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 1rem 1.25rem 2rem;
    box-sizing: border-box;
}

.page-head {
    margin-bottom: 1rem;
}

.hero {
    display: grid;
    grid-template-columns: 1.35fr 1fr;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.hero-card,
.panel,
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.hero-card {
    padding: 0.85rem 1rem;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem 0.85rem;
}

.stat-label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-weight: 600;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-size: 0.68rem;
    color: var(--accent);
    font-weight: 700;
    margin: 0 0 0.25rem;
}

.lede {
    color: var(--muted);
    max-width: min(52ch, 100%);
    line-height: 1.45;
    margin: 0;
    font-size: 0.875rem;
}

.panel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem;
}

.panel {
    padding: 0.85rem 1rem;
}

.panel p {
    margin: 0 0 0.5rem;
    font-size: 0.8125rem;
    color: var(--muted);
    line-height: 1.45;
}

.panel + .panel {
    margin-top: 0.75rem;
}

.filter-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11.5rem, 1fr));
    gap: 0.65rem 1rem;
    align-items: end;
}

.filter-panel .field {
    margin-bottom: 0;
}

.filter-panel-actions {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    align-items: center;
    margin-top: 0.15rem;
}

img.review-capture {
    display: block;
    max-width: min(100%, 320px);
    max-height: 320px;
    margin: 0.5rem 0 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    object-fit: contain;
    background: var(--media-well);
    image-orientation: from-image;
}

.review-capture-fullsize {
    display: inline-block;
    margin: -0.25rem 0 0.75rem;
    font-weight: 600;
}

.text-link {
    font-weight: 600;
    font-size: 0.875rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    font-size: 0.8125rem;
}

.table-scroll {
    overflow-x: auto;
}

.devices-table {
    min-width: 900px;
}

.device-credential,
.device-actions {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.device-credential {
    flex-direction: column;
}

.device-key-value {
    max-width: 20rem;
    overflow-wrap: anywhere;
}

.data-table th,
.data-table td {
    padding: 0.45rem 0.65rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background: var(--table-row-hover);
}

.data-table th {
    background: var(--accent-soft);
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 700;
    color: var(--muted);
}

.muted {
    color: var(--muted);
    font-size: 0.8125rem;
}

.company-switch {
    display: flex;
    flex-direction: column;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    color: var(--muted);
}

.company-switch select {
    margin-top: 0.15rem;
    padding: 0.25rem 0.4rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-size: 0.8125rem;
    min-width: 8rem;
}

.badge {
    display: inline-block;
    padding: 0.12rem 0.45rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
}

.badge-on {
    background: var(--accent-soft);
    color: var(--accent);
}

.badge-off {
    background: var(--badge-off-bg);
    color: var(--muted);
}

.auth-card {
    max-width: 380px;
    margin: 2rem auto;
    padding: 1.25rem 1.15rem;
}

.field {
    display: grid;
    gap: 0.25rem;
    margin-bottom: 0.65rem;
}

.field label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
}

.field input,
.field select,
.field textarea {
    width: 100%;
    max-width: 100%;
    padding: 0.45rem 0.6rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font: inherit;
    background: var(--input-bg);
    color: var(--ink);
}

.field input:focus,
.field select:focus {
    outline: 2px solid var(--accent-soft);
    border-color: var(--accent);
}

button,
.primary,
a.primary {
    display: inline-block;
    background: var(--accent);
    color: var(--on-accent);
    border: none;
    border-radius: 999px;
    padding: 0.45rem 0.95rem;
    font-weight: 700;
    font-size: 0.8125rem;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.35;
}

button:hover,
.primary:hover,
a.primary:hover {
    background: var(--accent-hover);
}

button.secondary {
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--border);
}

button.secondary:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

.data-table button {
    padding: 0.25rem 0.55rem;
    font-size: 0.75rem;
}

.worker-thumb img {
    display: block;
    margin-top: 0.35rem;
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border-subtle, var(--border));
}

.worker-profile-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
    gap: 1rem;
    margin-bottom: 1rem;
}

.worker-profile-photo-panel {
    min-width: 0;
}

.worker-photo-hero {
    display: block;
    width: 100%;
    max-width: 420px;
    max-height: 420px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--media-well);
    image-orientation: from-image;
}

.worker-photo-missing,
.worker-photo-grid li.worker-photo-missing img {
    display: none;
}

.worker-photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
    gap: 0.65rem;
    list-style: none;
    margin: 0.75rem 0 0;
    padding: 0;
}

.worker-photo-grid img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    display: block;
    image-orientation: from-image;
}

.worker-photo-meta {
    display: block;
    font-size: 0.72rem;
    margin-top: 0.2rem;
}

.worker-detail-list {
    display: grid;
    gap: 0.55rem 1rem;
    margin: 0;
}

.worker-detail-list > div {
    display: grid;
    grid-template-columns: 9rem minmax(0, 1fr);
    gap: 0.5rem;
    align-items: baseline;
}

.worker-detail-list dt {
    margin: 0;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
}

.worker-detail-list dd {
    margin: 0;
}

.error {
    color: var(--danger);
    font-size: 0.8125rem;
}

code {
    font-size: 0.78rem;
    background: var(--code-bg);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
}

@media (max-width: 899px) {
    .topbar {
        position: sticky;
        top: 0;
        z-index: 20;
    }

    .worker-profile-layout {
        grid-template-columns: 1fr;
    }

    .worker-detail-list > div {
        grid-template-columns: 1fr;
    }

    .hero {
        grid-template-columns: 1fr;
    }

    .content {
        padding: 0.85rem 0.75rem 1.5rem;
        padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
    }

    .company-switch select {
        max-width: min(168px, 42vw);
    }

    .data-table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}
