@import url("tokens.css");

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
}
body.phone {
  width: var(--phone-w);
  min-height: 915px;
  margin: 0 auto;
  position: relative;
  background: var(--color-paper);
}
body.desktop {
  min-width: 1280px;
  background: var(--color-paper);
}
h1,h2,h3,h4 { font-family: var(--font-display); font-weight: 800; margin: 0; line-height: var(--leading-tight); color: var(--color-navy); }
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); font-weight: 600; }
p { margin: 0; }
a { color: var(--color-blue); text-decoration: none; }
button { font-family: inherit; }

/* —— App shell (phone) —— */
.app {
  display: flex;
  flex-direction: column;
  min-height: 915px;
  background: var(--color-paper);
  position: relative;
}
.app-header {
  height: var(--header-h);
  padding: 0 var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--color-navy);
  color: var(--color-white);
  position: sticky;
  top: 0;
  z-index: 40;
}
.app-header .logo {
  width: 28px; height: 28px; flex-shrink: 0;
  border-radius: 6px;
}
.app-header .title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 17px;
  color: var(--color-white);
  flex: 1;
  letter-spacing: -0.01em;
  font-synthesis: none;
}
.app-header .meta {
  font-size: var(--text-sm);
  color: rgba(255,255,255,0.72);
}
.app-header .icon-btn {
  width: 40px; height: 40px;
  border: 0; background: transparent; color: #fff;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  font-size: 20px;
}
.app-body {
  flex: 1;
  padding: var(--space-4);
  padding-bottom: calc(var(--tabbar-h) + var(--space-8) + 56px);
}
.app-body.with-sticky-save {
  padding-bottom: calc(var(--tabbar-h) + 88px);
}

/* Tab bar */
.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: var(--phone-w);
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 6px 4px var(--safe-bottom);
  background: var(--color-white);
  border-top: 1px solid var(--color-border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 50;
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--color-ink-muted);
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-display);
  text-decoration: none;
  min-height: 48px;
  border-radius: var(--radius-sm);
}
.tab .ico { font-size: 20px; line-height: 1; }
.tab.active { color: var(--color-blue); }
.tab.active .ico { color: var(--color-blue); }

/* FAB */
.fab {
  position: fixed;
  right: calc(50% - 206px + 16px);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--color-blue);
  color: #fff;
  border: 0;
  box-shadow: var(--shadow-fab);
  font-size: 28px;
  font-weight: 400;
  display: grid; place-items: center;
  z-index: 45;
  line-height: 1;
}
.fab-menu {
  position: fixed;
  right: calc(50% - 206px + 16px);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 76px);
  width: 220px;
  background: var(--color-white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2);
  z-index: 46;
  border: 1px solid var(--color-border);
}
.fab-menu button {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: 0; background: transparent;
  font-size: 15px; font-weight: 600;
  font-family: var(--font-display);
  color: var(--color-navy);
  border-radius: var(--radius-sm);
  text-align: left;
}
.fab-menu button:hover { background: var(--color-surface-alt); }
.fab-menu .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--color-blue); flex-shrink: 0;
}

/* —— Components —— */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap-min);
  padding: 0 18px;
  border-radius: var(--radius-md);
  border: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
}
.btn-primary { background: var(--color-blue); color: #fff; }
.btn-primary:active { background: var(--color-blue-pressed); }
.btn-secondary {
  background: var(--color-white);
  color: var(--color-blue);
  border: 1.5px solid var(--color-blue);
}
.btn-ghost {
  background: transparent;
  color: var(--color-blue);
  border: 0;
}
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { min-height: 40px; padding: 0 12px; font-size: 14px; }

.sticky-save {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom));
  width: var(--phone-w);
  padding: 10px 16px;
  background: linear-gradient(180deg, rgba(245,248,253,0) 0%, var(--color-paper) 28%);
  z-index: 44;
}
.sticky-save .btn { width: 100%; box-shadow: var(--shadow-md); }

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--space-3); }
.card-row {
  display: flex; align-items: flex-start; gap: 12px;
}
.card-row .grow { flex: 1; min-width: 0; }
.section {
  margin-bottom: var(--space-5);
}
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-3);
}
.section-head h2 { font-size: 15px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; color: var(--color-ink-muted); }
.section-head a { font-size: 14px; font-weight: 600; }

