:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafd;
  --border: #dde3ee;
  --border-strong: #c3ccdc;
  --text: #1b2437;
  --muted: #5d6a82;
  --primary: #2354c8;
  --primary-dark: #1a3f98;
  --primary-soft: #e6edfc;
  --nav-bg: #14213d;
  --nav-text: #c9d3ea;
  --success: #17794a;
  --success-soft: #e2f5ec;
  --danger: #b3261e;
  --danger-soft: #fdeceb;
  --warn: #8a5a00;
  --warn-soft: #fff3d6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 33, 61, .06), 0 4px 14px rgba(20, 33, 61, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.45; }
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .6rem; }
a { color: var(--primary); }
:focus-visible { outline: 3px solid #7aa2ff; outline-offset: 2px; border-radius: 4px; }

.skip-link { position: absolute; left: -999px; top: 8px; background: var(--primary); color: #fff; padding: 8px 12px; border-radius: 6px; z-index: 100; }
.skip-link:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 14px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--nav-bg); color: var(--nav-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 700; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; background: #2f6bff; font-size: .85rem; letter-spacing: .5px; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; overflow-y: auto; flex: 1; }
.nav-group { padding: 14px 10px 4px; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: #8393b5; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; color: var(--nav-text); text-decoration: none; border-radius: 8px; }
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a[aria-current="page"] { background: #2f6bff; color: #fff; }
.nav .ico { width: 20px; text-align: center; opacity: .9; }
.sidebar-foot { padding: 12px 14px 16px; border-top: 1px solid rgba(255,255,255,.1); }
.user-box { display: flex; flex-direction: column; gap: 8px; font-size: .88rem; }
.user-box .who strong { color: #fff; }
.content { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.page-title { font-size: 1.3rem; margin-right: auto; }
.page-title:focus { outline: none; }
.context-bar { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.context-bar label { font-size: .78rem; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.main { padding: 22px 24px 48px; max-width: 1500px; width: 100%; }
.main:focus { outline: none; }
.menu-btn { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(10, 18, 36, .5); z-index: 19; }

@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 270px; z-index: 20; transform: translateX(-102%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 10px 14px; }
  .main { padding: 16px 14px 40px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.stack > * + * { margin-top: 16px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat .num { font-size: 1.9rem; font-weight: 700; letter-spacing: -.5px; }
.stat .lbl { color: var(--muted); font-size: .88rem; }

.btn { font: inherit; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; min-height: 38px; }
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: #9fb0cf; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { background: #8f1d17; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn.ghost:hover:not(:disabled) { background: var(--primary-soft); }
.btn.on-dark { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.25); color: #fff; }
.btn.on-dark:hover:not(:disabled) { background: rgba(255,255,255,.2); }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: .88rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.icon-btn { font: inherit; width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; place-items: center; font-size: 1.2rem; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .field > .lbl { font-weight: 600; font-size: .9rem; }
.req { color: var(--danger); margin-left: 2px; }
input[type=text], input[type=search], input[type=email], input[type=tel], input[type=url], input[type=number], input[type=date], input[type=password], select, textarea {
  font: inherit; color: var(--text); background: #fff; border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; min-height: 38px; width: 100%;
}
textarea { min-height: 84px; resize: vertical; }
input:disabled, select:disabled { background: #eef1f7; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); background: #fffafa; }
.help { font-size: .82rem; color: var(--muted); }
.err { font-size: .84rem; color: var(--danger); font-weight: 600; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: 18px; height: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px 18px; }
.form-grid .wide { grid-column: 1 / -1; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #e8ecf4; color: #34415c; white-space: nowrap; }
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--primary-soft); color: var(--primary-dark); }
.badge.sample { background: #fff3d6; color: #8a5a00; border: 1px dashed #d9a93c; }

.banner { padding: 11px 14px; border-radius: 8px; border: 1px solid; margin-bottom: 14px; }
.banner.info { background: var(--primary-soft); border-color: #b9ccf5; }
.banner.warn { background: var(--warn-soft); border-color: #ecc666; }
.banner.error { background: var(--danger-soft); border-color: #f1b2ae; color: #7a1812; }
.banner.success { background: var(--success-soft); border-color: #a6dcc0; color: #0f5233; }
.banner strong { display: block; }
.banner ul { margin: 6px 0 0; padding-left: 20px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 14px; }
.toolbar .field { min-width: 150px; }
.toolbar .grow { flex: 1 1 240px; }
.toolbar .spacer { margin-left: auto; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { background: var(--surface-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; position: sticky; top: 0; }
tbody tr:hover { background: #fafcff; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .cell { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sort-btn { font: inherit; text-transform: inherit; letter-spacing: inherit; color: inherit; background: none; border: none; padding: 0; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
.sort-btn:hover { color: var(--text); }
.row-actions { display: flex; gap: 6px; }
.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; justify-content: space-between; margin-top: 12px; }

.empty { text-align: center; padding: 44px 16px; color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: 6px; }
.empty .btn-row { justify-content: center; margin-top: 12px; }
.spinner { width: 22px; height: 22px; border: 3px solid #cdd8f0; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; gap: 10px; padding: 30px; justify-content: center; color: var(--muted); }

.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 28px 16px; text-align: center; background: var(--surface-2); cursor: pointer; transition: background .15s, border-color .15s; }
.dropzone:hover, .dropzone.over { background: var(--primary-soft); border-color: var(--primary); }
.dropzone .big { font-size: 1.05rem; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0 14px; }
.chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 14px; }
.chip b { font-size: 1.25rem; display: block; }
.chip.bad { background: var(--danger-soft); border-color: #f1b2ae; }
.chip.ok { background: var(--success-soft); border-color: #a6dcc0; }
.steps { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; padding: 0; list-style: none; }
.steps li { padding: 4px 12px; border-radius: 999px; background: #e8ecf4; color: var(--muted); font-size: .85rem; }
.steps li.on { background: var(--primary); color: #fff; }
.steps li.done { background: var(--success-soft); color: var(--success); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.col-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 16px; }

/* ---------- dialog ---------- */
dialog { border: none; border-radius: 12px; padding: 0; width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: 0 20px 60px rgba(10, 18, 36, .35); color: var(--text); }
dialog.narrow { width: min(460px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(10, 18, 36, .5); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: #fff; z-index: 1; }
.dlg-body { padding: 18px; overflow-y: auto; max-height: calc(100vh - 160px); }
.dlg-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; background: var(--surface-2); }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: min(420px, calc(100vw - 32px)); }
.toast { cursor: pointer; background: #1b2437; color: #fff; padding: 11px 14px; border-radius: 8px; box-shadow: var(--shadow); border-left: 5px solid #7aa2ff; }
.toast.success { border-left-color: #43c586; }
.toast.error { border-left-color: #ff7a72; background: #3a1512; }

/* ---------- login ---------- */
.login-view { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #14213d, #25418a); }
.login-card { background: #fff; border-radius: 14px; padding: 28px; width: min(400px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login-card h1 { font-size: 1.4rem; margin-bottom: 4px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }

/* ---------- business directory ---------- */
.name-cell { display: flex; align-items: center; gap: 8px; max-width: 340px; }
.link-btn { font: inherit; color: var(--primary); background: none; border: none; padding: 0; cursor: pointer; text-align: left; font-weight: 600; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-btn:hover { text-decoration: underline; }
td .cell.wrap { white-space: normal; max-width: 340px; overflow-wrap: anywhere; }
.break { overflow-wrap: anywhere; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; font-size: .85em; overflow-wrap: anywhere; }
ul.plain { margin: 6px 0 0; padding-left: 18px; }
ul.plain li { margin: 3px 0; }

.detail { display: flex; flex-direction: column; gap: 16px; }
.detail-sec h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.detail-grid { display: grid; grid-template-columns: minmax(120px, 190px) 1fr; gap: 6px 16px; margin: 0; }
.detail-grid dt { color: var(--muted); font-size: .88rem; }
.detail-grid dd { margin: 0; min-width: 0; }
@media (max-width: 560px) { .detail-grid { grid-template-columns: 1fr; gap: 0; } .detail-grid dd { margin-bottom: 8px; } }

.form-section { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 16px; margin: 0; min-width: 0; }
.form-section legend { font-weight: 700; padding: 0 8px; font-size: .92rem; }

/* explains, next to a button, why it can or cannot be pressed */
.why { margin: 12px 0 8px; padding: 8px 12px; border-radius: 8px; font-size: .92rem; border: 1px solid transparent; }
.why.needs { background: var(--warn-soft); color: var(--warn); border-color: #ecc666; }
.why.ok { background: var(--success-soft); color: var(--success); border-color: #a6dcc0; }
.req-list { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 4px 0 14px; }
.req-item.ok { color: var(--success); font-weight: 600; }
.req-item.bad { color: var(--danger); font-weight: 600; }
select.dup { border-color: var(--danger); background: #fffafa; }
.chip.warn { background: var(--warn-soft); border-color: #ecc666; }
.stat-link { margin-top: 4px; }

.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; margin-bottom: 16px; }
.two-col > .card + .card { margin-top: 0; }
.stack > .card + .card { margin-top: 16px; }
.bar-col { width: 38%; min-width: 90px; }
.bar { background: #e8ecf4; border-radius: 999px; height: 9px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }

.issue-group { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; background: var(--surface-2); }
.issue-group summary { cursor: pointer; }
details > summary { cursor: pointer; font-weight: 600; }
.steps li { white-space: nowrap; }
.card h3 { margin: 14px 0 6px; }
.card h3:first-child { margin-top: 0; }
.grid-cards.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .grid-cards.cols-4 { grid-template-columns: repeat(2, 1fr); } }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.filter-grid .grow { grid-column: span 2; }
.dir-table td .cell { max-width: 170px; }
.dir-table .name-cell { max-width: 260px; }
.dir-table .link-btn { max-width: 230px; }
.dir-table td { white-space: nowrap; }
.dir-table td .cell { overflow: hidden; text-overflow: ellipsis; }
