:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --text: #172033;
    --muted: #667085;
    --line: #d9e1ec;
    --primary: #2557d6;
    --primary-dark: #1d46ad;
    --green-bg: #dcfce7;
    --green-text: #166534;
    --red-bg: #fee2e2;
    --red-text: #991b1b;
}

* { box-sizing: border-box; }

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

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

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

img {
    max-width: 100%;
}

.app-shell {
    display: grid;
    grid-template-columns: 250px 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: 8px;
    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: 8px;
    color: #d9e3f0;
    display: block;
    padding: 12px 14px;
}

.nav-group-toggle {
    align-items: center;
    background: none;
    border: 0;
    border-radius: 8px;
    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-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: 8px;
    box-shadow: 0 10px 28px rgba(20, 30, 50, 0.06);
}

.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: 8px;
    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: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

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

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

.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;
}

.category-table .col-ready {
    width: 160px;
}

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 .col-ready,
.category-table .app-icon-cell,
.category-table .status-cell,
.category-table .ready-cell {
    text-align: center;
}

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

.app-icon {
    background: #eef2f7;
    border: 1px solid var(--line);
    border-radius: 8px;
    height: 48px;
    object-fit: cover;
    width: 48px;
}

.badge {
    border-radius: 999px;
    display: inline-block;
    font-size: 13px;
    font-weight: 700;
    padding: 6px 10px;
}

.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: 8px;
    box-shadow: 0 12px 28px rgba(20, 30, 50, 0.18);
    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: #bbf7d0;
    color: var(--green-text);
}

select.status-select.is-red {
    background: var(--red-bg);
    border-color: #fecaca;
    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: #dbeafe; color: #1e40af; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-gray { background: #e5e7eb; color: #374151; }

.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: #e5eaf2;
    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: 8px;
    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: #eef2f7;
    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: #bbf7d0;
}

.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: 8px;
    margin-bottom: 12px;
    overflow: hidden;
}

.app-group-toggle {
    align-items: center;
    background: #f8fafc;
    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: #eef2f7;
}

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

.app-group.open .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;
}

.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: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    min-height: 42px;
    padding: 9px 11px;
    width: 100%;
}

.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: grid;
    gap: 8px;
    grid-template-columns: minmax(150px, 1fr) minmax(120px, 1fr) auto;
}

.btn {
    align-items: center;
    background: #edf2f7;
    border: 0;
    border-radius: 8px;
    color: #243044;
    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-bg);
    color: var(--red-text);
}

.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: 8px;
    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;
    }
}
