/* ═══════════════════════════════════════════════════════
   LACASA BUSINESS TRACKER — app.css
   Cornerstone Labs · June 2026

   Theme: Light parchment (preserves original design)
   Auth overlay uses platform dark tokens (--p-*)
   Mobile: 680px breakpoint per platform standard
   ═══════════════════════════════════════════════════════ */

/* ── App design tokens (parchment theme) ─────────────── */
:root {
  --bg:            #f5f3ef;
  --surface:       #ffffff;
  --surface2:      #f9f8f6;
  --border:        #e8e4dc;
  --border2:       #d6d0c4;
  --ink:           #1a1814;
  --ink2:          #3d3a34;
  --muted:         #8a8278;
  --faint:         #c4bfb6;

  --amber:         #c97d10;
  --amber-bg:      #fef3dc;
  --amber-border:  #f0d08a;
  --red:           #c0392b;
  --red-bg:        #fdf0ee;
  --red-border:    #f0b8b2;
  --blue:          #1a5fa8;
  --blue-bg:       #eaf1fb;
  --blue-border:   #b8d0f0;
  --green:         #1a7a4a;
  --green-bg:      #eafaf2;
  --green-border:  #a8e0c4;
  --orange:        #b85c00;
  --orange-bg:     #fef4ec;

  --shadow-sm:     0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:     0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg:     0 12px 32px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.06);

  --font:          'DM Sans', sans-serif;
  --display:       'Playfair Display', serif;
  --mono:          'DM Mono', monospace;

  --radius:        12px;
  --radius-sm:     7px;
}

/* ── Platform dark tokens — auth overlay only ─────────── */
:root {
  --p-bg:      #0d0d0d;
  --p-surface: #1a1a1a;
  --p-border:  #333333;
  --p-t1:      #ffffff;
  --p-t2:      #999999;
  --p-t3:      #666666;
}

/* ── Reset ────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ────────────────────────────────────────── */
::-webkit-scrollbar        { width: 4px; height: 4px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: var(--border2); border-radius: 4px; }

/* ══════════════════════════════════════════════════════
   AUTH OVERLAY (platform dark style — injected by app.js)
   ══════════════════════════════════════════════════════ */
#auth-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  background: var(--p-bg);
  overflow: hidden;
}

/* ══════════════════════════════════════════════════════
   LOADING OVERLAY
   ══════════════════════════════════════════════════════ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(245, 243, 239, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
  gap: 14px;
}

.loading-overlay.hidden { display: none; }

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border2);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.06em;
}

/* ══════════════════════════════════════════════════════
   APP SHELL
   ══════════════════════════════════════════════════════ */
.app-wrap.hidden { display: none; }

/* ── Header ───────────────────────────────────────────── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  gap: 16px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Logo placeholder — replace with <img> when logo is provided */
.header-logo-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-family: var(--display);
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.header-brand-name {
  font-family: var(--display);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
  letter-spacing: -0.2px;
}

.header-brand-sub {
  font-size: 0.68rem;
  font-family: var(--mono);
  color: var(--muted);
  letter-spacing: 0.04em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-pill {
  font-size: 0.7rem;
  font-family: var(--mono);
  padding: 4px 11px;
  border-radius: 20px;
  background: var(--blue-bg);
  color: var(--blue);
  border: 1px solid var(--blue-border);
  letter-spacing: 0.04em;
  font-weight: 500;
  white-space: nowrap;
}

.sync-indicator {
  font-size: 0.68rem;
  font-family: var(--mono);
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface2);
  transition: all 0.2s;
  white-space: nowrap;
}

.sync-indicator.syncing { color: var(--amber); border-color: var(--amber-border); background: var(--amber-bg); }
.sync-indicator.error   { color: var(--red);   border-color: var(--red-border);   background: var(--red-bg); }
.sync-indicator.ok      { color: var(--green);  border-color: var(--green-border); background: var(--green-bg); }

.sync-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.syncing .sync-dot { animation: pulse 1s infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ── Buttons ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  font-family: var(--font);
  font-size: 0.83rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.01em;
  white-space: nowrap;
  min-height: 44px; /* platform tap target standard */
}

.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink2); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-primary:active { transform: translateY(0); }

.btn-ghost { background: transparent; border: 1px solid var(--border2); color: var(--ink2); }
.btn-ghost:hover { border-color: var(--ink2); background: var(--surface2); }

.btn-sm { padding: 6px 13px; font-size: 0.78rem; min-height: 36px; }

