:root {
  --bg: #0f1419;
  --bg-elev: #171e26;
  --bg-card: #1c2530;
  --line: #2a3644;
  --text: #e8eef4;
  --muted: #8b9aab;
  --accent: #2dd4a8;
  --accent-dim: #0f3d32;
  --danger: #f07167;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

html[data-theme="light"] {
  --bg: #f4f7fb;
  --bg-elev: #ffffff;
  --bg-card: #fafdff;
  --line: #d7e0eb;
  --text: #243447;
  --muted: #64748b;
  --accent: #2563a8;
  --accent-dim: #e3edf8;
  --danger: #b42335;
  --shadow: 0 2px 6px rgba(36, 52, 71, .08), 0 10px 24px rgba(36, 52, 71, .06);
}

html[data-theme="light"] input,
html[data-theme="light"] select,
html[data-theme="light"] textarea {
  background: #ffffff;
  border-color: #aebed0;
  color: #243447;
}

html[data-theme="light"] .button:not(.secondary),
html[data-theme="light"] form button {
  color: #ffffff;
}

html[data-theme="light"] .customer-link {
  background: transparent;
  border: 0;
  color: var(--accent) !important;
  font-weight: 400;
  padding: 0;
  text-decoration: underline;
}

html[data-theme="light"] header {
  background: #ffffff;
  border-bottom-color: #d7e0eb;
}

html[data-theme="light"] .card {
  border-radius: 12px;
}

html[data-theme="light"] .button:not(.secondary),
html[data-theme="light"] form button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fffaf7;
}

html[data-theme="light"] .button:hover,
html[data-theme="light"] button:hover {
  border-color: #174b82;
}

