:root {
    --ink: #14213d;
    --muted: #5c6b7a;
    --line: #d7dee7;
    --bg: #f3f5f8;
    --panel: #ffffff;
    --accent: #1f6f5b;
    --accent-ink: #0f3d32;
    --danger: #9b1c1c;
    --warning: #8a5a00;
    --success: #146c43;
    --sidebar: #102033;
    --sidebar-text: #d9e2ec;
    --admin-sidebar-width: 248px;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: "Segoe UI", "Helvetica Neue", sans-serif;
    color: var(--ink);
    background: var(--bg);
}
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }

.admin-shell { display: flex; min-height: 100vh; }
.admin-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--admin-sidebar-width);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 30;
    background: var(--sidebar);
    color: var(--sidebar-text);
    padding: 1.25rem 1rem;
    flex-shrink: 0;
}
.sidebar-brand { display: flex; gap: .75rem; align-items: center; margin-bottom: 1.75rem; flex-shrink: 0; }
.sidebar-brand strong, .sidebar-brand small { display: block; }
.sidebar-brand small { opacity: .7; font-size: .75rem; }
.sidebar-mark, .guest-mark, .profile-avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 2.25rem; height: 2.25rem; border-radius: .5rem;
    background: #1f6f5b; color: #fff; font-weight: 700; font-size: .8rem;
}
.sidebar-nav {
    display: grid;
    gap: .25rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}
.sidebar-nav a {
    padding: .65rem .75rem; border-radius: .45rem; color: var(--sidebar-text); opacity: .9;
}
.sidebar-nav a.is-active, .sidebar-nav a:hover:not(.is-disabled) { background: rgba(255,255,255,.08); }
.sidebar-nav a.is-disabled { opacity: .35; cursor: not-allowed; }
.sidebar-group { margin: 0; }
.sidebar-group-items {
    display: grid;
    gap: .2rem;
    padding-left: .55rem;
    border-left: 1px solid rgba(255,255,255,.08);
    margin-left: .55rem;
}
.sidebar-section {
    display: block;
    margin-top: 1rem; margin-bottom: .4rem; padding: 0 .75rem;
    font-size: .72rem; letter-spacing: .04em; opacity: .55;
}

.admin-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin-left: var(--admin-sidebar-width);
}
.admin-topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 1.5rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.admin-topbar h1 { margin: 0; font-size: 1.15rem; }
.admin-content { padding: 1.5rem; }

