:root {
    --ink: #14221f;
    --muted: #5c6f69;
    --paper: #f3eee4;
    --panel: #fffdf8;
    --invoice-paper: #ffffff;
    --line: #e4d9c8;
    --teal: #1f6f63;
    --teal-dark: #12352f;
    --coral: #d96b4c;
    --income: #1f6f63;
    --shadow: 0 12px 32px rgba(18, 53, 47, 0.08);
    --radius: 18px;
    --sidebar: 240px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    font-family: "Segoe UI", "Helvetica Neue", sans-serif;
    color: var(--ink);
    background: var(--paper);
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2 { margin: 0 0 0.4rem; font-weight: 650; letter-spacing: -0.02em; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.05rem; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar);
    background: var(--teal-dark);
    color: #f7f1e6;
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.brand {
    color: #fff;
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: -0.03em;
    margin: 0 0.6rem 1rem;
}

.nav-link {
    display: block;
    color: #d7ece7;
    padding: 0.65rem 0.8rem;
    border-radius: 12px;
}

.nav-link:hover,
.nav-link.is-active {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    text-decoration: none;
}

.nav-children {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    margin: 0.1rem 0 0.45rem 0.55rem;
}

.nav-link.nav-child {
    padding: 0.4rem 0.75rem;
    font-size: 0.88rem;
    color: #b7d4ce;
}

.nav-link.nav-child.is-active {
    background: rgba(255, 255, 255, 0.14);
}

.logout-form { margin-top: auto; }
.logout-form button {
    width: 100%;
    background: transparent;
    color: #d7ece7;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 12px;
    padding: 0.6rem;
    cursor: pointer;
}

.content {
    margin-left: var(--sidebar);
    padding: 2rem;
    max-width: 1200px;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.4rem;
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.72rem;
    color: var(--muted);
    margin: 0 0 0.3rem;
}

.muted { color: var(--muted); font-size: 0.9rem; }

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

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

.stat-card { padding: 1rem 1.1rem; }
.stat-card p { margin: 0; color: var(--muted); font-size: 0.85rem; }
.stat-card strong { display: block; font-size: 1.4rem; margin-top: 0.35rem; }

.panel { padding: 1.1rem 1.2rem; margin-bottom: 1.2rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.7rem; }

.split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

th, td {
    text-align: left;
    padding: 0.65rem 0.4rem;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.row-menu-col {
    width: 1%;
    text-align: right;
    white-space: nowrap;
}
.row-menu {
    position: relative;
    display: inline-block;
}
.row-menu-toggle {
    list-style: none;
    cursor: pointer;
    width: 2rem;
    height: 2rem;
    border-radius: 999px;
    display: grid;
    place-items: center;
    color: var(--ink);
}
.row-menu-toggle::-webkit-details-marker,
.row-menu-toggle::marker { display: none; content: ''; }
.row-menu-toggle:hover,
.row-menu[open] .row-menu-toggle { background: var(--line); }
.row-menu-dots {
    display: grid;
    gap: 0.16rem;
    justify-items: center;
}
.row-menu-dots span {
    width: 0.28rem;
    height: 0.28rem;
    border-radius: 999px;
    background: currentColor;
}
.row-menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 0.2rem);
    min-width: 9.5rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    z-index: 8;
    padding: 0.3rem;
    text-align: left;
}
.row-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    color: var(--ink);
    font: inherit;
}
.row-menu-item:hover { background: var(--paper); text-decoration: none; }
.row-menu-item.is-danger { color: #8a3b24; }

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
    align-items: end;
}

label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.82rem;
    color: var(--muted);
}

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

input, select, textarea {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.55rem 0.7rem;
    background: #fff;
    min-width: 10rem;
}

textarea {
    min-width: 0;
    width: 100%;
    resize: vertical;
}

.button, button[type="submit"].button {
    background: var(--teal);
    color: #fff;
    border: 0;
    border-radius: 999px;
    padding: 0.65rem 1.1rem;
    cursor: pointer;
    display: inline-block;
}

.button:hover { text-decoration: none; filter: brightness(1.05); }
.button.ghost {
    background: transparent;
    color: var(--teal-dark);
    border: 1px solid var(--line);
}
.button.danger {
    color: #8a3b24;
    border-color: #f3c4b8;
}

