:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --surface: #f8fafc;
    --surface-strong: #eef2f7;
    --btn-bg: #edf2f7;
    --btn-bg-hover: #e5eaf2;
    --btn-text: #243044;
    --green-line: #bbf7d0;
    --red-line: #fecaca;
    --on-primary: #ffffff;
    --text: #172033;
    --muted: #667085;
    --line: #dfe6f0;
    --line-strong: #c9d4e4;
    --primary: #2557d6;
    --primary-dark: #1d46ad;
    --primary-soft: #eaf0fe;
    --green-bg: #dcfce7;
    --green-text: #166534;
    --red-bg: #fee2e2;
    --red-text: #991b1b;
    --red-solid: #dc2626;
    --red-solid-dark: #b91c1c;
    --amber-bg: #fef3c7;
    --amber-text: #92400e;
    --blue-bg: #dbeafe;
    --blue-text: #1e40af;
    --gray-bg: #e9edf3;
    --gray-text: #374151;

    --sidebar-bg: #111827;
    --sidebar-text: #d9e3f0;
    --sidebar-muted: #8fa3bd;
    --sidebar-hover: #243044;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
        "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 24px;
    --sp-6: 32px;

    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 14px;
    --r-pill: 999px;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-md: 0 4px 14px rgba(20, 30, 50, 0.07);
    --shadow-lg: 0 16px 40px rgba(20, 30, 50, 0.14);
    --ring: 0 0 0 3px rgba(37, 87, 214, 0.28);
}

* { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    overflow-x: hidden;
}

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

img {
    max-width: 100%;
}

.app-shell {
    display: grid;
    grid-template-columns: 286px 1fr;
    min-height: 100vh;
    width: 100%;
}

.sidebar {
    background: #111827;
    color: #fff;
    padding: 24px 18px;
    min-width: 0;
}

.brand {
    display: block;
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 28px;
}

.sidebar-head {
    display: block;
}

.menu-toggle {
    align-items: center;
    background: #243044;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--r-md);
    color: #fff;
    cursor: pointer;
    display: none;
    font: inherit;
    font-weight: 700;
    gap: 9px;
    min-height: 42px;
    padding: 10px 12px;
}

.menu-icon,
.menu-icon::before,
.menu-icon::after {
    background: currentColor;
    border-radius: 999px;
    display: block;
    height: 2px;
    width: 18px;
}

.menu-icon {
    position: relative;
}

.menu-icon::before,
.menu-icon::after {
    content: "";
    left: 0;
    position: absolute;
}

.menu-icon::before {
    top: -6px;
}

.menu-icon::after {
    top: 6px;
}

.menu-panel {
    display: block;
}

.sidebar nav {
    display: grid;
    gap: 8px;
}

.sidebar nav {
    scrollbar-width: none;
}

.sidebar nav::-webkit-scrollbar {
    display: none;
}

.sidebar nav a,
.logout {
    border-radius: var(--r-md);
    color: #d9e3f0;
    display: block;
    padding: 12px 14px;
}

.nav-group-toggle {
    align-items: center;
    background: none;
    border: 0;
    border-radius: var(--r-md);
    color: #8fa3bd;
    cursor: pointer;
    display: flex;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    justify-content: space-between;
    letter-spacing: 0.5px;
    padding: 12px 14px;
    text-align: left;
    text-transform: uppercase;
    width: 100%;
}

.nav-group-toggle:hover {
    background: #243044;
    color: #fff;
}

.nav-chevron {
    border-bottom: 2px solid currentColor;
    border-right: 2px solid currentColor;
    display: inline-block;
    height: 7px;
    margin-right: 3px;
    transform: rotate(-45deg);
    transition: transform 0.15s ease;
    width: 7px;
}

.nav-group.open > .nav-group-toggle .nav-chevron {
    transform: rotate(45deg);
}

.collapse-inner {
    min-height: 0;
    overflow: hidden;
}

.nav-group-items {
    display: grid;
    grid-template-rows: 0fr;
    margin: 0 0 0 10px;
    transition: grid-template-rows 0.25s ease;
}

.nav-group.open > .nav-group-items {
    grid-template-rows: 1fr;
}

.nav-group-items > .collapse-inner {
    border-left: 1px solid #243044;
    display: grid;
    gap: 4px;
    padding: 0 0 0 8px;
    transition: padding 0.25s ease;
}

.nav-group.open > .nav-group-items > .collapse-inner {
    padding: 4px 0 4px 8px;
}

.sidebar nav a.nav-single {
    color: #8fa3bd;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.sidebar nav a.nav-single.active,
.sidebar nav a.nav-single:hover {
    background: #243044;
    color: #fff;
}

.sidebar nav a.active,
.sidebar nav a:hover,
.logout:hover {
    background: #243044;
    color: #fff;
}

.logout {
    margin-top: 28px;
}

.content {
    padding: 28px;
    min-width: 0;
}

.topbar {
    align-items: center;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

.eyebrow {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0;
    margin: 0 0 4px;
    text-transform: uppercase;
}

h1, h2 {
    margin: 0;
}

h1 { font-size: 30px; }
h2 { font-size: 20px; }

.user-pill {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    padding: 9px 14px;
}

.inline-pill {
    display: inline-block;
    font-size: 12px;
    margin-left: 8px;
    padding: 5px 9px;
}

.stats-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 22px;
}

.stat,
.panel,
.form-panel,
.login-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-md);
}

.stat {
    padding: 18px;
}

.stat span {
    display: block;
    font-size: 30px;
    font-weight: 700;
}

.stat p {
    color: var(--muted);
    margin: 6px 0 0;
}

.panel,
.form-panel {
    margin-bottom: 20px;
    padding: 18px;
}

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

.admin-grid h2 {
    margin-bottom: 16px;
}

