:root {
    --bg: #e9efec;
    --ink: #142029;
    --muted: #5c6b76;
    --accent: #0d6b5c;
    --accent-hover: #0a564a;
    --accent-soft: rgba(13, 107, 92, 0.11);
    --accent-ink: #ffffff;
    --danger: #a33b3b;
    --danger-soft: #f8eaea;
    --success-soft: #e7f5ef;
    --card: #ffffff;
    --line: #d5ddd8;
    --line-strong: #c3cdc7;
    --banner: #fff4d6;
    --banner-ink: #6a5208;
    --shadow: 0 12px 32px rgba(20, 32, 41, 0.07);
    --radius: 14px;
    --radius-sm: 10px;
    --font: "Figtree", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15.5px;
    line-height: 1.5;
    color: var(--ink);
    background:
        radial-gradient(900px 420px at -10% -20%, rgba(13, 107, 92, 0.16), transparent 55%),
        radial-gradient(700px 380px at 110% 0%, rgba(20, 32, 41, 0.06), transparent 50%),
        linear-gradient(180deg, #f4f7f5 0%, var(--bg) 42%, #e4ebe7 100%);
    min-height: 100vh;
}

a {
    color: var(--accent);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.15em;
}
a:hover { color: var(--accent-hover); }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    border-bottom: 1px solid rgba(213, 221, 216, 0.9);
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(14px) saturate(1.2);
    -webkit-backdrop-filter: blur(14px) saturate(1.2);
}

.topbar-inner {
    width: min(1120px, calc(100% - 2rem));
    margin: 0 auto;
    min-height: 4rem;
    display: flex;
    gap: 1rem;
    align-items: center;
}

.brand {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: -0.03em;
    text-decoration: none;
    color: var(--ink);
}
.brand:hover { color: var(--accent); }
.brand-mark {
    display: inline-block;
    width: 0.65rem;
    height: 0.65rem;
    flex: 0 0 auto;
    border-radius: 50%;
    background: #d62828;
    box-shadow: 0 0 0 1px rgba(214, 40, 40, 0.25);
}

.topbar nav {
    display: flex;
    flex: 1 1 auto;
    flex-wrap: wrap;
    gap: 0.2rem;
    align-items: center;
    justify-content: center;
}