.icon-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: var(--radius-sm);
  padding: 5px 9px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.12s;
  min-width: 32px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover              { border-color: var(--ink2); color: var(--ink); background: #fff; }
.icon-btn.danger:hover       { border-color: var(--red-border); color: var(--red); background: var(--red-bg); }
.icon-btn.hidden-role        { display: none; } /* hidden for viewer role */

/* ── Alert bar ────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 24px;
  font-size: 0.83rem;
  font-weight: 500;
}

.alert-warning {
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  color: var(--red);
}

.alert-icon { font-size: 1rem; flex-shrink: 0; margin-top: 1px; }
.alert.hidden { display: none; }

/* ── App body ─────────────────────────────────────────── */
.app-body {
  padding: 32px;
  max-width: 1280px;
  margin: 0 auto;
}

/* ══════════════════════════════════════════════════════
   KPI GRID
   ══════════════════════════════════════════════════════ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.kpi-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  cursor: pointer;
  transition: all 0.18s;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  user-select: none;
}

.kpi-card::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: var(--kpi-color, var(--amber));
  opacity: 0;
  transition: opacity 0.18s;
}

.kpi-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--kpi-color, var(--amber));
}

.kpi-card:hover::after { opacity: 1; }

.kpi-card.active {
  border-color: var(--kpi-color, var(--amber));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--kpi-color, var(--amber)) 15%, transparent);
}

.kpi-card.active::after { opacity: 1; }

.kpi-label {
  font-size: 0.68rem;
  font-family: var(--mono);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  margin-bottom: 10px;
  font-weight: 500;
}

.kpi-value {
  font-family: var(--display);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--kpi-color, var(--amber));
  line-height: 1;
  letter-spacing: -0.5px;
}

.kpi-sub  { font-size: 0.71rem; font-family: var(--mono); color: var(--muted); margin-top: 7px; }
.kpi-hint {
  font-size: 0.67rem;
  font-family: var(--mono);
  color: var(--faint);
  margin-top: 10px;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 4px;
}
.kpi-hint::before { content: '↗'; font-size: 0.7rem; }

/* ══════════════════════════════════════════════════════
   INSIGHT PANEL
   ══════════════════════════════════════════════════════ */
.insight-panel {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
  margin-bottom: 28px;
  box-shadow: var(--shadow-sm);
  animation: slideDown 0.2s ease;
  overflow: hidden;
}

.insight-panel.hidden { display: none; }

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.insight-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
}

.insight-title {
  font-family: var(--display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}

.insight-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 1.1rem;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all 0.12s;
  line-height: 1;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.insight-close:hover { background: var(--surface2); color: var(--ink); }

.insight-list { display: flex; flex-direction: column; gap: 0; }

.insight-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.insight-row:last-child { border-bottom: none; }

.insight-row-left { flex: 1; min-width: 0; }
.insight-prop     { font-weight: 600; font-size: 0.85rem; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.insight-client   { font-size: 0.73rem; color: var(--muted); font-family: var(--mono); margin-top: 1px; }
.insight-meta     { display: flex; align-items: center; gap: 10px; flex-shrink: 0; flex-wrap: wrap; }
.insight-amount   { font-family: var(--mono); font-size: 0.84rem; font-weight: 500; color: var(--ink2); }

.insight-tag {
  font-size: 0.68rem;
  font-family: var(--mono);
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}

.tag-warn    { background: var(--red-bg);   color: var(--red);   border: 1px solid var(--red-border); }
.tag-caution { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-border); }
.tag-info    { background: var(--blue-bg);  color: var(--blue);  border: 1px solid var(--blue-border); }
.tag-ok      { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }

.insight-note {
  font-size: 0.73rem;
  color: var(--muted);
  margin-top: 3px;
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

.insight-empty {
  text-align: center;
  padding: 32px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.8rem;
}

.insight-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.insight-stat {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.insight-stat-label {
  font-size: 0.65rem;
  font-family: var(--mono);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

.insight-stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  font-family: var(--display);
  color: var(--ink);
}

.audit-meta {
  font-size: 0.63rem;
  font-family: var(--mono);
  color: var(--faint);
  margin-top: 2px;
}

/* ══════════════════════════════════════════════════════
   TOOLBAR + SEARCH + SORT + FILTER
   ══════════════════════════════════════════════════════ */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.section-title {
  font-family: var(--display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
}

.search-wrap { position: relative; }

.search-input {
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--ink);
  font-family: var(--font);
  font-size: 0.83rem;
  padding: 7px 12px 7px 32px;
  border-radius: 20px;
  outline: none;
  transition: all 0.15s;
  width: 220px;
}

.search-input:focus { border-color: var(--ink2); background: #fff; width: 260px; }

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.78rem;
  pointer-events: none;
}

.search-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0;
  min-width: 20px;
  min-height: 20px;
}

.search-clear.hidden { display: none; }

.sort-wrap { display: flex; align-items: center; gap: 6px; }

.sort-label {
  font-size: 0.68rem;
  font-family: var(--mono);
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.sort-select {
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--ink2);
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 5px 26px 5px 10px;
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238a8278' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
}

.filter-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}

.filter-chip {
  padding: 5px 13px;
  border-radius: 20px;
  font-family: var(--mono);
  font-size: 0.7rem;
  cursor: pointer;
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--muted);
  transition: all 0.14s;
  letter-spacing: 0.04em;
  font-weight: 500;
  min-height: 32px;
}