/* Chips / segmented */
.chips {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--color-border-strong);
  background: var(--color-white);
  color: var(--color-ink-secondary);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}
.chip.active {
  background: var(--color-blue);
  border-color: var(--color-blue);
  color: #fff;
}
.chip.filter.active {
  background: var(--color-info-bg);
  border-color: var(--color-blue);
  color: var(--color-blue);
}
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--color-surface-alt);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
}
.segmented .seg {
  min-height: 44px;
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  color: var(--color-ink-secondary);
}
.segmented .seg.active {
  background: var(--color-white);
  color: var(--color-blue);
  box-shadow: var(--shadow-sm);
}

/* Status badges — color + text */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 24px;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.02em;
}
.badge::before {
  content: "";
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
}
.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-info { background: var(--color-info-bg); color: var(--color-info); }
.badge-muted { background: var(--color-surface-alt); color: var(--color-ink-muted); }
.badge-mint {
  background: var(--color-success-bg);
  color: var(--color-mint-dark);
}

/* Forms */
.field { margin-bottom: var(--space-4); }
.field label {
  display: block;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  color: var(--color-ink-secondary);
  margin-bottom: 6px;
}
.field .hint {
  font-size: 13px;
  color: var(--color-ink-muted);
  margin-top: 6px;
}
.input, .textarea, .select-like {
  width: 100%;
  min-height: var(--input-h);
  padding: 0 14px;
  border: 1.5px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-white);
  font-family: var(--font-body);
  font-size: 16px; /* prevent mobile zoom */
  color: var(--color-ink);
  outline: none;
}
.input:focus, .textarea:focus {
  border-color: var(--color-blue);
  box-shadow: 0 0 0 3px rgba(43,89,195,0.18);
}
.textarea {
  min-height: 110px;
  padding: 12px 14px;
  resize: vertical;
  line-height: 1.45;
}
.input-money {
  display: flex; align-items: stretch;
  width: 100%;
  max-width: 100%;
  border: 1.5px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-white);
  overflow: hidden;
  min-width: 0;
}
.input-money .prefix {
  display: grid; place-items: center;
  padding: 0 10px;
  background: var(--color-surface-alt);
  color: var(--color-ink-muted);
  font-weight: 700;
  font-family: var(--font-display);
  border-right: 1.5px solid var(--color-border);
  flex-shrink: 0;
}
.input-money input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  border: 0;
  min-height: var(--input-h);
  padding: 0 10px;
  font-size: 16px;
  font-family: var(--font-body);
  outline: none;
  background: transparent;
}
.input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 100%;
}
.input-row > .field {
  min-width: 0;
  margin-bottom: var(--space-4);
}
.field, .card, .line-card, .search, .textarea, .input {
  max-width: 100%;
}
.app, .app-body, .app-header, .tabbar, .sticky-save, .sheet {
  overflow-x: hidden;
}
.search {
  position: relative;
}
.search .input { padding-left: 42px; }
.search .ico {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--color-ink-muted); font-size: 18px;
}
.toggle {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 48px;
  padding: 8px 0;
}
.toggle .switch {
  width: 48px; height: 28px;
  border-radius: 14px;
  background: var(--color-border-strong);
  position: relative;
  flex-shrink: 0;
}
.toggle .switch.on { background: var(--color-blue); }
.toggle .switch::after {
  content: "";
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: left 0.15s;
}
.toggle .switch.on::after { left: 23px; }

