:root {
    /* Brand */
    --purple: #6B3FD4;
    --purple-bright: #9B7BEA;   /* accent text/active on dark */
    --purple-hover: #7C51E0;
    --coral: #F0705A;

    /* Dark surfaces */
    --bg: #0B0B0F;              /* app background (near black) */
    --surface: #16161C;         /* panels / cards */
    --surface-2: #1F1F28;       /* raised (hover, headers) */
    --sidebar: #101014;

    --text: #E7E8EC;
    --text-muted: #9A9CA6;
    --border: #2A2A33;

    --danger: #F0705A;
    --success: #37B47E;

    --radius: 6px;
    --gap: 1rem;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.40), 0 6px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.55);

    --sidebar-w: 250px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

/* ---- App shell: sidebar + content ---- */

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

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem 0.75rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.35rem 0.5rem 0.75rem;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    border-bottom: 1px solid var(--border);
}

.brand-mark {
    width: 1.75rem;
    height: 1.75rem;
    object-fit: contain;
    flex-shrink: 0;
}

.brand-name span { color: var(--purple-bright); }

.side-search { position: relative; }

.side-search input {
    width: 100%;
    margin: 0;
    padding: 0.5rem 0.7rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font: inherit;
    font-size: 0.875rem;
}

.side-nav { display: flex; flex-direction: column; gap: 0.15rem; }

.nav-section {
    margin: 1rem 0.5rem 0.35rem;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.nav-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.55rem 0.7rem;
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
}

.nav-item:hover { background: var(--surface); color: var(--text); }

.nav-item.active {
    background: linear-gradient(90deg, var(--purple), #7d4fe0);
    color: #FFFFFF;
    box-shadow: var(--shadow);
}

.nav-signout { color: var(--text-muted); }
.nav-signout:hover { color: var(--coral); background: var(--surface); }

.sidebar form { margin: 0; }

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

.topbar {
    height: 60px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.hamburger {
    display: none;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
}

.topbar-right { display: flex; align-items: center; gap: 0.6rem; margin-left: auto; }

.topbar-user { color: var(--text); font-weight: 600; font-size: 0.9rem; }

.topbar-avatar {
    width: 1.9rem;
    height: 1.9rem;
    border-radius: 50%;
    background: rgba(107, 63, 212, 0.22);
    color: var(--purple-bright);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
}

main {
    flex: 1;
    padding: 1.5rem 2rem 2.5rem;
    max-width: 1500px;
    width: 100%;
}

h1 { font-size: 1.375rem; margin: 0 0 1.25rem; font-weight: 600; }

/* ---- Tables ---- */

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

thead th {
    text-align: left;
    background: var(--surface-2);
    padding: 0.625rem 0.875rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 0.75rem 0.875rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

/* ---- Forms ---- */

form p { margin: 0 0 1rem; }

label {
    display: block;
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--text);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="search"],
select,
textarea {
    display: block;
    width: 100%;
    margin-top: 0.3125rem;
    padding: 0.5rem 0.625rem;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

input::placeholder, textarea::placeholder { color: var(--text-muted); }

/* dark dropdown options */
select option { background: var(--surface); color: var(--text); }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--purple-bright);
    box-shadow: 0 0 0 3px rgba(107, 63, 212, 0.25);
}

textarea { resize: vertical; }

/* ---- Buttons ---- */

button, .btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    font: inherit;
    font-weight: 600;
    color: #FFFFFF;
    background: var(--purple);
    border: 1px solid var(--purple);
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
}

button:hover, .btn:hover { background: var(--purple-hover); border-color: var(--purple-hover); }

/* ---- Links ---- */

a { color: var(--purple-bright); }

/* ---- Flash + errors ---- */

.flash {
    margin: 0 0 1.25rem;
    padding: 0.625rem 1rem;
    background: rgba(55, 180, 126, 0.12);
    border-left: 3px solid var(--success);
    color: var(--success);
    font-size: 0.875rem;
    border-radius: var(--radius);
    transition: opacity 0.4s ease;
}

.flash.flash-hide { opacity: 0; }

ul.errors {
    margin: 0 0 1.25rem;
    padding: 0.75rem 1rem 0.75rem 2rem;
    background: rgba(240, 112, 90, 0.12);
    border-left: 3px solid var(--coral);
    color: var(--coral);
    font-size: 0.875rem;
    border-radius: var(--radius);
}

/* ---- Page header bar (purple, like the reference title bar) ---- */

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--gap);
    margin-bottom: 1.25rem;
    padding: 0.85rem 1.25rem;
    background: linear-gradient(90deg, var(--purple), #7d4fe0);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.page-head h1 { margin: 0; color: #FFFFFF; font-size: 1.15rem; }

.page-head .btn {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.35);
    color: #FFFFFF;
}

