:root {
    --bg: #0b1220;
    --panel: #131c2e;
    --panel-2: #1b2740;
    --panel-3: #22304d;
    --border: #263353;
    --text: #e7ecf7;
    --text-dim: #8b97b3;
    --accent: #38bdf8;
    --accent-strong: #0ea5e9;
    --accent-2: #8b5cf6;
    --ok: #34d399;
    --warn: #fbbf24;
    --danger: #f87171;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --shadow: 0 8px 24px rgba(2, 6, 20, 0.35);
    --sidebar-w: 240px;
    --topbar-h: 64px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

h1, h2, h3 {
    margin: 0 0 0.5rem;
    font-weight: 600;
}

a {
    color: var(--accent);
}

button, input, select {
    font: inherit;
    color: inherit;
}

button {
    background: linear-gradient(135deg, var(--accent-strong), var(--accent-2));
    border: none;
    color: #041017;
    font-weight: 600;
    padding: 0.6rem 1.1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    transition: filter 0.15s ease, transform 0.05s ease;
}

button:hover {
    filter: brightness(1.08);
}

button:active {
    transform: translateY(1px);
}

button.secondary {
    background: var(--panel-3);
    color: var(--text);
    border: 1px solid var(--border);
}

button.danger {
    background: rgba(248, 113, 113, 0.15);
    color: var(--danger);
    border: 1px solid rgba(248, 113, 113, 0.35);
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    filter: none;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text);
    padding: 0.4rem;
    border-radius: var(--radius-sm);
    width: 40px;
    height: 40px;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--panel-3);
    filter: none;
}

.icon {
    display: block;
    inline-size: 18px;
    block-size: 18px;
    flex-shrink: 0;
}

input, select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.65rem;
    width: 100%;
}

input:focus, select:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

input:disabled, select:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.hidden {
    display: none !important;
}

/* --- Login --- */

#login-view {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 2rem;
    width: min(380px, 100%);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.login-brand-mark {
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--accent-strong), var(--accent-2));
    color: #041017;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    margin-top: 1.25rem;
}

/* --- App shell --- */

#app-view {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    background: var(--panel);
    border-right: 1px solid var(--border);
    padding: 1.1rem 0.9rem;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 40;
    transition: transform 0.2s ease;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.5rem;
    padding: 0 0.4rem;
}

.brand-mark {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent-strong), var(--accent-2));
    color: #041017;
    font-weight: 800;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.brand-name {
    font-weight: 700;
    letter-spacing: 0.02em;
}

.sidebar-close {
    margin-left: auto;
    display: none;
}

.nav-list {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    flex: 1;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    text-align: left;
    background: transparent;
    color: var(--text-dim);
    padding: 0.6rem 0.7rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
}

.nav-btn:hover {
    background: var(--panel-2);
    color: var(--text);
    filter: none;
}

.nav-btn.active {
    background: var(--panel-3);
    color: var(--text);
}

.nav-logout {
    width: 100%;
    justify-content: center;
    margin-top: 1rem;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 16, 0.6);
    z-index: 35;
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
    position: sticky;
    top: 0;
    z-index: 20;
}

#topbar-menu-btn {
    display: none;
}

.topbar-title {
    font-size: 1.1rem;
}

.topbar-spacer {
    flex: 1;
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-2), var(--accent-strong));
    color: #041017;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

main {
    flex: 1;
    padding: 1.25rem;
    overflow-y: auto;
    max-width: 100%;
}

@media (min-width: 640px) {
    main {
        padding: 1.5rem 2rem;
    }
}

/* --- Stat cards --- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.9rem;
    box-shadow: var(--shadow);
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon-purple { background: rgba(139, 92, 246, 0.18); color: var(--accent-2); }
.stat-icon-blue { background: rgba(56, 189, 248, 0.18); color: var(--accent); }
.stat-icon-amber { background: rgba(251, 191, 36, 0.18); color: var(--warn); }
.stat-icon-red { background: rgba(248, 113, 113, 0.18); color: var(--danger); }

.stat-label {
    margin: 0;
    font-size: 0.82rem;
    color: var(--text-dim);
}

.stat-value {
    margin: 0.1rem 0 0;
    font-size: 1.6rem;
    font-weight: 700;
}

/* --- Cards / forms --- */

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}

.row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: flex-end;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.field label {
    font-size: 0.8rem;
    color: var(--text-dim);
}

.checkbox-field label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text);
}

.checkbox-field input[type="checkbox"] {
    width: auto;
}

