:root {
    --navy: #082c3c;
    --navy-2: #0d3e51;
    --sea: #0f7085;
    --aqua: #36b7c4;
    --ice: #edf7f8;
    --paper: #ffffff;
    --ink: #17323d;
    --muted: #617881;
    --line: #dbe7ea;
    --danger: #a52d2d;
    --danger-bg: #fff0f0;
    --warning: #8b5c00;
    --warning-bg: #fff7dc;
    --success: #17633e;
    --success-bg: #eaf8ef;
    --shadow: 0 12px 34px rgba(8, 44, 60, .08);
    --radius: 14px;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: #f4f8f9; }

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background: linear-gradient(180deg, #f4f8f9 0, #eef5f6 100%);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--sea); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 28px;
    min-height: 72px;
    padding: 10px clamp(18px, 4vw, 58px);
    color: #fff;
    background: var(--navy);
    box-shadow: 0 4px 18px rgba(8, 44, 60, .18);
}

.brand { display: flex; align-items: center; gap: 12px; color: #fff; font-size: 20px; font-weight: 800; }
.brand:hover { text-decoration: none; }
.brand img { display: block; width: 108px; max-height: 56px; border-radius: 6px; object-fit: contain; }
.brand span { padding-left: 12px; border-left: 1px solid rgba(255,255,255,.35); }

.topbar nav { display: flex; gap: 5px; }
.topbar nav a { padding: 9px 12px; color: rgba(255,255,255,.78); border-radius: 9px; font-weight: 650; }
.topbar nav a:hover, .topbar nav a.active { color: #fff; background: rgba(255,255,255,.12); text-decoration: none; }

.user-menu { display: flex; align-items: center; gap: 12px; }
.user-menu a, .link-button { color: rgba(255,255,255,.9); }
.user-menu form { margin: 0; }
.link-button { padding: 0; border: 0; background: transparent; }
.link-button:hover { text-decoration: underline; }

.app-shell { width: min(1480px, calc(100% - 36px)); margin: 34px auto 70px; }
.auth-shell { display: grid; min-height: calc(100vh - 70px); place-items: center; padding: 24px; }
.footer { padding: 22px; color: var(--muted); text-align: center; font-size: 13px; }

.page-title { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.page-title h1 { margin: 0; color: var(--navy); font-size: clamp(28px, 4vw, 42px); line-height: 1.1; letter-spacing: -.035em; }
.page-title p { max-width: 760px; margin: 8px 0 0; color: var(--muted); font-size: 16px; }
.page-actions { flex: 0 0 auto; }
.eyebrow { margin: 0 0 6px; color: var(--sea); font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }

.card, .metric, .auth-card {
    border: 1px solid rgba(8, 44, 60, .09);
    border-radius: var(--radius);
    background: var(--paper);
    box-shadow: var(--shadow);
}

.card { padding: 22px; }
.narrow-card { max-width: 680px; }
.card-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.card-heading h2 { margin: 0; color: var(--navy); font-size: 19px; }
.card h3 { margin: 20px 0 6px; color: var(--navy); font-size: 14px; }
.card p { margin-top: 8px; }
.muted, .empty { color: var(--muted); }
.empty { padding: 12px 0; }

.auth-card { width: min(460px, 100%); padding: clamp(28px, 6vw, 48px); }
.auth-card h1 { margin: 0; color: var(--navy); font-size: 36px; }
.auth-card > p:not(.eyebrow) { color: var(--muted); }
.auth-logo { width: min(280px, 100%); max-height: 187px; margin: 0 auto 24px; border-radius: 10px; object-fit: contain; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.metric { display: flex; flex-direction: column; padding: 22px; color: var(--ink); transition: transform .16s ease, box-shadow .16s ease; }
.metric:hover { transform: translateY(-2px); text-decoration: none; box-shadow: 0 15px 38px rgba(8,44,60,.13); }
.metric strong { color: var(--navy); font-size: 34px; line-height: 1; }
.metric span { margin-top: 9px; color: var(--muted); font-weight: 650; }
.metric.danger { border-color: #efcccc; background: var(--danger-bg); }
.metric.warning { border-color: #efd88c; background: var(--warning-bg); }

.two-column { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(330px, .65fr); gap: 22px; align-items: start; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(330px, .7fr); gap: 22px; align-items: start; }
.detail-main, .detail-side { display: grid; gap: 22px; }

.prospect-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 22px; }
.prospect-summary > div { display: flex; min-width: 0; flex-direction: column; gap: 4px; padding-right: 16px; border-right: 1px solid var(--line); }
.prospect-summary > div:last-child { border-right: 0; }
.prospect-summary span { color: var(--muted); font-size: 12px; font-weight: 750; letter-spacing: .05em; text-transform: uppercase; }
.prospect-summary strong { color: var(--navy); }

.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; padding: 9px 16px; border: 1px solid transparent; border-radius: 9px; font-weight: 750; line-height: 1.2; text-decoration: none; }
.button:hover { text-decoration: none; }
.button.primary { color: #fff; border-color: var(--sea); background: var(--sea); }
.button.primary:hover { background: #0b5d6e; }
.button.secondary { color: var(--navy); border-color: #b9cdd2; background: #fff; }
.button.secondary:hover { border-color: var(--sea); background: var(--ice); }
.button.small { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.button.disabled { color: #839499; border-color: #d4dfe1; background: #eef2f3; cursor: not-allowed; }

.flash { margin: 0 0 18px; padding: 13px 16px; border: 1px solid #bfdce2; border-radius: 10px; background: var(--ice); }
.flash-success { color: var(--success); border-color: #b9e4ca; background: var(--success-bg); }
.flash-error { color: var(--danger); border-color: #efc4c4; background: var(--danger-bg); }
.flash-warning { color: var(--warning); border-color: #eed88f; background: var(--warning-bg); }

.stack-form { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 17px 20px; }
.form-grid.compact { gap: 12px 16px; }
.stack-form.compact { gap: 9px; margin-top: 14px; }
label { display: grid; gap: 6px; color: var(--navy); font-size: 13px; font-weight: 750; }
label:has(input[type="checkbox"]) { display: flex; align-items: center; gap: 8px; }
input, select, textarea { width: 100%; min-height: 42px; padding: 9px 11px; color: var(--ink); border: 1px solid #bfd0d4; border-radius: 8px; background: #fff; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(54,183,196,.22); border-color: var(--sea); }
input[type="checkbox"] { width: 18px; min-height: 18px; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 5px; }
.inline-form { display: flex; align-items: center; gap: 8px; }
.inline-form input, .inline-form select { min-width: 120px; }

.filter-bar { display: flex; align-items: end; gap: 12px; margin-bottom: 18px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.72); }
.filter-bar label { min-width: 160px; }
.filter-bar .grow { min-width: 220px; flex: 1; }

.table-card { padding: 0; overflow: hidden; }
.responsive-table { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
th { color: var(--muted); background: #f8fbfb; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
td strong, td small { display: block; }
td small { margin-top: 2px; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
.row-danger { background: var(--danger-bg); }

.status { display: inline-flex; width: fit-content; padding: 4px 8px; border-radius: 999px; color: var(--navy); background: var(--ice); font-size: 12px; font-weight: 750; }
.status-do_not_contact, .status-lost { color: var(--danger); background: var(--danger-bg); }
.status-qualified, .status-trial_order, .status-customer_won { color: var(--success); background: var(--success-bg); }

.list { margin: 0 -22px -22px; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px 22px; color: var(--ink); border-top: 1px solid var(--line); }
.list-row:hover { background: #f8fbfb; text-decoration: none; }
.list-row span { display: flex; flex-direction: column; }
.list-row small { color: var(--muted); }
.list-row .right { align-items: flex-end; text-align: right; }
.pipeline-list { display: grid; gap: 8px; }
.pipeline-list a { display: flex; justify-content: space-between; padding: 9px 11px; color: var(--ink); border-radius: 8px; background: #f6fafb; }
.pipeline-list a:hover { background: var(--ice); text-decoration: none; }

.subnav { display: flex; gap: 8px; margin-bottom: 16px; }
.subnav a { padding: 8px 12px; border-radius: 999px; color: var(--ink); background: #fff; }
.subnav a.active { color: #fff; background: var(--sea); }

.details { display: grid; grid-template-columns: minmax(95px, .7fr) minmax(0, 1.3fr); gap: 10px 14px; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; word-break: break-word; }
.details dd small { display: block; color: var(--muted); }

.timeline { display: grid; }
.timeline-item { position: relative; display: grid; grid-template-columns: 20px 1fr; gap: 12px; padding: 0 0 22px; }
.timeline-item::before { position: absolute; top: 12px; bottom: -2px; left: 6px; width: 2px; background: var(--line); content: ""; }
.timeline-item:last-child::before { display: none; }
.timeline-marker { position: relative; z-index: 1; width: 14px; height: 14px; margin-top: 4px; border: 3px solid #b9ccd1; border-radius: 50%; background: #fff; }
.timeline-item.open .timeline-marker { border-color: var(--aqua); background: var(--ice); }
.timeline-head { display: flex; justify-content: space-between; gap: 14px; }
.timeline-head span, .timeline-meta { color: var(--muted); font-size: 12px; }
.timeline-content p { margin: 7px 0; }
.timeline-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }

.contact-list, .clearance-list { display: grid; gap: 9px; }
.contact-list > div { display: flex; flex-direction: column; padding: 10px; border-radius: 8px; background: #f6fafb; }
.contact-list small, .contact-list span { color: var(--muted); }
.contact-list em { color: var(--danger); font-size: 12px; font-style: normal; font-weight: 750; }
.clearance-list > div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.clearance-list > div:last-child { border-bottom: 0; }
.clearance-list span { font-size: 12px; font-weight: 700; }
.clearance-list strong { font-size: 11px; }
.clearance-not_cleared { color: var(--warning); }
.clearance-cleared_by_human { color: var(--success); }
.clearance-do_not_contact { color: var(--danger); }
details { margin-top: 14px; }
summary { color: var(--sea); cursor: pointer; font-weight: 750; }
.simple-list { padding-left: 19px; }
.transfer-card { border-color: #d5c489; background: #fffdf4; }
.transfer-card small { display: block; margin-top: 10px; color: var(--muted); }
.transfer-intro { margin-bottom: 8px; }
.transfer-preview { display: grid; grid-template-columns: minmax(95px, .8fr) minmax(0, 1.2fr); gap: 7px 12px; margin: 0 0 16px; padding: 12px; border: 1px solid #eadfaf; border-radius: 9px; background: #fff; font-size: 14px; }
.transfer-preview dt { color: var(--muted); }
.transfer-preview dd { margin: 0; overflow-wrap: anywhere; font-weight: 650; }
.transfer-card form { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.transfer-confirmation { color: var(--success); font-weight: 700; }
.transfer-card button:disabled { cursor: wait; opacity: .72; }

@media (max-width: 1050px) {
    .topbar { grid-template-columns: auto 1fr; }
    .topbar nav { grid-column: 1 / -1; order: 3; overflow-x: auto; padding-bottom: 2px; }
    .user-menu { justify-self: end; }
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
    .two-column, .detail-grid { grid-template-columns: 1fr; }
    .detail-side { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
    .topbar { gap: 12px; padding: 10px 14px; }
    .brand img { width: 92px; }
    .brand span { font-size: 16px; }
    .user-menu > a { display: none; }
    .topbar nav a { white-space: nowrap; }
    .app-shell { width: min(100% - 22px, 1480px); margin-top: 22px; }
    .page-title { align-items: stretch; flex-direction: column; }
    .page-actions .button { width: 100%; }
    .metric-grid, .prospect-summary { grid-template-columns: repeat(2, 1fr); }
    .prospect-summary > div { border-right: 0; }
    .form-grid, .detail-side { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .filter-bar { align-items: stretch; flex-direction: column; }
    .filter-bar label, .filter-bar .grow { min-width: 0; width: 100%; }
    .filter-bar .button { width: 100%; }
    .timeline-head, .timeline-meta { align-items: flex-start; flex-direction: column; }
    .inline-form { width: 100%; align-items: stretch; flex-direction: column; }
    .inline-form input, .inline-form select, .inline-form .button { width: 100%; }
    .subnav { overflow-x: auto; }
    .subnav a { flex: 0 0 auto; }
    th:nth-child(2), td:nth-child(2) { }
}

@media (max-width: 430px) {
    .transfer-preview { grid-template-columns: 1fr; }
    .transfer-preview dd { margin-bottom: 5px; }
    .transfer-card form .button { width: 100%; }
    .metric-grid { grid-template-columns: 1fr; }
    .prospect-summary { grid-template-columns: 1fr; }
    .card { padding: 18px; }
    .list { margin: 0 -18px -18px; }
    .list-row { padding: 13px 18px; }
}
