:root {
  color-scheme: light;
  --page: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #162033;
  --muted: #667085;
  --line: #e3e8ef;
  --navy: #0b1f3a;
  --navy-2: #132f55;
  --blue: #1769e0;
  --blue-soft: #eaf2ff;
  --danger: #d92d20;
  --danger-soft: #fff0ee;
  --warning: #d96d00;
  --warning-soft: #fff4e7;
  --success: #087a55;
  --success-soft: #eaf8f2;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 8px 24px rgba(15, 23, 42, .04);
  --radius: 10px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--page); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--page); font-size: 14px; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { outline-color: var(--blue); }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(26px, 3vw, 36px); letter-spacing: -.035em; }
h2 { margin-bottom: 4px; font-size: 16px; letter-spacing: -.015em; }
p { color: var(--muted); line-height: 1.55; }
small { color: var(--muted); }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; width: 232px; display: flex; flex-direction: column; padding: 18px 14px; background: var(--navy); color: #fff; }
.brand { display: flex; align-items: center; gap: 11px; min-height: 48px; padding: 4px 8px 18px; }
.brand > span:last-child { display: grid; gap: 2px; }
.brand strong { font-size: 15px; letter-spacing: -.01em; }
.brand small { color: #aebcd0; font-size: 11px; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 9px; background: #ff7a21; color: #fff; font-weight: 800; }
.sidebar nav { display: grid; gap: 5px; }
.nav-link { min-height: 44px; display: flex; align-items: center; gap: 12px; padding: 0 12px; border-radius: 8px; color: #c8d2df; font-weight: 650; }
.nav-link span { width: 22px; font-size: 18px; text-align: center; }
.nav-link:hover, .nav-link.active { background: var(--navy-2); color: #fff; }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px 8px 0; border-top: 1px solid rgba(255,255,255,.12); }
.sidebar-footer small { max-width: 135px; overflow: hidden; color: #b8c3d1; text-overflow: ellipsis; }
.link-button { padding: 0; border: 0; background: none; color: #fff; }
.mobile-header { display: none; }
.main-content { margin-left: 232px; min-height: 100vh; padding: 30px clamp(20px, 3vw, 48px) 56px; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-header.compact { align-items: center; }
.page-header p { margin-bottom: 0; }
.eyebrow { margin-bottom: 5px !important; color: var(--blue) !important; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.breadcrumb { display: flex; gap: 8px; margin-bottom: 18px; color: var(--muted); }
.breadcrumb a { color: var(--blue); }

.primary-button, .secondary-button, .small-button, .text-button, .icon-button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 7px; font-weight: 700; }
.primary-button { padding: 0 17px; border: 1px solid var(--blue); background: var(--blue); color: #fff; box-shadow: 0 3px 10px rgba(23,105,224,.18); }
.primary-button:hover { background: #0f58c5; }
.secondary-button { padding: 0 16px; border: 1px solid #cfd7e3; background: #fff; color: var(--ink); }
.secondary-button:hover { border-color: #aebccc; background: #f9fbfd; }
.small-button { min-height: 34px; padding: 0 11px; border: 1px solid #cfd7e3; background: #fff; color: var(--ink); font-size: 12px; }
.text-button { border: 0; background: none; }
.icon-button { width: 44px; padding: 0; border: 1px solid var(--line); background: #fff; color: var(--ink); font-size: 20px; }
.align-start { align-self: flex-start; }
.full { width: 100%; }
.top-gap { margin-top: 14px; }
.text-link { color: var(--blue); font-weight: 700; }
.danger-text { color: var(--danger) !important; }

.metric-row { display: grid; grid-template-columns: repeat(4, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.metric-card { min-height: 104px; display: flex; flex-direction: column; justify-content: space-between; padding: 17px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.metric-card span { color: var(--muted); font-size: 12px; font-weight: 650; }
.metric-card strong { font-size: 29px; line-height: 1; }
.metric-card.danger { border-top: 3px solid var(--danger); }
.metric-card.warning { border-top: 3px solid var(--warning); }
.metric-card.info { border-top: 3px solid var(--blue); }
.metric-card.neutral { border-top: 3px solid #667085; }

.dashboard-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.work-panel, .card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.work-panel { min-width: 0; overflow: hidden; }
.work-panel > header, .card > header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 17px 18px; border-bottom: 1px solid var(--line); }
.work-panel header p { margin: 0; font-size: 12px; }
.count-badge { min-width: 25px; min-height: 25px; display: inline-grid; place-items: center; padding: 0 7px; border-radius: 999px; background: #edf1f6; color: var(--ink); font-size: 12px; font-weight: 800; }
.count-badge.danger { background: var(--danger-soft); color: var(--danger); }
.count-badge.warning { background: var(--warning-soft); color: var(--warning); }
.count-badge.info { background: var(--blue-soft); color: var(--blue); }
.work-list { min-height: 420px; }
.work-item { min-height: 72px; display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.work-item:hover { background: var(--surface-2); }
.entity-icon { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 7px; background: #edf3fb; color: #406085; }
.work-copy { min-width: 0; display: grid; gap: 4px; }
.work-copy strong, .work-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.due { font-size: 11px; font-weight: 750; }
.due.danger { color: var(--danger); }
.due.muted { color: var(--muted); }
.panel-link { min-height: 48px; display: grid; place-items: center; color: var(--blue); font-weight: 750; }
.empty-state { padding: 26px 18px; color: var(--muted); text-align: center; }
.empty-state.large { padding: 70px 20px; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.search-field { min-height: 44px; flex: 1; max-width: 620px; display: flex; align-items: center; gap: 9px; padding: 0 12px; border: 1px solid #cfd7e3; border-radius: 7px; background: #fff; }
.search-field input { width: 100%; border: 0; outline: 0; }
.kanban { display: flex; align-items: flex-start; gap: 12px; padding-bottom: 18px; overflow-x: auto; scroll-snap-type: x proximity; }
.kanban-column { width: 286px; min-width: 286px; border: 1px solid var(--line); border-radius: var(--radius); background: #eef2f7; scroll-snap-align: start; }
.kanban-column > header { min-height: 54px; display: flex; align-items: center; justify-content: space-between; padding: 0 13px; }
.kanban-column > header h2 { margin: 0; font-size: 13px; }
.kanban-column > header span { min-width: 24px; display: grid; place-items: center; padding: 3px 7px; border-radius: 999px; background: #dfe6ef; color: #44536a; font-size: 11px; font-weight: 800; }
.kanban-dropzone { min-height: 150px; padding: 0 8px 8px; }
.kanban-dropzone.drag-over { border-radius: 8px; background: #dce9ff; }
.deal-card { margin-bottom: 8px; padding: 13px; border: 1px solid #dbe2eb; border-radius: 8px; background: #fff; box-shadow: 0 1px 2px rgba(15,23,42,.05); }
.deal-card.dragging { opacity: .45; }
.deal-card > a { display: grid; gap: 8px; }
.deal-card strong { line-height: 1.35; }
.deal-company { color: var(--muted); font-size: 11px; font-weight: 750; }
.deal-value { font-weight: 750; }
.next-action { padding: 7px 8px; border-radius: 6px; background: var(--success-soft); color: var(--success); font-size: 11px; font-weight: 750; }
.next-action.missing { background: var(--warning-soft); color: var(--warning); }
.next-action.overdue { background: var(--danger-soft); color: var(--danger); }
.stage-select { width: 100%; min-height: 36px; margin-top: 10px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--muted); font-size: 11px; }

.modal { width: min(620px, calc(100% - 24px)); max-height: calc(100vh - 40px); padding: 0; border: 0; border-radius: 12px; box-shadow: 0 24px 80px rgba(15,23,42,.28); }
.modal::backdrop { background: rgba(10, 20, 36, .52); backdrop-filter: blur(2px); }
.modal form { padding: 20px; }
.modal header, .modal footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal header { margin-bottom: 8px; }
.modal footer { justify-content: flex-end; margin-top: 8px; }

.form-stack { display: grid; gap: 14px; }
.form-grid { display: grid; gap: 13px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label { display: grid; gap: 7px; color: #445066; font-size: 12px; font-weight: 700; }
input, select, textarea { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #cfd7e3; border-radius: 7px; background: #fff; color: var(--ink); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23,105,224,.12); outline: none; }

.detail-layout { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(280px, .75fr); align-items: start; gap: 14px; }
.detail-main, .detail-side { display: grid; gap: 14px; }
.card { padding: 18px; }
.card > header { margin: -18px -18px 18px; }
.next-action-callout { min-width: 260px; display: grid; gap: 2px; padding: 12px 14px; border: 1px solid #bbe7d5; border-radius: 8px; background: var(--success-soft); }
.next-action-callout small { color: var(--success); font-weight: 700; }
.next-action-callout.overdue, .next-action-callout.missing { border-color: #ffd4cc; background: var(--danger-soft); }
.next-action-callout.overdue small, .next-action-callout.missing small { color: var(--danger); }
.table-list, .task-list { display: grid; }
.table-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.table-row > span:first-child { min-width: 0; display: grid; gap: 3px; }
.table-row strong, .table-row small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.task-item > div { display: grid; gap: 4px; }
.task-item.done { opacity: .58; }
.task-item.done strong { text-decoration: line-through; }
.fact-list dl, .message-headers { display: grid; grid-template-columns: minmax(110px, .7fr) minmax(0, 1.3fr); gap: 10px 14px; margin: 0; }
.fact-list dt, .message-headers dt { color: var(--muted); }
.fact-list dd, .message-headers dd { margin: 0; overflow-wrap: anywhere; font-weight: 650; }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.tabs a { min-height: 44px; display: grid; place-items: center; padding: 0 14px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 700; }
.tabs a.active { border-color: var(--blue); color: var(--blue); }
.table-card { padding: 0; overflow: hidden; }
.data-table { min-width: 760px; }
.data-row { display: grid; grid-template-columns: 1.5fr 1.5fr .8fr .7fr .5fr; gap: 12px; align-items: center; min-height: 62px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.data-row > span { min-width: 0; }
.data-row > span:first-child, .data-row > span:nth-child(2) { display: grid; gap: 3px; }
.data-head { min-height: 44px; background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.companies-table .data-row { grid-template-columns: 1.5fr .7fr 1fr 1.2fr .45fr; }

.mail-list { padding: 0; overflow: hidden; }
.mail-row { display: grid; grid-template-columns: 34px minmax(160px, .75fr) minmax(240px, 1.7fr) minmax(130px, .55fr); align-items: center; gap: 12px; min-height: 76px; padding: 10px 15px; border-bottom: 1px solid var(--line); }
.mail-row:hover { background: var(--surface-2); }
.direction-icon { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 7px; background: #edf3fb; color: var(--blue); font-weight: 900; }
.direction-icon.outgoing { background: var(--success-soft); color: var(--success); }
.mail-sender, .mail-subject, .mail-meta { min-width: 0; display: grid; gap: 4px; }
.mail-sender strong, .mail-sender small, .mail-subject strong, .mail-subject small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-meta { justify-items: end; text-align: right; }
.mail-meta time { color: var(--muted); font-size: 11px; }
.status-pill { min-height: 30px; display: inline-grid; place-items: center; padding: 0 10px; border-radius: 999px; background: var(--blue-soft); color: var(--blue); font-size: 11px; font-weight: 800; }
.status-pill.linked { background: var(--success-soft); color: var(--success); }
.status-pill.ignored { background: #eef1f4; color: var(--muted); }
.message-card { min-width: 0; }
.message-body { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--line); }
.message-body pre { margin: 0; overflow: auto; color: #253149; font: 14px/1.65 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; white-space: pre-wrap; overflow-wrap: anywhere; }
.attachment-list { display: grid; gap: 8px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); }
.attachment-list a { padding: 10px 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2); }
.or-divider { display: grid; place-items: center; margin: 8px 0; color: var(--muted); font-size: 11px; }

.flash-stack { position: fixed; top: 18px; right: 20px; z-index: 90; display: grid; gap: 8px; }
.flash { padding: 12px 15px; border: 1px solid #b7d9c9; border-radius: 8px; background: var(--success-soft); color: var(--success); box-shadow: var(--shadow); font-weight: 700; }
.flash.error { border-color: #ffd4cc; background: var(--danger-soft); color: var(--danger); }

.login-page { display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 20%, #edf4ff, transparent 35%), var(--page); }
.login-card { width: min(430px, 100%); padding: 30px; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: 0 24px 70px rgba(15,23,42,.12); }
.login-brand { padding: 0 0 28px; color: var(--ink); }
.login-brand small { color: var(--muted); }
.login-card h1 { font-size: 28px; }

.sidebar-scrim { display: none; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1180px) {
  .dashboard-grid { grid-template-columns: 1fr 1fr; }
  .work-panel:last-child { grid-column: 1 / -1; }
  .metric-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 35; background: rgba(8,18,32,.5); }
  body.sidebar-open .sidebar-scrim { display: block; }
  .mobile-header { position: sticky; top: 0; z-index: 30; min-height: 60px; display: flex; align-items: center; gap: 12px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.94); backdrop-filter: blur(10px); font-weight: 800; }
  .main-content { margin-left: 0; padding: 22px 14px 40px; }
  .page-header { align-items: flex-start; flex-direction: column; }
  .page-header .primary-button { width: 100%; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .work-panel:last-child { grid-column: auto; }
  .work-list { min-height: 0; }
  .detail-layout { grid-template-columns: 1fr; }
  .next-action-callout { width: 100%; }
  .table-card { overflow-x: auto; }
  .mail-row { grid-template-columns: 34px minmax(0, 1fr) auto; }
  .mail-sender { display: none; }
  .mail-subject { min-width: 0; }
  .mail-meta small { display: none; }
}

@media (max-width: 560px) {
  .metric-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric-card { min-height: 92px; padding: 13px; }
  .metric-card strong { font-size: 25px; }
  .form-grid.two { grid-template-columns: 1fr; }
  .toolbar { align-items: stretch; flex-wrap: wrap; }
  .search-field { flex-basis: 100%; }
  .fact-list dl, .message-headers { grid-template-columns: 1fr; gap: 4px; }
  .fact-list dd, .message-headers dd { margin-bottom: 10px; }
  .tabs { overflow-x: auto; }
  .tabs a { white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .001ms !important; animation-duration: .001ms !important; }
}

