/* Razzolink Sales design system.
   Tokens first, then base elements, layout, components, and page-specific bits last. */

:root {
  color-scheme: light;

  /* Brand (from the Razzolink logo) */
  --brand-green: #4f9a2c;        /* marks, bars, borders, icons */
  --brand-green-dark: #3b841f;   /* primary buttons (white text passes AA) */
  --brand-green-darker: #2f6e17; /* green text, hover */
  --brand-green-light: #d6eac4;
  --brand-green-soft: #eef6e6;
  --brand-green-ring: rgb(79 154 44 / 0.22);

  /* Surfaces and text */
  --background: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f8f9fb;
  --text-primary: #111827;
  --text-secondary: #374151;
  --text-muted: #667085;
  --border: #e5e7eb;
  --border-light: #eef0f3;

  /* Status */
  --pending: #6b7280;
  --pending-soft: #f1f2f4;
  --scheduled: #0b6bcb;
  --scheduled-soft: #e8f1fc;
  --resched: #b45309;
  --resched-soft: #fdf1e3;
  --installed: #15803d;
  --installed-soft: #e7f5ec;
  --canceled: #b91c1c;
  --canceled-soft: #fcebeb;
  --error: #b91c1c;
  --ok: #15803d;

  /* Chart outcome colors, validated as a set (CVD-safe) on white. Keep the order. */
  --c-installed: #15803d;
  --c-open: #0b6bcb;
  --c-canceled: #b91c1c;
  --bar: #1f6fd6;
  --grid: #eef0f3;

  /* Shape and depth */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-xs: 0 1px 2px rgb(16 24 40 / 0.04);
  --shadow-sm: 0 1px 3px rgb(16 24 40 / 0.05), 0 1px 2px rgb(16 24 40 / 0.03);
  --shadow-md: 0 10px 30px rgb(16 24 40 / 0.10), 0 2px 6px rgb(16 24 40 / 0.05);

  --control-h: 46px;
  --page-max: 1600px;
  --gutter: 40px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--text-primary);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-green-darker); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
img { max-width: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.2; color: var(--text-primary); }
h1 { font-size: 2.1rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0; }
hr { border: 0; border-top: 1px solid var(--border-light); margin: 0.35rem 0; }
:focus-visible { outline: 3px solid var(--brand-green-ring); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

.i { width: 18px; height: 18px; flex: none; }
.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
.strong { font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.positive { color: var(--brand-green-darker); font-weight: 700; }
.error { color: var(--error); }
.ok { color: var(--ok); font-weight: 600; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; margin: -1px; padding: 0; border: 0;
}

/* ---------- Layout ---------- */
.page {
  width: 100%; max-width: var(--page-max); margin: 0 auto;
  padding: 28px var(--gutter) 56px;
  display: flex; flex-direction: column; gap: 20px;
}
.page.narrow { max-width: 1040px; }
.page.slim { max-width: 560px; }
.row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.columns { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 20px; align-items: start; }
.columns.even { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }
@media (max-width: 1080px) { :root { --gutter: 28px; } }
@media (max-width: 900px) { .columns, .columns.even { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 640px) {
  :root { --gutter: 16px; }
  .page { padding-top: 20px; gap: 16px; }
  h1 { font-size: 1.65rem; }
}

/* ---------- Top navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 2px rgb(16 24 40 / 0.03);
}
.topbar-inner {
  max-width: var(--page-max); margin: 0 auto; padding: 0 var(--gutter);
  height: 68px; display: flex; align-items: center; gap: 24px;
}
.brand { display: flex; align-items: center; flex: none; }
.brand img { height: 44px; width: auto; display: block; }
.brand:hover { text-decoration: none; }
.mainnav { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.topbar-actions { display: flex; align-items: center; gap: 10px; margin-left: 12px; }
.mainnav + .topbar-actions { margin-left: 16px; }

.navlink {
  display: inline-flex; align-items: center; gap: 8px;
  height: 42px; padding: 0 14px; border-radius: 10px;
  color: var(--text-secondary); font-weight: 500; font-size: 0.95rem; white-space: nowrap;
  background: none; border: 0; font-family: inherit; cursor: pointer;
}
.navlink .i { color: var(--text-primary); }
.navlink:hover { background: var(--surface-muted); color: var(--text-primary); text-decoration: none; }
.navlink.active { background: var(--brand-green-soft); color: var(--brand-green-darker); font-weight: 600; }
.navlink.active .i { color: var(--brand-green-dark); }
.inline-account { display: flex; align-items: center; gap: 2px; }
.signout { margin: 0; display: contents; }

/* Dropdowns (details/summary so they work without JavaScript) */
.dropdown { position: relative; }
.dropdown > summary { list-style: none; cursor: pointer; }
.dropdown > summary::-webkit-details-marker { display: none; }
.menu {
  position: absolute; top: calc(100% + 8px); z-index: 40; min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-md); padding: 6px;
  display: flex; flex-direction: column;
}
.menu-right { right: 0; }
.menu-wide { min-width: 240px; }
.menu-head { display: flex; flex-direction: column; padding: 10px 12px 10px; border-bottom: 1px solid var(--border-light); margin-bottom: 4px; }
.menu-head .small { overflow-wrap: anywhere; }
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px; border-radius: 10px; border: 0; background: none;
  color: var(--text-primary); font: inherit; font-weight: 500; text-align: left; cursor: pointer;
}
.menu-item .i { color: var(--text-secondary); }
.menu-item:hover { background: var(--surface-muted); text-decoration: none; }
.menu-item.active { background: var(--brand-green-soft); color: var(--brand-green-darker); }
.menu-item.active .i { color: var(--brand-green-dark); }

.avatar-btn { display: inline-flex; align-items: center; gap: 6px; padding: 3px 6px 3px 3px; border-radius: 999px; }
.avatar-btn:hover { background: var(--surface-muted); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-muted); border: 1px solid var(--border); color: var(--text-secondary);
  font-weight: 600; font-size: 0.9rem; letter-spacing: 0.02em;
}
.dropdown[open] .avatar { border-color: var(--brand-green); box-shadow: 0 0 0 3px var(--brand-green-ring); }
.avatar-btn .chev { width: 16px; height: 16px; color: var(--text-secondary); transition: transform 0.15s; }
.dropdown[open] .chev { transform: rotate(180deg); }

