@font-face {
    font-family: "Bai Jamjuree";
    src: url("fonts/BaiJamjuree-Regular.ttf") format("truetype");
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: "Bai Jamjuree";
    src: url("fonts/BaiJamjuree-SemiBold.ttf") format("truetype");
    font-weight: 600;
    font-display: swap;
}

@font-face {
    font-family: "Bai Jamjuree";
    src: url("fonts/BaiJamjuree-Bold.ttf") format("truetype");
    font-weight: 700 800;
    font-display: swap;
}

:root {
    --bg: #d8d8d5;
    --panel: #ffffff;
    --line: #c9c8c2;
    --text: #192b46;
    --muted: #5f6873;
    --sidebar: #173d73;
    --sidebar-soft: #244d84;
    --accent: #c9232a;
    --accent-dark: #a8171e;
    --cream: #fff0a8;
    --green: #29966f;
    --yellow: #b88218;
    --red: #c9232a;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Bai Jamjuree", ui-sans-serif, system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
}

[hidden] {
    display: none !important;
}

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

:focus-visible {
    outline: 3px solid #e0b928;
    outline-offset: 3px;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 264px;
    flex: 0 0 264px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    background: var(--sidebar);
    color: #f5f7f9;
    display: flex;
    flex-direction: column;
    padding: 22px 20px 28px;
}

.brand {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 8px 18px;
}

.brand > a {
    display: block;
    width: 100%;
}

.brand-logo {
    display: block;
    width: min(190px, 100%);
    margin-inline: auto;
}

.brand-logo img {
    display: block;
    width: 100%;
    height: auto;
}

.nav-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: 8px;
    color: #dce3ea;
    font-size: 14px;
    font-weight: 500;
}

.nav-item span {
    width: 8px;
    height: 8px;
    border-radius: 2px;
    background: #91a5c0;
}

.nav-item.active {
    background: var(--sidebar-soft);
    color: #ffffff;
    font-weight: 700;
}

.nav-item.active span {
    background: var(--cream);
}

.nav-subview {
    margin: 0 0 6px 28px;
    padding: 6px 10px 8px 18px;
    border-left: 2px solid var(--cream);
    color: #cbd5df;
    line-height: 1.3;
}

.nav-subview-name {
    font-size: 12.5px;
    font-weight: 700;
}

.nav-subview-role {
    margin-top: 2px;
    color: #93a4b4;
    font-size: 11px;
    font-weight: 600;
}

.sidebar-footer {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-identity {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
    padding: 14px 12px;
    border-radius: 10px;
    background: var(--sidebar-soft);
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex: 0 0 32px;
}

.user-meta {
    min-width: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 11.5px;
    color: #b9c4cf;
    margin-top: 2px;
}

.user-location {
    margin-top: 3px;
    color: #9eafc0;
    font-size: 10.5px;
    line-height: 1.3;
}

.logout-link {
    display: block;
    padding: 10px 12px;
    border-radius: 8px;
    color: #d2dbe4;
    font-size: 13px;
    font-weight: 600;
}

.logout-link:hover {
    background: var(--sidebar-soft);
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 26px 40px;
    border-bottom: 1px solid var(--line);
    background: #f5f4ef;
}

.topbar h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.2;
}

.topbar p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13.5px;
}

.topbar-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.topbar-actions form {
    margin: 0;
}

.content {
    padding: 32px 40px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 18px;
}

.home-welcome {
    padding: clamp(28px, 5vw, 48px);
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--panel);
}

.home-welcome-copy {
    max-width: 760px;
}

.home-eyebrow {
    color: var(--accent-dark);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .09em;
    text-transform: uppercase;
}

.home-welcome h2 {
    margin: 8px 0 10px;
    font-size: clamp(30px, 4vw, 44px);
}

.home-welcome-back {
    margin: 0;
    color: var(--muted);
    font-size: 16px;
}

.home-role-overview {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 28px;
    margin-top: 28px;
    padding-top: 28px;
    border-top: 1px solid var(--line);
}