.page-head .btn:hover { background: rgba(255, 255, 255, 0.26); border-color: rgba(255, 255, 255, 0.5); }

/* ---- Filter bar ---- */

.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
}

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

.filter label {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 700;
}

.filters select { width: auto; min-width: 9.5rem; margin-top: 0; }

.filters-clear { margin-left: auto; align-self: center; }

/* ---- Card (forms) ---- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    max-width: 560px;
}

.card form p:last-of-type { margin-bottom: 0; }

.form-actions {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-top: 1.5rem;
}

.btn-link {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 600;
}

.btn-link:hover { color: var(--text); text-decoration: underline; }

/* ---- Auth (login) ---- */

.auth {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background:
        radial-gradient(1200px 600px at 50% -10%, rgba(107, 63, 212, 0.25), transparent 60%),
        var(--bg);
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 3px solid var(--purple);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    padding: 2rem;
}

.auth-logo {
    display: block;
    height: 132px;
    width: auto;
    margin: 0.25rem auto 1rem;
}

.auth-sub { margin: 0 0 1.5rem; color: var(--text-muted); font-size: 0.875rem; text-align: center; }

.auth-card form p { margin: 0 0 1rem; }
.auth-card button[type="submit"] { width: 100%; margin-top: 0.5rem; }

.auth-alt {
    margin: 1rem 0 0;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.auth-alt a { color: var(--purple-bright); }
.auth-alt .btn-link { width: auto; padding: 0; }

.auth-hint {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin: -0.25rem 0 0.75rem;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 400;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.checkbox input { width: auto; margin: 0; }

/* ---- Sheet panel (tabs + table) ---- */

.sheet {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem 1.25rem 1.25rem;
}

.is-hidden { display: none; }

/* Month tabs */

.tab-strip {
    display: flex;
    gap: 0.25rem;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.tab-strip .tab {
    background: transparent;
    color: var(--text-muted);
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    padding: 0.6rem 0.9rem;
    margin-bottom: -1px;
    font: inherit;
    font-weight: 600;
    font-size: 0.875rem;
    white-space: nowrap;
    cursor: pointer;
    display: inline-flex;
    align-items: baseline;
    gap: 0.45rem;
}

.tab-strip .tab:hover { color: var(--text); }

.tab-strip .tab.tab-active {
    color: var(--purple-bright);
    border-bottom-color: var(--purple-bright);
}

.tab-count { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); }

.tab-panel { padding: 0; }

/* Client groups */

.client-group { margin-bottom: 1.75rem; }
.client-group:last-child { margin-bottom: 0; }

.client-group > summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    user-select: none;
}

.client-group > summary::-webkit-details-marker { display: none; }

.client-group > summary::before {
    content: "";
    width: 0;
    height: 0;
    border-left: 4px solid var(--purple-bright);
    border-top: 3px solid transparent;
    border-bottom: 3px solid transparent;
    transition: transform 0.15s ease;
    flex-shrink: 0;
}

.client-group[open] > summary::before { transform: rotate(90deg); }

.client-name {
    margin-right: auto;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--purple-bright);
}

.badge { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); }
.badge-overdue { color: var(--coral); }

/* Table inside a client group — purple header like the reference */

.client-group table { border: none; border-radius: var(--radius); box-shadow: none; background: transparent; overflow: hidden; }

.client-group thead th {
    background: linear-gradient(90deg, var(--purple), #7d4fe0);
    color: #FFFFFF;
    border-bottom: none;
    padding: 0.6rem 0.875rem;
}

.client-group tbody td {
    border-bottom: 1px solid var(--border);
    padding: 0.7rem 0.875rem;
}

.client-group tbody tr:last-child td { border-bottom: none; }
.client-group tbody tr:hover { background: var(--surface-2); }

.cell-title { font-weight: 600; }
.cell-due { white-space: nowrap; color: var(--text-muted); }

.client-group td.cell-actions,
.client-group th:last-child {
    width: 1%;
    text-align: right;
    white-space: nowrap;
}

/* Edit = filled action button; History = ghost */
.cell-actions a {
    display: inline-block;
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius);
    background: var(--purple);
    color: #FFFFFF;
    font-weight: 600;
    font-size: 0.8125rem;
    text-decoration: none;
}

.cell-actions a:hover { background: var(--purple-hover); }

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

/* Priority — quiet text, accent only at the urgent end */