/* Alerts / banners */
.banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.4;
  margin-bottom: var(--space-4);
}
.banner strong { font-family: var(--font-display); font-weight: 700; }
.banner-warn { background: var(--color-warning-bg); color: var(--color-warning); border: 1px solid #F5D78A; }
.banner-danger { background: var(--color-danger-bg); color: var(--color-danger); border: 1px solid #F3B4AE; }
.banner-info { background: var(--color-info-bg); color: var(--color-info); border: 1px solid #C5D3F5; }
.banner .ico { font-size: 18px; flex-shrink: 0; line-height: 1.2; }

/* Lists */
.list-item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 0;
  border-bottom: 1px solid var(--color-border);
}
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  color: var(--color-navy);
}
.list-item .sub {
  font-size: 14px;
  color: var(--color-ink-muted);
  margin-top: 2px;
}
.list-item .meta-r {
  text-align: right;
  flex-shrink: 0;
}
.list-item .amount {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 16px;
}
.avatar {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--color-info-bg);
  color: var(--color-blue);
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
}
.avatar.mint { background: var(--color-success-bg); color: var(--color-mint-dark); }
.avatar.warn { background: var(--color-warning-bg); color: var(--color-warning); }

/* Timeline */
.timeline { position: relative; padding-left: 18px; }
.timeline::before {
  content: "";
  position: absolute; left: 5px; top: 8px; bottom: 8px;
  width: 2px; background: var(--color-border);
}
.tl-item {
  position: relative;
  padding: 0 0 16px 14px;
}
.tl-item::before {
  content: "";
  position: absolute; left: -16px; top: 8px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--color-blue);
  border: 2px solid var(--color-white);
  box-shadow: 0 0 0 2px var(--color-blue);
}
.tl-item.kind-remote::before { background: var(--color-cornflower); box-shadow: 0 0 0 2px var(--color-cornflower); }
.tl-item.kind-call::before { background: var(--color-mint-dark); box-shadow: 0 0 0 2px var(--color-mint-dark); }
.tl-item.kind-note::before { background: var(--color-ink-muted); box-shadow: 0 0 0 2px var(--color-ink-muted); }
.tl-time {
  font-size: 12px; font-weight: 700;
  color: var(--color-ink-muted);
  font-family: var(--font-display);
  letter-spacing: 0.02em;
}
.tl-card {
  margin-top: 6px;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.tl-card.expanded { border-color: var(--color-blue); box-shadow: 0 0 0 2px rgba(43,89,195,0.12); }
.tl-card .kind {
  font-size: 12px; font-weight: 700; color: var(--color-blue);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.tl-card .sum {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  margin-top: 2px;
}
.tl-card .body {
  margin-top: 8px;
  font-size: 15px;
  color: var(--color-ink-secondary);
  white-space: pre-wrap;
}
.tl-card .footer {
  margin-top: 10px;
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  font-size: 13px; color: var(--color-ink-muted);
}

/* Tabs (customer page) */
.subtabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 0 0 12px;
  margin: 0 -16px;
  padding-left: 16px; padding-right: 16px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.subtabs::-webkit-scrollbar { display: none; }
.subtab {
  flex-shrink: 0;
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  border: 0;
  background: transparent;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: var(--color-ink-muted);
}
.subtab.active {
  background: var(--color-navy);
  color: #fff;
}

/* Money / totals bar */
.totals-bar {
  background: var(--color-navy);
  color: #fff;
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex; justify-content: space-between; align-items: center;
}
.totals-bar .label { font-size: 13px; opacity: 0.75; font-weight: 600; }
.totals-bar .value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
}

/* Line cards (quote/invoice) */
.line-card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 10px;
}
.line-card .line-top {
  display: flex; justify-content: space-between; gap: 8px; align-items: flex-start;
}
.line-card .desc {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
}
.line-card .sku { font-size: 12px; color: var(--color-ink-muted); }
.line-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}
.line-grid .mini label {
  display: block; font-size: 11px; font-weight: 700;
  color: var(--color-ink-muted); text-transform: uppercase;
  letter-spacing: 0.04em; margin-bottom: 4px;
}
.line-grid .mini .val {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
}
.tax-toggle {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px;
  font-size: 13px; color: var(--color-ink-secondary);
}

