:root {
    --ink: #1d2220;
    --ink-soft: #5e6661;
    --paper: #f4f1ea;
    --paper-strong: #fffdf8;
    --line: #d8d3c9;
    --line-dark: #393e3b;
    --sidebar: #202522;
    --sidebar-soft: #2a302c;
    --copper: #b9653f;
    --copper-dark: #914729;
    --sage: #667a69;
    --success: #397451;
    --danger: #a74639;
    --shadow: 0 18px 50px rgba(35, 30, 24, 0.1);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--paper);
    font-synthesis: none;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
}

body {
    min-width: 320px;
    background: var(--paper);
}

button,
input,
select {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
    outline: 3px solid rgba(185, 101, 63, 0.28);
    outline-offset: 2px;
}

.app-loading,
.fatal-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
}

.loading-mark {
    display: grid;
    width: 56px;
    height: 56px;
    place-items: center;
    border: 1px solid var(--line-dark);
    background: var(--sidebar);
    color: #fff;
    font-family: Georgia, serif;
    font-size: 30px;
    animation: breathe 1.4s ease-in-out infinite;
}

@keyframes breathe {
    50% { opacity: 0.55; transform: scale(0.96); }
}

.auth-body {
    overflow-x: hidden;
    background: var(--paper-strong);
}

.auth-page {
    display: grid;
    min-height: 100vh;
    grid-template-columns: minmax(360px, 44%) 1fr;
}

.auth-story {
    position: relative;
    display: flex;
    min-height: 100vh;
    flex-direction: column;
    overflow: hidden;
    padding: clamp(28px, 5vw, 72px);
    background:
        linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
        var(--sidebar);
    background-size: 42px 42px;
    color: #f5f0e7;
}

.auth-story::after {
    position: absolute;
    right: -100px;
    bottom: 80px;
    width: 360px;
    height: 360px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    content: "";
    transform: rotate(24deg);
}

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 13px;
    color: #f8f4ec;
    letter-spacing: 0.12em;
}

.brand-mark {
    display: grid;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.38);
    font-family: Georgia, serif;
    font-size: 24px;
    letter-spacing: 0;
}

.brand-lockup strong,
.brand-lockup small {
    display: block;
}

.brand-lockup strong {
    font-size: 15px;
}

.brand-lockup small {
    margin-top: 3px;
    color: rgba(255, 255, 255, 0.55);
    font-size: 9px;
}

.auth-story-copy {
    position: relative;
    z-index: 1;
    max-width: 630px;
    margin: auto 0;
}

