:root {
    --bg: #f4f6f3;
    --surface: #ffffff;
    --surface-soft: #f8faf7;
    --text: #17211b;
    --muted: #6c766f;
    --line: #dfe6df;
    --line-strong: #c8d3cb;
    --green: #0f8f5f;
    --green-dark: #103c2d;
    --green-soft: #e4f5ed;
    --amber: #b7791f;
    --amber-soft: #fff4d6;
    --red: #bd2f2f;
    --red-soft: #fde7e7;
    --blue: #2663a5;
    --shadow: 0 10px 30px rgba(23, 33, 27, 0.08);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 Arial, Helvetica, sans-serif;
}

a {
    color: var(--green);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

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

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

.sidebar {
    background: var(--green-dark);
    color: #fff;
    padding: 22px 16px;
}

.brand,
.auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: inherit;
    font-weight: 700;
}

.brand:hover {
    text-decoration: none;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius);
    background: #0dbb72;
    color: #052419;
    font-weight: 800;
}

.main-nav {
    display: grid;
    gap: 5px;
    margin-top: 28px;
}

.main-nav a {
    color: rgba(255, 255, 255, 0.84);
    padding: 10px 12px;
    border-radius: var(--radius);
}

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

.main-shell {
    min-width: 0;
}

.topbar {
    min-height: 78px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 18px 30px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.topbar h1,
.auth-brand h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.2;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0;
}

.user-menu,
.actions,
.form-actions,
.quick-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.user-menu {
    justify-content: flex-end;
}

.user-menu form {
    margin: 0;
}

.content {
    padding: 24px 30px 44px;
    display: grid;
    gap: 18px;
}

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

.panel {
    padding: 18px;
}

.panel-header,
.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.panel-header h2,
.detail-header h2 {
    margin: 0;
    font-size: 18px;
}

.detail-header {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
}

.detail-header p {
    margin: 4px 0 0;
    color: var(--muted);
}

.back-link {
    display: inline-block;
    margin-bottom: 8px;
    color: var(--muted);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.metric-card {
    display: grid;
    gap: 8px;
    padding: 16px;
    color: inherit;
    border-left: 4px solid var(--green);
}

.metric-card:hover {
    text-decoration: none;
    border-color: var(--green);
}

.metric-card span {
    color: var(--muted);
}

.metric-card strong {
    font-size: 32px;
    line-height: 1;
}

.metric-card.warning {
    border-left-color: var(--amber);
}

.metric-card.danger {
    border-left-color: var(--red);
}

.metric-card.muted {
    border-left-color: var(--blue);
}

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

.narrow {
    max-width: 760px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.table-wrap.compact table {
    min-width: 620px;
}

table {
    width: 100%;
    min-width: 860px;
    border-collapse: collapse;
}

th,
td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0;
    background: var(--surface-soft);
}

tr:hover td {
    background: #fbfdfb;
}

.sort-link {
    color: inherit;
}

.filters {
    display: grid;
    grid-template-columns: repeat(6, minmax(150px, 1fr));
    gap: 12px;
    align-items: end;
}

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

label {
    display: grid;
    gap: 6px;
}

label span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    padding: 9px 10px;
    background: #fff;
    color: var(--text);
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: 3px solid rgba(15, 143, 95, 0.18);
    border-color: var(--green);
}

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

.form-grid.single {
    grid-template-columns: 1fr;
}

.span-2 {
    grid-column: span 2;
}

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

.checkbox-line input {
    width: auto;
}

.form-actions {
    justify-content: flex-end;
    margin-top: 4px;
}

.form-note {
    margin: 0;
    color: var(--muted);
}

.divider {
    height: 1px;
    background: var(--line);
}

.button,
button.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 8px 13px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 700;
    text-decoration: none;
}

.button:hover {
    text-decoration: none;
}

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

.button-secondary {
    background: var(--surface-soft);
    border-color: var(--line-strong);
    color: var(--text);
}

