/* StitchBook — base design system, layout, controls and auth */
:root {
    --ink: #1c1917;
    --ink-2: #292524;
    --ink-3: #44403c;
    --cream: #f7f4ee;
    --paper: #fffdfa;
    --white: #ffffff;
    --gold: #b08d57;
    --gold-deep: #8a6a3b;
    --gold-soft: #f1e6d2;
    --rose: #9d5c63;
    --muted: #78716c;
    --line: #e8e1d6;
    --green: #2f7d5b;
    --green-soft: #e6f2ec;
    --amber: #a86a12;
    --amber-soft: #fbf0d9;
    --red: #b23b3b;
    --red-soft: #fbe9e9;
    --blue: #3b6ea5;
    --blue-soft: #e8f0f8;
    --shadow: 0 1px 2px rgba(28, 25, 23, .04), 0 10px 30px rgba(28, 25, 23, .05);
    --radius: 16px;
    --serif: Georgia, 'Times New Roman', 'Iowan Old Style', serif;
    --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

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

body {
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.45;
    color: var(--ink);
    background: var(--cream);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

body.modal-open { overflow: hidden; }

a { color: var(--gold-deep); }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }
h1, h2, h3, h4 { line-height: 1.2; }

.icon { display: block; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.right { text-align: right; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.money-in { color: var(--green); }
.money-out { color: var(--red); }
.danger-text { color: var(--red); }

/* ---------- Layout ---------- */
.layout { min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 252px;
    background: #1c1917;
    color: #e9e1d4;
    display: flex;
    flex-direction: column;
    z-index: 90;
    transition: transform .28s cubic-bezier(.4, 0, .2, 1);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.sidebar-brand .monogram { width: 38px; height: 38px; border-radius: 12px; font-size: 14px; }
.brand-text { min-width: 0; }
.brand-text strong { display: block; font-family: var(--serif); font-size: 17px; color: #fbf7ef; letter-spacing: .01em; }
.brand-text span { display: block; font-size: 10.5px; color: #b7ab99; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-close { display: none; margin-left: auto; color: #b7ab99; }

.side-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.nav-group { margin-bottom: 14px; }
.nav-label { display: block; font-size: 9px; letter-spacing: .16em; text-transform: uppercase; color: #8a7f70; padding: 6px 10px; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 9px;
    color: #d6cbbd;
    text-decoration: none;
    font-size: 12.5px;
    font-weight: 550;
    margin-bottom: 2px;
    transition: background .16s, color .16s;
}
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-item.active { background: rgba(176, 141, 87, .17); color: #f3d9a8; }
.nav-item .icon { opacity: .85; }

.sidebar-foot { padding: 14px; border-top: 1px solid rgba(255, 255, 255, .08); }
.who { display: flex; gap: 9px; align-items: center; margin-bottom: 10px; }
.who strong { display: block; font-size: 11.5px; color: #f5efe5; }
.who span { font-size: 10px; color: #a99d8c; }
.sidebar-foot .btn-ghost { border-color: rgba(255, 255, 255, .16); color: #e9e1d4; background: transparent; }
.sidebar-foot .btn-ghost:hover { background: rgba(255, 255, 255, .08); }

.main { margin-left: 252px; min-height: 100vh; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 28px;
    background: rgba(247, 244, 238, .9);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.topbar-title p { font-size: 11px; color: var(--muted); margin-top: 1px; }
.topbar-actions { display: flex; gap: 6px; align-items: center; }
.menu-btn { display: none; }

.view { max-width: 1240px; margin: 0 auto; padding: 26px 28px 90px; }

.scrim {
    position: fixed;
    inset: 0;
    background: rgba(28, 25, 23, .5);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity .25s;
    z-index: 80;
}
.scrim.show { opacity: 1; visibility: visible; }

.bottom-nav { display: none; }

/* ---------- Monogram and avatars ---------- */
.monogram {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: linear-gradient(140deg, #d5b98c, #a17c47);
    color: #241d16;
    display: grid;
    place-items: center;
    font-family: var(--serif);
    font-weight: 700;
    font-size: 16px;
    letter-spacing: .02em;
    flex: none;
}
.monogram.lg { width: 56px; height: 56px; font-size: 20px; border-radius: 16px; }

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--gold-soft);
    color: var(--gold-deep);
    display: inline-grid;
    place-items: center;
    font-weight: 700;
    font-size: 13px;
    flex: none;
}
.avatar.sm { width: 32px; height: 32px; font-size: 11px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 14px;
    border-radius: 10px;
    border: 1px solid transparent;
    font-size: 12.5px;
    font-weight: 650;
    text-decoration: none;
    background: transparent;
    color: var(--ink);
    transition: background .16s, border-color .16s, color .16s, transform .16s;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ink); color: #fdfaf5; }
.btn-primary:hover { background: var(--gold-deep); }
.btn-ghost { background: var(--paper); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: #fbf7ef; border-color: #d9cdbb; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #982f2f; }
.btn-sm { padding: 6px 10px; font-size: 11.5px; border-radius: 8px; }
.btn-lg { padding: 13px 18px; font-size: 14px; border-radius: 12px; }
.btn-block { width: 100%; }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    border: 0;
    background: transparent;
    color: var(--muted);
    transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--cream); color: var(--ink); }
.icon-btn.danger:hover { background: var(--red-soft); color: var(--red); }

.link-btn {
    background: none;
    border: 0;
    color: var(--gold-deep);
    font-size: 12px;
    font-weight: 650;
    cursor: pointer;
    padding: 8px;
    text-decoration: underline;
    text-underline-offset: 3px;
}
.link-btn.subtle { color: var(--muted); font-weight: 500; margin-top: 8px; }

/* ---------- Pills, tags, minis ---------- */
.pill {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 700;
    white-space: nowrap;
}
.pill.muted { background: #f1ede6; color: #78716c; }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.red { background: var(--red-soft); color: var(--red); }

.mini {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 700;
    white-space: nowrap;
}
.mini.amber { background: var(--amber-soft); color: var(--amber); }
.mini.green { background: var(--green-soft); color: var(--green); }
.mini.muted { background: #f1ede6; color: var(--muted); }

.tag {
    display: inline-block;
    background: #f6f1e8;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 2px 7px;
    font-size: 10.5px;
    color: var(--ink-3);
    white-space: nowrap;
}

/* ---------- Panels and headings ---------- */
.panel {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}
.panel h3 { font-family: var(--serif); font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.panel-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.panel-head p { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.panel-head .btn { flex: none; }

.page-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 18px;
    flex-wrap: wrap;
}
.page-head h2 { font-family: var(--serif); font-size: 28px; font-weight: 600; letter-spacing: -.025em; }
.page-head p { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.head-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--muted);
    text-decoration: none;
    margin-bottom: 12px;
}
.back-link:hover { color: var(--ink); }

.eyebrow {
    display: inline-block;
    text-transform: uppercase;
    letter-spacing: .16em;
    font-size: 10px;
    font-weight: 700;
    color: var(--gold);
    margin-bottom: 6px;
}

.note { font-size: 11px; color: var(--muted); line-height: 1.55; margin-top: 10px; }
.body-copy { font-size: 12.5px; color: var(--ink-3); line-height: 1.6; margin-top: 8px; white-space: pre-wrap; }
.fine { font-size: 10.5px; color: #a8a29e; line-height: 1.5; margin-top: 14px; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 11.5px; font-weight: 700; color: var(--ink-2); }
.field input, .field select, .field textarea {
    width: 100%;
    border: 1px solid var(--line);
    background: #fffdfa;
    border-radius: 9px;
    padding: 9px 11px;
    font-size: 13px;
    color: var(--ink);
    transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(176, 141, 87, .13);
}
.field-hint { font-size: 10.5px; color: var(--muted); line-height: 1.4; }
.form-error { color: var(--red); font-size: 11.5px; margin: 2px 0 4px; }

.input-inline {
    border: 1px solid var(--line);
    background: #fffdfa;
    border-radius: 8px;
    padding: 7px 9px;
    font-size: 11.5px;
    width: auto;
}
.status-select { min-width: 130px; }

.button-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th {
    text-align: left;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
    font-weight: 700;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.data-table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 1px solid var(--line); }
.data-table .right { text-align: right; }
.data-table tfoot td { font-weight: 700; background: #faf7f1; border-bottom: 0; }
.data-table .total-row td { font-weight: 700; background: #faf7f1; }
.cell-link { display: flex; flex-direction: column; text-decoration: none; color: inherit; }
.cell-link strong { font-size: 12.5px; }
.cell-link span { font-size: 11px; color: var(--muted); }
.cell-sub { display: block; font-size: 10.5px; color: var(--muted); margin-top: 2px; }

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(28, 25, 23, .56);
    backdrop-filter: blur(3px);
    display: grid;
    place-items: center;
    padding: 16px;
    z-index: 200;
    overflow-y: auto;
}
.modal {
    background: var(--paper);
    border-radius: 18px;
    width: min(100%, 620px);
    max-height: 92vh;
    overflow: auto;
    box-shadow: 0 30px 80px rgba(0, 0, 0, .32);
    animation: modal-in .2s ease both;
}
.modal-sm { width: min(100%, 430px); }
.modal-lg { width: min(100%, 860px); }
.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 17px 20px;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    background: var(--paper);
    z-index: 2;
}
.modal-head h2 { font-family: var(--serif); font-size: 19px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}
.confirm-text { font-size: 13px; color: var(--ink-3); line-height: 1.65; }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.99); } to { opacity: 1; transform: none; } }

/* ---------- Toast ---------- */
#toastRoot {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 400;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    pointer-events: none;
    width: max-content;
    max-width: 92vw;
}
.toast {
    background: var(--ink);
    color: #fdfaf5;
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 600;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .22s, transform .22s;
    text-align: center;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--red); }

/* ---------- Empty states ---------- */
.empty {
    text-align: center;
    padding: 36px 20px;
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 14px;
    background: #fcfaf6;
}
.empty-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--gold-soft);
    color: var(--gold-deep);
    display: grid;
    place-items: center;
    margin: 0 auto 12px;
}
.empty h3 { font-family: var(--serif); font-size: 18px; color: var(--ink); margin-bottom: 4px; }
.empty p { font-size: 12px; max-width: 340px; margin: 0 auto 14px; line-height: 1.6; }

/* ---------- Auth ---------- */
body.auth-mode {
    background:
        radial-gradient(circle at 82% 8%, rgba(176, 141, 87, .18), transparent 36%),
        radial-gradient(circle at 8% 92%, rgba(157, 92, 99, .1), transparent 34%),
        var(--cream);
    padding-bottom: 0;
}
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
    width: min(100%, 460px);
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 32px;
    box-shadow: 0 30px 80px rgba(28, 25, 23, .12);
    animation: auth-in .4s ease both;
}
.auth-card.wide { width: min(100%, 720px); }
.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 24px; }
.auth-brand strong { display: block; font-family: var(--serif); font-size: 18px; }
.auth-brand span { display: block; font-size: 11px; color: var(--muted); }
.auth-card h1 { font-family: var(--serif); font-size: 30px; font-weight: 600; letter-spacing: -.025em; margin: 2px 0 8px; }
.auth-lead { font-size: 13px; color: var(--muted); line-height: 1.6; margin-bottom: 20px; }
.role-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0; }
.role-choice {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fcfaf6;
    cursor: pointer;
    text-align: left;
    transition: border-color .16s, box-shadow .16s, background .16s;
}
.role-choice strong { font-size: 14px; }
.role-choice > span:last-child { font-size: 11px; color: var(--muted); }
.role-choice.is-active { border-color: var(--gold); background: #fbf5e9; box-shadow: 0 0 0 3px rgba(176, 141, 87, .14); }
.role-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--gold-soft);
    color: var(--gold-deep);
    display: grid;
    place-items: center;
    margin-bottom: 4px;
}
.pin-form { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.pin-form label { font-size: 11.5px; font-weight: 700; text-align: center; color: var(--ink-2); }
.pin-form input {
    text-align: center;
    font-size: 24px;
    letter-spacing: .5em;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fffdfa;
    text-indent: .5em;
}
.pin-form input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(176, 141, 87, .13); }
@keyframes auth-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Notices ---------- */
.notice {
    display: flex;
    gap: 12px;
    align-items: center;
    background: #fdf6e7;
    border: 1px solid #eed9ac;
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}
.notice-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: #f7e6c3;
    color: #8a6a3b;
    display: grid;
    place-items: center;
    flex: none;
}
.notice-copy { flex: 1; display: flex; flex-direction: column; min-width: 200px; }
.notice-copy strong { font-size: 12.5px; }
.notice-copy span { font-size: 11.5px; color: #8a6a3b; line-height: 1.45; }

/* ---------- Responsive ---------- */
@media (max-width: 1023px) {
    .sidebar { transform: translateX(-100%); width: 280px; }
    .sidebar.open { transform: none; }
    .sidebar-close { display: inline-grid; }
    .main { margin-left: 0; }
    .menu-btn { display: inline-grid; }
    .topbar { padding: 10px 14px; }
    .view { padding: 18px 16px 104px; }
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(255, 253, 250, .97);
        backdrop-filter: blur(12px);
        border-top: 1px solid var(--line);
        z-index: 70;
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    }
    .bottom-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        padding: 6px 4px;
        font-size: 9.5px;
        font-weight: 650;
        color: var(--muted);
        text-decoration: none;
        background: none;
        border: 0;
    }
    .bottom-item.active { color: var(--gold-deep); }
}

@media (max-width: 720px) {
    .form-grid { grid-template-columns: 1fr; }
    .topbar-title h1 { font-size: 15px; }
    .topbar-title p { display: none; }
    .topbar-actions .btn span { display: none; }
    .auth-card { padding: 24px; }
    .auth-card h1 { font-size: 25px; }
    .role-grid { grid-template-columns: 1fr; }
    .page-head h2 { font-size: 23px; }
    .hide-sm { display: none !important; }
    .modal { max-height: 94vh; }
    .modal-body { padding: 16px; }
    #toastRoot { bottom: 84px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