.panel-heading {
    align-items: center;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.dashboard-filter {
    align-items: flex-end;
    display: flex;
    margin-bottom: 16px;
    max-width: 100%;
    width: fit-content;
}

.dashboard-filter .inline-form {
    align-items: end;
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(240px, 320px);
}

.dashboard-filter label {
    max-width: 320px;
}

.category-summary-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.category-summary {
    align-items: center;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
}

.category-summary span {
    overflow-wrap: anywhere;
}

.category-summary strong {
    color: var(--primary);
    font-size: 20px;
}

.category-results,
.async-results {
    transition: opacity 0.18s ease;
}

.category-results.loading,
.async-results.loading {
    opacity: 0.55;
    pointer-events: none;
}

.category-panels {
    display: grid;
    gap: 20px;
}

.category-panels .panel {
    margin-bottom: 0;
}

.hint,
small {
    color: var(--muted);
    font-size: 13px;
}

.table-wrap {
    border-radius: var(--r-md);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

table {
    border-collapse: collapse;
    min-width: 720px;
    width: 100%;
}

.admin-table {
    min-width: 820px;
}

/* Accounts: dates stay whole, and each column takes only what it needs. */
.admin-table .col-user {
    width: 150px;
}

.admin-table .col-role {
    width: 170px;
}

.admin-table .col-when {
    white-space: nowrap;
    width: 118px;
}

.admin-table .admin-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
}

.admin-table .admin-actions .hint {
    max-width: 320px;
}

/* A badge is as wide as its word, not as wide as its column. */
.admin-table .col-role .badge {
    justify-self: start;
    margin-bottom: 2px;
}

.admin-actions-view,
.admin-actions-view[hidden] {
    align-items: center;
    display: flex;
    gap: 8px;
}

.admin-actions-view[hidden],
.inline-reset-form[hidden] {
    display: none;
}

.edit-table {
    min-width: 980px;
}

.category-table {
    border-collapse: collapse;
    min-width: 820px;
    table-layout: fixed;
    width: 100%;
}

.category-table .col-id {
    width: 70px;
}

.category-table .col-icon {
    width: 110px;
}

.category-table .col-loading {
    width: 140px;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 12px;
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 13px;
    text-transform: uppercase;
}

.category-table th,
.category-table td {
    overflow-wrap: break-word;
    white-space: normal;
    word-break: break-word;
}

.category-table .col-id,
.category-table .col-icon,
.category-table .col-loading,
.category-table .app-icon-cell,
.category-table .status-cell {
    text-align: center;
}

.category-table .col-name {
    text-align: left;
}

.app-icon {
    background: var(--surface-strong);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    height: 48px;
    object-fit: cover;
    width: 48px;
}

.badge {
    border-radius: 999px;
    display: inline-block;
    font-size: 13px;
    font-weight: 700;
    padding: 6px 10px;
    /* A badge is a label, not a paragraph: it never breaks mid-word. */
    white-space: nowrap;
}

.bulk-status-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 20px;
    margin-bottom: 12px;
}

/* Each label stays on the same line as the buttons it controls. */
.bulk-status-set {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.action-menu-wrap {
    display: inline-block;
    position: relative;
}

.action-menu-btn {
    font-size: 17px;
    line-height: 1;
    min-width: 36px;
    padding: 6px 8px;
}

.action-menu {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-lg);
    display: none;
    max-height: calc(100vh - 24px);
    max-width: calc(100vw - 16px);
    min-width: 175px;
    overflow-y: auto;
    padding: 6px;
    position: fixed;
    z-index: 60;
}

.action-menu.open {
    display: grid;
    gap: 2px;
}

.action-menu form {
    margin: 0;
}

.menu-item {
    background: none;
    border: 0;
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    display: block;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    padding: 8px 10px;
    text-align: left;
    width: 100%;
}

.menu-item:hover {
    background: var(--bg);
}

.menu-item:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.menu-item.danger {
    color: var(--red-text);
}

.menu-item.danger:hover {
    background: var(--red-bg);
}

.done-toggle {
    align-items: center;
    cursor: pointer;
    display: flex;
    gap: 10px;
    width: fit-content;
}

.done-toggle input[type="checkbox"] {
    cursor: pointer;
    height: 18px;
    min-height: 0;
    width: 18px;
}

select.status-select {
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    min-height: 36px;
    padding: 6px 10px;
    width: 100%;
}

select.status-select.is-green {
    background: var(--green-bg);
    border-color: var(--green-line);
    color: var(--green-text);
}

select.status-select.is-red {
    background: var(--red-bg);
    border-color: var(--red-line);
    color: var(--red-text);
}

.badge-green { background: var(--green-bg); color: var(--green-text); }
.badge-red { background: var(--red-bg); color: var(--red-text); }
.badge-blue { background: var(--blue-bg); color: var(--blue-text); }
.badge-amber { background: var(--amber-bg); color: var(--amber-text); }
.badge-gray { background: var(--gray-bg); color: var(--gray-text); }

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.tabs a {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
    padding: 9px 14px;
}

.tabs a:hover {
    color: var(--text);
}

.tabs a.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.progress {
    background: var(--btn-bg-hover);
    border-radius: 999px;
    height: 8px;
    min-width: 110px;
    overflow: hidden;
    width: 100%;
}

.progress span {
    background: var(--primary);
    border-radius: 999px;
    display: block;
    height: 100%;
}

.progress-label {
    color: var(--muted);
    display: block;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 6px;
}

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

.checklist-form .inline-actions {
    grid-column: 1 / -1;
}

.checklist-item {
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: 10px 12px;
}

.checklist-item-main {
    align-items: center;
    cursor: pointer;
    display: grid;
    gap: 12px;
    grid-template-columns: auto 1fr;
    width: 100%;
}

.checklist-item input[type="checkbox"] {
    height: 18px;
    min-height: 0;
    width: 18px;
}

.checklist-field {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.25s ease;
}

.checklist-item.field-open .checklist-field {
    grid-template-rows: 1fr;
}

.checklist-field > .collapse-inner {
    padding-top: 0;
    transition: padding-top 0.25s ease;
}

.checklist-item.field-open .checklist-field > .collapse-inner {
    padding-top: 10px;
}