.home-role-capability h3 {
    margin: 0 0 12px;
    font-size: 15px;
    line-height: 1.45;
}

.home-role-capability ul {
    margin: 0;
    padding-left: 20px;
    color: var(--muted);
    font-size: 13.5px;
    line-height: 1.55;
}

.home-role-capability li + li {
    margin-top: 7px;
}

.home-demo-button {
    white-space: nowrap;
}

.home-stats {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.home-stat-card {
    min-height: 142px;
    transition: border-color .16s ease, transform .16s ease, box-shadow .16s ease;
}

.home-stat-card:hover {
    border-color: #8ca0b9;
    box-shadow: 0 8px 22px rgba(25, 43, 70, .09);
    transform: translateY(-2px);
}

.card,
.table-card,
.form-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
}

.card {
    padding: 20px 22px;
}

.stat-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.stat-value {
    margin-top: 10px;
    font-size: 28px;
    font-weight: 800;
}

.stat-value-small {
    font-size: 20px;
    line-height: 1.25;
}

.stat-sub {
    margin-top: 6px;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
}

.survey-status-list {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

.survey-status-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.survey-status-symbol {
    color: var(--text);
    font-size: 22px;
    line-height: 1;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--line);
}

.table-title {
    font-size: 16px;
    font-weight: 800;
}

