:root {
  --ink: #172033;
  --muted: #657187;
  --line: #d9deea;
  --surface: #ffffff;
  --canvas: #f4f6fa;
  --primary: #174ea6;
  --primary-dark: #103b7d;
  --primary-soft: #e8f0fe;
  --teal: #096b62;
  --teal-soft: #e5f5f2;
  --danger: #a52626;
  --danger-soft: #fff0ef;
  --warning: #725a00;
  --warning-soft: #fff8d8;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(18 32 58 / 8%), 0 8px 24px rgb(18 32 58 / 5%);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; line-height: 1.5; }
a { color: var(--primary); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--primary-dark); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid #f5b942; outline-offset: 2px; }
.skip-link { position: fixed; z-index: 20; top: -5rem; left: 1rem; padding: .7rem 1rem; background: #fff; border: 2px solid var(--primary); }
.skip-link:focus { top: 1rem; }
.app-header { min-height: 66px; display: flex; align-items: center; gap: 2rem; padding: .7rem max(1rem, calc((100vw - 1440px) / 2)); background: #10233f; color: #fff; box-shadow: 0 1px 0 rgb(255 255 255 / 12%); }
.app-header a { color: #fff; text-decoration: none; }
.brand { font-weight: 750; letter-spacing: -.02em; white-space: nowrap; }
.app-header nav { display: flex; gap: .35rem; }
.app-header nav a { padding: .55rem .7rem; border-radius: 6px; color: #dbe7f8; }
.app-header nav a:hover { background: rgb(255 255 255 / 9%); color: #fff; }
.user-menu { margin-left: auto; display: flex; align-items: center; gap: .8rem; }
.user-menu form { margin: 0; }
.page-shell { width: min(1440px, calc(100% - 2rem)); margin: 0 auto; padding: 2rem 0 4rem; }
.page-heading, .company-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1.5rem; margin-bottom: 1.5rem; }
h1, h2, h3, h4 { margin-top: 0; line-height: 1.2; letter-spacing: -.015em; }
h1 { margin-bottom: .45rem; font-size: clamp(1.8rem, 3vw, 2.55rem); }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
h4 { margin: 1rem 0 .35rem; font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
p { margin-top: 0; }
.eyebrow { margin-bottom: .3rem; color: var(--primary); font-size: .75rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.muted, small { color: var(--muted); }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: .6rem .9rem; border: 1px solid transparent; border-radius: 7px; cursor: pointer; font-weight: 700; line-height: 1.1; text-decoration: none; }
.button-primary { background: var(--primary); color: #fff; }
.button-primary:hover { background: var(--primary-dark); color: #fff; }
.button-secondary { background: #fff; border-color: #aeb8ca; color: var(--ink); }
.button-secondary:hover { border-color: var(--primary); color: var(--primary); }
.button-quiet { min-height: 34px; padding: .4rem .65rem; background: transparent; border-color: #5f7393; color: #fff; }
.button-danger-quiet { background: #fff; border-color: #dca8a8; color: var(--danger); }
.button-wide { width: 100%; }
.panel, .company-section, .search-form, .result-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel { padding: 1rem; }
.panel-heading, .section-heading, .results-heading, .result-title-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.panel-heading h2, .panel-heading h3, .results-heading h2 { margin: 0; }
.panel-accent { border-top: 4px solid var(--primary); }
.panel-danger-soft { border-top: 4px solid var(--danger); }
.count { display: inline-flex; min-width: 1.7rem; height: 1.7rem; align-items: center; justify-content: center; padding: 0 .45rem; border-radius: 1rem; background: var(--primary-soft); color: var(--primary); font-size: .78rem; font-weight: 800; }
.dashboard-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.compact-list, .company-list, .contact-list, .history-list, .plain-list { margin: .8rem 0 0; padding: 0; list-style: none; }
.compact-list li + li, .company-list li + li, .contact-list li + li, .history-list li + li { border-top: 1px solid var(--line); }
.compact-list a, .company-list a { display: flex; flex-direction: column; gap: .12rem; padding: .65rem 0; color: var(--ink); text-decoration: none; }
.compact-list a span, .company-list a span { color: var(--muted); font-size: .86rem; }
.empty { padding: 1rem 0; color: var(--muted); }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 2rem 0; }
.login-card { width: min(440px, 100%); padding: 2rem; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 24px 70px rgb(16 35 63 / 13%); }
.stacked-form { display: grid; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field label { font-size: .88rem; font-weight: 700; }
.field input:not([type=checkbox]), .field select, .field textarea { width: 100%; min-height: 42px; padding: .58rem .65rem; border: 1px solid #aeb8ca; border-radius: 6px; background: #fff; color: var(--ink); }
.field textarea { min-height: 95px; resize: vertical; }
.field-check label, .check-row label { display: flex; align-items: flex-start; gap: .5rem; font-weight: 600; }
.errorlist, .form-errors { margin: .2rem 0 0; padding-left: 1.1rem; color: var(--danger); font-size: .86rem; }
.form-actions, .header-actions, .action-strip, .small-actions, .heading-badges { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.messages { margin-bottom: 1rem; }
.message, .notice { padding: .8rem 1rem; border-radius: 7px; border: 1px solid var(--line); background: #fff; }
.message-success { border-color: #93cdbf; background: var(--teal-soft); }
.message-error, .notice-danger { border-color: #e5adad; background: var(--danger-soft); color: #7f1d1d; }
.notice-warning { border-color: #e7ce70; background: var(--warning-soft); color: #5f4b00; }
.search-form { padding: 1rem; margin-bottom: 1.4rem; }
.search-main { display: flex; gap: .7rem; align-items: flex-end; }
.field-grow { flex: 1; }
.search-main input { font-size: 1.05rem; }
.filter-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .8rem; margin-top: 1rem; }
.more-filters { margin-top: 1rem; padding-top: .8rem; border-top: 1px solid var(--line); }
.more-filters summary { cursor: pointer; color: var(--primary); font-weight: 700; }
.check-row { display: flex; gap: 1.2rem; flex-wrap: wrap; margin-top: .9rem; }
.results-heading { margin: 1rem 0 .7rem; }
.results-heading span { color: var(--muted); }
.results-list { display: grid; gap: .7rem; }
.result-card { display: grid; grid-template-columns: minmax(0, 1fr) 190px; gap: 1rem; padding: 1rem; }
.result-title-row h3 { margin: 0; font-size: 1.1rem; }
.location { margin: .3rem 0; color: var(--muted); }
.product-preview { margin-bottom: .45rem; }
.result-meta { display: flex; gap: 1rem; flex-wrap: wrap; color: var(--muted); font-size: .85rem; }
.match-reason { margin: .55rem 0 0; color: var(--teal); font-size: .85rem; font-weight: 700; }
.result-action { display: flex; flex-direction: column; align-items: flex-end; justify-content: center; gap: .6rem; }
.selection-badge, .historical-badge, .current-badge, .primary-label { display: inline-flex; padding: .28rem .55rem; border-radius: 999px; background: var(--teal-soft); color: var(--teal); font-size: .75rem; font-weight: 800; }
.historical-badge { background: #f1ecff; color: #5d3aa5; }
.current-badge { background: var(--primary-soft); color: var(--primary); }
.primary-label { padding: .14rem .4rem; font-size: .65rem; }
.status { display: inline-flex; padding: .28rem .55rem; border-radius: 999px; background: #edf0f5; color: #38445a; font-size: .75rem; font-weight: 800; white-space: nowrap; }
.status-do_not_contact { background: var(--danger-soft); color: var(--danger); }
.status-interested, .status-meeting_planned { background: var(--teal-soft); color: var(--teal); }
.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1.2rem; }
.pagination a { padding: .45rem .7rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; text-decoration: none; }
.company-heading { padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.back-link { display: inline-block; margin-bottom: .7rem; color: var(--muted); text-decoration: none; }
.company-layout { display: grid; gap: 1.4rem; }
.company-section { padding: 1.2rem; }
.historical-section { border-left: 5px solid #7656b5; }
.crm-section { border-left: 5px solid var(--primary); }
.section-heading { margin-bottom: 1rem; }
.section-heading h2 { margin: 0; font-size: 1.55rem; }
.info-grid, .crm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
.info-card { padding: .9rem; border: 1px solid var(--line); border-radius: 8px; background: #fbfbfd; }
.info-card h3 { margin-bottom: .6rem; }
.info-card address { margin-bottom: .7rem; font-style: normal; }
.plain-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .3rem 0; }
.metric { margin: 0; font-size: 1.65rem; font-weight: 800; }
.metric small { font-size: .8rem; font-weight: 500; }
.products-block { margin-top: .9rem; padding-top: .9rem; border-top: 1px solid var(--line); }
.tag-list { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0; padding: 0; list-style: none; }
.tag-list li { padding: .35rem .55rem; border: 1px solid #d7ddeb; border-radius: 5px; background: #f7f8fb; font-size: .84rem; }
.products-block details { margin-top: .7rem; }
.products-block summary { cursor: pointer; color: var(--primary); font-weight: 700; }
.all-products { margin-top: .7rem; }
.action-strip { margin-bottom: 1rem; }
.crm-grid { margin-bottom: .8rem; }
.definition-list { display: grid; grid-template-columns: 110px 1fr; gap: .45rem .7rem; margin: .8rem 0 0; }
.definition-list dt { color: var(--muted); font-size: .85rem; }
.definition-list dd { margin: 0; overflow-wrap: anywhere; }
.contact-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .7rem 0; }
.contact-list li > div:first-child { display: flex; flex-direction: column; align-items: flex-start; gap: .12rem; }
.contact-list .inactive { opacity: .58; }
.small-actions { font-size: .82rem; }
.small-actions form { margin: 0; }
.link-button { padding: 0; border: 0; background: transparent; color: var(--primary); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.danger-text { color: var(--danger); }
.full-panel { margin-top: .8rem; }
.table-wrap { overflow-x: auto; margin-top: .7rem; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .65rem .55rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: .75rem; letter-spacing: .04em; text-transform: uppercase; }
.history-list li { padding: .7rem 0; }
.history-list time, .timeline time { display: block; color: var(--muted); font-size: .78rem; }
.history-list p { margin: .25rem 0; }
.timeline { margin: .8rem 0 0; padding: 0 0 0 1.2rem; list-style: none; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 1rem 1rem; }
.timeline li::before { content: ""; position: absolute; left: -1.57rem; top: .3rem; width: .65rem; height: .65rem; border: 3px solid #fff; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 1px var(--line); }
.timeline p { margin: .2rem 0 0; white-space: pre-wrap; }
.narrow-page { width: min(720px, 100%); margin: 0 auto; }
.narrow-page .panel { padding: 1.2rem; }
.form-actions { margin-top: .4rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 980px) {
  .dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .app-header { flex-wrap: wrap; gap: .5rem 1rem; }
  .user-menu { margin-left: 0; }
  .result-card { grid-template-columns: 1fr; }
  .result-action { align-items: flex-start; }
}

@media (max-width: 680px) {
  .page-shell { width: min(100% - 1rem, 1440px); padding-top: 1rem; }
  .app-header nav { order: 3; width: 100%; overflow-x: auto; }
  .user-menu { margin-left: auto; }
  .page-heading, .company-heading, .search-main { flex-direction: column; align-items: stretch; }
  .dashboard-grid, .info-grid, .crm-grid, .filter-row { grid-template-columns: 1fr; }
  .header-actions { justify-content: flex-start; }
  .contact-list li { flex-direction: column; }
}