/* --- Tables --- */

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table th, .data-table td {
    text-align: left;
    padding: 0.65rem 0.7rem;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    color: var(--text-dim);
    font-weight: 500;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.data-table tbody tr {
    transition: background 0.1s ease;
}

.data-table tbody tr:hover {
    background: var(--panel-2);
}

.row-actions {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.row-actions button {
    padding: 0.4rem 0.7rem;
    font-size: 0.8rem;
}

.empty-state {
    color: var(--text-dim);
    text-align: center;
    padding: 1.5rem 0 0.25rem;
    margin: 0;
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge.ok { background: rgba(52, 211, 153, 0.15); color: var(--ok); }
.badge.warn { background: rgba(251, 191, 36, 0.15); color: var(--warn); }
.badge.danger { background: rgba(248, 113, 113, 0.15); color: var(--danger); }

.msg {
    font-size: 0.85rem;
    margin-top: 0.6rem;
}

.msg.ok { color: var(--ok); }
.msg.error { color: var(--danger); }

.table-wrap {
    overflow-x: auto;
}

/* --- Toasts --- */

.toast-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 100;
    max-width: min(340px, calc(100vw - 2rem));
}

.toast {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 0.7rem 0.9rem;
    font-size: 0.85rem;
    box-shadow: var(--shadow);
    animation: toast-in 0.15s ease;
}

.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--danger); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Responsive: sidebar becomes an off-canvas drawer --- */

@media (max-width: 959px) {
    .sidebar {
        width: min(82vw, 280px);
        max-width: calc(100vw - 24px);
        height: 100dvh;
        overflow-y: auto;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow);
    }

    .sidebar-close {
        display: inline-flex;
    }

    .app-main {
        margin-left: 0;
    }

    #topbar-menu-btn {
        display: inline-flex;
    }
}

/* --- Responsive: tables collapse into stacked cards --- */

@media (max-width: 720px) {
    .data-table thead {
        display: none;
    }

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

    .data-table tr {
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: 0.75rem;
        padding: 0.4rem 0.7rem;
        background: var(--panel-2);
    }

    .data-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.75rem;
        border-bottom: 1px dashed var(--border);
        padding: 0.5rem 0;
        text-align: right;
    }

    .data-table td:last-child {
        border-bottom: none;
    }

    .data-table td::before {
        content: attr(data-label);
        color: var(--text-dim);
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        text-align: left;
        flex-shrink: 0;
    }

    .data-table td.cell-actions {
        justify-content: flex-end;
    }

    .data-table td.cell-actions::before {
        content: none;
    }

    .row-actions {
        justify-content: flex-end;
        width: 100%;
    }
}

@media (max-width: 520px) {
    body {
        overflow-x: hidden;
    }

    .app-main {
        width: 100%;
        min-width: 0;
    }

    .topbar {
        height: 56px;
        padding: 0 0.85rem;
    }

    .topbar-title {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    main {
        padding: 0.85rem;
    }

    .sidebar {
        padding: 0.9rem 0.75rem;
    }

    .sidebar .icon,
    .topbar .icon,
    button .icon {
        inline-size: 18px;
        block-size: 18px;
        max-inline-size: 18px;
        max-block-size: 18px;
    }

    .sidebar-close,
    #topbar-menu-btn {
        width: 40px;
        height: 40px;
        padding: 0;
        background: transparent;
        color: var(--text);
    }

    .brand {
        margin-bottom: 1rem;
    }

    .nav-btn {
        min-height: 44px;
        padding: 0.65rem 0.7rem;
        gap: 0.65rem;
    }

    .stat-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .stat-card,
    .card {
        border-radius: var(--radius);
        padding: 0.9rem;
    }

    .row {
        flex-direction: column;
        align-items: stretch;
    }

    .row > .field,
    .row > button {
        width: 100%;
    }

    #dashboard-days {
        width: 100% !important;
    }

    .toast-container {
        left: 0.85rem;
        right: 0.85rem;
        bottom: 0.85rem;
    }
}
/* --- Premium admin polish --- */
.brand-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.brand-copy small,
.eyebrow,
.muted {
    color: var(--text-dim);
}

.brand-copy small {
    font-size: 0.72rem;
}

.page-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.1rem;
}

.page-heading h2 {
    margin-bottom: 0;
    font-size: 1.35rem;
}

.eyebrow {
    margin: 0 0 0.25rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.compact-filters {
    padding: 1rem;
}

.client-workspace {
    display: grid;
    grid-template-columns: minmax(340px, 0.85fr) minmax(420px, 1.35fr);
    gap: 1rem;
    align-items: start;
}

.client-list-card,
.client-profile-card {
    margin-bottom: 1rem;
}

.list-toolbar,
.detail-header,
.section-title-row,
.modal-header,
.modal-actions {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 0.75rem;
}

.list-toolbar {
    margin-bottom: 0.85rem;
}

.list-toolbar .field {
    flex: 1;
}

.selectable-row {
    cursor: pointer;
}

.selectable-row.selected,
.selectable-row.selected:hover {
    background: rgba(56, 189, 248, 0.12);
    outline: 1px solid rgba(56, 189, 248, 0.4);
    outline-offset: -1px;
}

.soft-pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.12);
    color: var(--text);
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.warn-pill {
    color: var(--warn);
    background: rgba(251, 191, 36, 0.12);
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.empty-detail {
    min-height: 220px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 120;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(2, 6, 16, 0.68);
}

.modal-card {
    width: min(520px, 100%);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.25rem;
}

.modal-header {
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

.modal-actions {
    justify-content: flex-end;
    margin-top: 1.1rem;
}

@media (max-width: 1180px) {
    .client-workspace,
    .detail-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .page-heading,
    .list-toolbar,
    .detail-header,
    .modal-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .client-workspace {
        gap: 0.75rem;
    }

    .row-actions button {
        justify-content: center;
        flex: 1 1 120px;
    }
}