.topbar nav a {
    display: inline-flex;
    align-items: center;
    padding: 0.42rem 0.78rem;
    border-radius: 0.65rem;
    text-decoration: none;
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.topbar nav a:hover {
    color: var(--ink);
    background: rgba(20, 32, 41, 0.05);
}
.topbar nav a.is-active {
    color: var(--accent);
    background: var(--accent-soft);
}

.topbar-user {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 0.65rem;
}
.topbar-user-name {
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 500;
    max-width: 10rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.container {
    width: min(1120px, calc(100% - 2rem));
    margin: 1.75rem auto 3.5rem;
}

.impersonation-banner {
    background: var(--banner);
    color: var(--banner-ink);
    padding: 0.7rem 1rem;
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: center;
    font-size: 0.92rem;
    font-weight: 500;
}

.flash {
    padding: 0.9rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.1rem;
    font-size: 0.95rem;
}
.flash.success {
    background: var(--success-soft);
    border: 1px solid #c5e6d6;
    color: #1d5c45;
}
.flash.error {
    background: var(--danger-soft);
    border: 1px solid #ecc0c0;
    color: var(--danger);
}
.flash ul { margin: 0; padding-left: 1.1rem; }

h1, h2, h3 {
    margin-top: 0;
    letter-spacing: -0.025em;
    line-height: 1.25;
}
h1 { font-size: 1.85rem; font-weight: 700; margin-bottom: 1rem; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }

.panel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.35rem 1.4rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}

.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
}
.stat {
    padding: 1.1rem 1.15rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: var(--shadow);
}
.stat .muted {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}
.stat strong {
    display: block;
    margin-top: 0.35rem;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

label {
    display: block;
    font-size: 0.86rem;
    font-weight: 600;
    margin: 0.75rem 0 0.3rem;
    color: var(--muted);
}

input, select, textarea, button { font: inherit; }

input, select, textarea {
    width: 100%;
    padding: 0.62rem 0.78rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--ink);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: rgba(13, 107, 92, 0.55);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    border: 0;
    border-radius: var(--radius-sm);
    padding: 0.6rem 1rem;
    background: var(--accent);
    color: var(--accent-ink);
    cursor: pointer;
    text-decoration: none;
    font-weight: 600;
    letter-spacing: -0.01em;
    transition: background-color 0.15s ease, transform 0.15s ease;
}
button:hover, .button:hover {
    background: var(--accent-hover);
    color: var(--accent-ink);
}
button:active, .button:active { transform: translateY(1px); }
button.secondary, .button.secondary { background: #3f4f5f; }
button.secondary:hover, .button.secondary:hover { background: #334352; }
button.danger { background: var(--danger); }
button.danger:hover { background: #8d3131; }

button.linkish, .linkish {
    background: transparent;
    color: var(--muted);
    padding: 0.35rem 0.55rem;
    border-radius: 0.55rem;
    font-weight: 600;
    font-size: 0.88rem;
}
button.linkish:hover, .linkish:hover {
    background: rgba(20, 32, 41, 0.05);
    color: var(--ink);
}

.table-wrap { max-width: 100%; overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}
th, td {
    text-align: left;
    padding: 0.78rem 0.55rem;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
    overflow-wrap: anywhere;
    word-break: break-word;
}
th {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(13, 107, 92, 0.03); }

.audio-table {
    table-layout: fixed;
    width: 100%;
}
.audio-table .audio-col-when { width: 9.5rem; }
.audio-table .audio-col-site { width: 14%; }
.audio-table .audio-col-pa { width: 16%; }
.audio-table .audio-col-play { width: auto; min-width: 16rem; }
.audio-table .audio-col-actions { width: 14rem; }
.audio-table .audio-col-play {
    overflow: visible;
}
.audio-player {
    display: block;
    width: 100%;
    max-width: 100%;
    height: 2.25rem;
}
.audio-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}
.audio-actions form {
    margin: 0;
}
.audio-transcript-row td {
    padding-top: 0;
    border-bottom-color: var(--line);
}
.audio-transcript {
    margin: 0 0 0.85rem;
    padding: 0.65rem 0.75rem;
    background: rgba(13, 107, 92, 0.06);
    border-radius: 0.4rem;
}
.audio-transcript strong {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}
.audio-transcript p {
    margin: 0;
    white-space: pre-wrap;
}
.audio-transcript-meta {
    margin: 0 0 0.75rem;
    font-size: 0.86rem;
}
.audio-translations {
    margin-top: 0.85rem;
}
.audio-translations > strong {
    display: block;
    margin-bottom: 0.45rem;
}
.audio-translation {
    margin: 0 0 0.55rem;
}
.audio-translation-lang {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #4a5b66;
    margin-bottom: 0.15rem;
}
.audio-translation p {
    margin: 0;
}
.busy-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.busy-btn .btn-spinner {
    display: none;
    width: 0.85rem;
    height: 0.85rem;
    border: 2px solid rgba(20, 32, 41, 0.2);
    border-top-color: rgba(20, 32, 41, 0.85);
    border-radius: 50%;
    flex: 0 0 auto;
}
.busy-btn.is-busy .btn-spinner {
    display: inline-block;
    animation: spin 0.7s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

code {
    font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
    font-size: 0.88em;
    background: rgba(20, 32, 41, 0.05);
    padding: 0.12rem 0.35rem;
    border-radius: 0.35rem;
}

.muted { color: var(--muted); }

.map-wrap {
    height: 360px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--line);
}

.map-pin {
    background: transparent !important;
    border: 0 !important;
}
.map-pin-dot {
    display: block;
    width: 14px;
    height: 14px;
    margin: 2px auto 0;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(28, 36, 48, 0.35);
}

.inline { display: inline; }
.stack-form > * + * { margin-top: 0.35rem; }

.panel-heading {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.85rem;
}
.panel-heading h2 { margin: 0; flex: 1; }

.icon-add {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.7rem;
    height: 1.7rem;
    padding: 0;
    border-radius: 0.55rem;
    background: transparent;
    color: var(--muted);
    border: 1px solid transparent;
    font-size: 1.15rem;
    line-height: 1;
    font-weight: 500;
}
.icon-add:hover,
.icon-add[aria-expanded="true"] {
    color: var(--accent);
    border-color: var(--line);
    background: var(--accent-soft);
}

.add-form {
    margin-top: 1rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--line);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    align-items: center;
    margin-top: 1rem;
}

.pagination {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-top: 1rem;
    font-size: 0.92rem;
}
.pagination .disabled { color: var(--muted); }

.container--wide {
    width: min(1680px, calc(100% - 1.25rem));
}

.devices-panel .devices-table,
.devices-table {
    font-size: 0.76rem;
    width: 100%;
}
.devices-table th,
.devices-table td {
    padding: 0.4rem 0.45rem;
    vertical-align: top;
    white-space: nowrap;
}
.devices-table td.muted,
.devices-table .tiny {
    white-space: normal;
    max-width: 14rem;
}
.devices-table .tiny {
    font-size: 0.9em;
    opacity: 0.85;
    margin-top: 0.15rem;
}
.devices-actions {
    display: flex;
    gap: 0.35rem;
    align-items: center;
    flex-wrap: wrap;
}
.devices-actions form { margin: 0; }
button.small,
a.button.small {
    font-size: 0.75rem;
    padding: 0.28rem 0.55rem;
}
.column-toggle {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    cursor: pointer;
    user-select: none;
    padding: 0.35rem 0;
    font-size: 0.92rem;
}
.icon-button {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.modal {
    border: 0;
    padding: 0;
    background: transparent;
    max-width: min(420px, calc(100vw - 2rem));
}
.modal::backdrop {
    background: rgba(20, 28, 36, 0.45);
}
.modal-card {
    background: var(--card);
    border-radius: var(--radius-sm);
    box-shadow: 0 18px 50px rgba(20, 28, 36, 0.22);
    padding: 1.1rem 1.2rem 1rem;
    border: 1px solid rgba(20, 28, 36, 0.08);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.35rem;
}
.modal-checklist {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.15rem 1rem;
    max-height: min(60vh, 28rem);
    overflow: auto;
    margin: 0.5rem 0 0.85rem;
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
}
.device-page-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 0.75rem 1rem;
    margin-bottom: 1rem;
}
.device-page-header__back {
    margin: 0;
    justify-self: start;
}
.device-page-header__serial {
    margin: 0;
    text-align: center;
    font-family: "Courier New", Courier, monospace;
    font-size: clamp(1.15rem, 2.4vw, 1.65rem);
    letter-spacing: 0.04em;
    justify-self: center;
}
.device-page-header__actions {
    margin: 0;
    justify-self: end;
}
@media (max-width: 720px) {
    .device-page-header {
        grid-template-columns: 1fr;
        justify-items: stretch;
    }
    .device-page-header__serial {
        order: -1;
        font-size: 1.2rem;
        word-break: break-all;
    }
    .device-page-header__actions {
        justify-self: stretch;
    }
    .device-page-header__actions .danger {
        width: 100%;
    }
}
.device-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.85rem;
}
.device-stat h2 { margin-top: 0; }
.device-stat-value {
    font-size: 1.65rem;
    font-weight: 700;
    margin: 0.35rem 0;
}
.status-indicators {
    list-style: none;
    margin: 0.65rem 0 0;
    padding: 0;
    display: grid;
    gap: 0.55rem;
    font-size: 0.88rem;
}
.status-indicators li {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}
.status-dot {
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 50%;
    flex: 0 0 auto;
    background: #c9d2d8;
}
.status-dot.is-on {
    background: #1f9d6a;
}
.status-dot.is-off {
    background: #c9d2d8;
}
.device-status-badge {
    display: inline-block;
    margin: 0.45rem 0 0.35rem;
    padding: 0.4rem 0.7rem;
    font-family: "Courier New", Courier, monospace;
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #142029;
    background: #f4f7f5;
    border: 2px solid #142029;
    border-radius: 0.2rem;
    box-shadow: 3px 3px 0 rgba(20, 32, 41, 0.18);
}
.device-status-badge[data-status="unclaimed"],
.device-status-badge[data-status="waiting_adopt"] {
    color: #5a4a12;
    background: #fbf6e6;
    border-color: #5a4a12;
    box-shadow: 3px 3px 0 rgba(90, 74, 18, 0.18);
}
.device-status-badge[data-status="revoked"] {
    color: #7a2424;
    background: #f8ecec;
    border-color: #7a2424;
    box-shadow: 3px 3px 0 rgba(122, 36, 36, 0.18);
}
.storage-bar {
    height: 0.45rem;
    background: #e8ecef;
    border-radius: 999px;
    overflow: hidden;
    margin-top: 0.65rem;
}
.storage-bar > span {
    display: block;
    height: 100%;
    background: var(--ink);
}
.device-identity-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.85rem 1.25rem;
    font-size: 0.88rem;
}
.device-identity-wide {
    grid-column: 1 / -1;
}
.break-all {
    overflow-wrap: anywhere;
    word-break: break-all;
    white-space: normal;
}
.inline-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}
.bulk-delete-actions {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    align-items: flex-end;
}
.clip-section-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    background: transparent;
    color: inherit;
    padding: 0;
    font: inherit;
    font-weight: inherit;
    letter-spacing: inherit;
    box-shadow: none;
    border-radius: 0;
    text-align: left;
}
.clip-section-toggle:hover,
.clip-section-toggle:active {
    background: transparent;
    transform: none;
}
.clip-chevron {
    display: inline-block;
    width: 1rem;
    transition: transform 0.15s ease;
}
.clip-section.is-collapsed .clip-chevron {
    transform: rotate(-90deg);
}
.clip-section-body {
    margin-top: 0.85rem;
}
.device-settings-form {
    margin-top: 0.35rem;
    max-width: 36rem;
}
.device-settings-group {
    margin: 1rem 0 0.35rem;
    font-size: 0.95rem;
}
.device-setting {
    margin: 0.65rem 0;
}
.device-setting label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.25rem;
}
.device-setting .checkbox-label {
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.45rem;
}
.device-setting input[type="number"] {
    width: 100%;
    max-width: 12rem;
}
.device-setting .muted {
    margin: 0.25rem 0 0;
    font-size: 0.82rem;
}
.clip-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem 1rem;
    align-items: end;
    margin: 0.75rem 0;
    font-size: 0.86rem;
}
.clip-filters label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    color: var(--muted);
}
.clip-filters input[type="date"],
.clip-filters input[type="search"] {
    min-width: 10rem;
}
.clip-pager {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-top: 0.75rem;
}