.prio { font-size: 0.8125rem; }
.prio-low, .prio-medium { color: var(--text-muted); }
.prio-high { color: #F0956A; font-weight: 600; }
.prio-urgent { color: var(--coral); font-weight: 700; }

/* Status — colored dot + borderless inline select */

.status-control { display: inline-flex; align-items: center; gap: 0.45rem; }

.status-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}

.status-select {
    width: auto;
    min-width: 0;
    margin-top: 0;
    padding: 0.2rem 0.6rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text);
    background-color: transparent;
    border: 1px solid transparent;
    border-radius: 999px;
    cursor: pointer;
    transition: box-shadow 0.15s ease, background-color 0.15s ease, filter 0.15s ease;
}

.status-select:hover { filter: brightness(1.18); }

/* Pending — blue */
.status-pending .status-dot    { background: #4F9BFF; }
.status-pending .status-select {
    color: #8FBEFF;
    background: rgba(59, 130, 246, 0.16);
    border-color: rgba(59, 130, 246, 0.55);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.28);
}

/* In progress — yellow */
.status-in_progress .status-dot    { background: #F5C518; }
.status-in_progress .status-select {
    color: #F7D64F;
    background: rgba(245, 197, 24, 0.16);
    border-color: rgba(245, 197, 24, 0.55);
    box-shadow: 0 0 10px rgba(245, 197, 24, 0.26);
}

/* Blocked — orange */
.status-blocked .status-dot    { background: #F97316; }
.status-blocked .status-select {
    color: #FCA35C;
    background: rgba(249, 115, 22, 0.16);
    border-color: rgba(249, 115, 22, 0.55);
    box-shadow: 0 0 10px rgba(249, 115, 22, 0.26);
}

/* Done — green */
.status-done .status-dot    { background: #2FD08A; }
.status-done .status-select {
    color: #5AE3A6;
    background: rgba(47, 208, 138, 0.16);
    border-color: rgba(47, 208, 138, 0.55);
    box-shadow: 0 0 10px rgba(47, 208, 138, 0.26);
}

/* Cancelled — red */
.status-cancelled .status-dot    { background: #EF4444; }
.status-cancelled .status-select {
    color: #F98A8A;
    background: rgba(239, 68, 68, 0.14);
    border-color: rgba(239, 68, 68, 0.5);
    text-decoration: line-through;
}

/* Overdue cue */

.row-overdue .cell-due { color: var(--coral); font-weight: 600; }

/* History toggle + activity timeline */

.link-btn {
    background: none;
    border: none;
    padding: 0;
    margin: 0 0.9rem 0 0;
    font: inherit;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
}

.link-btn:hover { color: var(--purple-bright); text-decoration: underline; }

.activity-row td {
    background: var(--bg);
    padding: 0.75rem 0.875rem 0.9rem;
}

.activity-row td::before { display: none; }

.timeline {
    list-style: none;
    margin: 0;
    padding: 0 0 0 1rem;
    border-left: 1px solid var(--border);
}

.timeline li {
    position: relative;
    padding: 0.3rem 0 0.3rem 0.85rem;
    font-size: 0.8125rem;
    line-height: 1.5;
}

.timeline li::before {
    content: "";
    position: absolute;
    left: -0.32rem;
    top: 0.62rem;
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--purple-bright);
}

.tl-when { display: inline-block; min-width: 11rem; color: var(--text-muted); }
.tl-change { color: var(--text-muted); }

/* ---- Responsive ---- */

@media (max-width: 900px) {
    .hamburger { display: inline-block; }

    .sidebar {
        position: fixed;
        top: 0;
        left: calc(-1 * var(--sidebar-w) - 4px);
        bottom: 0;
        z-index: 40;
        transition: left 0.2s ease;
        box-shadow: var(--shadow-lg);
    }

    .app-shell.sidebar-open .sidebar { left: 0; }

    .app-shell.sidebar-open::after {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 30;
    }
}

@media (max-width: 720px) {
    main { padding: 1rem; }

    table, thead, tbody, tr, td { display: block; width: 100%; }

    thead { display: none; }

    table { border: none; background: transparent; }

    tbody tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: 0.75rem;
        padding: 0.25rem 0;
    }

    tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: var(--gap);
        border-bottom: 1px solid var(--border);
        padding: 0.625rem 0.875rem;
    }

    tbody td::before {
        content: attr(data-label);
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--text-muted);
        font-weight: 600;
        flex-shrink: 0;
    }

    tbody td select { width: auto; margin-top: 0; }

    .tab-strip .tab { padding: 0.45rem 0.7rem; }

    .activity-row td { display: block; }
    .tl-when { display: block; min-width: 0; }
}