.icon-btn {
  width: 42px; height: 42px; border-radius: 10px; display: inline-grid; place-items: center;
  color: var(--text-primary); border: 1px solid transparent; background: none;
}
.icon-btn:hover { background: var(--surface-muted); }
.icon-btn .i { width: 22px; height: 22px; }
.icon-btn-sm { width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 9px; color: var(--text-secondary); }
.icon-btn-sm .i { width: 18px; height: 18px; }
.dropdown .when-open { display: none; }
.dropdown[open] .when-open { display: block; }
.dropdown[open] .when-closed { display: none; }

/* Which account controls show at which width */
.usermenu, .navmenu { display: none; }
@media (max-width: 1240px) {
  .inline-account { display: none; }
  .usermenu { display: block; }
}
@media (max-width: 860px) {
  .topbar-inner { height: 64px; gap: 12px; }
  .mainnav { display: none; }
  .navmenu { display: block; }
  .topbar-actions { margin-left: auto; gap: 6px; }
  .brand img { height: 38px; }
}
@media (max-width: 374px) {
  .btn-new span { display: none; }
  .btn-new { width: 42px; padding: 0; }
}
@media (max-width: 440px) {
  .topbar-inner { gap: 8px; }
  .topbar .btn-new { padding: 0 12px; gap: 6px; font-size: 0.9rem; }
  .brand img { height: 32px; }
  .avatar { width: 38px; height: 38px; }
  .avatar-btn { padding: 0; }
  .avatar-btn .chev { display: none; }
  .topbar-actions { gap: 4px; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--control-h); padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-primary);
  font: inherit; font-weight: 600; font-size: 0.95rem; white-space: nowrap; cursor: pointer;
  box-shadow: var(--shadow-xs); transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover { background: var(--surface-muted); border-color: #d6d9de; text-decoration: none; }
.btn .i { width: 18px; height: 18px; }
.btn-primary, .btn.primary {
  background: var(--brand-green-dark); border-color: var(--brand-green-dark); color: #fff;
  box-shadow: 0 1px 2px rgb(47 110 23 / 0.25), inset 0 1px 0 rgb(255 255 255 / 0.12);
}
.btn-primary:hover, .btn.primary:hover { background: var(--brand-green-darker); border-color: var(--brand-green-darker); }
.btn-danger { color: var(--canceled); border-color: #f1c4c4; background: var(--canceled-soft); }
.btn-danger:hover { background: #f9dddd; border-color: #e9a9a9; }
.btn-text { border-color: transparent; background: none; box-shadow: none; color: var(--brand-green-darker); padding: 0 10px; }
.btn-text:hover { background: var(--brand-green-soft); border-color: transparent; }
.btn-sm { height: 36px; padding: 0 12px; border-radius: 10px; font-size: 0.875rem; }
.topbar .btn { height: 42px; border-radius: 11px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; box-shadow: none; }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid currentColor; border-color: #fff #fff transparent transparent;
  animation: spin 0.7s linear infinite;
}
.btn:not(.btn-primary):not(.primary).is-loading::after { border-color: var(--text-secondary) var(--text-secondary) transparent transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.back-link { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 0.9rem; color: var(--text-muted); width: max-content; }
.back-link:hover { color: var(--brand-green-darker); text-decoration: none; }
.back-link .i { width: 16px; height: 16px; }

/* ---------- Page head ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; }
.page-head-main { display: flex; align-items: center; gap: 16px; min-width: 0; }
.page-head-text { min-width: 0; }
.page-head h1 { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; overflow-wrap: anywhere; }
.page-sub { color: var(--text-muted); font-size: 1rem; margin-top: 4px; }
.page-head-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
@media (max-width: 640px) {
  .page-head-main { gap: 12px; }
  .page-head .icon-badge-lg { width: 44px; height: 44px; border-radius: 12px; }
  .page-head-actions { width: 100%; }
  .page-head-actions > .btn { flex: 1; }
}

/* ---------- Icon badges ---------- */
.icon-badge {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: inline-grid; place-items: center;
  background: var(--brand-green-soft); color: var(--brand-green-dark);
}
.icon-badge .i { width: 22px; height: 22px; }
.icon-badge-lg { width: 54px; height: 54px; border-radius: 14px; }
.icon-badge-lg .i { width: 26px; height: 26px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); padding: 24px; min-width: 0;
}
.card-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.card-head-text { min-width: 0; flex: 1; }
.card-head h2 { font-size: 1.25rem; }
.card-sub { color: var(--text-muted); font-size: 0.9rem; margin-top: 2px; }
.card-head-extra { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.card-flush { padding: 0; overflow: hidden; }
.card-flush > .card-head { padding: 22px 24px 0; }
@media (max-width: 640px) {
  .card { padding: 18px; border-radius: 16px; }
  .card-flush { padding: 0; }
  .card-flush > .card-head { padding: 18px 18px 0; }
  .card-head h2 { font-size: 1.1rem; }
}

/* ---------- Metric cards ---------- */
.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 16px; }
.stat {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); padding: 20px; color: var(--text-primary);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.stat .icon-badge { margin-bottom: 12px; }
.stat .label { font-size: 0.95rem; font-weight: 600; color: var(--text-secondary); }
.stat .n { font-size: 2.1rem; font-weight: 700; line-height: 1.15; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 0.875rem; color: var(--text-muted); }
a.stat:hover { border-color: var(--brand-green); box-shadow: 0 0 0 3px var(--brand-green-soft), var(--shadow-sm); text-decoration: none; }
@media (max-width: 1320px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .stat { padding: 16px; }
  .stat .n { font-size: 1.75rem; }
  .stat .icon-badge { width: 38px; height: 38px; margin-bottom: 10px; }
}
@media (max-width: 340px) { .stats { grid-template-columns: minmax(0, 1fr); } }

/* Status filter tiles (sales list) */
.tiles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.tile {
  display: flex; align-items: center; gap: 12px; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 16px; color: var(--text-secondary); box-shadow: var(--shadow-xs);
}
.tile:hover { border-color: #d0d5dc; text-decoration: none; }
.tile .icon-badge { width: 38px; height: 38px; border-radius: 10px; }
.tile .icon-badge .i { width: 20px; height: 20px; }
.tile-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.tile .n { font-size: 1.45rem; font-weight: 700; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.tile .t-label { font-size: 0.85rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile.active { border-color: var(--brand-green); background: #fbfdf8; box-shadow: 0 0 0 3px var(--brand-green-soft); }
@media (max-width: 1240px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 12px; gap: 10px; }
  .tile .icon-badge { width: 34px; height: 34px; }
}

/* Tone variants for icon badges */
.tone-PENDING { background: var(--pending-soft); color: var(--pending); }
.tone-SCHEDULED { background: var(--scheduled-soft); color: var(--scheduled); }
.tone-NEEDS_RESCHEDULE { background: var(--resched-soft); color: var(--resched); }
.tone-INSTALLED { background: var(--installed-soft); color: var(--installed); }
.tone-CANCELED { background: var(--canceled-soft); color: var(--canceled); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; vertical-align: middle;
  font-size: 0.8rem; font-weight: 600; line-height: 1; padding: 6px 10px;
  border-radius: 999px; white-space: nowrap; letter-spacing: 0;
}
.badge .dot { width: 7px; height: 7px; }
h1 .badge { font-size: 0.85rem; }
.s-PENDING, .c-NOT_DUE { background: var(--pending-soft); color: #4b5563; }
.s-SCHEDULED { background: var(--scheduled-soft); color: var(--scheduled); }
.s-NEEDS_RESCHEDULE, .c-PENDING { background: var(--resched-soft); color: var(--resched); }
.s-INSTALLED, .c-PAID { background: var(--installed-soft); color: var(--installed); }
.s-CANCELED, .c-CLAWED_BACK { background: var(--canceled-soft); color: var(--canceled); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; background: currentColor; }
.swatch { display: inline-block; width: 11px; height: 11px; border-radius: 3px; flex: none; }

/* ---------- Forms ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; font-weight: 600; color: var(--text-secondary); }
.req { color: var(--canceled); margin-left: 2px; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text-primary); background: var(--surface);
  border: 1px solid #d9dde3; border-radius: 12px; padding: 0 14px; width: 100%;
  height: var(--control-h); transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { height: auto; min-height: 88px; padding: 12px 14px; resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: #9aa3af; }
input:hover, select:hover, textarea:hover { border-color: #c5cad2; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand-green); box-shadow: 0 0 0 4px var(--brand-green-ring);
}
input:disabled, select:disabled, textarea:disabled { background: var(--surface-muted); color: var(--text-muted); cursor: not-allowed; }
select {
  appearance: none; -webkit-appearance: none; padding-right: 42px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23111827' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 18px;
}
input[type="checkbox"] {
  width: 20px; height: 20px; padding: 0; border-radius: 6px; accent-color: var(--brand-green-dark); cursor: pointer; flex: none;
}
input[type="date"] { min-width: 0; }
label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; color: var(--text-primary); cursor: pointer; }
.grid label.check { align-self: end; min-height: var(--control-h); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px 18px; }
.grid .wide { grid-column: 1 / -1; }
.hint { font-weight: 400; color: var(--text-muted); font-size: 0.8rem; }
.form-error, p.error {
  display: flex; align-items: center; gap: 10px; margin: 0;
  background: var(--canceled-soft); color: var(--canceled); border: 1px solid #f3c9c9;
  border-radius: 12px; padding: 12px 14px; font-weight: 500;
}
.form-error .i { width: 18px; height: 18px; }
.form-actions {
  display: flex; justify-content: flex-end; align-items: center; gap: 10px; flex-wrap: wrap;
  position: sticky; bottom: 0; z-index: 5; margin: 0 calc(-1 * var(--gutter));
  padding: 14px var(--gutter); background: rgb(246 247 249 / 0.92); backdrop-filter: blur(6px);
  border-top: 1px solid var(--border);
}
.form-actions .btn { min-width: 140px; }
@media (max-width: 560px) {
  .grid { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .form-actions .btn { flex: 1; min-width: 0; }
}

/* Filters: label + select in a soft green frame (dashboard "Sold [All time]") */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 0; }
.filter {
  display: flex; flex-direction: row; align-items: center; gap: 12px;
  padding: 6px 6px 6px 16px; border: 1px solid var(--brand-green-light); border-radius: 14px;
  background: #f9fcf6; box-shadow: 0 0 0 3px rgb(238 246 230 / 0.6);
  font-weight: 700; color: var(--text-primary); font-size: 0.95rem;
}
.filter select { width: auto; min-width: 180px; height: 42px; border-radius: 10px; font-weight: 500; }
@media (max-width: 640px) {
  .filters { width: 100%; }
  .filter { flex: 1 1 100%; justify-content: space-between; }
  .filter select { flex: 1; min-width: 0; }
}

/* Search toolbar */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 0; }
.search-field { position: relative; flex: 1; min-width: 220px; }
.search-field .i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.search-field input { padding-left: 42px; }
@media (max-width: 560px) {
  .search-field { flex: 1 1 100%; }
  .toolbar .btn { flex: 1; }
}

/* ---------- Alerts / flash ---------- */
.flash-wrap { max-width: var(--page-max); margin: 20px auto 0; padding: 0 var(--gutter); }
.flash {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 12px;
  background: var(--installed-soft); color: var(--installed); border: 1px solid #bfe3cb; font-weight: 600;
}
.flash.error { background: var(--canceled-soft); color: var(--canceled); border-color: #f3c9c9; }
.flash-wrap + .page { padding-top: 16px; }

/* ---------- Tables ---------- */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 0.925rem; }
.table th, .table td { text-align: left; padding: 14px 18px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
.table thead th {
  background: var(--surface-muted); color: var(--text-muted); font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap; padding-top: 12px; padding-bottom: 12px;
}
.table th.num, .table td.num { text-align: right; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background 0.1s; }
.table tbody tr:hover { background: #fafbfc; }
.table td .sub { color: var(--text-muted); font-size: 0.83rem; margin-top: 2px; }
.table a.strong { color: var(--text-primary); }
.table a.strong:hover { color: var(--brand-green-darker); }
.table td.pick { width: 48px; }
.table tr.is-picked { background: #f7fbf3; }
.table-compact th, .table-compact td { padding: 8px 14px; }
.card-flush .table-scroll { border-top: 1px solid var(--border-light); margin-top: 18px; }
.card-foot { padding: 14px 24px; border-top: 1px solid var(--border-light); color: var(--text-muted); font-size: 0.875rem; }

/* On phones, list tables become stacked cards. */
@media (max-width: 760px) {
  .table.stack-mobile thead { display: none; }
  .table.stack-mobile tbody tr {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px;
    padding: 16px 18px; border-bottom: 1px solid var(--border-light);
  }
  .table.stack-mobile tbody tr:last-child { border-bottom: 0; }
  .table.stack-mobile td { border: 0; padding: 0; min-width: 0; text-align: left; overflow-wrap: anywhere; }
  .table.stack-mobile td::before {
    content: attr(data-label); display: block; font-size: 0.7rem; font-weight: 700; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 2px;
  }
  .table.stack-mobile td.lead { grid-column: 1 / -1; order: -1; }
  .table.stack-mobile td.lead::before, .table.stack-mobile td.pick::before { display: none; }
  .table.stack-mobile td.pick { grid-column: 1 / -1; order: -2; width: auto; }
  .table.stack-mobile td.full { grid-column: 1 / -1; }
  .table.stack-mobile td:empty { display: none; }
}

/* ---------- Empty states ---------- */
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 48px 20px; }
.empty-state .icon-badge { margin-bottom: 6px; background: var(--surface-muted); color: var(--text-muted); }
.empty-state p { color: var(--text-muted); max-width: 40ch; }
.empty-state .btn { margin-top: 10px; }
.empty-inline { padding: 12px 0; }

/* ---------- Charts ---------- */
.chart { margin: 0; }
.legend { display: flex; gap: 8px 22px; flex-wrap: wrap; font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 16px; }
.legend span { display: inline-flex; align-items: center; gap: 8px; }
.plot { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: 280px auto; column-gap: 12px; }
.yaxis {
  display: flex; flex-direction: column; justify-content: space-between; margin: -0.55em 0;
  font-size: 0.8rem; color: var(--text-muted); text-align: right; font-variant-numeric: tabular-nums; min-width: 1.6rem;
}
.area { position: relative; border-bottom: 1px solid #d9dde3; }
.gridline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--grid); }
.cols { position: absolute; inset: 0; display: flex; }
.col { flex: 1; min-width: 0; position: relative; display: flex; justify-content: center; align-items: flex-end; outline: none; border-radius: 8px 8px 0 0; }
.col:hover, .col:focus-visible { background: rgb(79 154 44 / 0.09); }
.bar { width: min(52%, 64px); display: flex; flex-direction: column-reverse; gap: 2px; }
.seg { min-height: 2px; }
.bar .seg:last-child { border-radius: 5px 5px 0 0; }
.cap { position: absolute; transform: translateY(-4px); font-size: 0.85rem; font-weight: 700; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.tip {
  display: none; position: absolute; bottom: calc(100% - 2rem); left: 50%; transform: translateX(-50%); z-index: 6;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
  box-shadow: var(--shadow-md); font-size: 0.85rem; white-space: nowrap; pointer-events: none; line-height: 1.55;
}
.tip strong { display: block; margin-bottom: 2px; }
.tip div { display: flex; align-items: center; gap: 8px; }
.col:hover .tip, .col:focus .tip { display: block; }
.cols .col:first-child .tip { left: 0; transform: none; }
.cols .col:last-child .tip { left: auto; right: 0; transform: none; }
.xaxis { grid-column: 2; display: flex; font-size: 0.8rem; color: var(--text-muted); padding-top: 8px; }
.xaxis span { flex: 1; min-width: 0; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-view { margin-top: 18px; }
.table-view summary {
  cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px;
  color: var(--brand-green-darker); font-weight: 600; font-size: 0.9rem; border-radius: 8px; padding: 4px 6px 4px 2px;
}
.table-view summary::-webkit-details-marker { display: none; }
.table-view summary .i { width: 16px; height: 16px; transform: rotate(-90deg); transition: transform 0.15s; }
.table-view[open] summary .i { transform: none; }
.table-view .table-scroll { margin-top: 10px; border: 1px solid var(--border-light); border-radius: 12px; }
@media (max-width: 640px) {
  .plot { grid-template-rows: 220px auto; column-gap: 8px; }
  .bar { width: min(62%, 44px); }
  .cap { font-size: 0.75rem; }
  .xaxis { font-size: 0.72rem; }
}

/* Horizontal bar lists */
.barlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.barlist li { display: grid; grid-template-columns: minmax(9rem, 44%) minmax(0, 1fr); gap: 14px; align-items: center; font-size: 0.9rem; }
.bl-label { display: inline-flex; align-items: center; gap: 12px; color: var(--text-secondary); min-width: 0; line-height: 1.35; }
.barlist a:hover { text-decoration: none; }
.barlist a:hover .bl-label { color: var(--brand-green-darker); }
.bl-track { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bl-bar { height: 14px; width: calc((100% - 9rem) * var(--w)); min-width: 3px; border-radius: 4px; background: var(--bar); flex: none; }
.bl-value { white-space: nowrap; font-variant-numeric: tabular-nums; font-size: 0.875rem; }
.bl-value strong { font-weight: 700; color: var(--text-primary); }
/* Share-of-total rows: dot, label, gray track, value */
.barlist-track { gap: 18px; }
.barlist-track li { grid-template-columns: minmax(8rem, 34%) minmax(0, 1fr) 6.5rem; }
.barlist-track .bl-track { height: 12px; background: #eef0f3; border-radius: 999px; overflow: hidden; display: block; }
.barlist-track .bl-bar { display: block; height: 100%; width: calc(100% * var(--w)); border-radius: 999px; }
.barlist-track .bl-value { text-align: left; }
@media (max-width: 560px) {
  .barlist li { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .barlist-track li { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; }
  .barlist-track .bl-track { grid-column: 1 / -1; grid-row: 2; }
  .barlist-track .bl-value { grid-row: 1; grid-column: 2; }
  .bl-bar { width: calc((100% - 8rem) * var(--w)); }
}

/* ---------- Tabs (commissions) ---------- */
.tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.tabs .tile { padding: 18px 20px; }
.tabs .tile .n { font-size: 1.8rem; }
@media (max-width: 900px) { .tabs .tile { padding: 14px 16px; } .tabs .tile .n { font-size: 1.5rem; } }
@media (max-width: 640px) { .tabs { grid-template-columns: minmax(0, 1fr); gap: 10px; } }
.tabs .t-label { white-space: normal; }

.paybar { display: flex; gap: 14px 16px; align-items: flex-end; flex-wrap: wrap; padding: 18px 20px; }
.paybar label.check { align-self: center; min-height: auto; }
.paybar .grow { flex: 1; min-width: 14rem; }
.paybar input[type="date"] { width: auto; }
.pay-count { font-weight: 600; color: var(--text-secondary); align-self: center; }
@media (max-width: 560px) {
  .paybar > * { flex: 1 1 100%; }
  .paybar input[type="date"] { width: 100%; }
}

/* ---------- Sale detail ---------- */
dl { margin: 0; display: grid; gap: 0; }
.field { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border-light); }
.field:first-child { padding-top: 0; }
.field:last-child { border-bottom: 0; padding-bottom: 0; }
dt { color: var(--text-muted); font-size: 0.9rem; }
dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-weight: 500; }
@media (max-width: 480px) { .field { grid-template-columns: minmax(0, 1fr); gap: 2px; } }

.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.timeline li { position: relative; padding: 0 0 18px 28px; }
.timeline li::before { content: ""; position: absolute; left: 6px; top: 8px; bottom: -8px; width: 2px; background: var(--border-light); }
.timeline li:last-child { padding-bottom: 0; }
.timeline li:last-child::before { display: none; }
.timeline .tl-dot { position: absolute; left: 0; top: 4px; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 3px solid var(--brand-green); }
.timeline .tl-note { margin-top: 2px; color: var(--text-secondary); overflow-wrap: anywhere; }
.timeline .tl-meta { margin-top: 4px; }

/* ---------- Sign-in, first password and setup ---------- */
.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 32px 16px;
  background: radial-gradient(1200px 500px at 50% -10%, #eaf4e0 0%, rgb(234 244 224 / 0) 70%), var(--background);
}
.auth-card { width: 100%; max-width: 440px; padding: 36px; }
.auth-card.setup { max-width: 580px; }
.auth-brand { display: flex; justify-content: center; margin-bottom: 26px; }
.auth-brand img { height: 56px; width: auto; }
.auth-card h1 { font-size: 1.6rem; text-align: center; }
.auth-card .lead { color: var(--text-muted); text-align: center; margin: 6px 0 24px; }
.auth-card .btn-primary { width: 100%; }
.auth-foot { text-align: center; margin-top: 18px; color: var(--text-muted); font-size: 0.85rem; }
.auth-card fieldset { padding-top: 6px; }
.auth-card legend { font-weight: 700; font-size: 1rem; color: var(--text-primary); margin-bottom: 10px; }
.steps { display: flex; justify-content: center; gap: 8px; margin: -8px 0 20px; }
.steps span { height: 6px; width: 44px; border-radius: 999px; background: var(--border); }
.steps span.on { background: var(--brand-green); }
.secret-box { display: grid; gap: 0; padding: 16px 18px; background: var(--surface-muted); border: 1px solid var(--border); border-radius: 12px; }
.setup textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }
@media (max-width: 480px) { .auth-card { padding: 24px 20px; } }

/* Password page inside the app */
.password-card { max-width: 520px; width: 100%; }

@media print {
  .topbar, .form-actions, .page-head-actions { display: none; }
  body { background: #fff; }
}

/* Search bar sitting on top of a table card */
.card-toolbar { padding: 16px 18px; border-bottom: 1px solid var(--border-light); }
.nowrap { white-space: nowrap; }
.form-note { margin-right: auto; }
.form-row-end { justify-content: flex-end; }
.password-card .form-row-end .btn { min-width: 140px; }
@media (max-width: 480px) { .form-row-end .btn { flex: 1; min-width: 0; } }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.auth-card .mt .btn { width: 100%; }

/* Phones: the top bar already has "New sale", so the page button is dropped. */
@media (max-width: 860px) { .page-new { display: none; } }
@media (max-width: 560px) { .tile .t-label { white-space: normal; overflow: visible; } }
@media (max-width: 640px) {
  .tabs .tile { padding: 12px 14px; }
  .tabs .tile-text { flex-direction: row; align-items: baseline; flex-wrap: wrap; gap: 0 10px; flex: 1; }
  .tabs .tile-text .n { order: 2; margin-left: auto; font-size: 1.35rem; }
  .tabs .tile-text .muted { display: none; }
  .tabs .t-label:first-child { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }
}

/* App-like feel on phones: no double-tap zoom, and 16px fields so iPhone doesn't zoom in on focus. */
html { touch-action: manipulation; }
@media (max-width: 860px) {
  input, select, textarea { font-size: 16px; }
}