.button-ghost,
.link-button {
    background: transparent;
    color: var(--muted);
}

.button-danger {
    background: var(--red-soft);
    color: var(--red);
    border-color: #f1b5b5;
}

.button:disabled,
.is-disabled {
    opacity: 0.45;
    pointer-events: none;
}

.link-button {
    border: 0;
    padding: 0;
    min-height: 0;
    cursor: pointer;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 8px;
    border-radius: 999px;
    background: #edf1ee;
    color: #4d5851;
    font-size: 12px;
    font-weight: 700;
}

.badge-success,
.status-won {
    background: var(--green-soft);
    color: #08643f;
}

.badge-danger,
.status-lost {
    background: var(--red-soft);
    color: var(--red);
}

.status-new {
    background: #e7f0ff;
    color: var(--blue);
}

.status-negotiation,
.status-offer_sent {
    background: var(--amber-soft);
    color: var(--amber);
}

.flash,
.notice,
.note-box {
    border-radius: var(--radius);
    padding: 12px 14px;
}

.flash-success {
    background: var(--green-soft);
    border: 1px solid #b9e6d0;
    color: #075b39;
}

.flash-error {
    background: var(--red-soft);
    border: 1px solid #f1b5b5;
    color: var(--red);
}

.notice {
    background: #eef5ff;
    border: 1px solid #c8dcf3;
    margin-bottom: 14px;
}

.notice.warning {
    background: var(--amber-soft);
    border-color: #f1d38a;
}

.note-box {
    background: var(--surface-soft);
    border: 1px solid var(--line);
    margin-top: 12px;
    white-space: normal;
}

.error {
    color: var(--red);
    font-weight: 700;
}

.empty-inline,
.empty-state {
    color: var(--muted);
}

.empty-state {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 28px;
    text-align: center;
}

.detail-list {
    display: grid;
    grid-template-columns: 170px minmax(0, 1fr);
    gap: 10px 14px;
    margin: 0;
}

.detail-list dt {
    color: var(--muted);
    font-weight: 700;
}

.detail-list dd {
    margin: 0;
    min-width: 0;
    overflow-wrap: anywhere;
}

.sum-list {
    display: grid;
    gap: 10px;
}

.sum-list div {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-soft);
}

.timeline {
    display: grid;
    gap: 10px;
}

.timeline article {
    display: grid;
    gap: 2px;
    padding-left: 12px;
    border-left: 3px solid var(--line-strong);
}

.timeline span,
.timeline small {
    color: var(--muted);
}

.plain-list {
    margin: 0;
    padding-left: 18px;
}

.email-body {
    margin: 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-soft);
    color: var(--text);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-family: Consolas, Monaco, "Courier New", monospace;
    font-size: 13px;
}

.run-status {
    margin-top: 12px;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 16px;
    color: var(--muted);
}

.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(15, 143, 95, 0.18), transparent 44%),
        var(--bg);
}

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

.auth-brand {
    margin-bottom: 24px;
    color: var(--text);
}

.stack {
    display: grid;
    gap: 14px;
}

[hidden] {
    display: none !important;
}

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

    .filters {
        grid-template-columns: repeat(3, minmax(150px, 1fr));
    }
}

@media (max-width: 760px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: sticky;
        top: 0;
        z-index: 10;
        padding: 12px;
    }

    .brand {
        margin-bottom: 10px;
    }

    .main-nav {
        display: flex;
        gap: 6px;
        margin: 0;
        overflow-x: auto;
        padding-bottom: 2px;
    }

    .main-nav a {
        white-space: nowrap;
    }

    .topbar,
    .detail-header,
    .panel-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar,
    .content {
        padding-left: 16px;
        padding-right: 16px;
    }

    .metric-grid,
    .split-grid,
    .form-grid,
    .filters {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: auto;
    }

    .detail-list {
        grid-template-columns: 1fr;
    }

    .user-menu {
        justify-content: flex-start;
    }
}