.filter-chip:hover  { border-color: var(--ink2); color: var(--ink); }
.filter-chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ══════════════════════════════════════════════════════
   TABLE
   ══════════════════════════════════════════════════════ */
.table-wrap {
  overflow-x: auto;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }

thead tr { border-bottom: 1.5px solid var(--border); background: var(--surface2); }

th {
  padding: 11px 16px;
  text-align: left;
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  white-space: nowrap;
  font-weight: 500;
}

td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s; }
tbody tr:hover { background: var(--surface2); }

.prop-name   { font-weight: 600; color: var(--ink); font-size: 0.85rem; }
.prop-client { font-size: 0.72rem; color: var(--muted); font-family: var(--mono); margin-top: 2px; }

/* ── Badges ───────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.67rem;
  font-family: var(--mono);
  font-weight: 500;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.b-amber { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-border); }
.b-blue  { background: var(--blue-bg);  color: var(--blue);  border: 1px solid var(--blue-border); }
.b-red   { background: var(--red-bg);   color: var(--red);   border: 1px solid var(--red-border); }
.b-green { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }

.days-pill {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 2px 9px;
  border-radius: 10px;
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.days-pill.warn    { background: var(--red-bg);   color: var(--red);   border-color: var(--red-border); }
.days-pill.caution { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-border); }

.followup-pill {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 2px 9px;
  border-radius: 10px;
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.followup-pill.soon  { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-border); }
.followup-pill.today { background: var(--red-bg);   color: var(--red);   border-color: var(--red-border); }
.followup-pill.past  { background: var(--red-bg);   color: var(--red);   border-color: var(--red-border); }

/* ── Notes tooltip ────────────────────────────────────── */
.notes-wrap    { position: relative; display: inline-block; }
.notes-icon    { cursor: pointer; color: var(--muted); font-size: 0.85rem; padding: 2px 6px; border-radius: 4px; transition: all 0.12s; }
.notes-icon:hover { background: var(--surface2); color: var(--ink); }

.tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  font-size: 0.75rem;
  white-space: normal;
  width: 240px;
  z-index: 20;
  display: none;
  font-family: var(--font);
  line-height: 1.5;
  box-shadow: var(--shadow-md);
}

.tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--ink);
}

.notes-wrap:hover .tooltip { display: block; }

/* ── Overdue mark ─────────────────────────────────────── */
.overdue-mark {
  font-size: 0.65rem;
  font-family: var(--mono);
  color: var(--red);
  margin-left: 5px;
  background: var(--red-bg);
  padding: 1px 6px;
  border-radius: 8px;
  border: 1px solid var(--red-border);
}

/* ── Empty state ──────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 56px 20px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.82rem;
}

.empty-state.hidden { display: none; }
.empty-icon { font-size: 2.4rem; margin-bottom: 12px; }

/* ══════════════════════════════════════════════════════
   MODAL
   ══════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 24, 20, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
  backdrop-filter: blur(3px);
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 32px 32px 28px;
  width: 100%;
  max-width: 540px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: fadeUp 0.2s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-title {
  font-family: var(--display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 6px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.conflict-warning {
  background: var(--amber-bg);
  border: 1px solid var(--amber-border);
  color: var(--amber);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  font-size: 0.78rem;
  font-family: var(--mono);
  margin-bottom: 14px;
  line-height: 1.5;
}

.conflict-warning.hidden { display: none; }

/* ══════════════════════════════════════════════════════
   FORM FIELDS
   ══════════════════════════════════════════════════════ */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 0.7rem;
  font-family: var(--mono);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  margin-bottom: 7px;
  font-weight: 500;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  color: var(--ink);
  font-family: var(--font);
  font-size: 0.88rem;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--ink2);
  box-shadow: 0 0 0 3px rgba(26, 24, 20, 0.08);
  background: #fff;
}