.console-url {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.console-url code {
    background: var(--surface-strong);
    border-radius: 6px;
    padding: 6px 10px;
    word-break: break-all;
}

.input-with-copy {
    align-items: center;
    display: flex;
    gap: 8px;
}

.input-with-copy input {
    flex: 1;
}

.console-stats {
    color: var(--muted);
    display: flex;
    flex-wrap: wrap;
    gap: 8px 24px;
    margin-bottom: 16px;
}

.console-stats strong {
    color: var(--text);
    font-size: 16px;
}

.console-actions {
    margin-top: 14px;
}

.app-group-toggle .badge {
    margin-left: 10px;
}

input[readonly] {
    background: var(--bg);
    color: var(--muted);
}

.checklist-item strong {
    color: var(--text);
    display: block;
}

.checklist-item small {
    display: block;
    margin-top: 2px;
}

.checklist-item.done {
    background: var(--green-bg);
    border-color: var(--green-line);
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

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

.cycle-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.cycle-controls {
    align-items: end;
    margin-bottom: 10px;
}

.cycle-days-form {
    grid-template-columns: minmax(140px, 200px) auto;
}

.task-group {
    margin-bottom: 20px;
}

.app-group {
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    margin-bottom: 12px;
    overflow: hidden;
}

.app-group-toggle {
    align-items: center;
    background: var(--surface);
    border: 0;
    color: var(--text);
    cursor: pointer;
    display: flex;
    font: inherit;
    font-size: 15px;
    font-weight: 700;
    justify-content: space-between;
    padding: 14px 16px;
    text-align: left;
    width: 100%;
}

.app-group-toggle:hover {
    background: var(--surface-strong);
}

.app-group-toggle .nav-chevron {
    margin-right: 2px;
}

.app-group.open > .app-group-toggle .nav-chevron {
    transform: rotate(45deg);
}

.app-group-body {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.3s ease;
}

.app-group.open > .app-group-body {
    grid-template-rows: 1fr;
}

.app-group-body > .collapse-inner {
    padding: 0 12px;
    transition: padding 0.3s ease;
}

.app-group.open > .app-group-body > .collapse-inner {
    padding: 12px;
}

/* Nested groups (month > day) sit flush inside their parent. */
.app-group .app-group-body .app-group {
    background: var(--panel);
}

.app-group .app-group-body .app-group-toggle {
    background: var(--panel);
    font-size: 14px;
    padding: 12px 14px;
}

.app-group .app-group-body .app-group-toggle:hover {
    background: var(--bg);
}

.app-group .app-group-body .app-group:last-child {
    margin-bottom: 0;
}

.task-group h3 {
    font-size: 16px;
    margin: 0 0 10px;
}

.console-assign-form {
    align-items: center;
    display: grid;
    gap: 8px;
    grid-template-columns: minmax(140px, 1fr) auto;
}

label {
    color: var(--muted);
    display: grid;
    font-size: 14px;
    gap: 7px;
    width: 100%;
}

input,
select {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    color: var(--text);
    font: inherit;
    min-height: 42px;
    padding: 9px 11px;
    width: 100%;
}

/*
 * A tick box is not a text field. The shared input styling gave it a 42px
 * tall box with a border, which showed up as a rectangle around the tick
 * the moment it was clicked. It keeps its own small box instead, and still
 * shows a ring when someone reaches it with the keyboard.
 */
input[type="checkbox"],
input[type="radio"] {
    accent-color: var(--primary);
    background: none;
    border: 0;
    border-radius: 0;
    min-height: 0;
    padding: 0;
    width: auto;
}

input[type="checkbox"]:focus,
input[type="radio"]:focus {
    border: 0;
    box-shadow: none;
}

input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
    box-shadow: var(--ring);
    outline: none;
}

.stacked-form {
    display: grid;
    gap: 16px;
    max-width: 760px;
}

.stacked-form.wide {
    max-width: none;
}

.stacked-form > .btn {
    justify-self: start;
    min-width: 220px;
}

.form-row,
.search-form,
.inline-form {
    align-items: end;
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

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

.inline-reset-form {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.inline-reset-form input {
    flex: 0 1 128px;
    min-height: 36px;
    padding: 7px 10px;
    width: auto;
}

.btn {
    align-items: center;
    background: var(--btn-bg);
    border: 0;
    border-radius: var(--r-md);
    color: var(--btn-text);
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    font-weight: 700;
    justify-content: center;
    min-height: 42px;
    padding: 10px 14px;
    white-space: nowrap;
}

.btn.primary {
    background: var(--primary);
    color: #fff;
}

.btn.primary:hover {
    background: var(--primary-dark);
}

.btn.danger {
    background: var(--red-solid);
    color: var(--on-primary);
}

.btn.danger:hover {
    background: var(--red-solid-dark);
}

.btn.small {
    min-height: 36px;
    padding: 8px 10px;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.bulk-actions {
    display: flex;
    justify-content: flex-end;
    padding-top: 16px;
}

.alert {
    border-radius: var(--r-md);
    font-weight: 700;
    margin-bottom: 18px;
    padding: 12px 14px;
}

.alert.success { background: var(--green-bg); color: var(--green-text); }
.alert.error { background: var(--red-bg); color: var(--red-text); }

.empty {
    color: var(--muted);
    text-align: center;
}

.empty.block {
    padding: 24px;
}

.login-page {
    align-items: center;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    max-width: 420px;
    padding: 28px;
    width: 100%;
}

.login-card h1 {
    margin-bottom: 8px;
}

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

.login-card form {
    display: grid;
    gap: 16px;
}

@media (max-width: 1180px) {
    .app-shell {
        grid-template-columns: 220px 1fr;
    }

    .sidebar {
        padding: 22px 14px;
    }

    .content {
        padding: 22px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

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

@media (max-width: 900px) {
    /* Table rows already scroll sideways, so keep row actions on one
       line instead of stacking them into tall cells. */
    .actions {
        flex-wrap: nowrap;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: grid;
        gap: 14px;
        grid-template-columns: 1fr;
        position: static;
    }

    .brand {
        margin-bottom: 0;
    }

    .menu-panel {
        display: grid;
        gap: 14px;
    }

    .sidebar nav {
        align-items: start;
        display: grid;
        gap: 10px;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .logout {
        margin-top: 0;
        width: fit-content;
    }

    .content {
        padding: 18px;
    }

    .admin-grid,
    .form-row,
    .search-form,
    .inline-form,
    .checklist-form {
        grid-template-columns: 1fr;
    }

    .inline-reset-form {
        align-items: stretch;
        grid-template-columns: 1fr;
    }

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

@media (max-width: 640px) {
    .sidebar {
        padding: 18px 14px;
    }

    .sidebar-head {
        align-items: center;
        display: flex;
        gap: 12px;
        justify-content: space-between;
    }

    .brand {
        font-size: 20px;
    }

    .menu-toggle {
        display: inline-flex;
    }

    .menu-toggle[aria-expanded="true"] {
        background: var(--primary);
    }

    .menu-panel {
        display: none;
    }

    .menu-panel.open {
        display: grid;
        gap: 10px;
    }

    .sidebar nav {
        display: grid;
        gap: 8px;
        grid-template-columns: 1fr;
        overflow: visible;
        padding-bottom: 0;
    }

    .sidebar nav a {
        white-space: normal;
    }

    .sidebar nav a,
    .logout {
        padding: 10px 12px;
        width: 100%;
    }

    .logout {
        margin-top: 0;
    }

    .content {
        padding: 14px;
    }

    h1 {
        font-size: 26px;
    }

    h2 {
        font-size: 18px;
    }

    .stats-grid {
        gap: 12px;
        grid-template-columns: 1fr;
        margin-bottom: 16px;
    }

    .stat,
    .panel,
    .form-panel,
    .login-card {
        box-shadow: 0 8px 20px rgba(20, 30, 50, 0.05);
    }

    .stat {
        padding: 14px;
    }

    .stat span {
        font-size: 26px;
    }

    .panel,
    .form-panel {
        margin-bottom: 16px;
        padding: 14px;
    }

    .panel-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .category-summary-grid {
        grid-template-columns: 1fr;
    }

    .category-panels {
        gap: 16px;
    }

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

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

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

    th,
    td {
        padding: 10px;
    }

    .app-icon {
        height: 44px;
        width: 44px;
    }

    .btn {
        min-height: 44px;
        padding: 10px 12px;
        width: 100%;
    }

    .actions .btn,
    .btn.small {
        width: auto;
    }

    input,
    select {
        font-size: 16px;
        min-height: 44px;
    }

    .bulk-actions {
        justify-content: stretch;
    }

    .dashboard-filter,
    .dashboard-filter .inline-form,
    .dashboard-filter label {
        width: 100%;
    }

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

    .login-card {
        padding: 22px;
    }
}

@media (max-width: 420px) {
    .content {
        padding: 12px;
    }

    .topbar {
        gap: 10px;
        margin-bottom: 16px;
    }

    h1 {
        font-size: 24px;
    }

    .user-pill {
        padding: 8px 12px;
    }

    .panel,
    .form-panel {
        padding: 12px;
    }

    .category-table {
        min-width: 700px;
    }
}

@keyframes page-fade {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.content,
.login-card {
    animation: page-fade 0.3s ease;
}

.alert {
    animation: page-fade 0.25s ease;
}

.btn,
input,
select,
.sidebar nav a,
.logout,
.tabs a,
.nav-group-toggle,
.app-group-toggle,
.user-pill {
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.btn:active {
    transform: scale(0.97);
}

input:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 87, 214, 0.12);
    outline: none;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* Publish Info: copy-ready store listing values. */
.publish-search {
    margin-bottom: 16px;
}

.publish-console-urls {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    margin-bottom: 14px;
    padding: 12px;
}

.publish-app {
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    margin-bottom: 12px;
    padding: 12px;
}

.publish-app:last-child {
    margin-bottom: 0;
}

.publish-app-head {
    align-items: center;
    border-bottom: 1px solid var(--line);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: space-between;
    margin-bottom: 10px;
    padding-bottom: 10px;
}

.publish-app-head h4 {
    font-size: 15px;
    margin: 0;
}

.publish-row {
    align-items: baseline;
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 6px 0;
}

.publish-label {
    color: var(--muted);
    flex: 0 0 120px;
    font-size: 13px;
    font-weight: 600;
}

@media (max-width: 700px) {
    .publish-label {
        flex-basis: 100%;
    }

    .publish-row .console-url {
        width: 100%;
    }
}

/* A group nested inside a group reads as a sub-menu, not a section header. */
.nav-group-items .nav-group-toggle {
    color: #cbd5e1;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0;
    padding: 10px 12px;
    text-transform: none;
}

/* A single visible focus style, so keyboard use looks deliberate. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
    box-shadow: var(--ring);
    outline: 2px solid transparent;
    outline-offset: 2px;
}

code,
kbd,
pre {
    font-family: var(--font-mono);
}

/* --- Phase 1 polish: depth, motion and hierarchy on shared components --- */

.stat,
.panel,
.form-panel {
    border-color: var(--line);
}

.stat {
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.stat:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
}

.stat span {
    letter-spacing: -0.02em;
}

h1 {
    letter-spacing: -0.02em;
}

.btn {
    border: 1px solid transparent;
    box-shadow: var(--shadow-sm);
    transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}

.btn:hover {
    box-shadow: var(--shadow-md);
}

.btn:active {
    transform: translateY(1px);
}

.btn.primary {
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12), 0 4px 12px rgba(37, 87, 214, 0.24);
}

.badge {
    border-radius: var(--r-pill);
    letter-spacing: 0.01em;
}

input[type="text"],
input[type="search"],
input[type="number"],
input[type="url"],
input[type="password"],
select,
textarea {
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

table thead th {
    letter-spacing: 0.04em;
}

tbody tr {
    transition: background 0.15s ease;
}

tbody tr:hover {
    background: var(--surface);
}

@media (prefers-reduced-motion: reduce) {
    .stat,
    .btn,
    tbody tr {
        transition: none;
    }

    .stat:hover,
    .btn:active {
        transform: none;
    }
}

/* --- Phase 2: sidebar icons, counts and an active marker --- */

.sidebar nav a,
.nav-group-toggle,
.logout {
    align-items: center;
    display: flex;
    gap: 10px;
    justify-content: space-between;
}

.nav-label {
    align-items: center;
    display: flex;
    gap: 10px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-ico {
    flex: 0 0 18px;
    height: 18px;
    opacity: 0.75;
    width: 18px;
}

.sidebar nav a.active .nav-ico,
.nav-group-toggle:hover .nav-ico,
.sidebar nav a:hover .nav-ico {
    opacity: 1;
}

/* Active page gets a left marker, not just a fill. */
.sidebar nav a {
    position: relative;
}

.sidebar nav a.active::before {
    background: #60a5fa;
    border-radius: var(--r-pill);
    bottom: 8px;
    content: "";
    left: -8px;
    position: absolute;
    top: 8px;
    width: 3px;
}

.nav-count {
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--r-pill);
    color: #cbd5e1;
    flex: 0 0 auto;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    padding: 4px 8px;
}

.sidebar nav a.active .nav-count {
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
}

.sidebar nav a.nav-single .nav-label {
    letter-spacing: 0.5px;
}

/* A second nesting level indents less, so nav rows keep their count badge
   inside the sidebar. */
.nav-group-items .nav-group-items {
    margin-left: 4px;
}

.nav-group-items .nav-group-items > .collapse-inner {
    padding-left: 6px;
}

/* --- Phase 3: tables become cards on phones, plus a density switch --- */

@media (max-width: 760px) {
    .table-wrap {
        overflow-x: visible;
    }

    .table-wrap table {
        min-width: 0;
    }

    .table-wrap thead {
        clip: rect(0 0 0 0);
        height: 1px;
        overflow: hidden;
        position: absolute;
        width: 1px;
    }

    .table-wrap table,
    .table-wrap tbody,
    .table-wrap tr,
    .table-wrap td {
        display: block;
        width: 100%;
    }

    .table-wrap tr {
        background: var(--panel);
        border: 1px solid var(--line);
        border-radius: var(--r-md);
        box-shadow: var(--shadow-sm);
        margin-bottom: 10px;
        overflow: hidden;
    }

    .table-wrap tr:last-child {
        margin-bottom: 0;
    }

    .table-wrap tr:hover {
        background: var(--panel);
    }

    .table-wrap td {
        align-items: center;
        border: 0;
        border-bottom: 1px solid var(--line);
        display: flex;
        gap: 12px;
        justify-content: space-between;
        /* A long package name wraps inside the card instead of running off it. */
        overflow-wrap: anywhere;
        padding: 10px 12px;
    }

    .table-wrap td:last-child {
        border-bottom: 0;
    }

    .table-wrap td::before {
        color: var(--muted);
        content: attr(data-label);
        flex: 0 0 40%;
        font-size: 12px;
        font-weight: 700;
        letter-spacing: 0.02em;
        text-transform: uppercase;
    }

    .table-wrap td:not([data-label])::before,
    .table-wrap td[data-label=""]::before {
        display: none;
    }

    .table-wrap td.actions {
        background: var(--surface);
        justify-content: flex-end;
    }

    .table-wrap td .console-url,
    .table-wrap td .inline-actions {
        justify-content: flex-end;
    }
}

/* Compact density: same rows, less air. */
body.density-compact th,
body.density-compact td {
    padding: 7px 10px;
}

body.density-compact .app-icon {
    height: 30px;
    width: 30px;
}

body.density-compact .btn {
    min-height: 34px;
    padding: 6px 10px;
}

body.density-compact .panel,
body.density-compact .form-panel {
    padding: 14px;
}

.density-toggle {
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--r-pill);
    display: inline-flex;
    gap: 2px;
    padding: 3px;
}

.density-toggle button {
    background: none;
    border: 0;
    border-radius: var(--r-pill);
    color: var(--muted);
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    padding: 6px 12px;
}

.density-toggle button.active {
    background: var(--primary-soft);
    color: var(--primary);
}

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

@media (max-width: 640px) {
    .density-toggle {
        display: none;
    }
}

/* Secondary identity line under a name, for lists full of look-alike apps. */
.cell-title {
    display: grid;
    gap: 2px;
}

.cell-sub {
    color: var(--muted);
    font-size: 12px;
}

/* --- Phase 4: toasts, undo and a working-state on buttons --- */

.toast-stack {
    bottom: 20px;
    display: grid;
    gap: 10px;
    justify-items: end;
    pointer-events: none;
    position: fixed;
    right: 20px;
    z-index: 60;
}

.toast {
    align-items: center;
    box-shadow: var(--shadow-lg);
    display: flex;
    gap: 12px;
    margin-bottom: 0;
    max-width: min(420px, calc(100vw - 40px));
    opacity: 0;
    pointer-events: auto;
    transform: translateY(10px);
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.toast.shown {
    opacity: 1;
    transform: none;
}

.toast.leaving {
    opacity: 0;
    transform: translateY(6px);
}

.toast-message {
    flex: 1;
    min-width: 0;
}

.toast-undo button {
    background: rgba(255, 255, 255, 0.65);
    border: 0;
    border-radius: var(--r-sm);
    color: inherit;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    padding: 5px 10px;
}

.toast-undo button:hover {
    background: var(--panel);
}

.toast-close {
    background: none;
    border: 0;
    color: inherit;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    opacity: 0.6;
    padding: 0 2px;
}

.toast-close:hover {
    opacity: 1;
}

@media (max-width: 640px) {
    .toast-stack {
        bottom: 12px;
        justify-items: stretch;
        left: 12px;
        right: 12px;
    }

    .toast {
        max-width: none;
    }
}

/* A pressed button shows it is working, and the form only submits once. */
.btn.is-loading,
button.is-loading {
    color: transparent !important;
    pointer-events: none;
    position: relative;
}

.btn.is-loading::after,
button.is-loading::after {
    animation: btn-spin 0.6s linear infinite;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-right-color: transparent;
    color: #fff;
    content: "";
    height: 16px;
    left: calc(50% - 8px);
    position: absolute;
    top: calc(50% - 8px);
    width: 16px;
}

.btn.is-loading:not(.primary):not(.danger)::after {
    color: var(--btn-text);
}

@keyframes btn-spin {
    to { transform: rotate(360deg); }
}

/* Row actions stay on one line; the table scrolls if it must. */
td.actions {
    flex-wrap: nowrap;
}

@media (prefers-reduced-motion: reduce) {
    .toast {
        transition: none;
    }

    .btn.is-loading::after,
    button.is-loading::after {
        animation-duration: 2s;
    }
}

/* --- Phase 5: command palette and the workflow stepper --- */

.search-trigger {
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--r-pill);
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    font-size: 13px;
    gap: 8px;
    padding: 8px 12px;
}

.search-trigger:hover {
    border-color: var(--line-strong);
    color: var(--text);
}

.search-trigger svg {
    height: 15px;
    width: 15px;
}

.search-trigger kbd {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    font-size: 11px;
    padding: 2px 5px;
}

.palette {
    background: rgba(15, 23, 42, 0.45);
    inset: 0;
    padding: 12vh 16px 16px;
    position: fixed;
    z-index: 80;
}

.palette-box {
    background: var(--panel);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    margin: 0 auto;
    max-width: 560px;
    overflow: hidden;
}

.palette-box input {
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    font-size: 16px;
    padding: 16px;
    width: 100%;
}

.palette-box input:focus-visible {
    box-shadow: none;
}

.palette-results {
    list-style: none;
    margin: 0;
    max-height: 46vh;
    overflow-y: auto;
    padding: 6px;
}

.palette-item {
    align-items: baseline;
    border-radius: var(--r-md);
    cursor: pointer;
    display: grid;
    gap: 2px 10px;
    grid-template-columns: 1fr auto;
    padding: 10px 12px;
}

.palette-item.active {
    background: var(--primary-soft);
}

.palette-title {
    font-weight: 700;
    grid-column: 1;
    grid-row: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.palette-group {
    align-self: center;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    grid-column: 2;
    grid-row: 1 / span 2;
    text-transform: uppercase;
}

.palette-sub {
    color: var(--muted);
    font-size: 12px;
    grid-column: 1;
    grid-row: 2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.palette-empty {
    color: var(--muted);
    padding: 16px;
    text-align: center;
}

.palette-hint {
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
    margin: 0;
    padding: 10px 16px;
}

@media (max-width: 640px) {
    .search-trigger span,
    .search-trigger kbd {
        display: none;
    }

    .search-trigger {
        padding: 8px;
    }

    .palette {
        padding-top: 6vh;
    }
}

.stepper {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 4px;
    list-style: none;
    margin: 0 0 16px;
    padding: 0;
}

.step {
    align-items: center;
    color: var(--muted);
    display: flex;
    flex: 1 1 0;
    font-size: 13px;
    font-weight: 700;
    gap: 8px;
    min-width: 120px;
    position: relative;
}

.step + .step::before {
    background: var(--line);
    content: "";
    height: 2px;
    margin-right: 4px;
    width: 14px;
}

.step-dot {
    align-items: center;
    background: var(--gray-bg);
    border-radius: 50%;
    color: var(--gray-text);
    display: inline-flex;
    flex: 0 0 24px;
    height: 24px;
    justify-content: center;
    font-size: 12px;
}

.step-done .step-dot {
    background: var(--green-bg);
    color: var(--green-text);
}

.step-current .step-dot {
    background: var(--primary);
    color: #fff;
}

.step-current {
    color: var(--text);
}

.stepper-off .step-dot {
    opacity: 0.5;
}

/* A tab that leads to another page, not another view of this one. */
.tabs .tab-link {
    color: var(--muted);
}

.tabs .tab-link:hover {
    color: var(--primary);
}

/* Grid items refuse to shrink below their text by default, which pushed
   long menu labels past the sidebar edge. */
.nav-group-items > .collapse-inner,
.nav-group-items > .collapse-inner > *,
.sidebar nav a,
.nav-group-toggle {
    min-width: 0;
}

/* Sub-menu rows carry an icon and a count, so give the label a little
   more room by tightening its own spacing. */
.nav-group-items .nav-group-items a {
    font-size: 13.5px;
    padding: 11px 12px;
}

.nav-group-items .nav-group-items .nav-label {
    gap: 8px;
}

/* The app page's stage buttons sit on one row and wrap as a group. */
.app-stage-actions {
    border-top: 1px solid var(--line);
    flex-wrap: wrap;
    margin-top: 14px;
    padding-top: 14px;
}

/* --- Home: what is due today and what is waiting --- */

.home-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    margin-bottom: 14px;
}

.home-card {
    margin-bottom: 0;
}

.home-list {
    display: grid;
    gap: 2px;
    list-style: none;
    margin: 12px 0 0;
    padding: 0;
}

.home-list li {
    align-items: center;
    border-top: 1px solid var(--line);
    display: flex;
    gap: 12px;
    justify-content: space-between;
    padding: 9px 2px;
}

.home-list-name {
    font-weight: 700;
}

.home-list-meta {
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
}

.attention-list {
    display: grid;
    gap: 8px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.attention-list a {
    align-items: center;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    display: flex;
    gap: 12px;
    padding: 12px 14px;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.attention-list a:hover {
    background: var(--surface);
    border-color: var(--line-strong);
}

.attention-count {
    flex: 0 0 auto;
    font-size: 13px;
    min-width: 36px;
    text-align: center;
}

.attention-label {
    flex: 1;
    font-weight: 700;
}

.attention-list .nav-chevron {
    color: var(--muted);
    transform: rotate(-45deg);
}

.attention-list li.is-clear a {
    opacity: 0.65;
}

.attention-list li.is-clear .attention-label {
    font-weight: 400;
}

/* Pipeline tiles are links, so they should feel like it. */
a.stat:hover {
    border-color: var(--line-strong);
}

/* An add form that stays out of the way until it is wanted. */
.add-panel {
    padding: 0;
}

.add-panel .app-group {
    border: 0;
    margin-bottom: 0;
}

.add-panel .app-group-toggle {
    background: var(--panel);
    border-radius: var(--r-md);
    font-size: 15px;
}

.add-panel .app-group-toggle:hover {
    background: var(--surface);
}

.add-panel .app-group.open .app-group-toggle {
    border-bottom: 1px solid var(--line);
    border-radius: var(--r-md) var(--r-md) 0 0;
}

/* --- Bulk selection --- */

.col-select {
    width: 38px;
}

.col-select input {
    cursor: pointer;
    height: 16px;
    width: 16px;
}

tbody tr.is-picked {
    background: var(--primary-soft);
}

.bulk-bar {
    align-items: center;
    background: var(--primary-soft);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: space-between;
    margin-bottom: 10px;
    padding: 10px 12px;
}

/* display:flex would otherwise beat the hidden attribute. */
.bulk-bar[hidden] {
    display: none;
}

.bulk-count {
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
}

.bulk-bar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

@media (max-width: 760px) {
    .bulk-bar {
        position: sticky;
        top: 8px;
        z-index: 5;
    }

    .table-wrap td.col-select {
        background: var(--surface);
        justify-content: flex-start;
    }

    .table-wrap td.col-select::before {
        content: "Select";
    }

    /* An app id is short and should never be broken across lines. */
    .table-wrap td.col-id {
        white-space: nowrap;
        word-break: normal;
    }

    /* Card rows set their own width, so the desktop columns step aside. */
    .admin-table .col-user,
    .admin-table .col-role,
    .admin-table .col-when {
        width: auto;
    }
}

/* The search + console bar above a list. */
.list-filters {
    align-items: end;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
}

.list-filters label {
    display: grid;
    gap: 4px;
    min-width: 180px;
}

.list-filters label:first-of-type {
    flex: 1 1 240px;
}

@media (max-width: 640px) {
    .list-filters label {
        flex: 1 1 100%;
    }

    .list-filters .btn {
        flex: 1 1 auto;
    }
}

/* --- Activity list --- */
.activity-list {
    display: grid;
    gap: 2px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.activity-list li {
    align-items: baseline;
    border-top: 1px solid var(--line);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 2px;
}

.activity-list li:first-child {
    border-top: 0;
}

.activity-time {
    color: var(--muted);
    flex: 0 0 auto;
    font-family: var(--font-mono);
    font-size: 12px;
}

.activity-what {
    flex: 1 1 260px;
    min-width: 0;
}

.activity-what small {
    color: var(--muted);
    display: block;
    font-size: 12px;
}

.activity-who {
    color: var(--muted);
    flex: 0 0 auto;
    font-size: 12px;
}

/* --- Pager --- */
.pager {
    align-items: center;
    border-top: 1px solid var(--line);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: space-between;
    margin-top: 14px;
    padding-top: 12px;
}

.pager-count,
.pager-position {
    color: var(--muted);
    font-size: 13px;
}

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

/* When a checklist item was first ticked. */
.checklist-done-at {
    color: var(--green-text);
    font-family: var(--font-mono);
    font-size: 11px;
}

/* --- Dark theme. The sidebar was already dark, so only the content
   surfaces flip; every colour below is a token defined in :root. --- */
:root[data-theme="dark"] {
    --bg: #0f1622;
    --panel: #172033;
    --surface: #1c2739;
    --surface-strong: #22304a;
    --text: #e7edf7;
    --muted: #9fb0c9;
    --line: #2a3852;
    --line-strong: #3b4c6b;
    --primary: #4f83f1;
    --primary-dark: #3c6cd8;
    --primary-soft: #1e2c47;
    --btn-bg: #22304a;
    --btn-bg-hover: #2b3c5b;
    --btn-text: #e7edf7;
    --on-primary: #0f1622;

    --green-bg: #123524;
    --green-text: #86efac;
    --green-line: #1d4f36;
    --red-bg: #3a1618;
    --red-text: #fca5a5;
    --red-line: #55242a;
    --red-solid: #dc2626;
    --red-solid-dark: #ef4444;
    --amber-bg: #3a2b10;
    --amber-text: #fcd34d;
    --blue-bg: #14273f;
    --blue-text: #93c5fd;
    --gray-bg: #253145;
    --gray-text: #c7d2e4;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
    --ring: 0 0 0 3px rgba(79, 131, 241, 0.35);

    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f1622;
        --panel: #172033;
        --surface: #1c2739;
        --surface-strong: #22304a;
        --text: #e7edf7;
        --muted: #9fb0c9;
        --line: #2a3852;
        --line-strong: #3b4c6b;
        --primary: #4f83f1;
        --primary-dark: #3c6cd8;
        --primary-soft: #1e2c47;
        --btn-bg: #22304a;
        --btn-bg-hover: #2b3c5b;
        --btn-text: #e7edf7;
        --on-primary: #0f1622;

        --green-bg: #123524;
        --green-text: #86efac;
        --green-line: #1d4f36;
        --red-bg: #3a1618;
        --red-text: #fca5a5;
        --red-line: #55242a;
        --red-solid: #dc2626;
        --red-solid-dark: #ef4444;
        --amber-bg: #3a2b10;
        --amber-text: #fcd34d;
        --blue-bg: #14273f;
        --blue-text: #93c5fd;
        --gray-bg: #253145;
        --gray-text: #c7d2e4;

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
        --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
        --ring: 0 0 0 3px rgba(79, 131, 241, 0.35);

        color-scheme: dark;
    }
}

/* Primary buttons keep readable text in both themes. */
.btn.primary,
.btn.danger {
    color: var(--on-primary);
}

.theme-toggle {
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--r-pill);
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    height: 34px;
    justify-content: center;
    padding: 0;
    width: 34px;
}

.theme-toggle:hover {
    border-color: var(--line-strong);
    color: var(--text);
}

.theme-toggle svg {
    height: 16px;
    width: 16px;
}

.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
    :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* --- Console health, empty states, shortcuts card --- */

.console-head {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    align-items: baseline;
    min-width: 0;
}

.console-head-name {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.console-head-meta {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.empty.block {
    border: 1px dashed var(--line-strong);
    border-radius: var(--r-md);
    line-height: 1.9;
}

.empty.block .btn {
    margin-top: 8px;
}

.shortcuts-head {
    border-bottom: 1px solid var(--line);
    padding: 14px 16px;
}

.shortcuts-list {
    display: grid;
    gap: 4px;
    list-style: none;
    margin: 0;
    padding: 10px 16px;
}

.shortcuts-list li {
    align-items: center;
    display: flex;
    gap: 10px;
    padding: 6px 0;
}

.shortcuts-list kbd {
    background: var(--surface-strong);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    font-size: 12px;
    min-width: 30px;
    padding: 3px 7px;
    text-align: center;
}

.shortcuts-list span {
    color: var(--muted);
}

/* The loading controls sit in a row, not stretched across the panel. */
.loading-form {
    align-items: end;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.loading-form label {
    display: grid;
    gap: 4px;
    min-width: 180px;
}

@media (max-width: 640px) {
    .loading-form label,
    .loading-form .btn {
        flex: 1 1 100%;
    }
}

/* A rotation's name inside a console group. */
.rotation-title {
    color: var(--muted);
    font-size: 12px;
    letter-spacing: 0.06em;
    margin: 14px 0 8px;
    text-transform: uppercase;
}

.app-group-body > .rotation-title:first-child {
    margin-top: 0;
}

/* The app's own icon, and the store fetch row. */
.app-title {
    align-items: center;
    display: flex;
    gap: 10px;
}

.app-title .app-icon {
    height: 32px;
    width: 32px;
}

.store-form {
    align-items: end;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
}

.store-form label {
    display: grid;
    flex: 1 1 340px;
    gap: 4px;
}

.store-form label small {
    color: var(--muted);
    font-weight: 400;
}

@media (max-width: 640px) {
    .store-form label,
    .store-form .btn {
        flex: 1 1 100%;
    }
}

/* The app's own domain URL: it reads like the rows above, and edits in place. */
.domain-url-form {
    align-items: center;
    display: flex;
    flex: 1 1 100%;
    flex-wrap: wrap;
    gap: 8px;
    padding-left: 132px;
}

.domain-url-form[hidden] {
    display: none;
}

.domain-url-form input {
    background: var(--surface-strong);
    flex: 1 1 280px;
    font-family: var(--font-mono);
    font-size: 13px;
    min-height: 34px;
    padding: 6px 10px;
}

.console-url[hidden] {
    display: none;
}

@media (max-width: 700px) {
    .domain-url-form {
        padding-left: 0;
    }
}

.domain-url-hint {
    margin-top: 0;
}

.domain-url-hint code {
    background: var(--surface-strong);
    border-radius: var(--r-sm);
    padding: 2px 6px;
}

.inline-post {
    display: inline-block;
    margin-left: 6px;
}

/* --- Ads config: the app's own ads.json, as fields or as the file --- */

.tabs button {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    min-height: 0;
    padding: 9px 14px;
    width: auto;
}

.tabs button:hover {
    color: var(--text);
}

.tabs button.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.ads-target code {
    background: var(--surface-strong);
    border-radius: var(--r-sm);
    overflow-wrap: anywhere;
    padding: 2px 6px;
}

.ads-rows {
    display: grid;
    gap: 10px;
    margin-bottom: 16px;
    max-width: 760px;
}

.ads-row {
    align-items: center;
    display: grid;
    gap: 12px;
    grid-template-columns: 160px minmax(0, 1fr);
}

.ads-row.is-custom {
    grid-template-columns: 160px minmax(0, 1fr) auto;
}

.ads-key {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.ads-row input {
    font-family: var(--font-mono);
    font-size: 13px;
    min-height: 38px;
}

.ads-row input:disabled {
    background: var(--surface-strong);
    color: var(--muted);
}

.ads-raw-label textarea {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    padding: 12px;
    width: 100%;
}

.ads-raw-form[hidden],
.ads-form[hidden] {
    display: none;
}

.ads-foot {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
}

@media (max-width: 700px) {
    .ads-row,
    .ads-row.is-custom {
        gap: 6px;
        grid-template-columns: minmax(0, 1fr);
    }

    .ads-row .ads-remove {
        justify-self: start;
    }
}

/* A selection that cannot be fully zipped says so before you press the button. */
.bulk-note {
    background: var(--surface-strong);
    border-radius: 999px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
}

.bulk-note[hidden] {
    display: none;
}

/* A name that carries its own icon reads faster in a long list. */
.cell-with-icon {
    align-items: center;
    display: inline-flex;
    gap: 10px;
    min-width: 0;
}

/* A path in a cell wraps rather than running past the card edge. */
@media (max-width: 900px) {
    .table-wrap td code {
        overflow-wrap: anywhere;
    }
}

/* A pager that belongs to one console sits under its own list. */
.group-pager {
    margin-top: 14px;
}

/* Today's IPs: the cell only says how many, and opens the picker. */
.ip-cell {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* The picker itself: one dialog for the page, a table and a search over it. */
.ip-modal {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
    color: var(--text);
    max-height: 86vh;
    max-width: none;
    padding: 0;
    width: min(900px, 94vw);
}

.ip-modal[open] {
    display: flex;
    flex-direction: column;
}

.ip-modal::backdrop {
    background: rgba(15, 23, 42, 0.55);
}

.ip-modal-head {
    align-items: flex-start;
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 12px;
    justify-content: space-between;
    padding: 16px 18px;
}

.ip-modal-title {
    font-size: 17px;
    margin: 0;
}

.ip-modal-for {
    color: var(--muted);
    font-size: 13px;
    margin: 4px 0 0;
}

.ip-modal-x {
    background: none;
    border: 0;
    color: var(--muted);
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
    padding: 0 4px;
}

.ip-modal-x:hover {
    color: var(--text);
}

.ip-modal-tools {
    align-items: center;
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 12px;
    padding: 12px 18px;
}

.ip-modal-search {
    flex: 1 1 auto;
    min-height: 38px;
    padding: 8px 12px;
}

.ip-modal-count {
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
}

.ip-modal-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 0 18px 8px;
}

.ip-modal-table {
    min-width: 0;
}

.ip-modal-table thead th {
    background: var(--panel);
    position: sticky;
    top: 0;
    z-index: 1;
}

.ip-modal-table td,
.ip-modal-table th {
    padding: 9px 10px;
}

.ip-modal-table tbody tr:hover {
    background: var(--surface);
}

.ip-modal-table .col-pick {
    width: 38px;
}

.ip-modal-name {
    font-weight: 600;
}

/* The green tag shows only on the rows this app already has today. */
.ip-modal-today .badge {
    display: none;
}

.ip-modal-table tr.is-added .ip-modal-today .badge {
    display: inline-block;
}

.ip-modal-foot {
    border-top: 1px solid var(--line);
    display: flex;
    gap: 10px;
    padding: 14px 18px;
}

/* The import dialog holds a form, so its body breathes a little more. */
.import-modal {
    width: min(560px, 94vw);
}

.import-form {
    display: contents;
}

.import-modal .ip-modal-body {
    padding: 18px;
}

.import-modal .ip-modal-for {
    max-width: 42ch;
}

.import-modal input[type="file"] {
    padding: 8px 10px;
}

/* The lists behind the IP pickers, three short columns side by side. */
.option-lists {
    display: grid;
    gap: 20px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.option-add {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.option-add input {
    flex: 1 1 auto;
    min-height: 36px;
    padding: 7px 10px;
}

.option-items {
    display: grid;
    gap: 6px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.option-items li {
    align-items: center;
    background: var(--surface);
    border-radius: var(--r-sm);
    display: flex;
    gap: 8px;
    justify-content: space-between;
    padding: 6px 6px 6px 10px;
}

/* Addresses recorded together sit on one line, each with its own way out. */
.ip-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ip-chip {
    align-items: center;
    background: var(--surface-strong);
    border-radius: var(--r-sm);
    display: inline-flex;
    gap: 4px;
    padding: 3px 4px 3px 9px;
}

.ip-chip code {
    font-size: 13px;
}

.ip-chip.is-repeat {
    background: var(--amber-bg);
}

.ip-chip.is-repeat code,
.ip-chip.is-repeat small {
    color: var(--amber-text);
}

.ip-chip small {
    font-size: 11px;
    font-weight: 700;
}

.ip-chip form {
    display: flex;
}

.ip-chip button {
    background: none;
    border: 0;
    border-radius: var(--r-sm);
    color: var(--muted);
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 2px 5px;
}

.ip-chip button:hover {
    background: var(--red-solid);
    color: var(--on-primary);
}

.col-when {
    white-space: nowrap;
}

/* Roles: what each one means, and the picker on a row. */
.role-guide {
    display: grid;
    gap: 10px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.role-guide li {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.role-form select {
    min-height: 36px;
    padding: 7px 9px;
    width: auto;
}

.role-note {
    margin-top: -6px;
}

/* The list of IPs: one row edits itself in place. */
/* One row, one form: the fields sit in the columns their headings name. */
.pool-table td {
    vertical-align: middle;
}

.pool-table input,
.pool-table select {
    min-height: 36px;
    padding: 7px 9px;
    width: 100%;
}

.pool-table input[name="ip"] {
    font-family: var(--font-mono);
    font-size: 13px;
}

.pool-table td.actions {
    text-align: right;
    white-space: nowrap;
}

.pool-table td.actions .btn + .btn {
    margin-left: 8px;
}

/* Fixed columns wide enough to read, and the wrap scrolls if the screen is not. */
.pool-table {
    min-width: 940px;
    table-layout: fixed;
}

.pool-table th:nth-child(1),
.pool-table td:nth-child(1) {
    width: 140px;
}

.pool-table th:nth-child(2),
.pool-table td:nth-child(2) {
    width: 130px;
}

.pool-table th:nth-child(3),
.pool-table td:nth-child(3),
.pool-table th:nth-child(5),
.pool-table td:nth-child(5) {
    width: 120px;
}

.pool-table th:nth-child(4),
.pool-table td:nth-child(4) {
    width: 116px;
}

.pool-table th:nth-child(6),
.pool-table td:nth-child(6) {
    width: auto;
}

.pool-table th:nth-child(7),
.pool-table td:nth-child(7) {
    text-align: center;
    width: 55px;
}

.pool-table th:nth-child(8),
.pool-table td:nth-child(8) {
    width: 166px;
}

/* Searching a long list, above the table it filters. */
.pool-tools {
    align-items: center;
    display: flex;
    gap: 12px;
    margin: 4px 0 14px;
}

.pool-search {
    flex: 1 1 auto;
    max-width: 420px;
    min-height: 38px;
    padding: 8px 12px;
}

.pool-count {
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
}

/* A row the search has put away stays away, cards included. */
.table-wrap tr[hidden] {
    display: none;
}

/* The list keeps its own height: the page below it stays where it is. */
.pool-scroll {
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    max-height: 62vh;
    overflow-y: auto;
}

.pool-scroll .pool-table thead th {
    background: var(--panel);
    /* Collapsed borders do not travel with a sticky row; this one does. */
    box-shadow: inset 0 -1px 0 var(--line);
    position: sticky;
    top: 0;
    z-index: 1;
}

/* A desk narrower than the full row keeps the note out of the way; the field
   is still there, so what it holds is saved untouched. */
@media (min-width: 761px) and (max-width: 1340px) {
    .pool-table {
        min-width: 860px;
    }

    .pool-table th:nth-child(6),
    .pool-table td:nth-child(6) {
        display: none;
    }
}

/* The new row waits behind this until it is asked for. */
.pool-add-bar {
    margin-top: 14px;
}

.pool-add-bar .btn[hidden] {
    display: none;
}

/* On a card the picker gets the whole width instead of a narrow column. */
@media (max-width: 760px) {
    /* Narrow screens keep the picker to what a phone can read. */
    .ip-modal-table th:nth-child(4),
    .ip-modal-table td:nth-child(4),
    .ip-modal-table th:nth-child(5),
    .ip-modal-table td:nth-child(5),
    .ip-modal-table th:nth-child(6),
    .ip-modal-table td:nth-child(6) {
        display: none;
    }

    .ip-modal-foot .btn {
        flex: 1 1 auto;
    }

    /* On a phone the page scrolls; a box inside a box is no help there. */
    .pool-scroll {
        border: 0;
        max-height: none;
        overflow-y: visible;
    }

    /* Desktop column widths would squash the fields inside a card. */
    .pool-table td:nth-child(n) {
        text-align: left;
        width: auto;
    }

    .pool-table input,
    .pool-table select {
        flex: 1 1 auto;
        min-width: 0;
    }

    .pool-table td.actions .btn + .btn {
        margin-left: 0;
    }
}
