:root {
    --bg: #f8fafc;
    --card: #fff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --primary: #0891b2;
    --primary-dark: #0e7490;
    --danger: #e11d48;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}
a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1100px; margin: 0 auto; padding: 0 1rem; }
.main { padding: 2rem 1rem 3rem; }
.guest { background: linear-gradient(180deg, #ecfeff 0%, var(--bg) 40%); min-height: 100vh; }
.guest-main { padding: 3rem 1rem; max-width: 480px; }

.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: .75rem 0;
    box-shadow: 0 1px 0 rgba(15, 23, 42, .04);
}
.topbar-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .75rem 1.25rem;
}
.brand-block {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    min-width: 0;
    flex: 0 1 auto;
}
.brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    line-height: 0;
}
.brand:hover { text-decoration: none; opacity: .92; }
.brand-sub { font-size: .8rem; color: var(--muted); }
.site-logo {
    height: var(--logo-h-header, 52px);
    max-height: var(--logo-h-header, 52px);
    width: auto;
    max-width: min(280px, 55vw);
    display: block;
    border-radius: 8px;
    object-fit: contain;
}
.site-logo--small { height: var(--logo-h-footer, 36px); max-width: 180px; }
.site-logo--guest { height: var(--logo-h-guest, 100px); max-width: min(280px, 90vw); margin: 0 auto; }
.guest-logo { text-align: center; margin: 0 0 1.5rem; }
.guest-logo a { display: inline-block; text-decoration: none; }
.guest-logo a:hover { opacity: .92; }
.footer-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
}
.footer-logo { line-height: 0; text-decoration: none; }
.footer-logo:hover { opacity: .92; }
.nav {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem .8rem;
    align-items: center;
    justify-content: flex-end;
    flex: 1 1 auto;
}
.nav a {
    padding: .35rem 0;
    white-space: nowrap;
    line-height: 1.2;
}
.nav a.active { font-weight: 600; color: var(--primary-dark); }
.nav .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.25rem;
    padding: .5rem .95rem;
    line-height: 1;
}
.nav .btn-small {
    font-size: .88rem;
}
.language-switcher {
    display: inline-flex;
    align-items: center;
    gap: .15rem;
    padding: .15rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #f8fafc;
    min-height: 2.25rem;
}
.language-switcher a {
    min-width: 2.15rem;
    padding: .32rem .52rem;
    border-radius: 999px;
    text-align: center;
    font-size: .78rem;
    font-weight: 700;
    color: var(--muted);
    text-decoration: none;
}
.language-switcher a.active {
    background: var(--primary);
    color: #fff;
}
.guest-language {
    display: flex;
    justify-content: center;
    margin: -0.5rem 0 1rem;
}
@media (min-width: 768px) {
    .brand-block {
        flex-direction: row;
        align-items: center;
        gap: .75rem;
    }
    .brand-sub { margin: 0; white-space: nowrap; }
}
@media (max-width: 640px) {
    .topbar-inner {
        align-items: flex-start;
    }
    .nav {
        width: 100%;
        justify-content: flex-start;
    }
}

.footer {
    border-top: 1px solid var(--border);
    padding: 1.5rem 0;
    color: var(--muted);
    font-size: .9rem;
}

.hero-logo { margin: 0 0 1.25rem; line-height: 0; }
.site-logo--hero { height: var(--logo-h-hero, 110px); max-width: min(320px, 92vw); }
.hero {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 1.25rem;
    padding: 2rem;
    margin-bottom: 2rem;
}
.hero h1 { margin: 0 0 .75rem; font-size: 2rem; }
.hero-lead {
    font-size: 1.15rem;
    color: var(--text);
    font-weight: 500;
    margin: 0 0 1rem;
    line-height: 1.5;
}
.hero p { color: var(--muted); margin: 0 0 .75rem; max-width: 42rem; }
.hero p:last-of-type { margin-bottom: 0; }
.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem 1rem;
    margin-top: 1.5rem;
}

h1 { margin: 0 0 1rem; font-size: 1.65rem; line-height: 1.25; }
.page-lead { margin: -.25rem 0 1.25rem; color: var(--muted); }

.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.25rem;
}
.card h2, .card h3 { margin-top: 0; }

.btn {
    display: inline-block;
    background: var(--text);
    color: #fff !important;
    border: none;
    border-radius: 999px;
    padding: .65rem 1.25rem;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none !important;
}
.btn:hover { opacity: .9; }
.btn-primary { background: var(--primary); }
.btn-danger { background: var(--danger); }
.btn-small { padding: .4rem .9rem; font-size: .85rem; }
.btn-outline {
    background: transparent;
    color: var(--text) !important;
    border: 1px solid var(--border);
}