html[data-theme="light"] main > .card > .grid:first-of-type > .card:nth-child(1) { background: #2563a8; }
html[data-theme="light"] main > .card > .grid:first-of-type > .card:nth-child(2) { background: #4f83b8; }
html[data-theme="light"] main > .card > .grid:first-of-type > .card:nth-child(3) { background: #64748b; }
html[data-theme="light"] main > .card > .grid:first-of-type > .card:nth-child(4) { background: #7896b5; }
html[data-theme="light"] main > .card > .grid:first-of-type > .card:nth-child(5) { background: #536273; }
html[data-theme="light"] main > .card > .grid:first-of-type > .card:nth-child(6) { background: #2dd4a8; }
html[data-theme="light"] main > .card > .grid:first-of-type > .card .help,
html[data-theme="light"] main > .card > .grid:first-of-type > .card strong {
  color: #fffaf7;
}

html[data-theme="dark"] {
  --bg: #080b10;
  --bg-elev: #101722;
  --bg-card: #151d28;
  --line: #303d4d;
  --text: #f2f5f8;
  --muted: #a5b2c0;
  --accent: #7dd3fc;
  --accent-dim: #12354a;
  --shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
html[data-theme="colorful"] {
  --bg: #071a3d;
  --bg-elev: #0b2b68;
  --bg-card: #123d86;
  --line: #3764ae;
  --text: #ffffff;
  --muted: #d7e3ff;
  --accent: #ffffff;
  --accent-dim: #173c78;
  --danger: #ed1c24;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); }
button, input, select, textarea { color: inherit; font: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

header {
  align-items: center;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  min-height: 64px;
  padding: 12px 5vw;
  position: sticky;
  top: 0;
  z-index: 20;
}
html[data-theme="colorful"] header {
  background: linear-gradient(105deg, #08245a 0%, #0b3d91 48%, #c51f32 100%);
  border-bottom: 3px solid #ed1c24;
}
html[data-theme="colorful"] .card {
  background: #123d86;
  border-color: #3764ae;
}
html[data-theme="colorful"] .button,
html[data-theme="colorful"] button {
  background: #0d3278;
  border-color: #4d78c4;
}
html[data-theme="colorful"] .button:not(.secondary),
html[data-theme="colorful"] form button {
  background: #ed1c24;
  border-color: #ff4a50;
  color: #fff;
}
html[data-theme="colorful"] .button:hover,
html[data-theme="colorful"] button:hover {
  border-color: #ffffff;
}
html[data-theme="colorful"] .button.secondary {
  color: #ffffff;
}
/* Dashboard metric tiles: give each theme its own set of distinct, on-brand
   tile colors (light mode already has its own rule set further below). */
main > .card > .grid:first-of-type > .card:nth-child(1) { background: #1f5fa8; }
main > .card > .grid:first-of-type > .card:nth-child(2) { background: #3a7cba; }
main > .card > .grid:first-of-type > .card:nth-child(3) { background: #45806f; }
main > .card > .grid:first-of-type > .card:nth-child(4) { background: #a8792f; }
main > .card > .grid:first-of-type > .card:nth-child(5) { background: #6b4f42; }
main > .card > .grid:first-of-type > .card:nth-child(6) { background: #1f9d78; }
main > .card > .grid:first-of-type > .card { border: 0; color: #fffaf7; }
main > .card > .grid:first-of-type > .card .help,
main > .card > .grid:first-of-type > .card strong {
  color: #fffaf7;
}
html[data-theme="dark"] main > .card > .grid:first-of-type > .card:nth-child(1) { background: #0e4a75; }
html[data-theme="dark"] main > .card > .grid:first-of-type > .card:nth-child(2) { background: #1c6690; }
html[data-theme="dark"] main > .card > .grid:first-of-type > .card:nth-child(3) { background: #2f6a5c; }
html[data-theme="dark"] main > .card > .grid:first-of-type > .card:nth-child(4) { background: #8a651f; }
html[data-theme="dark"] main > .card > .grid:first-of-type > .card:nth-child(5) { background: #4a3a30; }
html[data-theme="dark"] main > .card > .grid:first-of-type > .card:nth-child(6) { background: #12805f; }
html[data-theme="colorful"] main > .card > .grid:first-of-type > .card:nth-child(1) { background: #0b3d91; }
html[data-theme="colorful"] main > .card > .grid:first-of-type > .card:nth-child(2) { background: #1655b8; }
html[data-theme="colorful"] main > .card > .grid:first-of-type > .card:nth-child(3) { background: #c51f32; }
html[data-theme="colorful"] main > .card > .grid:first-of-type > .card:nth-child(4) { background: #ed1c24; }
html[data-theme="colorful"] main > .card > .grid:first-of-type > .card:nth-child(5) { background: #08245a; }
html[data-theme="colorful"] main > .card > .grid:first-of-type > .card:nth-child(6) { background: #175a3f; }
.brand { align-items: center; color: var(--text); display: inline-flex; font-weight: 700; gap: 8px; letter-spacing: .04em; text-decoration: none; }
.brand-logo { border-radius: 7px; height: 38px; object-fit: cover; width: 38px; }
.brand-name > span { color: var(--accent); }
header nav { align-items: center; color: var(--muted); display: inline-flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
header nav a { color: inherit; }
header nav a.button { color: var(--text); text-decoration: none; }
header nav a.button:not(.secondary) { color: #06241c; }
.nav-user { font-size: 13px; padding: 0 4px; }
.theme-picker { align-items: center; color: var(--muted); display: inline-flex; gap: 5px; }
.theme-picker select { border-radius: 6px; padding: 4px 6px; }
.nav-toggle { background: none; border: 1px solid var(--line); border-radius: 8px; color: var(--text); display: none; font-size: 20px; line-height: 1; margin-left: auto; padding: 6px 10px; }

main { margin: 0 auto; max-width: 1296px; padding: 24px; }
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  overflow-x: auto;
}
.narrow { margin: 8vh auto; max-width: 440px; }
.customer-form-card { max-width: 760px; }
h1 { margin: 0 0 20px; }
h2 { margin: 28px 0 12px; }
.demo-entry { border-top: 1px solid var(--line); margin-top: 28px; padding-top: 2px; }
.demo-entry form { display: block; }
.demo-entry .help { margin-bottom: 12px; }

.toolbar { align-items: center; display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.toolbar h1 { margin: 0 auto 0 0; }
.button, button {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
  padding: 7px 10px;
  text-decoration: none;
}
.button:hover, button:hover { border-color: #3d4d5e; }
.compact { padding: 6px 9px; font-size: 12px; }
.button:not(.secondary), form button { background: var(--accent); border-color: transparent; color: #06241c; font-weight: 700; }
.secondary { color: var(--text); }

form { display: grid; gap: 15px; }
.inline-form { display: inline; }
.customer-link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; text-align: left; text-decoration: underline; }
.password-form { align-items: center; display: inline-flex; gap: 6px; }
.password-form input { padding: 6px 8px; width: 150px; }
label { color: var(--muted); display: grid; font-size: 13px; gap: 6px; }
input, select, textarea {
  box-sizing: border-box;
  background: #0b1015;
  border: 1px solid #4a5d70;
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 2px solid var(--accent); }
input[readonly] { background: #151d25; color: var(--muted); cursor: not-allowed; }
input[type="date"] { max-width: 170px; width: auto; }
small { color: var(--muted); font-weight: 400; }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.shopify-insights > .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.table-filter { display: block; max-width: 360px; margin: 16px 0; }
.tag { background: var(--accent-dim); border: 1px solid var(--accent); border-radius: 999px; color: var(--text); display: inline-block; font-size: 13px; margin: 2px 4px 2px 0; padding: 4px 9px; }
.tag-remove { background: transparent; border: 0; color: inherit; font-size: 14px; padding: 0 0 0 4px; }
.tag-form { align-items: end; display: flex; gap: 8px; }
.tag-form label { flex: 1; }
.address-grid { display: grid; gap: 32px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 28px 0; }
.address-grid address { color: var(--muted); font-style: italic; line-height: 1.5; }
.address-autocomplete-wrap { position: relative; }
.address-autocomplete-results { background: #0b1015; border: 1px solid #4a5d70; border-radius: 10px; list-style: none; margin: 4px 0 0; max-height: 220px; overflow-y: auto; padding: 0; position: absolute; width: 100%; z-index: 20; }
.address-autocomplete-results:empty { border: none; }
.address-autocomplete-results li { cursor: pointer; font-size: 13px; padding: 8px 12px; }
.address-autocomplete-results li:hover { background: var(--accent-dim); }
.order-totals { margin-left: auto; max-width: 320px; text-align: right; }
.order-totals > div { display: flex; justify-content: space-between; gap: 24px; padding: 3px 0; }
.order-totals .total { border-top: 1px solid var(--line); font-size: 1.1em; font-weight: 700; margin-top: 5px; padding-top: 8px; }
.order-note { background: var(--bg-elev); border: 1px solid var(--line); border-radius: 10px; margin: 20px 0; padding: 12px 16px; }
.order-note p { line-height: 1.5; margin: 0; white-space: normal; }
.order-note-dialog { background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); max-width: 620px; padding: 24px; width: calc(100% - 32px); }
.order-note-dialog::backdrop { background: rgba(0, 0, 0, .65); }
.order-tracking { margin: 20px 0; }
.order-tracking summary { color: var(--text); cursor: pointer; font-size: 1.25em; font-weight: 700; padding: 8px 0; }
.settings-section { border: 1px solid var(--line); border-radius: 10px; margin: 20px 0; padding: 12px 16px; }
.settings-section summary { cursor: pointer; font-weight: 700; padding: 6px 0; }
.settings-section form { margin-top: 12px; }
.settings-preferences { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.settings-preferences form { align-items: start; }
.print-actions { align-items: center; display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
.grid .card { box-shadow: none; text-align: center; }
.dashboard-metric { color: inherit; display: block; text-decoration: none; }
.dashboard-metric:hover { border-color: var(--accent); transform: translateY(-1px); }
.grid .card > strong { display: block; font-size: 28px; }
.dashboard-metrics { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.dashboard-metrics .card { padding: 10px; }
.dashboard-metrics .card > strong { font-size: 20px; }
.dashboard-metrics .help { font-size: 12px; }
html[data-theme="light"] main > .card > .grid:first-of-type > .card {
  border: 0;
  color: #ffffff;
  min-height: 112px;
  padding: 20px 16px;
}
html[data-theme="light"] main > .card > .grid:first-of-type > .card:nth-child(1) { background: #b85c4b; }
html[data-theme="light"] main > .card > .grid:first-of-type > .card:nth-child(2) { background: #d18b78; }
html[data-theme="light"] main > .card > .grid:first-of-type > .card:nth-child(3) { background: #6f8f86; }
html[data-theme="light"] main > .card > .grid:first-of-type > .card:nth-child(4) { background: #d8aa72; }
html[data-theme="light"] main > .card > .grid:first-of-type > .card:nth-child(5) { background: #806b63; }
html[data-theme="light"] main > .card > .grid:first-of-type > .card:nth-child(6) { background: #4b8f7a; }
html[data-theme="light"] main > .card > .grid:first-of-type > .card .help { color: rgba(255, 255, 255, .88); }
html[data-theme="light"] main > .card > .shopify-insights {
  border-color: #d7e0eb;
}
pre { background: #0b1015; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); overflow: auto; padding: 12px; white-space: pre-wrap; }

table { border-collapse: collapse; margin: 18px 0; min-width: 0; width: 100%; }
th, td { border-bottom: 1px solid var(--line); padding: 12px 8px; text-align: left; white-space: nowrap; }
th { max-width: 420px; min-width: 90px; overflow: hidden; resize: horizontal; }
td { max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: normal; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; }
th[data-sort-index] { cursor: pointer; }
th[data-sort-index]::after { content: " ↕"; opacity: .55; }
th[data-sort-index][data-sort-direction="asc"]::after { content: " ↑"; }
th[data-sort-index][data-sort-direction="desc"]::after { content: " ↓"; }
.notice { background: var(--accent-dim); border: 1px solid #1d6b56; border-radius: 10px; color: var(--accent); padding: 12px; }
.notice.error { border-color: var(--danger); color: var(--danger); }
.help { color: var(--muted); line-height: 1.45; }
.event-notes { color: var(--muted); font-size: 12px; margin-top: 8px; }
.event-notes-text { line-height: 1.45; margin: 6px 0; }
.event-notes-table-wrap { max-width: 100%; overflow-x: auto; }
.event-notes-table { background: var(--bg-elev); border: 1px solid var(--line); margin: 8px 0 2px; width: auto; }
.event-notes-table th,
.event-notes-table td { max-width: none; min-width: 100px; padding: 6px 8px; white-space: normal; }
.event-notes-table th { background: var(--accent-dim); color: var(--text); resize: none; }

.summary-clamp { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; white-space: normal; }
.summary-clamp.expanded { -webkit-line-clamp: unset; overflow: visible; }
.summary-toggle { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 12px; margin-top: 4px; padding: 0; text-decoration: underline; }

.draft-search { display: flex; align-items: flex-end; gap: 10px; margin: 10px 0 16px; flex-wrap: wrap; }
.draft-search label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted, #666); flex: 1 1 260px; }
.draft-search input { padding: 8px 10px; }
.draft-search label:has(input[type="checkbox"]) { flex-direction: row; align-items: center; }
.import-panel { border-top: 1px solid var(--line); margin: 24px 0; padding-top: 4px; }
.import-panel h2 { margin-top: 0; }
.lead-details { border: 1px solid var(--line); border-radius: 10px; margin: 18px 0; padding: 16px; }
.lead-details legend { color: var(--text); font-weight: 700; padding: 0 8px; }
.task-detail-grid { display: grid; gap: 16px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.task-detail-grid > div { background: var(--bg-elev); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.task-detail-grid p { margin-bottom: 0; }
.task-description { background: var(--bg-elev); border: 1px solid var(--line); border-radius: 10px; line-height: 1.7; padding: 16px; }
.task-detail-actions { margin-top: 20px; }
.task-edit-form { border-top: 1px solid var(--line); display: grid; gap: 14px; margin-top: 24px; padding-top: 20px; }
.task-edit-form textarea { font-family: inherit; min-height: 260px; resize: vertical; }
.task-bulk-actions { display: flex; gap: 10px; margin: 12px 0; }
.task-bulk-actions .danger { background: var(--danger); color: #fff; }
.task-pagination { align-items: center; display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; }

code { color: var(--accent); font-family: var(--mono); }
.hidden { display: none !important; }

@media (max-width: 650px) {
  header { flex-wrap: wrap; padding: 10px 16px; row-gap: 8px; }
  .nav-toggle { display: inline-block; }
  header nav {
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
    display: none;
    flex-basis: 100%;
    flex-direction: column;
    align-items: stretch;
    font-size: 13px;
    gap: 4px;
    margin: 8px 0 0;
    padding: 10px;
  }
  header.nav-open nav { display: flex; }
  header nav a.button, header nav button:not(.nav-toggle) { justify-content: flex-start; text-align: left; width: 100%; }
  .nav-user { order: -1; padding: 4px 4px 8px; }
  .theme-picker { flex-wrap: wrap; font-size: 12px; justify-content: space-between; width: 100%; }
  main { padding: 12px; }
  .card { overflow-x: auto; padding: 16px; }
  .grid { grid-template-columns: 1fr; }
  .dashboard-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .task-detail-grid { grid-template-columns: 1fr; }
  .shopify-insights > .grid { grid-template-columns: 1fr; }
  .address-grid { grid-template-columns: 1fr; }
  .toolbar { align-items: flex-start; }
  .toolbar h1 { flex-basis: 100%; }
  table { font-size: 13px; }
  .draft-search { flex-direction: column; align-items: stretch; }
  .draft-search label { flex-basis: auto; }
  .tag-form { flex-direction: column; align-items: stretch; }
  .task-bulk-actions { flex-wrap: wrap; }
  .button, button { min-height: 40px; }
  input, select, textarea { font-size: 16px; }
  /* Wide tables scroll horizontally inside their card on mobile; pin the last
     action column so it stays reachable without scrolling all the way right. */
  table td:last-child, table th:last-child {
    background: var(--bg-card);
    position: sticky;
    right: 0;
    white-space: nowrap;
    z-index: 1;
  }
  .event-notes-table td:last-child, .event-notes-table th:last-child {
    background: inherit;
    position: static;
    white-space: normal;
  }
}

@media (max-width: 420px) {
  .toolbar { gap: 8px; }
  .task-bulk-actions { flex-direction: column; align-items: stretch; }
  .task-bulk-actions .button, .task-bulk-actions button { width: 100%; }
}

@media print {
  header, .print-actions, .button, button, .order-note-dialog { display: none !important; }
  body { background: #ffffff; color: #000000; }
  main { max-width: none; padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .address-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .order-totals { color: #000000; }
}
