:root {
  color-scheme: dark;
  --bg: #071827;
  --panel: #0c2236;
  --panel-soft: #102b43;
  --line: #26455f;
  --text: #f1f7fb;
  --muted: #9db4c7;
  --accent: #25bce8;
  --accent-dark: #087ca1;
  --done: #29ca8c;
  --danger: #ff7885;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-view { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: radial-gradient(circle at top, #163d5e, var(--bg) 54%); }
.login-card { width: min(430px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 24px; background: rgba(12, 34, 54, .95); box-shadow: 0 22px 60px rgba(0, 0, 0, .38); }
.brand-mark { display: grid; width: 54px; height: 54px; place-items: center; border-radius: 16px; color: #042031; background: var(--accent); font-weight: 950; }
.eyebrow { margin: 18px 0 6px; color: var(--accent); font-size: .76rem; font-weight: 900; letter-spacing: .11em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
.login-card h1 { margin-bottom: 10px; font-size: 2rem; }
.login-card > p:not(.eyebrow):not(.error) { color: var(--muted); line-height: 1.55; }
label { color: var(--muted); font-size: .86rem; font-weight: 800; }
input, select, textarea { width: 100%; min-height: 44px; margin-top: 7px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; color: var(--text); background: #081b2b; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 188, 232, .15); }
.login-card button { width: 100%; margin-top: 16px; }
.error { min-height: 20px; margin: 12px 0 0; color: var(--danger); }

.primary, .secondary { min-height: 42px; border-radius: 10px; padding: 9px 14px; font-weight: 850; }
.primary { border: 1px solid var(--accent); color: #041f2e; background: var(--accent); }
.primary:hover { background: #68d8f5; }
.secondary { border: 1px solid var(--line); color: var(--text); background: var(--panel-soft); }
.secondary:hover { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: wait; }

.app-shell { min-height: 100vh; }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 84px; padding: 14px 22px; border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar .eyebrow { margin: 0 0 4px; }
.topbar h1 { margin: 0; font-size: clamp(1.2rem, 2vw, 1.75rem); }
.topbar-actions, .bulk-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.workspace { display: grid; grid-template-columns: 390px minmax(0, 1fr); height: calc(100vh - 126px); min-height: 620px; transition: grid-template-columns .2s ease; }
.app-shell.sidebar-collapsed .workspace { grid-template-columns: 0 minmax(0, 1fr); }
.app-shell.sidebar-collapsed .sidebar { visibility: hidden; padding: 0; border: 0; overflow: hidden; }
.sidebar { overflow-y: auto; padding: 16px; border-right: 1px solid var(--line); background: var(--panel); }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.summary-grid article { padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-soft); }
.summary-grid span { display: block; color: var(--muted); font-size: .72rem; font-weight: 800; }
.summary-grid strong { display: block; margin-top: 5px; font-size: 1.45rem; }
.load-card, .import-panel, .mailing-panel { margin-top: 14px; padding: 15px; border: 1px solid var(--line); border-radius: 14px; background: #0a1e31; }
.load-card h2, .import-panel h2, .mailing-panel h2, .list-heading h2 { margin-bottom: 6px; font-size: 1rem; }
.load-card p, .import-panel p, .mailing-panel > p { margin-bottom: 12px; color: var(--muted); font-size: .82rem; line-height: 1.45; }
.load-card .primary { width: 100%; }
.load-card small { display: block; margin-top: 9px; color: var(--muted); }
.filters { display: grid; gap: 11px; margin: 16px 0; }
.check-row { display: flex; align-items: center; gap: 9px; }
.check-row input, .business-check input { width: 19px; min-height: 19px; margin: 0; accent-color: var(--done); }
.bulk-actions button { flex: 1 1 150px; }
.mailing-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mailing-heading .eyebrow { margin: 0 0 4px; }
.mailing-heading h2 { margin: 0; }
.mailing-heading strong { display: grid; min-width: 43px; height: 43px; place-items: center; border-radius: 50%; color: #052333; background: var(--accent); font-size: 1.05rem; }
.mailing-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.mailing-actions .wide { grid-column: 1 / -1; }
.mailing-panel .check-row { margin: 10px 0; }
.mailing-panel select { margin-bottom: 4px; }
.mailing-panel small { display: block; margin: 5px 0 10px; color: var(--muted); line-height: 1.35; }
.mailing-panel > .primary { width: 100%; }
.import-panel input { margin-bottom: 10px; }
.list-heading { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 9px; }
.list-heading h2 { margin: 0; }
.list-heading span { color: var(--muted); font-size: .8rem; }
.business-list { display: grid; gap: 9px; padding-bottom: 30px; }
.business-card { display: grid; grid-template-columns: 27px minmax(0, 1fr); gap: 9px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-soft); transition: border-color .15s, opacity .15s; }
.business-card:hover { border-color: var(--accent); }
.business-card.done { opacity: .68; }
.business-card.done h3 { text-decoration: line-through; }
.business-card.label-excluded { border-color: #4a3a45; }
.business-card h3 { margin: 0 0 5px; font-size: .94rem; }
.business-card p { margin: 3px 0; color: var(--muted); font-size: .77rem; line-height: 1.35; }
.business-card button { border: 0; padding: 0; color: var(--accent); background: transparent; font-size: .76rem; font-weight: 800; }
.postal-address { color: #d4e5f0 !important; }
.address-source { display: block; margin: 3px 0 6px; color: #f4bb69; font-size: .7rem; font-weight: 750; line-height: 1.35; }
.card-links { display: flex; flex-wrap: wrap; gap: 5px 10px; margin-top: 7px; }
.card-links a { color: #7edcf5; font-size: .74rem; font-weight: 750; text-decoration: none; }
.card-links a:hover { text-decoration: underline; }
.card-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }
.business-check { display: flex; align-items: flex-start; padding-top: 2px; }
.label-choice { display: inline-flex; align-items: center; gap: 7px; margin: 1px 0 7px; color: #bdeeff; font-size: .75rem; }
.label-choice input { width: 17px; min-height: 17px; margin: 0; accent-color: var(--accent); }
.empty { padding: 24px 10px; color: var(--muted); text-align: center; line-height: 1.5; }

.map-panel { position: relative; min-width: 0; }
#map { width: 100%; height: 100%; background: #dbe7ed; }
.map-legend { position: absolute; z-index: 500; right: 14px; bottom: 24px; display: flex; flex-wrap: wrap; gap: 12px; max-width: calc(100% - 28px); padding: 9px 12px; border-radius: 10px; color: #11283a; background: rgba(255, 255, 255, .94); box-shadow: 0 4px 18px rgba(0, 0, 0, .2); font-size: .76rem; font-weight: 800; }
.map-legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot, .ring { display: inline-block; width: 12px; height: 12px; border-radius: 50%; }
.dot.todo { background: var(--accent-dark); }
.dot.done { background: #169f6d; }
.ring { border: 2px solid #e48f27; background: rgba(255, 174, 58, .2); }
.status-message { position: absolute; z-index: 600; top: 13px; left: 50%; max-width: min(620px, calc(100% - 28px)); margin: 0; padding: 10px 14px; border-radius: 9px; color: #10283b; background: #fff; box-shadow: 0 5px 18px rgba(0, 0, 0, .22); transform: translateX(-50%); font-weight: 750; }
.status-message:empty { display: none; }
.leaflet-popup-content { min-width: 230px; color: #10283b; }
.popup-card h3 { margin-bottom: 6px; }
.popup-card p { margin: 5px 0; }
.popup-card a { color: #087ca1; }
.popup-links a { display: inline-block; margin: 2px 0; }
.popup-card .address-source { color: #7c5319; }
.popup-check { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-weight: 800; }
.popup-check input { width: 18px; min-height: 18px; margin: 0; }

footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 42px; padding: 8px 18px; color: var(--muted); background: #06131f; font-size: .72rem; }

.contact-dialog { width: min(590px, calc(100% - 28px)); border: 1px solid var(--line); border-radius: 18px; padding: 0; color: var(--text); background: var(--panel); box-shadow: 0 24px 70px rgba(0, 0, 0, .52); }
.contact-dialog::backdrop { background: rgba(2, 12, 21, .76); backdrop-filter: blur(3px); }
.contact-dialog form { display: grid; gap: 12px; padding: 22px; }
.contact-dialog input, .contact-dialog textarea { margin-top: 5px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dialog-heading .eyebrow { margin: 0 0 4px; }
.dialog-heading h2 { margin: 0; }
.icon-button { border: 0; color: var(--text); background: transparent; font-size: 2rem; line-height: 1; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 4px; }

.print-labels-view { min-height: 100vh; padding: 24px; color: #14202a; background: #dce5ea; }
.print-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; max-width: 8.5in; margin: 0 auto 20px; padding: 18px; border-radius: 14px; color: var(--text); background: var(--panel); box-shadow: 0 10px 30px rgba(0, 0, 0, .16); }
.print-toolbar .eyebrow { margin: 0 0 4px; }
.print-toolbar h1 { margin: 0 0 5px; font-size: 1.45rem; }
.print-toolbar p:last-child { margin: 0; color: var(--muted); font-size: .84rem; }
.print-toolbar .print-tip { margin-top: 4px; color: #f4bb69; font-weight: 750; }
.label-sheets { display: grid; justify-content: center; gap: 22px; }
.label-sheet { display: grid; grid-template-columns: repeat(3, 2.625in); grid-template-rows: repeat(10, 1in); column-gap: .125in; width: 8.5in; min-height: 11in; padding: .5in .1875in; overflow: hidden; background: #fff; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); }
.postal-label { display: flex; min-width: 0; padding: .08in .1in; overflow: hidden; flex-direction: column; justify-content: center; color: #000; font-family: Arial, Helvetica, sans-serif; font-size: 9pt; line-height: 1.15; overflow-wrap: anywhere; }
.postal-label strong { display: block; margin-bottom: 2px; font-size: 9.5pt; }
.postal-label span { display: block; }

@media (max-width: 850px) {
  .topbar { align-items: flex-start; flex-direction: column; gap: 10px; }
  .workspace { display: flex; height: auto; min-height: 0; flex-direction: column-reverse; }
  .app-shell.sidebar-collapsed .workspace { display: block; }
  .app-shell.sidebar-collapsed .map-panel { height: calc(100vh - 138px); }
  .map-panel { height: 58vh; min-height: 410px; }
  .sidebar { overflow: visible; border-top: 1px solid var(--line); border-right: 0; }
  footer { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 480px) {
  .topbar { padding: 13px; }
  .topbar-actions { width: 100%; }
  .topbar-actions button { flex: 1; }
  .summary-grid article { padding: 10px; }
  .sidebar { padding: 12px; }
  .map-panel { height: 52vh; }
}

@media print {
  @page { size: Letter portrait; margin: .5in .1875in; }
  body { min-height: 0; background: #fff; }
  #appView, .print-toolbar { display: none !important; }
  #printLabelsView { display: block !important; min-height: 0; padding: 0; background: #fff; }
  .label-sheets { display: block; }
  .label-sheet { width: 8.125in; min-height: 10in; padding: 0; box-shadow: none; break-after: page; page-break-after: always; }
  .label-sheet:last-child { break-after: auto; page-break-after: auto; }
}
