/* Liora CRM — app styles. Mobile first; desktop sidebar at 900px+. */

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--ivory);
  color: var(--charcoal);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.15;
  margin: 0;
  color: var(--charcoal);
}

p { margin: 0; }

a { color: var(--green); }

button, input, select, textarea { font: inherit; color: inherit; }

/* 16px+ inputs stop iOS from zooming in on focus */
input, select, textarea { font-size: 16px; }

:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

.view:focus { outline: none; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Wordmark (Pinyon Script only here) ---------- */
.wordmark {
  font-family: var(--font-script);
  font-size: 30px;
  line-height: 1;
  color: var(--green);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 4px;
}

/* ---------- Mobile layout ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) max(var(--gutter), env(safe-area-inset-right)) 0
           max(var(--gutter), env(safe-area-inset-left));
  min-height: calc(52px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--ivory) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}

.view {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 20px max(var(--gutter), env(safe-area-inset-right))
           calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 32px)
           max(var(--gutter), env(safe-area-inset-left));
}

.nav-brand { display: none; }

.nav {
  position: fixed;
  z-index: 20;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: stretch;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: color-mix(in srgb, var(--ivory) 94%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--line);
}

.tab {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.tab svg {
  width: 24px; height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab[aria-current="page"] { color: var(--green); font-weight: 600; }
.tab[aria-current="page"] svg { stroke-width: 2; }

/* Center "+" button */
.tab-new-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.tab-new-circle {
  width: 56px; height: 56px;
  margin-top: -18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--green);
  color: var(--on-dark);
  box-shadow: 0 4px 14px rgba(74, 82, 36, 0.35);
  border: 3px solid var(--ivory);
  transition: transform 0.12s ease, background 0.12s ease;
}

.tab-new-circle svg { width: 26px; height: 26px; stroke-width: 2.2; }
.tab-new:active .tab-new-circle { transform: scale(0.94); background: var(--deep); }
.tab-new[aria-current="page"] .tab-new-circle { background: var(--deep); }

/* ---------- Page content ---------- */
.page-head { margin-bottom: 20px; }

.eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 4px;
}

.page-head h1 { font-size: 38px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.placeholder {
  text-align: center;
  padding: 36px 20px;
}

.placeholder h2 { font-size: 24px; margin-bottom: 6px; }
.placeholder p { color: var(--muted); max-width: 32ch; margin: 0 auto; }

.placeholder-mark {
  width: 48px; height: 48px;
  margin: 0 auto 14px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--green-tint);
  color: var(--green);
}

.placeholder-mark svg {
  width: 24px; height: 24px;
  fill: none; stroke: currentColor; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 16px;
  text-decoration: none;
  cursor: pointer;
}

.btn-primary { background: var(--green); color: var(--on-dark); }
.btn-primary:active { background: var(--deep); }
.btn-secondary { background: transparent; color: var(--green); border-color: var(--line-strong); }