@media (max-width: 860px) {
    .topbar-inner {
        flex-wrap: wrap;
        padding: 0.75rem 0;
        min-height: 0;
    }
    .topbar nav {
        order: 3;
        width: 100%;
        justify-content: flex-start;
    }
    .topbar-user { margin-left: auto; }
    .topbar-user-name { display: none; }
}

/* Public mobile listener styles live in public/css/mobile.css */

.users-table {
    table-layout: fixed;
    width: 100%;
    font-size: 0.92rem;
}
.users-table .users-col-name { width: 12%; }
.users-table .users-col-email { width: 16%; }
.users-table .users-col-company { width: 12%; }
.users-table .users-col-role { width: 8%; }
.users-table .users-col-tz { width: 12%; }
.users-table .users-col-status { width: 8%; }
.users-table .users-col-progress { width: 16%; }
.users-table .users-col-sites { width: 5%; }
.users-table .users-col-actions { width: 11%; }
.users-table tr.is-pending td {
    background: rgba(196, 140, 32, 0.06);
}
.users-table .user-edit-row td {
    background: #f7faf8;
    padding: 1rem 0.75rem 1.15rem;
}
.users-table .user-edit-form {
    margin: 0;
}
.users-table .users-col-actions {
    white-space: nowrap;
}
.users-table .users-col-actions .inline {
    display: inline;
    margin-left: 0.55rem;
}
.user-status-badge {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 0.3rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border: 1px solid var(--line);
    background: #eef3f1;
    color: var(--ink);
}
.user-status-badge[data-status="pending"] {
    background: #fff4d6;
    border-color: #e6c76a;
    color: #7a5400;
}
.user-status-badge[data-status="disabled"] {
    background: #f4e8e8;
    border-color: #d9b0b0;
    color: #8a3030;
}
.user-status-badge[data-status="active"] {
    background: #e5f4ec;
    border-color: #9dceb4;
    color: #1f6b4a;
}
.users-resend-form {
    margin-top: 0.45rem;
}
.users-table .tiny-button {
    font-size: 0.78rem;
    padding: 0.3rem 0.55rem;
}