.profile-menu { position: relative; }
.profile-trigger {
    display: flex; align-items: center; gap: .65rem; border: 1px solid var(--line);
    background: #fff; border-radius: .6rem; padding: .35rem .7rem .35rem .35rem; cursor: pointer;
}
.profile-meta { display: grid; text-align: left; }
.profile-meta strong { font-size: .85rem; }
.profile-meta small { color: var(--muted); font-size: .72rem; }
.profile-dropdown {
    display: none; position: absolute; right: 0; top: calc(100% + .4rem); width: 220px;
    background: #fff; border: 1px solid var(--line); border-radius: .6rem; box-shadow: 0 10px 30px rgba(16,32,51,.08);
    overflow: hidden; z-index: 50;
}
.profile-dropdown.is-open { display: block; }
.profile-dropdown-head { padding: .85rem 1rem; border-bottom: 1px solid var(--line); }
.profile-dropdown-head strong, .profile-dropdown-head small { display: block; }
.profile-dropdown-head small { color: var(--muted); margin-top: .15rem; }
.profile-logout {
    width: 100%; border: 0; background: transparent; text-align: left;
    padding: .85rem 1rem; cursor: pointer; color: var(--danger);
}
.profile-logout:hover { background: #fff5f5; }

.flash {
    border-radius: .55rem; padding: .85rem 1rem; margin-bottom: 1rem; border: 1px solid;
}
.flash ul { margin: .4rem 0 0; padding-left: 1.1rem; }
.flash-success { background: #e8f8ef; border-color: #b7e4c7; color: var(--success); }
.flash-error { background: #fdecec; border-color: #f2c0c0; color: var(--danger); }
.flash-warning { background: #fff7e6; border-color: #f0d59a; color: var(--warning); }

.dashboard-group-title {
    margin: 1.5rem 0 .75rem;
    font-size: 1rem;
    color: var(--muted);
    font-weight: 600;
}
.dashboard-group-title:first-of-type {
    margin-top: 1rem;
}
 margin-bottom: 1.5rem; }
.dashboard-kicker {
    margin: 0 0 .35rem;
    color: var(--accent);
    font-size: .85rem;
    font-weight: 600;
}
.dashboard-heading {
    margin: 0 0 .35rem;
    font-size: 1.45rem;
    line-height: 1.3;
}
.dashboard-lead { color: var(--muted); margin: 0 0 1.25rem; }
.stat-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem;
}
.stat-card {
    background: var(--panel); border: 1px solid var(--line); border-radius: .75rem; padding: 1.25rem 1.35rem;
}
.stat-card span { display: block; color: var(--muted); font-size: .85rem; margin-bottom: .55rem; }
.stat-card strong { font-size: 2rem; font-variant-numeric: tabular-nums; }

.admin-guest-body {
    min-height: 100vh; display: grid; place-items: center;
    background:
        radial-gradient(circle at top left, rgba(31,111,91,.12), transparent 40%),
        linear-gradient(160deg, #eef2f6, #f7f8fa 50%, #e9eef3);
}
.guest-shell { width: min(420px, calc(100% - 2rem)); }
.guest-card {
    background: #fff; border: 1px solid var(--line); border-radius: 1rem; padding: 1.75rem;
    box-shadow: 0 18px 50px rgba(16,32,51,.08);
}
.guest-brand { margin-bottom: 1.25rem; }
.guest-brand h1 { margin: .75rem 0 .25rem; font-size: 1.35rem; }
.guest-brand p { margin: 0; color: var(--muted); }
.login-form { display: grid; gap: .9rem; }
.login-form label { display: grid; gap: .35rem; font-size: .9rem; }
.login-form input[type="email"],
.login-form input[type="password"] {
    border: 1px solid var(--line); border-radius: .5rem; padding: .7rem .8rem; background: #fff;
}
.remember-row { display: flex !important; align-items: center; gap: .5rem; }
.btn-primary,
a.btn-primary {
    display: inline-flex; justify-content: center; align-items: center;
    border: 0; border-radius: .5rem; padding: .75rem 1rem; background: var(--accent);
    color: #fff; font-weight: 600; cursor: pointer;
}
.btn-primary:hover,
a.btn-primary:hover { background: var(--accent-ink); color: #fff; }
a.btn-secondary,
a.btn-danger { color: inherit; }
.error-panel { text-align: center; }
.error-code { font-size: 2.5rem; font-weight: 700; margin: 0; color: var(--accent); }
.error-panel h2 { margin: .35rem 0; }
.error-panel p { color: var(--muted); }
.error-panel .btn-primary { margin-top: 1rem; }

@media (max-width: 860px) {
    .admin-shell { flex-direction: column; }
    .admin-sidebar {
        position: static;
        inset: auto;
        width: 100%;
        height: auto;
        overflow: visible;
        z-index: auto;
    }
    .sidebar-nav {
        overflow: visible;
        flex: none;
    }
    .admin-main { margin-left: 0; }
    .profile-meta { display: none; }
}

.filters-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: space-between;
    align-items: end;
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: .75rem;
}
.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: .75rem;
    flex: 1;
}
.filters-grid label,
.form-grid label,
.form-grid .field-label-group {
    display: grid;
    gap: .35rem;
    font-size: .9rem;
}
.filters-grid input,
.filters-grid select,
.form-grid input,
.form-grid select,
.form-grid textarea {
    border: 1px solid var(--line);
    border-radius: .5rem;
    padding: .65rem .75rem;
    background: #fff;
    width: 100%;
}
.filters-actions,
.form-actions,
.preview-actions,
.media-picker-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
}
.checkbox-inline {
    display: flex !important;
    align-items: center;
    gap: .5rem;
    padding-top: 1.5rem;
}
.inline-form { display: inline; }

.btn-secondary,
.btn-danger {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    border-radius: .5rem;
    padding: .55rem .85rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--line);
    background: #fff;
}
.btn-secondary:hover { background: #f7f9fb; }
.btn-danger {
    border-color: #efc2c2;
    background: #fff5f5;
    color: var(--danger);
}
.btn-danger:hover { background: #fdecec; }

.table-wrap {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: .75rem;
    overflow: auto;
}
.admin-table {
    width: 100%;
    border-collapse: collapse;
}
.admin-table th,
.admin-table td {
    padding: .85rem 1rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}
.admin-table th {
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    background: #fafbfc;
}
.table-meta {
    display: block;
    color: var(--muted);
    font-size: .78rem;
    margin-top: .2rem;
}
.table-empty {
    text-align: center;
    color: var(--muted);
    padding: 2rem 1rem !important;
}
.col-actions { white-space: nowrap; width: 1%; }

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: .2rem .55rem;
    font-size: .72rem;
    font-weight: 600;
    margin-right: .25rem;
    margin-bottom: .25rem;
}
.badge-muted { background: #eef2f6; color: var(--muted); }
.badge-featured { background: #fff7e6; color: var(--warning); }
.badge-status-draft { background: #eef2f6; color: var(--muted); }
.badge-status-in_review { background: #eef4ff; color: #1d4ed8; }
.badge-status-scheduled { background: #f3e8ff; color: #6b21a8; }
.badge-status-published { background: #e8f8ef; color: var(--success); }
.badge-status-archived { background: #fdecec; color: var(--danger); }
.badge-status-suspended { background: #fff1e8; color: #c2410c; }
.badge-bar { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.75rem; }
.badge-bar-active { background: #e8f8ef; color: var(--success); }
.badge-bar-inactive { background: #eef2f6; color: var(--muted); }
.badge-bar-suspended { background: #fff1e8; color: #c2410c; }
.badge-bar-retired { background: #f3e8ff; color: #6b21a8; }
.badge-bar-unknown { background: #fff7e6; color: var(--warning); }
.detail-section { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.detail-section h3 { margin: 0 0 0.75rem; font-size: 1rem; }

.pagination-wrap {
    margin-top: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: .75rem 1rem;
    align-items: center;
    justify-content: space-between;
}
.pagination-meta {
    margin: 0;
    color: var(--muted);
    font-size: .85rem;
}
.pagination-wrap nav { display: flex; gap: .35rem; flex-wrap: wrap; }
.pagination-wrap a,
.pagination-wrap span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    padding: .45rem .65rem;
    border: 1px solid var(--line);
    border-radius: .45rem;
    background: #fff;
}
.pagination-wrap span[aria-current="page"] {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.form-section {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: .75rem;
    padding: 1.1rem 1.2rem;
    margin-bottom: 1rem;
}
.form-section h2 {
    margin: 0 0 1rem;
    font-size: 1rem;
}
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .9rem;
}
.form-grid .span-2 { grid-column: span 2; }
.field-label,
.required-mark { font-weight: 600; }
.required-mark { color: var(--danger); margin-left: .15rem; }

.media-picker {
    border: 1px dashed var(--line);
    border-radius: .65rem;
    padding: .85rem;
    background: #fafbfc;
}
.media-picker-preview {
    min-height: 120px;
    display: grid;
    place-items: center;
    margin: .65rem 0;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: .5rem;
    overflow: hidden;
}
.media-picker-preview img {
    max-width: 100%;
    max-height: 180px;
    display: block;
}
.media-picker-empty { color: var(--muted); font-size: .85rem; }

.preview-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: .75rem;
    padding: 1.25rem;
}
.preview-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: start;
    margin-bottom: 1rem;
}
.preview-header h2 { margin: 0 0 .25rem; }
.preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: .85rem 1rem;
    margin: 0 0 1rem;
}
.preview-grid dt {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    margin-bottom: .2rem;
}
.preview-grid dd { margin: 0; }
.preview-grid .span-2 { grid-column: span 2; }
.preview-media img {
    max-width: 320px;
    border-radius: .5rem;
    border: 1px solid var(--line);
}
.badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin-top: .55rem;
}
.notice-box {
    margin: 0 0 1rem;
    padding: .85rem 1rem;
    border-radius: .55rem;
    background: #eef4ff;
    border: 1px solid #c9d8f5;
    color: #1d4ed8;
    font-size: .9rem;
    line-height: 1.5;
}
.notice-box-warning {
    background: #fff7e6;
    border-color: #f0d59a;
    color: var(--warning);
}
.pre-wrap { white-space: pre-wrap; word-break: break-word; }
.plain-list {
    margin: 0;
    padding-left: 1.1rem;
}
.activity-timeline {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: .85rem;
}
.activity-item {
    border: 1px solid var(--line);
    border-radius: .55rem;
    padding: .85rem 1rem;
    background: #fafbfc;
}
.activity-head {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    align-items: baseline;
    margin-bottom: .35rem;
}
.activity-payload {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: .5rem .75rem;
    margin: .6rem 0 0;
}
.activity-payload dt {
    font-size: .72rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.activity-payload dd { margin: 0; }

.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.media-grid-item {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: .65rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.media-grid-thumb {
    aspect-ratio: 4 / 3;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.media-grid-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.media-grid-body {
    padding: .65rem .75rem;
    display: flex;
    flex-direction: column;
    gap: .35rem;
    flex: 1;
}
.media-grid-title {
    font-size: .85rem;
    font-weight: 600;
    margin: 0;
    word-break: break-word;
}
.media-grid-meta {
    font-size: .75rem;
    color: var(--muted);
}
.media-grid-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    margin-top: auto;
}
.media-grid-meta + .media-grid-meta {
    margin-top: -.15rem;
}
.preview-grid .mono,
.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .8rem;
    word-break: break-all;
}
.media-picker-library {
    margin-top: .75rem;
    border: 1px solid var(--line);
    border-radius: .5rem;
    padding: .75rem;
    background: var(--bg);
}
.media-picker-library-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-bottom: .75rem;
}
.media-picker-library-toolbar input[type="search"] {
    flex: 1;
    min-width: 140px;
}
.media-picker-library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: .5rem;
    max-height: 280px;
    overflow: auto;
}
.media-picker-library-item {
    border: 1px solid var(--line);
    border-radius: .4rem;
    background: var(--panel);
    padding: .35rem;
    cursor: pointer;
    text-align: left;
}
.media-picker-library-item.is-selected {
    border-color: var(--accent, #2563eb);
    box-shadow: 0 0 0 1px var(--accent, #2563eb);
}
.media-picker-library-item img {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    display: block;
    border-radius: .25rem;
}
.media-picker-library-item span {
    display: block;
    margin-top: .25rem;
    font-size: .7rem;
    color: var(--muted);
    word-break: break-word;
}
.media-picker-library-empty {
    font-size: .85rem;
    color: var(--muted);
}
.media-picker-library-more {
    margin-top: .5rem;
}
.form-help {
    font-size: .8rem;
    color: var(--muted);
    margin: .25rem 0 0;
}
.form-help.code-sample {
    display: block;
    white-space: pre-wrap;
    background: #f6f8fb;
    border: 1px solid var(--line);
    border-radius: .5rem;
    padding: .75rem .9rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .75rem;
    line-height: 1.45;
    overflow-x: auto;
}
.preview-section {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
}
.preview-section h3 {
    margin: 0 0 .75rem;
    font-size: 1rem;
}
.preview-block {
    margin: .75rem 0;
    padding: .75rem .9rem;
    border: 1px solid var(--line);
    border-radius: .55rem;
    background: #fafbfd;
}
.preview-block h4 {
    margin: 0 0 .35rem;
    font-size: .95rem;
}
.preview-block-item {
    margin-top: .5rem;
    padding-top: .5rem;
    border-top: 1px dashed var(--line);
}

@media (max-width: 860px) {
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .span-2 { grid-column: span 1; }
    .preview-header { flex-direction: column; }
}

/* Sprint 5 — Operations & Trust CMS */
.settings-group {
    border: 1px solid var(--line);
    border-radius: .75rem;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    background: var(--panel);
}
.settings-group h2 {
    margin: 0 0 1rem;
    font-size: 1rem;
    color: var(--accent-ink);
}
.lock-banner {
    background: #fff7e6;
    border: 1px solid #f0d59a;
    border-radius: .55rem;
    padding: .85rem 1rem;
    margin-bottom: 1rem;
    color: var(--warning);
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
}
.lock-banner-action { margin-left: auto; }
.consultation-section {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
}
.consultation-section h3 {
    margin: 0 0 .75rem;
    font-size: .95rem;
}
.page-subtitle {
    margin: -.35rem 0 1rem;
    color: var(--muted);
    font-size: .95rem;
    line-height: 1.5;
}
.stat-row {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    margin-bottom: 1rem;
}
.stat-chip {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: .55rem;
    padding: .65rem .9rem;
    min-width: 8rem;
}
.stat-chip .stat-label {
    display: block;
    font-size: .72rem;
    color: var(--muted);
    margin-bottom: .2rem;
}
.stat-chip strong {
    font-size: 1.05rem;
}
.badge-status-new { background: #eef4ff; color: #1d4ed8; }
.badge-status-under_review { background: #fff7e6; color: var(--warning); }
.badge-status-information_required { background: #f3e8ff; color: #6b21a8; }
.badge-status-accepted { background: #e8f8ef; color: var(--success); }
.badge-status-declined { background: #fdecec; color: var(--danger); }
.badge-status-active { background: #e7f6f2; color: var(--accent-ink); }
.badge-status-closed { background: #eef2f6; color: var(--muted); }
.masked-cell {
    font-family: ui-monospace, "Cascadia Code", monospace;
    letter-spacing: .02em;
}
.badge-warning {
    background: #fff7e6;
    color: var(--warning);
    border: 1px solid #f0d59a;
}
.workflow-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
    gap: 1rem;
    margin-top: .85rem;
}
.workflow-card {
    border: 1px solid var(--border);
    border-radius: .7rem;
    padding: .9rem 1rem;
    background: #fff;
    display: grid;
    gap: .65rem;
}
.workflow-card h4 {
    margin: 0;
    font-size: .95rem;
}
.workflow-amount-fields {
    display: grid;
    gap: .65rem;
}
.field-error {
    margin: 0;
    color: var(--danger);
    font-size: .82rem;
}
.field-warning {
    margin: .35rem 0;
    color: #c2410c;
    font-size: .9rem;
    font-weight: 600;
}
.notes-list {
    list-style: none;
    margin: .75rem 0 0;
    padding: 0;
    display: grid;
    gap: .75rem;
}
.note-item {
    border: 1px solid var(--border);
    border-radius: .65rem;
    padding: .75rem .9rem;
    background: #fcfcfd;
}
.note-head {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: .4rem;
}
.badge-priority {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
}
.badge-priority-normal { background: #eef2f6; color: var(--muted); }
.badge-priority-high { background: #fff7e6; color: var(--warning); }
.badge-priority-urgent { background: #fdecec; color: var(--danger); }
.page-notice {
    margin: .5rem 0 0;
    color: var(--muted);
    font-size: .9rem;
    max-width: 42rem;
}
.legacy-note {
    margin-top: .75rem;
    background: #f8fafc;
}
.note-form {
    margin: .75rem 0 1rem;
}
.activity-payload {
    display: grid;
    gap: .25rem;
    margin: .4rem 0 0;
    font-size: .85rem;
}
.activity-payload dt {
    color: var(--muted);
    display: inline;
}
.activity-payload dd {
    display: inline;
    margin-left: .35rem;
}