/* Bottom sheet */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: var(--color-overlay);
  z-index: 60;
}
.sheet {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: var(--phone-w);
  max-height: 85vh;
  background: var(--color-white);
  border-radius: 20px 20px 0 0;
  padding: 12px 16px calc(24px + var(--safe-bottom));
  z-index: 61;
  box-shadow: var(--shadow-lg);
}
.sheet-handle {
  width: 40px; height: 4px; border-radius: 2px;
  background: var(--color-border-strong);
  margin: 4px auto 14px;
}
.sheet h2 { margin-bottom: 16px; }

/* Schedule day */
.day-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.day-header .nav {
  display: flex; gap: 4px;
}
.day-header .nav button {
  width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--color-border);
  background: #fff; font-size: 18px; color: var(--color-navy);
}
.hour-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  min-height: 56px;
  border-top: 1px solid var(--color-border);
}
.hour-row .t {
  font-size: 12px; font-weight: 700;
  color: var(--color-ink-muted);
  padding-top: 4px;
  font-family: var(--font-display);
}
.appt-block {
  margin: 4px 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--color-info-bg);
  border-left: 4px solid var(--color-blue);
  min-height: 48px;
}
.appt-block.remote { background: #EEF2FF; border-left-color: var(--color-cornflower); }
.appt-block.done { background: var(--color-success-bg); border-left-color: var(--color-mint-dark); }
.appt-block .when { font-size: 12px; font-weight: 700; color: var(--color-ink-muted); }
.appt-block .who { font-family: var(--font-display); font-weight: 700; font-size: 15px; }
.appt-block .what { font-size: 13px; color: var(--color-ink-secondary); }

/* Customer header */
.cust-hero {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
}
.cust-hero .name-row {
  display: flex; align-items: flex-start; gap: 12px;
}
.cust-hero h1 { font-size: 22px; flex: 1; }
.cust-hero .balance {
  text-align: right;
}
.cust-hero .balance .amt {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 20px;
  color: var(--color-danger);
}
.cust-hero .balance .lbl { font-size: 11px; color: var(--color-ink-muted); font-weight: 700; text-transform: uppercase; }
.contact-chips {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 14px;
}
.contact-chip {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  background: var(--color-surface-alt);
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
  font-size: 14px;
  font-weight: 600;
  color: var(--color-navy);
  text-decoration: none;
}
.contact-chip .phone { color: var(--color-blue); }
.sites {
  margin-top: 12px;
  font-size: 13px;
  color: var(--color-ink-muted);
}

/* Receipt photo button */
.photo-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 120px;
  border: 2px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface-alt);
  color: var(--color-ink-secondary);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
}
.photo-btn .cam { font-size: 28px; }

/* Empty / muted */
.muted { color: var(--color-ink-muted); }
.small { font-size: 13px; }
. Tight { letter-spacing: -0.02em; }

/* Desktop shell */
.desktop-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.rail {
  background: var(--color-navy);
  color: #fff;
  padding: 24px 16px;
  display: flex; flex-direction: column; gap: 4px;
}
.rail .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 8px 24px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 18px;
}
.rail .brand img { width: 32px; height: 32px; border-radius: 8px; }
.rail a {
  display: flex; align-items: center; gap: 10px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.78);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
}
.rail a.active, .rail a:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}
.rail .ico { width: 22px; text-align: center; }
.desktop-main {
  padding: 28px 32px 48px;
  max-width: calc(var(--content-max) + 64px);
}
.desktop-main .grid-2 {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 20px;
}
.desktop-main .grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.stat {
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
}
.stat .n {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 28px;
  color: var(--color-navy);
}
.stat .l { font-size: 13px; color: var(--color-ink-muted); font-weight: 600; margin-top: 2px; }

/* Utility */
.row { display: flex; align-items: center; gap: 8px; }
.between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 8px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.truncate {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fake-tag {
  position: absolute; top: 8px; right: 8px;
  background: rgba(20,33,61,0.7);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.04em;
  z-index: 100;
  pointer-events: none;
}