/* ---------- Desktop: sidebar ---------- */
@media (min-width: 900px) {
  .app {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 100vh;
  }

  .topbar { display: none; }

  .nav {
    position: sticky;
    top: 0;
    grid-column: 1;
    grid-row: 1;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    height: 100vh;
    padding: 28px 16px;
    background: var(--deep);
    border-top: 0;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .nav-brand {
    display: inline-flex;
    color: var(--on-dark);
    font-size: 40px;
    padding: 0 12px;
    margin-bottom: 20px;
  }

  .tab {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    letter-spacing: 0;
    color: rgba(255, 255, 240, 0.78);
  }

  .tab svg { width: 20px; height: 20px; }
  .tab:hover { background: rgba(255, 255, 240, 0.08); color: var(--on-dark); }
  .tab[aria-current="page"] { background: rgba(255, 255, 240, 0.14); color: var(--on-dark); }

  /* "+" becomes a full "New inquiry" button at the top of the sidebar */
  .tab-new {
    order: -1;
    margin-bottom: 16px;
    background: var(--gold);
    color: #fff;
    font-weight: 600;
  }
  .nav-brand { order: -2; }
  .tab-new:hover, .tab-new[aria-current="page"] { background: #7a6139; color: #fff; }
  .tab-new-circle {
    width: auto; height: auto; margin: 0;
    background: none; border: 0; box-shadow: none;
  }
  .tab-new-circle svg { width: 20px; height: 20px; }
  .tab-new-label { position: static; width: auto; height: auto; overflow: visible; clip: auto; }
  .tab-new[aria-current="page"] .tab-new-circle { background: none; }

  .view {
    grid-column: 2;
    grid-row: 1;
    max-width: 960px;
    margin: 0;
    padding: 40px 48px 64px;
  }

  .page-head h1 { font-size: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* =====================================================================
   Step 7: shared bits
   ===================================================================== */
.muted { color: var(--muted); }
.loading { color: var(--muted); padding: 24px 0; }
.due { color: var(--st-due-fg); font-weight: 600; }
.discount { color: var(--gold); font-weight: 600; }
.tag {
  display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; background: var(--gold-tint); color: var(--st-due-fg);
}

.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}

.btn-block { width: 100%; }
.btn-small { min-height: var(--tap); padding: 0 14px; font-size: 15px; }
.btn:disabled { opacity: 0.6; cursor: default; }

/* Status pills (soft tints) */
.pill {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.02em;
  white-space: nowrap;
}
.st-inquiry       { background: var(--st-inquiry-bg);   color: var(--st-inquiry-fg); }
.st-quoted        { background: var(--st-quoted-bg);    color: var(--st-quoted-fg); }
.st-contract_sent { background: var(--st-contract-bg);  color: var(--st-contract-fg); }
.st-booked        { background: var(--st-booked-bg);    color: var(--st-booked-fg); }
.st-completed     { background: var(--st-completed-bg); color: var(--st-completed-fg); }
.st-paid_in_full  { background: var(--st-paid-bg);      color: var(--st-paid-fg); }
.st-lost, .st-cancelled { background: var(--st-closed-bg); color: var(--st-closed-fg); }

/* Toast */
.toast {
  position: fixed; z-index: 60;
  left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translate(-50%, 12px);
  max-width: calc(100vw - 32px);
  padding: 12px 18px; border-radius: 999px;
  background: var(--charcoal); color: var(--ivory);
  font-size: 15px; font-weight: 500;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  opacity: 0; pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast:empty { display: none; }

/* =====================================================================
   Forms
   ===================================================================== */
.form { display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 14px; font-weight: 600; color: var(--charcoal); }
.optional { font-weight: 400; color: var(--muted); font-size: 13px; }
.hint { font-size: 14px; color: var(--muted); }

.field input, .field select, .field textarea {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--charcoal);
}
.field textarea { min-height: 88px; resize: vertical; line-height: 1.45; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(93, 100, 47, 0.18);
}
.field [aria-invalid="true"] { border-color: var(--gold); }

/* iOS date/time inputs: keep them full-height and left-aligned */
.field input[type="date"], .field input[type="time"] {
  -webkit-appearance: none; appearance: none; display: block;
}
.field input::-webkit-date-and-time-value { text-align: left; }

.field select {
  -webkit-appearance: none; appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b675d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px;
}

.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.check {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--tap); font-size: 15px; cursor: pointer;
}
.check input, .addon-check input {
  width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--green);
}

.input-money { position: relative; display: block; }
.input-money > span {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}
.field .input-money input, .input-money input { padding-left: 28px; }

.form-error {
  padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--gold-tint); color: var(--st-due-fg); font-size: 15px; font-weight: 500;
}

/* =====================================================================
   Pipeline
   ===================================================================== */
.seg {
  position: relative;
  display: flex; gap: 8px; align-items: center;
  overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none;
  margin: 0 calc(-1 * var(--gutter)) 16px; padding: 2px var(--gutter);
  scroll-padding: 0 var(--gutter);
}
.seg::-webkit-scrollbar { display: none; }
.seg-tab {
  flex: none; display: inline-flex; align-items: center; gap: 8px;
  min-height: var(--tap); padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--surface); color: var(--charcoal);
  font-size: 15px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.seg-tab[aria-selected="true"] { background: var(--green); border-color: var(--green); color: var(--on-dark); }
.seg-count {
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px;
  display: inline-grid; place-items: center;
  font-size: 12px; font-weight: 600;
  background: var(--green-tint); color: var(--deep);
}
.seg-tab[aria-selected="true"] .seg-count { background: rgba(255, 255, 240, 0.2); color: var(--on-dark); }
.seg-divider { flex: none; width: 1px; height: 24px; background: var(--line-strong); margin: 0 4px; }

.card-list { display: flex; flex-direction: column; gap: 10px; }
.event-card {
  display: flex; align-items: center; gap: 12px;
  padding: 16px; min-height: 88px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: inherit; text-decoration: none;
}
.event-card:active { background: var(--green-tint); }
.ec-main { flex: 1; min-width: 0; }
.ec-client { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ec-title { color: var(--muted); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ec-meta { display: flex; flex-wrap: wrap; gap: 0 6px; margin-top: 4px; font-size: 14px; color: var(--charcoal); }
.ec-total { flex: none; font-family: var(--font-display); font-size: 24px; font-weight: 600; color: var(--gold); }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); display: grid; gap: 14px; justify-items: center; }

/* =====================================================================
   Event detail
   ===================================================================== */
.detail-top { display: flex; align-items: center; justify-content: space-between; margin: -8px 0 8px; }
.back-link {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: var(--tap); padding: 0 8px 0 0;
  border: 0; background: none; cursor: pointer;
  color: var(--green); font-weight: 600; font-size: 16px; text-decoration: none;
}
.detail-head h1 { margin-top: 8px; font-size: 34px; overflow-wrap: anywhere; }
.detail-head .sub { margin-top: 4px; color: var(--muted); }

.actions { display: grid; gap: 10px; margin-bottom: 20px; }
.action-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.action {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 64px; padding: 8px 4px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--green);
  font-size: 13px; font-weight: 600; text-decoration: none; cursor: pointer;
  text-align: center;
}
.action:active { background: var(--green-tint); }
.action.is-disabled { color: var(--muted); opacity: 0.5; cursor: default; }