.table-title-group {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.scope-toggle {
    display: inline-flex;
    padding: 4px;
    border: 2px solid #aeb9c4;
    border-radius: 10px;
    background: #eef1f4;
}

.scope-toggle a {
    padding: 6px 10px;
    border-radius: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-decoration: none;
}

.scope-toggle a.active {
    background: #ffffff;
    color: var(--sidebar);
    box-shadow: 0 2px 6px rgba(21, 39, 64, 0.2);
}

.scope-help {
    flex-basis: 100%;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 24px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 700;
}

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

table {
    width: 100%;
    border-collapse: collapse;
}

.telemetry-table {
    table-layout: auto;
}

.story-table {
    min-width: 560px;
}

.scene-table {
    min-width: 760px;
}

.event-table {
    min-width: 640px;
}

.dialogue-table {
    min-width: 900px;
}

.event-log-table {
    min-width: 960px;
}

.event-log-details {
    min-width: 320px;
    max-width: 640px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

th {
    text-align: left;
    padding: 10px 24px;
    color: var(--muted);
    background: #eeede7;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.actions-column,
.actions-cell {
    text-align: right;
}

.actions-cell {
    min-width: 240px;
}

.sort-label {
    display: inline-block;
    margin-right: 8px;
}

.sort-control {
    min-width: 24px;
    height: 24px;
    padding: 0;
    border-radius: 6px;
    font-size: 12px;
    line-height: 1;
    vertical-align: middle;
}

.sort-control:hover {
    color: var(--text);
}

.sort-control [data-sort-indicator] {
    min-width: 14px;
    text-align: center;
}

td {
    padding: 12px 24px;
    border-top: 1px solid #edf0f3;
    vertical-align: middle;
    font-size: 13.5px;
}

.name-cell {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar-light {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--sidebar);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
}

.subtle {
    color: var(--muted);
    font-size: 12.5px;
    margin-top: 2px;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid #cfd7de;
    border-radius: 8px;
    background: #ffffff;
    color: #354252;
    padding: 9px 14px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.button.primary,
button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

.button.primary:hover,
button.primary:hover {
    background: var(--accent-dark);
}

.button.danger,
button.danger {
    border-color: #efc2ba;
    color: #a43d2c;
}

.button.warning,
button.warning {
    border-color: #e7d2a2;
    background: #fff8e8;
    color: #866012;
}

.button.disabled {
    opacity: 0.45;
    cursor: default;
}

button:disabled,
.button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.button-plus {
    font-size: 16px;
    line-height: 1;
}

input,
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cfd7de;
    border-radius: 8px;
    font-family: inherit;
    font-size: 13.5px;
    color: var(--text);
    background: white;
}

input[readonly],
textarea[readonly] {
    background: #eef1f4;
    border-color: #d8dee4;
    color: #6b7786;
    cursor: default;
}

input[type="checkbox"],
input[type="radio"] {
    width: auto;
    padding: 0;
}

label {
    display: block;
    margin-bottom: 6px;
    color: #435162;
    font-size: 12.5px;
    font-weight: 800;
}

.search-form {
    display: flex;
    gap: 10px;
    min-width: 300px;
}

.table-tools {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.action-row,
.progress-cell {
    display: flex;
    align-items: center;
    gap: 8px;
}

.action-row {
    justify-content: flex-end;
    flex-wrap: wrap;
}

.actions-cell .action-row {
    min-width: max-content;
}

.actions-cell .button,
.actions-cell button {
    white-space: nowrap;
}

.disabled-play-tooltip {
    display: inline-flex;
}

.disabled-play-tooltip .button {
    pointer-events: none;
}

.bulk-actions {
    display: flex;
}

.select-cell {
    width: 44px;
    text-align: center;
}

.form-panel {
    padding: 24px;
}

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

.form-grid-full {
    grid-column: 1 / -1;
}

.form-row {
    margin-bottom: 16px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 6vh 24px 32px;
    background: rgba(22, 31, 42, 0.52);
    overflow-y: auto;
}

.modal {
    width: min(720px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 22px 60px rgba(16, 24, 36, 0.28);
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.modal-header h2 {
    margin: 0;
    font-size: 18px;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--muted);
    font-size: 22px;
    font-weight: 700;
}

.modal-close:hover {
    background: #f0f3f6;
    color: var(--text);
}

.modal-action-row {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.modal-secondary-row {
    display: flex;
    justify-content: flex-start;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 18px;
}

.notice {
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 700;
}

.notice-info {
    background: #eaf6f6;
    color: #237070;
}

.notice-success {
    background: #eaf7f1;
    color: #277654;
}

.notice-error,
.notice-warning {
    background: #fff1ed;
    color: #9c442f;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}

.badge-green {
    background: #e7f5ef;
    color: #287653;
}

.badge-gray {
    background: #eef1f4;
    color: #667383;
}

.progress {
    width: 96px;
    height: 7px;
    border-radius: 999px;
    background: #e7ebef;
    overflow: hidden;
}

.completion-row {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 12px;
}

.completion-progress {
    flex: 1;
}

.completion-progress .progress {
    width: 100%;
    height: 14px;
}

.access-label {
    display: flex;
    align-items: center;
    gap: 7px;
}

.help-tooltip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--sidebar);
    color: #ffffff;
    font-size: 12px;
    font-weight: 800;
    cursor: help;
}

.floating-tooltip {
    position: fixed;
    z-index: 100;
    width: max-content;
    max-width: min(320px, calc(100vw - 24px));
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--sidebar);
    color: #ffffff;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.45;
    letter-spacing: normal;
    text-align: left;
    text-transform: none;
    pointer-events: none;
    box-shadow: 0 8px 24px rgba(16, 24, 36, 0.25);
}

.floating-tooltip[hidden] {
    display: none;
}

.access-status {
    display: inline-flex;
    margin: 10px 0 8px;
    padding: 5px 11px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 800;
}

.access-status.active {
    background: #e7f5ef;
    color: #287653;
}

.access-status.expired {
    background: #fff1ed;
    color: #9c442f;
}

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

.icon-button {
    width: 34px;
    height: 34px;
    padding: 0;
    flex: 0 0 34px;
}

.section-search {
    width: 240px;
}

.play-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 8vh 24px 32px;
    background: rgba(22, 31, 42, 0.52);
}

.play-modal-backdrop[hidden] {
    display: none;
}

.play-modal {
    width: min(380px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 22px;
    box-shadow: 0 22px 60px rgba(16, 24, 36, 0.28);
}

.qr-panel {
    display: flex;
    justify-content: center;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f9fafb;
}

.qr-panel img {
    width: 220px;
    height: 220px;
    image-rendering: pixelated;
}

.progress-fill {
    height: 100%;
    border-radius: 999px;
}

.progress-fill.good {
    background: var(--green);
}

.progress-fill.mid {
    background: var(--yellow);
}

.progress-fill.low {
    background: var(--red);
}

.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background: var(--bg);
    position: relative;
    overflow: hidden;
}

.login-card {
    width: min(440px, 100%);
    background: white;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 30px;
    box-shadow: 10px 10px 0 rgba(23, 61, 115, 0.18);
    position: relative;
    z-index: 2;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
}

.login-logo {
    width: 116px;
    flex: 0 0 116px;
}

.login-logo img {
    display: block;
    width: 100%;
    height: auto;
}

.login-card h1 {
    margin: 0;
    font-size: 22px;
}

.login-card p {
    color: var(--muted);
}

.password-field {
    display: flex;
    align-items: stretch;
}

.password-field input {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.password-toggle {
    width: 46px;
    flex: 0 0 46px;
    border-left: 0;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    padding: 0;
    color: var(--muted);
}

.inline-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 18px;
}

.link-button {
    border: none;
    padding: 0;
    background: transparent;
    color: var(--accent-dark);
    font-weight: 800;
}

.demo-login-links {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 14px;
    color: var(--muted);
    font-size: 12px;
    flex-wrap: wrap;
}

.demo-login-links form {
    margin: 0;
}

.demo-login-links .link-button {
    font-size: 12.5px;
}

.story-name-cell {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 150px;
    font-weight: 700;
}

.story-portrait {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    display: block;
    overflow: hidden;
    border: 2px solid var(--sidebar);
    border-radius: 50%;
    background: #d8d8d5;
}

.story-portrait img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 18%;
}

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.detail-actions {
    display: flex;
    gap: 10px;
}

.back-link {
    color: var(--accent-dark);
    font-weight: 800;
    font-size: 13px;
}

.mono {
    font-variant-numeric: tabular-nums;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (max-width: 700px) {
    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex-basis: auto;
        position: static;
        height: auto;
        overflow: visible;
    }

    .brand-logo {
        width: min(170px, 100%);
    }

    .topbar,
    .content {
        padding: 22px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .table-header,
    .table-tools,
    .search-form,
    .modal-action-row,
    .modal-secondary-row,
    .completion-row {
        align-items: stretch;
        flex-direction: column;
    }

    .search-form,
    .section-search {
        min-width: 0;
        width: 100%;
    }

    .topbar-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar-actions form,
    .topbar-actions .button,
    .topbar-actions button {
        width: 100%;
    }

    .login-body {
        align-items: flex-start;
        padding: 24px 18px;
    }

    .login-brand {
        align-items: flex-start;
        flex-direction: column;
    }

}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition: none !important;
        animation: none !important;
    }
}

@media (max-width: 1180px), (max-aspect-ratio: 16 / 10) {
    .table-header {
        padding: 16px 18px;
    }

    th {
        padding: 9px 14px;
        font-size: 11.5px;
    }

    td {
        padding: 10px 14px;
        font-size: 13px;
    }

    .progress {
        width: 72px;
    }

    .progress-cell {
        gap: 6px;
    }

    .sort-label {
        margin-right: 6px;
    }

    .sort-control {
        min-width: 22px;
        height: 22px;
    }

    .actions-cell {
        min-width: 220px;
    }

    .actions-cell .button,
    .actions-cell button {
        padding-inline: 10px;
        font-size: 12.5px;
    }
}

@media (max-width: 640px) {
    .table-header {
        padding: 14px 16px;
    }

    th {
        padding: 8px 12px;
        font-size: 11px;
    }

    td {
        padding: 9px 12px;
        font-size: 12.5px;
    }

    .progress {
        width: 64px;
    }
}
