:root {
    --soil: #1c1712;
    --bark: #2b241c;
    --clay: #c45c26;
    --clay-deep: #9a4318;
    --sage: #3d6b5a;
    --sage-soft: #d7e4dc;
    --sand: #f4eee4;
    --paper: #fbf7f0;
    --ink: #241d16;
    --muted: #6f655a;
    --line: #e4d9c8;
    --white: #fffdf8;
    --danger: #8b3a3a;
    --ok: #2f5d4a;
    --shadow: 0 18px 40px rgba(36, 29, 22, 0.08);
    --radius: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: Outfit, system-ui, sans-serif;
    background: var(--paper);
    color: var(--ink);
    font-size: 15px;
}

a { color: var(--sage); text-decoration: none; }
a:hover { color: var(--clay-deep); }

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

.sidebar {
    width: 250px;
    background: linear-gradient(180deg, var(--soil) 0%, var(--bark) 100%);
    color: #f3eadc;
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    color: inherit;
    padding: 6px 8px 22px;
}
.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: var(--clay);
    font-family: Fraunces, serif;
    font-weight: 650;
    color: #fff;
}
.brand strong { display: block; font-size: 15px; }
.brand small { color: #cbbba6; font-size: 12px; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar nav a {
    color: #e6d8c6;
    padding: 10px 12px;
    border-radius: 12px;
}
.sidebar nav a.is-active,
.sidebar nav a:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}
.sidebar-foot { border-top: 1px solid rgba(255,255,255,0.08); padding-top: 16px; }
.who { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--sage); display: grid; place-items: center; font-weight: 650;
}
.who strong, .who small { display: block; color: #fff; }
.who small { color: #cbbba6; font-weight: 400; }
.logout { color: #cbbba6; font-size: 13px; }

.main { flex: 1; min-width: 0; }
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 22px 28px 8px;
}
.topbar h1 {
    margin: 0;
    font-family: Fraunces, serif;
    font-size: 28px;
    font-weight: 650;
}
.top-search { flex: 1; min-width: 0; max-width: 360px; }
.top-search input {
    width: 100%;
    border: 1px solid var(--line);
    background: var(--white);
    border-radius: 999px;
    padding: 10px 16px;
    font: inherit;
}
.content { padding: 12px 28px 40px; }

.flash {
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 14px;
}
.flash-success { background: #e5f0ea; color: var(--ok); }
.flash-danger { background: #f6e4e0; color: var(--danger); }
.flash-info { background: #efe6d4; color: #6a5424; }

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}
.stat {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 18px 16px;
    box-shadow: var(--shadow);
}
.stat span { color: var(--muted); font-size: 13px; }
.stat strong {
    display: block;
    font-family: Fraunces, serif;
    font-size: 32px;
    margin-top: 6px;
}
.stat a { color: inherit; }

.panel {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
}
.panel-head h2 {
    margin: 0;
    font-size: 16px;
    font-family: Fraunces, serif;
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 560; }
tr:hover td { background: #faf6ef; }
.muted { color: var(--muted); }
.lead-name { font-weight: 560; color: var(--ink); }
.lead-name:hover { color: var(--clay); }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 560;
}
.tone-contact { background: #efe0d4; color: #8a4318; }
.tone-retreat { background: var(--sage-soft); color: #245241; }
.tone-news { background: #ece7dc; color: #5c5348; }
.tone-other { background: #eee; color: #555; }
.wp-unread { background: #f6d9c8; color: var(--clay-deep); }
.wp-read { background: #e8eee9; color: var(--sage); }

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}
.filters input, .filters select {
    border: 1px solid var(--line);
    background: var(--white);
    border-radius: 12px;
    padding: 9px 12px;
    font: inherit;
}
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 0;
    border-radius: 12px;
    padding: 9px 14px;
    font: inherit;
    font-weight: 560;
    cursor: pointer;
    background: var(--clay);
    color: #fff;
}
.btn:hover { background: var(--clay-deep); color: #fff; }
.btn-ghost {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--line);
}
.btn-ghost:hover { background: #f3ece2; color: var(--ink); }
.btn-sage { background: var(--sage); }
.btn-sage:hover { background: #2f5547; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.grid-2 {
    display: grid;
    grid-template-columns: 1.4fr .8fr;
    gap: 16px;
}
.field-list dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin-top: 12px; }
.field-list dd { margin: 4px 0 0; font-size: 16px; }
.concern { white-space: pre-wrap; line-height: 1.5; }

.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
        radial-gradient(900px 400px at 10% 0%, rgba(196,92,38,.18), transparent 50%),
        radial-gradient(700px 400px at 90% 100%, rgba(61,107,90,.18), transparent 50%),
        var(--paper);
    padding: 24px;
}
.login-card {
    width: min(440px, 100%);
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 24px;
    padding: 36px 32px;
    box-shadow: var(--shadow);
}
.login-card h1 {
    font-family: Fraunces, serif;
    margin: 8px 0 6px;
}
.login-card p { color: var(--muted); margin-top: 0; }
.login-card label { display: block; font-size: 13px; margin: 14px 0 6px; }
.login-card input[type=text],
.login-card input[type=password] {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    font: inherit;
}
.login-card .btn { width: 100%; margin-top: 18px; padding: 12px; }
.hint { margin-top: 16px; font-size: 12px; color: var(--muted); background: var(--sand); padding: 10px 12px; border-radius: 12px; }

.note { background: var(--sand); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; }
.note small { color: var(--muted); }
.pager { display: flex; gap: 8px; padding: 14px 16px; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.split-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 22px;
}
.bar-row { display: flex; align-items: center; gap: 10px; padding: 6px 18px 10px; }
.bar-row span { width: 110px; font-size: 13px; }
.bar {
    flex: 1; height: 10px; background: #efe8dc; border-radius: 99px; overflow: hidden;
}
.bar i { display: block; height: 100%; background: var(--clay); border-radius: 99px; }

.actions a, .actions button { margin-right: 4px; }

.topbar-start {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.menu-toggle {
    display: none;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--white);
    padding: 11px 10px;
    gap: 5px;
    flex-direction: column;
    justify-content: center;
    cursor: pointer;
}
.menu-toggle span {
    display: block;
    height: 2px;
    background: var(--ink);
    border-radius: 2px;
}
.nav-scrim {
    display: none;
}
.inline-form {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}
.table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.lead-actions { margin-top: 18px; }
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    justify-content: flex-end;
    min-width: 0;
}
.add-lead-btn { white-space: nowrap; }
.stack-form {
    padding: 18px;
    display: grid;
    gap: 4px;
}
.stack-form label { font-size: 13px; margin-top: 10px; }
.stack-form input,
.stack-form select,
.stack-form textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 11px 12px;
    font: inherit;
    background: var(--white);
}
.stack-form .btn-row { margin-top: 16px; }
.field-group { display: grid; gap: 4px; }
.create-panel { max-width: 720px; }

@media (max-width: 1100px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .split-charts { grid-template-columns: 1fr; }
}

@media (max-width: 980px) {
    .grid-2 { grid-template-columns: 1fr; }
    .menu-toggle { display: inline-flex; }
    .nav-scrim {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(28, 23, 18, 0.45);
        z-index: 30;
    }
    .nav-scrim[hidden] { display: none; }
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        z-index: 40;
        transform: translateX(-105%);
        transition: transform .22s ease;
        width: min(280px, 86vw);
        height: 100vh;
        height: 100dvh;
        padding-top: calc(16px + env(safe-area-inset-top));
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
    body.nav-open .sidebar { transform: translateX(0); }
    body.nav-open { overflow: hidden; }
    .topbar {
        flex-direction: column;
        align-items: stretch;
        padding: calc(12px + env(safe-area-inset-top)) 14px 8px;
        gap: 10px;
    }
    .topbar h1 { font-size: 22px; line-height: 1.2; overflow-wrap: anywhere; }
    .topbar-actions { flex-direction: column; align-items: stretch; }
    .top-search { max-width: none; }
    .content { padding: 8px 14px calc(28px + env(safe-area-inset-bottom)); }
    .stat strong { font-size: 26px; }
    .panel-head { gap: 10px; flex-wrap: wrap; }
    .filters { flex-direction: column; }
    .filters input,
    .filters select,
    .filters .btn,
    .filters a.btn { width: 100%; }
    .btn { min-height: 44px; }
    .lead-actions .btn { flex: 1 1 140px; }
    .pager { flex-wrap: wrap; }
    .bar-row { padding-left: 14px; padding-right: 14px; }
    .bar-row span { width: 88px; flex-shrink: 0; }
    .login-wrap { padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
    .login-card { padding: 24px 18px; border-radius: 18px; }
    .inline-form input[type=password] { width: 100%; min-width: 0; }
    .hide-on-phone { display: none !important; }
}

@media (max-width: 720px) {
    .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stack-table thead { display: none; }
    .stack-table,
    .stack-table tbody,
    .stack-table tr,
    .stack-table td { display: block; width: 100%; }
    .stack-table tr {
        padding: 12px 14px;
        border-bottom: 1px solid var(--line);
    }
    .stack-table td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        padding: 6px 0;
        border: 0;
        text-align: right;
    }
    .stack-table td::before {
        content: attr(data-label);
        font-size: 12px;
        letter-spacing: .04em;
        text-transform: uppercase;
        color: var(--muted);
        font-weight: 560;
        text-align: left;
        flex: 0 0 38%;
    }
    .stack-table td.empty {
        display: block;
        text-align: center;
    }
    .stack-table td.empty::before { content: none; }
    .stack-table tr:hover td { background: transparent; }
}

@media (max-width: 420px) {
    .stats { grid-template-columns: 1fr; }
    html { font-size: 16px; }
    input, select, textarea { font-size: 16px !important; }
}
