:root {
  --ink: #142135;
  --muted: #637083;
  --line: #dce3ea;
  --panel: #ffffff;
  --canvas: #f4f6f9;
  --navy: #12375a;
  --blue: #1769aa;
  --blue-dark: #0c4c83;
  --cyan: #dff4ff;
  --green: #17734b;
  --green-bg: #e5f6ee;
  --amber: #93610a;
  --amber-bg: #fff3cf;
  --red: #a22e32;
  --red-bg: #fde9e9;
  --shadow: 0 14px 36px rgba(20, 33, 53, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: linear-gradient(180deg, #edf3f8 0, var(--canvas) 240px); }
a { color: var(--blue-dark); text-underline-offset: 3px; }
a:hover { color: var(--blue); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 10px clamp(18px, 4vw, 56px);
  color: #fff;
  background: linear-gradient(110deg, #0c2946, #114f7e);
  box-shadow: 0 3px 16px rgba(7, 28, 48, .24);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; white-space: nowrap; }
.brand:hover { color: #fff; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: #fff; color: var(--navy); font-size: 24px; font-weight: 850; }
.brand strong, .brand small { display: block; }
.brand small { color: #b8d1e5; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.nav { display: flex; align-items: center; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { color: #eaf6ff; text-decoration: none; padding: 9px 11px; border-radius: 8px; white-space: nowrap; font-size: 14px; }
.nav a:hover { background: rgba(255,255,255,.12); }
.account { display: grid; grid-template-columns: auto auto; align-items: center; gap: 2px 8px; font-size: 13px; }
.account a, .link-button { color: #fff; }
.account form { grid-column: 2; grid-row: 1 / 3; }
.account .role { color: #b8d1e5; font-size: 11px; }
.link-button { border: 0; background: transparent; cursor: pointer; text-decoration: underline; padding: 5px; }

.page { width: min(1760px, calc(100% - 32px)); margin: 34px auto; min-height: calc(100vh - 160px); }
.footer { padding: 22px; text-align: center; color: var(--muted); font-size: 12px; }
.page-heading { margin: 0 0 24px; }
.page-heading h1, .auth-heading h1 { margin: 4px 0 8px; font-size: clamp(28px, 4vw, 42px); line-height: 1.08; letter-spacing: -.035em; }
.page-heading p, .auth-heading p { margin: 0; color: var(--muted); max-width: 760px; }
.heading-actions { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.eyebrow { color: var(--blue); text-transform: uppercase; letter-spacing: .12em; font-size: 11px; font-weight: 800; }
h2 { margin: 4px 0 14px; font-size: 19px; }
.panel, .table-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.panel { padding: 20px; }
.top-gap { margin-top: 20px; }

.toolbar, .inline-form, .bulk-bar, .form-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.button { min-height: 39px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 9px; padding: 8px 13px; font-weight: 720; font-size: 13px; text-decoration: none; cursor: pointer; transition: transform .1s ease, box-shadow .1s ease, background .1s ease; }
.button:hover { transform: translateY(-1px); text-decoration: none; }
.button.primary { color: #fff; background: var(--blue); border-color: var(--blue); box-shadow: 0 5px 13px rgba(23,105,170,.22); }
.button.primary:hover { color: #fff; background: var(--blue-dark); }
.button.secondary { color: var(--navy); background: #fff; border-color: #bdcad6; }
.button.warning { color: #5f3a00; background: #ffd978; border-color: #e6b84c; }
.button.danger-outline { color: var(--red); background: #fff; border-color: #e8b7ba; }
.button.tiny { min-height: 30px; padding: 5px 9px; font-size: 12px; }
.button.wide { width: 100%; }

.flash-stack { display: grid; gap: 8px; margin-bottom: 20px; }
.flash { border-radius: 10px; padding: 12px 15px; border: 1px solid; font-size: 14px; }
.flash-success { color: #0d5637; background: var(--green-bg); border-color: #aedcc8; }
.flash-error { color: #812126; background: var(--red-bg); border-color: #efb6b8; }
.flash-warning { color: #6e4703; background: var(--amber-bg); border-color: #eed386; }

.auth-card { width: min(470px, 100%); margin: max(5vh, 30px) auto; padding: clamp(24px, 5vw, 44px); background: #fff; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.auth-heading { margin-bottom: 26px; }
.error-card { text-align: center; }
.stack-form { display: grid; gap: 16px; }
label { display: grid; gap: 6px; color: #344156; font-size: 13px; font-weight: 690; }
input, select, textarea { width: 100%; border: 1px solid #bac7d3; border-radius: 8px; background: #fff; color: var(--ink); padding: 9px 10px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23,105,170,.14); }
textarea { resize: vertical; line-height: 1.45; }
input[type="file"] { background: #f8fafc; padding: 8px; }
.check { display: flex; grid-auto-flow: column; align-items: center; justify-content: start; gap: 7px; font-weight: 550; }
.check input { width: 16px; height: 16px; margin: 0; }
.hint, small { display: block; color: var(--muted); font-size: 12px; line-height: 1.4; }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.control-strip { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; padding: 14px 18px; }
.control-strip label { display: flex; align-items: center; gap: 10px; }
.control-strip select { width: auto; min-width: 150px; }
.summary-grid { display: grid; grid-template-columns: repeat(6, minmax(125px, 1fr)); gap: 10px; margin: 0 0 18px; }
.summary-grid article { padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.summary-grid article.accent { background: var(--amber-bg); border-color: #efd281; }
.summary-grid strong { display: block; font-size: 27px; line-height: 1; }
.summary-grid span { display: block; color: var(--muted); margin-top: 7px; font-size: 12px; }
.upload-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.upload-card { display: grid; grid-template-columns: 1.1fr 1.4fr auto; gap: 14px; align-items: center; }
.upload-card h2, .upload-card p { margin: 2px 0; }
.upload-card p { color: var(--muted); font-size: 13px; }
.bulk-bar { margin-bottom: 12px; padding: 12px 16px; }

.table-panel { overflow: hidden; }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { padding: 13px 11px; text-align: left; color: #4b5a70; background: #eef3f7; border-bottom: 1px solid #cbd6df; white-space: nowrap; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.data-table td { padding: 12px 11px; vertical-align: top; border-bottom: 1px solid #e5e9ee; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #f8fbfd; }
.data-table td > strong { display: inline-block; margin-bottom: 5px; }
.data-table td a { display: block; margin-top: 5px; font-size: 12px; }
.select-cell { width: 34px; text-align: center !important; }
.select-cell input { width: 17px; height: 17px; }
.row-missing { box-shadow: inset 4px 0 var(--red); }
.row-wait { box-shadow: inset 4px 0 #e8b436; }
.row-good { box-shadow: inset 4px 0 var(--green); }
.row-archived { opacity: .65; }
.badge { display: inline-block; border-radius: 999px; padding: 3px 8px; font-size: 10px; font-weight: 820; letter-spacing: .035em; text-transform: uppercase; }
.badge.success { color: var(--green); background: var(--green-bg); }
.badge.warning { color: var(--amber); background: var(--amber-bg); }
.badge.danger { color: var(--red); background: var(--red-bg); }
.badge.muted { color: #556174; background: #e9edf1; }
.compact-form { min-width: 170px; display: grid; gap: 6px; }
.compact-form input, .compact-form select { padding: 6px 7px; font-size: 12px; }
details { min-width: 124px; }
summary { color: var(--blue-dark); cursor: pointer; font-weight: 700; }
.mini-upload { display: grid; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.mini-upload:last-child { border-bottom: 0; }
.mini-upload label { font-size: 11px; }
.mini-upload input { max-width: 170px; font-size: 10px; }
.empty { padding: 36px !important; text-align: center; color: var(--muted); }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.full-span { grid-column: 1 / -1; }
.company-form { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; }
.company-form label { min-width: 180px; }
.company-form .grow { flex: 1; min-width: 270px; }
.card-list { display: grid; gap: 12px; margin-top: 14px; }
.company-card { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.company-card.archived { background: #f0f2f4; }
.company-card > form:first-child { flex: 1; }
.archive-action { display: grid; justify-items: end; gap: 9px; min-width: 110px; }
.user-card { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.user-card h2 { margin-bottom: 4px; }
.unmatched-card { display: grid; grid-template-columns: minmax(220px, .7fr) 1.3fr; gap: 30px; }
.unmatched-delete-form { margin-top: 16px; }
.assign-form { display: grid; grid-template-columns: 1.4fr .8fr 1fr; gap: 10px; align-items: end; }
.assign-form .two-cols { grid-column: 1 / 3; }
.error-text { color: var(--red); }
.message-preview { max-width: 900px; margin: 0 auto; }
.message-preview dl { display: grid; grid-template-columns: 90px 1fr; gap: 8px 16px; margin: 0 0 24px; }
.message-preview dt { color: var(--muted); font-size: 12px; font-weight: 750; text-transform: uppercase; }
.message-preview dd { margin: 0; }
.message-body { padding: 22px; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; white-space: pre-wrap; line-height: 1.55; }

.report-table td:not(:first-child), .report-table th:not(:first-child) { text-align: center; }
.stat-good { box-shadow: inset 5px 0 var(--green); }
.stat-warn { box-shadow: inset 5px 0 #e8b436; }
.stat-bad { box-shadow: inset 5px 0 var(--red); }
meter { display: block; width: 130px; height: 11px; margin: 5px auto 0; }
.legend { display: flex; justify-content: flex-end; align-items: center; gap: 7px; margin: 12px 5px; color: var(--muted); font-size: 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-left: 8px; }
.dot.good { background: var(--green); }.dot.warn { background: #e8b436; }.dot.bad { background: var(--red); }
.sr-only { 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: 1100px) {
  .topbar { flex-wrap: wrap; gap: 10px 18px; }
  .nav { order: 3; width: 100%; }
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
  .upload-card { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .full-span { grid-column: auto; }
  .company-card, .user-card { align-items: stretch; flex-direction: column; }
  .archive-action { display: flex; align-items: center; justify-content: flex-end; }
}

@media (max-width: 760px) {
  .page { width: min(100% - 20px, 1760px); margin-top: 22px; }
  .topbar { padding: 10px 14px; }
  .account { margin-left: auto; }
  .heading-actions, .control-strip { align-items: stretch; flex-direction: column; }
  .toolbar { width: 100%; }
  .toolbar .button { flex: 1; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .upload-grid { grid-template-columns: 1fr; }
  .two-cols { grid-template-columns: 1fr; }
  .company-form { align-items: stretch; flex-direction: column; }
  .company-form label, .company-form .grow { min-width: 0; width: 100%; }
  .unmatched-card { grid-template-columns: 1fr; }
  .assign-form { grid-template-columns: 1fr; }
  .assign-form .two-cols { grid-column: auto; }
}