label { display: block; font-size: .9rem; font-weight: 500; margin-bottom: .35rem; }
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]),
select,
textarea {
    width: 100%;
    padding: .6rem .75rem;
    border: 1px solid var(--border);
    border-radius: .6rem;
    font: inherit;
    margin-bottom: 1rem;
}
input[type="checkbox"],
input[type="radio"] {
    width: 1.125rem !important;
    height: 1.125rem !important;
    min-width: 1.125rem;
    min-height: 1.125rem;
    max-width: 1.125rem;
    margin: 0 !important;
    padding: 0 !important;
    border: none;
    border-radius: .25rem;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
    display: inline-block;
    vertical-align: middle;
}
textarea { min-height: 100px; resize: vertical; }

.alert {
    padding: .75rem 1rem;
    border-radius: .6rem;
    margin-bottom: 1rem;
}
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: #fff1f2; color: #9f1239; border: 1px solid #fecdd3; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -0.25rem; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; min-width: 520px; }
th, td { padding: .75rem .65rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; }
td code {
    font-size: .8rem;
    background: #f1f5f9;
    padding: .15rem .4rem;
    border-radius: .35rem;
}
td.actions {
    white-space: nowrap;
    min-width: 11rem;
}
td.actions .action-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: .35rem;
}

.badge {
    display: inline-block;
    padding: .2rem .55rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    background: #f1f5f9;
}
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-approved { background: #d1fae5; color: #065f46; }
.badge-rejected { background: #ffe4e6; color: #9f1239; }
.badge-invoice-draft { background: #f1f5f9; color: #475569; }
.badge-invoice-sent { background: #dbeafe; color: #1e40af; }
.badge-invoice-paid { background: #d1fae5; color: #065f46; }

td.num, th.num { text-align: right; }
.totals-table { width: 100%; max-width: 280px; margin-left: auto; }
.totals-table td { padding: .35rem 0; border: none; }
.totals-table td.num { text-align: right; }
.totals-table tr.total-row td { border-top: 2px solid var(--border); padding-top: .5rem; }

.timer-active {
    background: #0f172a;
    color: #fff;
    border-radius: 1rem;
    padding: 1.5rem;
}
.timer-active h3 { margin-top: 0; }
.work-session-active {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, .15);
}
.work-session-active:first-of-type { margin-top: .75rem; padding-top: 0; border-top: none; }
.work-session-time { font-size: .9rem; opacity: .9; margin: .35rem 0 .75rem; }
.timer-live { font-weight: 600; color: #67e8f9; }
.work-stop-form { margin-top: .5rem; }
.work-stop-label { color: #cbd5e1 !important; font-size: .85rem; }
.work-stop-input {
    margin-bottom: .5rem !important;
    background: rgba(255, 255, 255, .08);
    border-color: rgba(255, 255, 255, .2);
    color: #fff;
}
.work-grid { align-items: stretch; }

.stats { display: flex; gap: 1rem; flex-wrap: wrap; }
.stat { flex: 1; min-width: 140px; background: #ecfeff; border-radius: .75rem; padding: 1rem; }
.stat strong { display: block; font-size: 1.5rem; }

.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.muted { color: var(--muted); font-size: .85rem; }

.detail-list { margin: 0; }
.detail-list dt {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    margin-top: .75rem;
}
.detail-list dt:first-child { margin-top: 0; }
.detail-list dd { margin: .15rem 0 0; }

.agreement-log { margin-top: .5rem; }
.log-entry {
    border: 1px solid var(--border);
    border-radius: .75rem;
    padding: 1rem;
    margin-bottom: 1rem;
    background: #fafbfc;
}
.log-entry-meta { font-size: .9rem; margin-bottom: .5rem; }
.log-entry-body { white-space: pre-wrap; }
.log-add-form { margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }
.log-edit-form textarea { margin-bottom: .5rem; }

.placeholder-box {
    margin-bottom: 1.25rem;
    border: 1px solid var(--border);
    border-radius: .65rem;
    background: #f8fafc;
    overflow: hidden;
}
.placeholder-box summary {
    cursor: pointer;
    padding: .65rem .85rem;
    font-weight: 600;
    font-size: .9rem;
    list-style-position: outside;
}
.placeholder-box[open] summary { border-bottom: 1px solid var(--border); margin-bottom: 0; }
.placeholder-list {
    font-size: .85rem;
    margin: 0;
    padding: .75rem .85rem .85rem 1.5rem;
}
.placeholder-list li { margin-bottom: .35rem; }
.placeholder-list li:last-child { margin-bottom: 0; }
.placeholder-list code {
    font-size: .8rem;
    background: #fff;
    padding: .1rem .35rem;
    border-radius: .3rem;
    border: 1px solid var(--border);
}

.placeholder-chips {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin: 0 0 1rem;
}
.placeholder-chip {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .78rem;
    padding: .35rem .55rem;
    border: 1px solid var(--border);
    border-radius: .45rem;
    background: #f8fafc;
    color: var(--primary-dark);
    cursor: pointer;
    line-height: 1.2;
}
.placeholder-chip:hover {
    background: #ecfeff;
    border-color: #99f6e4;
}
.placeholder-live-preview {
    margin: -.25rem 0 1rem;
    padding: .65rem .85rem;
    background: #f0fdfa;
    border: 1px solid #99f6e4;
    border-radius: .5rem;
    font-size: .9rem;
}

.template-editor {
    display: grid;
    gap: 1.5rem;
    align-items: start;
}
@media (min-width: 960px) {
    .template-editor {
        grid-template-columns: minmax(0, 1fr) minmax(300px, 38%);
    }
    .template-editor-preview {
        position: sticky;
        top: 1rem;
        max-height: calc(100vh - 7rem);
        overflow: auto;
    }
}
.template-editor .card form { margin-top: 0; }
.template-editor textarea#body { min-height: 280px; }
.form-meta-hint {
    margin: -.65rem 0 1rem;
    font-size: .85rem;
    color: var(--muted);
}
.form-meta-hint code {
    font-size: .8rem;
    background: #f1f5f9;
    padding: .1rem .35rem;
    border-radius: .3rem;
}
.form-actions-bar {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
    margin-top: .5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
fieldset.form-fieldset {
    border: 1px solid var(--border);
    border-radius: .75rem;
    padding: 1rem 1.1rem;
    margin: 0 0 1rem;
}
fieldset.form-fieldset legend {
    padding: 0 .35rem;
    font-weight: 600;
    font-size: .95rem;
}
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    margin: .25rem 0 1rem;
    padding: .75rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: .65rem;
}
.checkbox-group--flat {
    padding: 0;
    background: transparent;
    border: none;
    margin-bottom: 1rem;
}
.checkbox-option {
    display: grid;
    grid-template-columns: 1.25rem minmax(0, 1fr);
    column-gap: .65rem;
    align-items: center;
    margin: 0;
    padding: .6rem .7rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: .5rem;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
.checkbox-option:hover {
    border-color: #94a3b8;
    background: #f0fdfa;
}
.checkbox-option input[type="checkbox"] {
    grid-column: 1;
    grid-row: 1;
    place-self: center start;
}
.checkbox-option label {
    grid-column: 2;
    grid-row: 1;
    margin: 0 !important;
    padding: 0;
    font-weight: 400;
    font-size: .9rem;
    line-height: 1.45;
    cursor: pointer;
}
td.actions form { margin: 0; }
.btn-link {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: var(--primary-dark);
    cursor: pointer;
    text-decoration: underline;
}
.btn-link-danger { color: var(--danger); }
.email-preview {
    background: #f1f5f9;
    border: 1px solid var(--border);
    border-radius: .5rem;
    padding: 1rem;
    white-space: pre-wrap;
    font-size: .9rem;
    line-height: 1.55;
    margin: .5rem 0 0;
    max-height: 420px;
    overflow: auto;
}
.preview-subject {
    margin: .75rem 0 0;
    padding: .65rem .85rem;
    background: #ecfeff;
    border: 1px solid #a5f3fc;
    border-radius: .5rem;
    font-size: .95rem;
}
.card-spaced { margin-bottom: 1.5rem; }
.card-muted { margin-top: 1.5rem; background: #f8fafc; }
.sub-form { margin-top: 1rem; }
.sub-form input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.sub-form select,
.sub-form textarea { margin-bottom: .75rem; }
.sub-form .checkbox-group { margin-bottom: .75rem; }

.invoice-send-card {
    background: #f0fdfa;
    border-color: #99f6e4;
}
.email-preview-box {
    margin: 1rem 0;
    border: 1px solid var(--border);
    border-radius: .65rem;
    background: #fff;
    overflow: hidden;
}
.email-preview-box summary {
    cursor: pointer;
    padding: .65rem .85rem;
    font-weight: 600;
    font-size: .9rem;
    background: #f8fafc;
}
.email-preview-box[open] .email-preview {
    margin: 0 .85rem .85rem;
}
.invoice-preview-box {
    padding: 1rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: .75rem;
    font-size: .95rem;
    line-height: 1.5;
}
.site-logo--invoice-preview { margin-bottom: .75rem; }

.credentials-box code {
    font-size: 1rem;
    word-break: break-all;
}