.fy-switch { display: flex; gap: 0.5rem; }

.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--line);
}

.pill {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: var(--line);
    font-size: 0.8rem;
    text-transform: capitalize;
}

.pill-paid { background: #d8efe8; color: var(--teal-dark); }
.pill-sent { background: #fbe3d8; color: #8a3b24; }

.hero-amount { font-size: 1.8rem; font-weight: 700; margin: 0; }

.meta { display: grid; gap: 0.6rem 1.2rem; }
.meta.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.meta dt { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.meta dd { margin: 0.15rem 0 0; }

.notes { white-space: pre-wrap; }

.preview, .preview-image {
    width: 100%;
    border: 0;
    border-radius: 12px;
    background: #eee;
}

.preview { height: 480px; }
.preview.tall { height: 720px; }
.preview-image { max-height: 720px; object-fit: contain; }

.pagination { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 1rem; }
.pagination a {
    min-width: 2rem;
    text-align: center;
    padding: 0.3rem 0.45rem;
    border-radius: 8px;
    border: 1px solid var(--line);
    color: var(--ink);
}
.pagination a.is-current { background: var(--teal); color: #fff; border-color: var(--teal); }

.tabs { display: flex; gap: 0.5rem; margin: 0 0 1rem; flex-wrap: wrap; }
.tabs a {
    padding: 0.45rem 0.9rem;
    border-radius: 999px;
    background: #fff;
    border: 1px solid var(--line);
    color: var(--ink);
}
.tabs a.is-active { background: var(--teal-dark); color: #fff; border-color: var(--teal-dark); }

.report-periods { margin: 0 0 1rem; }
.report-periods-label {
    margin: 0 0 0.45rem;
    font-size: 0.82rem;
    color: var(--muted);
}

.report-lines { margin: 0; }
.report-lines div {
    display: flex;
    justify-content: space-between;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--line);
}
.report-lines .is-total { font-weight: 700; }

.flash {
    padding: 0.75rem 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
}
.flash[hidden] {
    display: none;
}
.flash-error { background: #fde8e4; color: #8a3b24; }
.flash-success { background: #d8efe8; color: var(--teal-dark); }
.pill-draft { background: #e8efe4; color: var(--teal-dark); }

.checkbox {
    flex-direction: row;
    align-items: center;
    gap: 0.45rem;
    min-width: auto;
}
.checkbox input { min-width: 0; width: auto; }

.timer-start, .timer-manual, .timer-running {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: end;
}
.timer-running {
    justify-content: space-between;
    align-items: center;
}
.timer-running-meta {
    display: grid;
    gap: 0.4rem;
    min-width: min(100%, 22rem);
}
.timer-running-meta label {
    margin: 0;
}
.timer-entries {
    table-layout: fixed;
}

.timer-entries th,
.timer-entries td {
    vertical-align: middle;
}

.timer-col-description {
    font-size: 0.82rem;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.timer-col-duration,
.timer-col-rate,
.timer-col-total,
.timer-col-status,
.timer-col-actions {
    white-space: nowrap;
}

.timer-col-project { width: 8.5rem; }
.timer-col-duration { width: 5rem; font-variant-numeric: tabular-nums; }
.timer-col-rate { width: 5.2rem; }
.timer-col-total { width: 5.6rem; }
.timer-col-status { width: 8rem; }
.timer-col-actions { width: 6rem; }

.timer-entries td.timer-col-rate {
    font-size: 0.75rem;
}

.timer-project-cell {
    display: grid;
    gap: 0.28rem;
    justify-items: start;
    min-width: 0;
}
.timer-project-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.timer-actions {
    display: flex;
    gap: 0.55rem;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: nowrap;
}
.timer-play {
    width: 1.7rem;
    height: 1.7rem;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: var(--teal);
    color: #fff;
    cursor: pointer;
    display: inline-grid;
    place-items: center;
    flex-shrink: 0;
}
.timer-play:hover { filter: brightness(1.05); }
.timer-play-icon {
    width: 0.68rem;
    height: 0.68rem;
    margin-left: 0.1rem;
}
.timer-clock {
    font-size: 1.6rem;
    font-weight: 700;
    margin: 0;
    font-variant-numeric: tabular-nums;
}
.timer-day-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem 1.2rem;
    flex-wrap: wrap;
    margin-bottom: 0.7rem;
}
.timer-day-head h2 { margin-bottom: 0; }
.timer-day-totals {
    margin: 0;
    font-variant-numeric: tabular-nums;
}

.timer-projects {
    display: grid;
    gap: 1.4rem;
}
.timer-project-client {
    display: grid;
    gap: 0.7rem;
    padding-bottom: 1.1rem;
    border-bottom: 1px solid var(--line);
}
.timer-project-client:last-of-type { border-bottom: 0; padding-bottom: 0; }
.timer-project-client-head,
.timer-project-row,
.timer-project-edit {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    align-items: end;
}
.timer-project-edit { flex: 1 1 18rem; }
.timer-project-client-head input,
.timer-project-edit input { min-width: 8rem; }
.timer-projects h3 { margin: 1.1rem 0 0.4rem; }

body:has(.slide-over.is-open) {
    overflow: hidden;
}

.slide-over {
    position: fixed;
    inset: 0;
    z-index: 40;
    pointer-events: none;
    visibility: hidden;
    transition: visibility 0s linear 0.3s;
}

.slide-over.is-open {
    pointer-events: auto;
    visibility: visible;
    transition-delay: 0s;
}

.slide-over-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(18, 53, 47, 0.45);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.slide-over-backdrop:hover {
    text-decoration: none;
}

.slide-over.is-open .slide-over-backdrop {
    opacity: 1;
}

.slide-over-panel {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: min(28rem, 100%);
    height: 100%;
    overflow-y: auto;
    padding: 1.4rem 1.3rem 1.8rem;
    background: var(--panel);
    box-shadow: -16px 0 40px rgba(18, 53, 47, 0.18);
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.slide-over.is-open .slide-over-panel {
    transform: translateX(0);
}

.slide-over-panel.is-wide {
    width: min(36rem, 100%);
}
.slide-over-panel .form-grid input,
.slide-over-panel .form-grid select,
.slide-over-panel .form-grid textarea {
    min-width: 0;
}
.slide-over-panel .form-actions {
    margin-bottom: 0;
}
button.slide-over-backdrop {
    border: 0;
    padding: 0;
    cursor: pointer;
}

@keyframes expense-row-in {
    from { background: #d8efe8; }
    to { background: transparent; }
}
.expense-row-new td {
    animation: expense-row-in 1.4s ease;
}

.slide-over-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}

.slide-over-head h2 {
    margin: 0;
}

.slide-over-panel .stack input,
.slide-over-panel .stack select {
    width: 100%;
    min-width: 0;
}

@media (prefers-reduced-motion: reduce) {
    .slide-over,
    .slide-over-backdrop,
    .slide-over-panel {
        transition: none;
    }
}

.login-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, #2a8f7e 0, transparent 40%),
        var(--teal-dark);
}

.login-card {
    width: min(420px, calc(100% - 2rem));
    padding: 2rem;
}

.brand-mark { font-weight: 700; color: var(--teal); margin: 0 0 0.4rem; }
.lede { color: var(--muted); }
.stack { display: grid; gap: 0.9rem; }
.stack input { width: 100%; min-width: 0; }

.nav-toggle { display: none; }

.bar-chart,
#fy-chart,
#timer-day-chart { width: 100%; display: block; }
#timer-day-chart { margin-top: 0.6rem; }

@media (max-width: 960px) {
    .stat-grid, .split, .meta.three { grid-template-columns: 1fr; }
    .nav-toggle {
        display: block;
        position: fixed;
        top: 0.8rem;
        left: 0.8rem;
        z-index: 20;
        background: var(--teal-dark);
        color: #fff;
        border: 0;
        border-radius: 999px;
        padding: 0.5rem 0.9rem;
    }
    .sidebar {
        transform: translateX(-105%);
        transition: transform 0.2s ease;
        z-index: 15;
    }
    .sidebar.is-open { transform: none; }
    .content { margin-left: 0; padding: 4rem 1rem 1.5rem; }
}

.client-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    color: inherit;
    max-width: 100%;
}
.client-badge:hover { text-decoration: none; }
.client-badge-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
a.client-badge:hover .client-badge-name { text-decoration: underline; }
.client-avatar {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 1.85rem;
    height: 1.85rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    overflow: hidden;
    letter-spacing: 0.02em;
}
.client-badge-lg .client-avatar {
    width: 3rem;
    height: 3rem;
    font-size: 1rem;
}
.client-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.client-title { margin: 0.2rem 0 0.3rem; font-size: inherit; font-weight: inherit; }
.client-title .client-badge-name { font-size: 1.8rem; font-weight: 650; letter-spacing: -0.02em; }
.client-accent {
    height: 6px;
    border-radius: 999px;
    margin: -0.4rem 0 1.2rem;
}
.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    justify-content: flex-end;
    align-items: center;
}
.row-actions .button,
.row-actions button {
    padding: 0.35rem 0.85rem;
}
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.9rem 1rem;
}
.form-grid .span-2 { grid-column: 1 / -1; }
.form-grid input,
.form-grid textarea,
.form-grid select { width: 100%; min-width: 0; }
.expense-form input[type="file"] { min-width: 0; width: 100%; }
.expense-form .form-grid .checkbox { justify-content: flex-start; margin-top: 1.7rem; }
.identity-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.2rem;
}
.color-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0.4rem 0 0.8rem;
}
.color-swatch {
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 999px;
    border: 2px solid transparent;
    padding: 0;
    cursor: pointer;
}
.color-swatch.is-selected { border-color: var(--ink); }
.avatar-upload {
    display: grid;
    gap: 0.7rem;
    justify-items: start;
}
.contact-list { display: grid; gap: 0.75rem; }
.contact-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr auto;
    gap: 0.6rem;
    align-items: end;
}
.form-actions {
    display: flex;
    gap: 0.6rem;
    margin-bottom: 1.5rem;
}
.client-form .stack input,
.client-form input[type="color"] { min-width: 0; }

@media (max-width: 960px) {
    .form-grid, .identity-row, .contact-row { grid-template-columns: 1fr; }
}

.stack textarea { width: 100%; min-width: 0; }

.line-editor input,
.line-editor select {
    min-width: 0;
    width: 100%;
}

.invoice-document {
    background: var(--invoice-paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.4rem 1.5rem;
    margin-bottom: 1.2rem;
}

.invoice-letterhead {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.2rem;
    margin-bottom: 1.4rem;
}

.invoice-notes {
    margin: 0 0 1.4rem;
}

.invoice-col-description {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.invoice-col-time,
.invoice-col-rate,
.invoice-col-amount {
    white-space: nowrap;
    width: 1%;
}

.invoice-form .invoice-col-time input,
.invoice-form .invoice-col-rate input,
.invoice-form .invoice-col-amount input {
    min-width: 4.5rem;
    width: 5.25rem;
}

.invoice-col-discount-type {
    width: 1%;
}

.invoice-col-remove {
    width: 1%;
    white-space: nowrap;
}

.invoice-col-remove .button {
    padding: 0.25rem 0.7rem;
    font-size: 0.8rem;
}

.invoice-form .invoice-col-discount-type select {
    min-width: 8.5rem;
    width: 10rem;
}

.report-lines .is-discount dd {
    color: var(--muted);
}

.invoice-logo {
    max-width: 220px;
    max-height: 80px;
    object-fit: contain;
    margin-bottom: 0.6rem;
}

.print-body {
    margin: 0;
    background: var(--invoice-paper);
}

.print-body .print-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 900px;
    margin: 1rem auto;
    padding: 0 1rem;
}

.print-body .invoice-document {
    max-width: 900px;
    margin: 0 auto 2rem;
    background: var(--invoice-paper);
    box-shadow: var(--shadow);
}

@media print {
    .print-toolbar, .nav-toggle, .no-print { display: none !important; }
    html, body, .print-body, .invoice-document {
        background: #fff !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }
    .invoice-document {
        border: 0;
        box-shadow: none;
        border-radius: 0;
        margin: 0;
        padding: 0;
    }
}

@media (max-width: 960px) {
    .invoice-letterhead { grid-template-columns: 1fr; }
}

fieldset.filters {
    border: 0;
    padding: 0;
    margin: 0;
}

.recipient-list {
    display: grid;
    gap: 0.35rem;
    margin-bottom: 1rem;
}

.recipient-row {
    display: grid;
    gap: 0.45rem;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--line);
}

.recipient-row textarea { display: none; }
.recipient-row:has(input[type="checkbox"]:checked) textarea { display: block; }