.field textarea { resize: vertical; min-height: 80px; }

.field select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238a8278' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-color: var(--surface2);
  padding-right: 32px;
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ══════════════════════════════════════════════════════
   TOAST
   ══════════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 0.82rem;
  font-family: var(--mono);
  z-index: 999;
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.28s ease;
  max-width: 320px;
  box-shadow: var(--shadow-md);
}

.toast.show    { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }

/* Deal cards hidden on desktop — table shown instead */
#dealCards { display: none; }

/* ══════════════════════════════════════════════════════
   RESPONSIVE — 680px breakpoint (platform standard)
   ══════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 680px) {

  /* ── Header — two elements only: brand left, add deal right ── */
  .app-header {
    padding: 0 16px;
    height: 56px;
    flex-wrap: nowrap;
    gap: 0;
  }

  /* Hide sub-text, sync badge, user pill, sign out on mobile */
  .header-brand-sub   { display: none; }
  .sync-indicator     { display: none; }
  .user-pill          { display: none; }
  .header-actions .btn-ghost { display: none; } /* Sign Out hidden — accessible via profile later */

  /* header-actions becomes just the Add Deal button */
  .header-actions {
    gap: 0;
    flex-shrink: 0;
  }

  /* Add Deal button — full label visible, right-aligned */
  #btnAddDeal {
    padding: 8px 14px;
    font-size: 0.82rem;
    min-height: 40px;
    white-space: nowrap;
  }

  /* ── Body ─────────────────────────────────────────────────── */
  .app-body { padding: 16px 16px 100px; }

  /* ── KPI ──────────────────────────────────────────────────── */
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-value { font-size: 1.4rem; }

  /* ── Form ─────────────────────────────────────────────────── */
  .field-row { grid-template-columns: 1fr; }

  /* 16px minimum — prevents iOS zoom on input focus */
  .field input,
  .field select,
  .field textarea {
    font-size: 16px;
    padding: 11px 12px;
  }

  /* ── Toolbar ──────────────────────────────────────────────── */
  .toolbar { flex-direction: column; align-items: flex-start; gap: 8px; }
  .toolbar-left { width: 100%; justify-content: space-between; }
  .sort-wrap { width: 100%; }
  .sort-select { flex: 1; width: 100%; }

  .search-input { width: 180px; }
  .search-input:focus { width: 220px; }

  /* ── Filter chips ─────────────────────────────────────────── */
  .filter-chip { padding: 8px 12px; font-size: 0.7rem; }

  /* ── TABLE — hidden on mobile, replaced by cards below ─────── */
  .table-wrap table { display: none; }

  /* ── DEAL CARDS — mobile-only layout ─────────────────────── */
  .deal-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .deal-card {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
  }

  .deal-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
  }

  .deal-card-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--ink);
    line-height: 1.3;
  }

  .deal-card-client {
    font-size: 0.72rem;
    color: var(--muted);
    font-family: var(--mono);
    margin-top: 2px;
  }

  .deal-card-amount {
    font-family: var(--mono);
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--ink2);
    white-space: nowrap;
    flex-shrink: 0;
  }

  .deal-card-mid {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 10px;
  }

  .deal-card-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
  }

  .deal-card-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    flex: 1;
  }

  .deal-card-meta-item {
    font-size: 0.68rem;
    font-family: var(--mono);
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 3px;
  }

  .deal-card-meta-item strong {
    color: var(--ink2);
    font-weight: 500;
  }

  .deal-card-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
  }

  .deal-card-actions .icon-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
    font-size: 1rem;
  }

  /* Show cards on mobile */
  #dealCards { display: flex; }


  /* ── Modal — bottom sheet ─────────────────────────────────── */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    max-width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
    margin-top: auto;
    padding: 24px 20px 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  /* ── Toast — safe area ────────────────────────────────────── */
  .toast {
    bottom: calc(20px + env(safe-area-inset-bottom));
    right: 16px;
    left: 16px;
    max-width: none;
  }

  /* ── Insight panel ────────────────────────────────────────── */
  .insight-panel { padding: 16px; }
  .insight-stats { grid-template-columns: 1fr 1fr; }
}


@media (max-width: 420px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .search-input { width: 140px; }
  .search-input:focus { width: 180px; }
}