.eyebrow {
    margin: 0 0 18px;
    color: var(--copper);
    font-size: 11px;
    font-weight: 750;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.auth-story h1 {
    max-width: 600px;
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(42px, 5vw, 76px);
    font-weight: 400;
    letter-spacing: -0.045em;
    line-height: 0.98;
}

.auth-story-copy > p:last-child {
    max-width: 500px;
    margin: 30px 0 0;
    color: rgba(255, 255, 255, 0.62);
    font-size: 16px;
    line-height: 1.65;
}

.auth-story-foot {
    position: relative;
    z-index: 1;
    margin: 0;
    color: rgba(255, 255, 255, 0.42);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.blueprint-line {
    position: absolute;
    right: 54px;
    bottom: 128px;
    width: 180px;
    height: 90px;
    border-top: 1px solid rgba(255, 255, 255, 0.18);
    border-right: 1px solid rgba(255, 255, 255, 0.18);
}

.blueprint-line::before,
.blueprint-line::after {
    position: absolute;
    background: rgba(255, 255, 255, 0.18);
    content: "";
}

.blueprint-line::before {
    top: -5px;
    left: 0;
    width: 1px;
    height: 10px;
}

.blueprint-line::after {
    right: -5px;
    bottom: 0;
    width: 10px;
    height: 1px;
}

.auth-panel {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 44px;
    background:
        radial-gradient(circle at 80% 16%, rgba(185, 101, 63, 0.09), transparent 28%),
        var(--paper-strong);
}

.auth-card {
    width: min(100%, 450px);
}

.auth-index {
    margin: 0 0 60px;
    color: var(--ink-soft);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    letter-spacing: 0.16em;
}

.auth-card h2 {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(38px, 4vw, 56px);
    font-weight: 400;
    letter-spacing: -0.045em;
}

.auth-hint {
    max-width: 420px;
    margin: 18px 0 34px;
    color: var(--ink-soft);
    line-height: 1.6;
}

.auth-form {
    display: grid;
    gap: 18px;
}

.field {
    display: grid;
    gap: 8px;
}

.field > span,
.company-fieldset legend {
    color: var(--ink-soft);
    font-size: 11px;
    font-weight: 750;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.field > small {
    color: #8a8f8b;
    font-size: 11px;
}

.field input,
.field select,
.filter-bar select,
.search-field input {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 0;
    background: #fff;
    color: var(--ink);
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.field input,
.field select {
    padding: 0 14px;
}

.field input:focus,
.field select:focus,
.filter-bar select:focus,
.search-field input:focus {
    border-color: var(--copper);
    box-shadow: 0 0 0 3px rgba(185, 101, 63, 0.1);
    outline: none;
}

.code-input {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace !important;
    font-size: 24px !important;
    letter-spacing: 0.32em;
}

.button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border: 1px solid transparent;
    border-radius: 0;
    padding: 0 18px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 720;
    transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.button:hover:not(:disabled) {
    transform: translateY(-1px);
}

.button:disabled {
    cursor: wait;
    opacity: 0.55;
}

.button-primary {
    border-color: var(--copper);
    background: var(--copper);
    color: #fff;
}

.button-primary:hover:not(:disabled) {
    border-color: var(--copper-dark);
    background: var(--copper-dark);
}

.button-secondary {
    border-color: var(--ink);
    background: var(--ink);
    color: #fff;
}

.button-quiet {
    border-color: var(--line);
    background: transparent;
    color: var(--ink);
}

.button-wide {
    width: 100%;
}

.button-small {
    min-height: 36px;
    padding: 0 13px;
    font-size: 12px;
}

.text-button {
    margin: 0 0 28px;
    border: 0;
    padding: 0;
    background: none;
    color: var(--copper-dark);
    cursor: pointer;
    font-size: 13px;
}

.form-error {
    min-height: 20px;
    margin: 0;
    color: var(--danger);
    font-size: 13px;
    line-height: 1.45;
}

.auth-security {
    margin: 28px 0 0;
    color: #8a8f8b;
    font-size: 12px;
    line-height: 1.55;
}

.crm-shell {
    display: grid;
    min-height: 100vh;
    grid-template-columns: 250px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    height: 100vh;
    flex-direction: column;
    padding: 30px 22px 22px;
    background: var(--sidebar);
    color: #fff;
}

.side-nav {
    display: grid;
    gap: 5px;
    margin-top: 56px;
}

.side-nav-link {
    display: grid;
    min-height: 46px;
    grid-template-columns: 22px 1fr auto;
    align-items: center;
    gap: 12px;
    border-left: 2px solid transparent;
    padding: 0 12px;
    color: rgba(255, 255, 255, 0.62);
    text-decoration: none;
    transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}

.side-nav-link:hover,
.side-nav-link.is-active {
    border-left-color: var(--copper);
    background: var(--sidebar-soft);
    color: #fff;
}

.side-nav-link svg,
.icon-button svg,
.search-field svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.6;
}

.side-nav-link small {
    color: rgba(255, 255, 255, 0.3);
    font-size: 9px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.side-nav-link.is-coming {
    cursor: default;
}

.sidebar-foot {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-top: auto;
    color: rgba(255, 255, 255, 0.38);
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.environment-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #69a479;
    box-shadow: 0 0 0 4px rgba(105, 164, 121, 0.12);
}

.workspace {
    min-width: 0;
}

.topbar {
    position: sticky;
    z-index: 10;
    top: 0;
    display: flex;
    min-height: 82px;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    border-bottom: 1px solid var(--line);
    padding: 14px clamp(20px, 3vw, 44px);
    background: rgba(244, 241, 234, 0.96);
}

.page-heading span,
.page-heading strong,
.page-heading small {
    display: block;
}

.page-heading span {
    margin-bottom: 3px;
    color: var(--copper-dark);
    font-size: 9px;
    font-weight: 760;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.page-heading strong {
    font-family: Georgia, serif;
    font-size: 22px;
    font-weight: 400;
}

.page-heading small {
    margin-top: 3px;
    color: var(--ink-soft);
    font-size: 11px;
}

.account {
    display: flex;
    align-items: center;
    gap: 10px;
}

.account-avatar,
.person-avatar {
    display: grid;
    place-items: center;
    background: var(--sidebar-soft);
    color: #fff;
    font-weight: 750;
}

.account-avatar {
    width: 38px;
    height: 38px;
    font-size: 12px;
}

.account-copy strong,
.account-copy small {
    display: block;
}

.account-copy strong {
    font-size: 12px;
}

.account-copy small {
    margin-top: 2px;
    color: var(--ink-soft);
    font-size: 10px;
}

.mobile-menu {
    display: none;
}

.icon-button {
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
    cursor: pointer;
}

.page-content {
    padding: clamp(22px, 3vw, 44px);
}

.welcome-panel {
    position: relative;
    display: flex;
    min-height: 260px;
    align-items: flex-end;
    justify-content: space-between;
    overflow: hidden;
    padding: clamp(28px, 5vw, 64px);
    background: var(--paper-strong);
    box-shadow: var(--shadow);
}

.welcome-panel::after {
    position: absolute;
    top: 0;
    right: 22%;
    width: 1px;
    height: 100%;
    background: var(--line);
    content: "";
    transform: rotate(19deg);
}

.welcome-panel h2 {
    max-width: 600px;
    margin: 0;
    font-family: Georgia, serif;
    font-size: clamp(36px, 5vw, 68px);
    font-weight: 400;
    letter-spacing: -0.045em;
}

.welcome-panel p:last-child {
    max-width: 620px;
    color: var(--ink-soft);
    line-height: 1.6;
}

.welcome-number {
    color: var(--line);
    font-family: Georgia, serif;
    font-size: clamp(90px, 13vw, 180px);
    line-height: 0.7;
}

.stage-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    margin-top: 28px;
    border-top: 1px solid var(--line);
    border-left: 1px solid var(--line);
}

.stage-card {
    min-height: 190px;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    padding: 24px;
    background: rgba(255, 253, 248, 0.5);
}

.stage-card > span {
    color: var(--copper);
    font-family: ui-monospace, monospace;
    font-size: 11px;
}

.stage-card h3 {
    margin: 36px 0 7px;
    font-family: Georgia, serif;
    font-size: 24px;
    font-weight: 400;
}

.stage-card p {
    min-height: 38px;
    margin: 0 0 22px;
    color: var(--ink-soft);
    font-size: 12px;
    line-height: 1.5;
}

.stage-card small {
    font-size: 9px;
    font-weight: 760;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.stage-ready small { color: var(--success); }
.stage-next small { color: var(--copper-dark); }
.stage-later small { color: #9b9c97; }

.users-toolbar,
.filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.users-toolbar {
    margin-bottom: 22px;
}

.metric-inline {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.metric-inline strong {
    font-family: Georgia, serif;
    font-size: 28px;
    font-weight: 400;
}

.metric-inline span {
    color: var(--ink-soft);
    font-size: 11px;
}

.metric-inline i {
    width: 1px;
    height: 22px;
    margin: 0 8px;
    background: var(--line);
}

.filter-bar {
    justify-content: flex-start;
    border: 1px solid var(--line);
    border-bottom: 0;
    padding: 13px;
    background: var(--paper-strong);
}

.search-field {
    position: relative;
    flex: 1 1 320px;
    max-width: 420px;
}

.search-field svg {
    position: absolute;
    top: 50%;
    left: 13px;
    width: 17px;
    height: 17px;
    color: var(--ink-soft);
    transform: translateY(-50%);
}

.search-field input {
    padding: 0 14px 0 40px;
}

.filter-bar select {
    width: auto;
    min-width: 170px;
    padding: 0 36px 0 13px;
}

.table-card {
    border: 1px solid var(--line);
    background: var(--paper-strong);
    box-shadow: 0 12px 34px rgba(35, 30, 24, 0.05);
}

.table-scroll {
    overflow-x: auto;
}

.users-table {
    width: 100%;
    min-width: 1050px;
    border-collapse: collapse;
}

.users-table th,
.users-table td {
    border-bottom: 1px solid #e7e3db;
    padding: 15px 14px;
    text-align: left;
    vertical-align: middle;
}

.users-table th {
    color: var(--ink-soft);
    font-size: 9px;
    font-weight: 760;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.users-table td {
    font-size: 12px;
}

.users-table tbody tr:last-child td {
    border-bottom: 0;
}

.users-table tbody tr:hover {
    background: #faf7f1;
}

.person-cell {
    display: flex;
    min-width: 220px;
    align-items: center;
    gap: 11px;
}

.person-avatar {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    font-size: 10px;
}

.person-cell strong,
.person-cell small {
    display: block;
}

.person-cell small {
    margin-top: 3px;
    color: var(--ink-soft);
}

.role-label,
.status-pill {
    display: inline-flex;
    min-height: 26px;
    align-items: center;
    border: 1px solid var(--line);
    padding: 0 8px;
    font-size: 10px;
}

.status-pill.is-active {
    border-color: #b9d0c0;
    background: #eef6f0;
    color: var(--success);
}

.status-pill.is-inactive {
    border-color: #e0c3bf;
    background: #fbefed;
    color: var(--danger);
}

.row-actions {
    display: flex;
    gap: 8px;
}

.table-action {
    border: 0;
    border-bottom: 1px solid transparent;
    padding: 3px 0;
    background: none;
    color: var(--copper-dark);
    cursor: pointer;
    font-size: 10px;
}

.table-action:hover {
    border-bottom-color: currentColor;
}

.protected-label {
    color: #9c9f9b;
    font-size: 10px;
}

.empty-cell {
    height: 130px;
    color: var(--ink-soft);
    text-align: center !important;
}

.modal {
    width: min(760px, calc(100vw - 28px));
    max-height: calc(100vh - 28px);
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--ink);
}

.modal::backdrop {
    background: rgba(20, 24, 22, 0.72);
}

.modal-card {
    background: var(--paper-strong);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
}

.modal-head,
.modal-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 22px 26px;
}

.modal-head {
    border-bottom: 1px solid var(--line);
}

.modal-head span {
    color: var(--copper-dark);
    font-size: 9px;
    font-weight: 760;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.modal-head h2 {
    margin: 5px 0 0;
    font-family: Georgia, serif;
    font-size: 30px;
    font-weight: 400;
}

.modal-close {
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    font-size: 26px;
    font-weight: 300;
}

.modal-body {
    max-height: calc(100vh - 210px);
    overflow-y: auto;
    padding: 26px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.company-fieldset {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 26px 0 0;
    border: 0;
    padding: 0;
}

.company-fieldset legend {
    margin-bottom: 10px;
}

.check-card {
    display: flex;
    min-height: 60px;
    align-items: center;
    gap: 11px;
    border: 1px solid var(--line);
    padding: 11px 13px;
    cursor: pointer;
}

.check-card:has(input:checked) {
    border-color: var(--copper);
    background: #fff8f3;
}

.check-card strong,
.check-card small {
    display: block;
}

.check-card strong {
    font-size: 12px;
}

.check-card small {
    margin-top: 2px;
    color: var(--ink-soft);
    font-size: 10px;
}

.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-top: 22px;
    border-top: 1px solid var(--line);
    padding-top: 20px;
}

.switch-row strong,
.switch-row small {
    display: block;
}

.switch-row strong {
    font-size: 13px;
}

.switch-row small {
    margin-top: 3px;
    color: var(--ink-soft);
    font-size: 11px;
}

.switch-row input {
    width: 42px;
    height: 22px;
    accent-color: var(--copper);
}

.modal-foot {
    justify-content: flex-end;
    border-top: 1px solid var(--line);
}

.page-state {
    display: grid;
    min-height: 280px;
    place-items: center;
    align-content: center;
    color: var(--ink-soft);
    text-align: center;
}

.page-state p {
    margin: 12px 0 0;
}

.page-error strong {
    color: var(--danger);
}

.spinner {
    width: 28px;
    height: 28px;
    border: 2px solid var(--line);
    border-top-color: var(--copper);
    border-radius: 50%;
    animation: spin 700ms linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.toast-root {
    position: fixed;
    z-index: 1000;
    right: 18px;
    bottom: 18px;
    display: grid;
    gap: 9px;
}

.toast {
    min-width: 260px;
    max-width: 420px;
    border-left: 4px solid var(--success);
    padding: 14px 16px;
    background: var(--sidebar);
    color: #fff;
    box-shadow: var(--shadow);
    font-size: 12px;
}

.toast-error {
    border-left-color: var(--danger);
}

@media (max-width: 1050px) {
    .stage-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .account-copy {
        display: none;
    }

    .filter-bar {
        flex-wrap: wrap;
    }

    .search-field {
        max-width: none;
    }
}

@media (max-width: 820px) {
    .auth-page {
        grid-template-columns: 1fr;
    }

    .auth-story {
        min-height: 350px;
        padding: 28px;
    }

    .auth-story-copy {
        margin: 70px 0 30px;
    }

    .auth-story h1 {
        font-size: clamp(38px, 11vw, 60px);
    }

    .auth-story-foot,
    .blueprint-line {
        display: none;
    }

    .auth-panel {
        min-height: 560px;
        padding: 42px 24px;
    }

    .auth-index {
        margin-bottom: 40px;
    }

    .crm-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        z-index: 50;
        left: 0;
        width: 270px;
        transform: translateX(-105%);
        transition: transform 190ms ease;
    }

    .sidebar.sidebar-open {
        box-shadow: 24px 0 60px rgba(0, 0, 0, 0.28);
        transform: translateX(0);
    }

    .mobile-menu {
        display: grid;
        flex: 0 0 42px;
        place-items: center;
    }

    .topbar {
        gap: 12px;
        padding: 12px 16px;
    }

    .page-heading {
        min-width: 0;
        margin-right: auto;
    }

    .page-heading small {
        display: none;
    }

    .account-avatar {
        display: none;
    }

    .page-content {
        padding: 20px 16px;
    }

    .welcome-panel {
        min-height: 360px;
        align-items: flex-end;
        padding: 28px;
    }

    .welcome-number {
        position: absolute;
        top: 36px;
        right: 22px;
        font-size: 100px;
    }

    .users-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .filter-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .filter-bar select,
    .search-field {
        width: 100%;
        min-width: 0;
    }
}

@media (max-width: 560px) {
    .stage-grid,
    .form-grid,
    .company-fieldset {
        grid-template-columns: 1fr;
    }

    .metric-inline {
        flex-wrap: wrap;
    }

    .metric-inline i {
        display: none;
    }

    .modal-head,
    .modal-body,
    .modal-foot {
        padding-right: 18px;
        padding-left: 18px;
    }

    .modal-foot .button {
        flex: 1;
    }

    .toast-root {
        right: 12px;
        bottom: 12px;
        left: 12px;
    }

    .toast {
        min-width: 0;
    }
}