.detail-grid { display: grid; gap: 14px; }
.section { padding: 18px; }
.section h2 { font-size: 22px; margin-bottom: 8px; }
.subhead {
  font-family: var(--font-ui); font-size: 12px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold);
  margin: 16px 0 6px;
}
.section dl { margin: 0; }
.dl-row {
  display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 12px;
  padding: 9px 0; border-top: 1px solid var(--line);
}
.dl-row:first-child { border-top: 0; }
.dl-row dt { color: var(--muted); font-size: 14px; }
.dl-row dd { margin: 0; overflow-wrap: anywhere; }
.big-number { font-family: var(--font-display); font-size: 28px; font-weight: 600; color: var(--gold); line-height: 1; }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; }

.addon-list, .history { list-style: none; margin: 0; padding: 0; }
.addon-list li, .history li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 0; border-top: 1px solid var(--line);
}
.addon-list li:first-child, .history li:first-child { border-top: 0; }
.history time { color: var(--muted); font-size: 14px; white-space: nowrap; }

/* Edit form */
.edit-form fieldset { border: 1px solid var(--line); margin: 0; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.edit-form legend { float: left; width: 100%; padding: 0; }
.edit-form legend h2 { margin: 0; }
.edit-form legend + * { clear: both; }

.addon-picker { display: grid; gap: 8px; }
.addon {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 4px 12px; background: var(--surface);
}
.addon[hidden] { display: none; }
.addon-check { display: flex; align-items: center; gap: 12px; min-height: 48px; cursor: pointer; }
.addon-name { flex: 1; min-width: 0; font-weight: 500; }
.addon-cat { color: var(--muted); font-size: 14px; }
.addon-controls { display: flex; align-items: center; gap: 10px; padding: 0 0 10px 34px; flex-wrap: wrap; }
.addon-controls[hidden] { display: none; }
.input-small { width: 110px; }
.input-small input {
  width: 100%; min-height: var(--tap); padding: 8px 10px 8px 26px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface);
}
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line-strong); border-radius: 999px; }
.stepper button {
  width: var(--tap); height: var(--tap); display: grid; place-items: center;
  border: 0; background: none; color: var(--green); cursor: pointer; border-radius: 999px;
}
.stepper output { min-width: 24px; text-align: center; font-weight: 600; }
.addon-note { margin-top: 4px; }

.calc-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-sm); background: var(--green-tint);
}
.calc-row strong { font-family: var(--font-display); font-size: 26px; color: var(--deep); }
.discount-line { margin-top: -6px; }

.edit-bar {
  position: sticky; z-index: 5;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px);
  display: grid; gap: 8px;
  padding: 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--ivory) 90%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.edit-bar:has(.form-error:not([hidden])) { border-radius: var(--radius); }
.edit-bar-buttons { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }

/* =====================================================================
   Bottom sheet
   ===================================================================== */
.sheet {
  margin: auto 0 0; width: 100%; max-width: 100%;
  max-height: 88vh; overflow-y: auto;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  border: 0; border-radius: 22px 22px 0 0;
  background: var(--ivory); color: var(--charcoal);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
}
.sheet[open] { animation: sheet-up 0.22s ease-out; }
.sheet::backdrop { background: rgba(42, 42, 42, 0.38); }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 4px auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head h2 { font-size: 24px; }
.sheet-close {
  width: var(--tap); height: var(--tap); border: 0; background: none;
  font-size: 28px; line-height: 1; color: var(--muted); cursor: pointer;
}
.sheet-body { display: grid; gap: 8px; }
.status-list { display: grid; gap: 6px; }
.status-option {
  display: flex; align-items: center; gap: 12px;
  min-height: 52px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--charcoal);
  font-size: 16px; font-weight: 500; text-align: left; cursor: pointer;
}
.status-option.is-current { border-color: var(--green); background: var(--green-tint); }
.status-option-label { flex: 1; }
.status-option-current { color: var(--green); display: inline-flex; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; background: currentColor !important; opacity: 0.75; }
.status-sep {
  display: flex; align-items: center; gap: 10px; margin: 10px 0 4px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.status-sep::before, .status-sep::after { content: ""; flex: 1; height: 1px; background: var(--line-strong); }
.lost-form { display: grid; gap: 14px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }

/* =====================================================================
   Desktop tweaks for step 7
   ===================================================================== */
@media (min-width: 900px) {
  .toast { bottom: 24px; left: calc(50% + var(--sidebar-w) / 2); }
  .seg { flex-wrap: wrap; margin: 0 0 20px; padding: 2px 0; overflow: visible; }
  .card-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .detail-head h1 { font-size: 42px; }
  .actions { grid-template-columns: 240px minmax(0, 1fr); align-items: stretch; max-width: 760px; }
  .action { flex-direction: row; gap: 8px; min-height: 48px; font-size: 14px; }
  .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .edit-form { max-width: 680px; }
  .edit-bar { bottom: 16px; }
  .sheet {
    margin: auto; width: 420px; max-height: 80vh;
    border-radius: 22px; padding-bottom: 20px;
  }
  .sheet-grip { display: none; }
}
