/* =========================================================================
   Moh OS V3 — Design System
   Canonboy-inspired palette · Fraunces serif headlines · Inter body
   Mobile-first. Sidebar = drawer on phone, persistent on tablet+.
   ========================================================================= */

:root {
  /* Palette */
  --bg: #f7f3ec;
  --bg-2: #fbf7f0;
  --surface: #ffffff;
  --ink: #2a2520;
  --ink-2: #4a3f35;
  --muted: #7a6f62;
  --line: #e8dfd1;
  --line-2: #d6c9b1;
  --accent: #8a6440;
  --accent-2: #b8895a;
  --gold: #c5a572;
  --success: #4a7c4e;
  --warn: #d97706;
  --urgent: #c0392b;
  --info: #4a7ba7;

  /* Type */
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Inter', -apple-system, system-ui, sans-serif;

  /* Layout */
  --topbar-h: 56px;
  --sidebar-w: 240px;

  /* Radius / shadow */
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --shadow-sm: 0 2px 6px rgba(42,37,32,0.04);
  --shadow: 0 8px 24px rgba(42,37,32,0.08);
  --shadow-lg: 0 24px 60px rgba(42,37,32,0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; max-width: 100vw; overflow-x: hidden; }
html { font-size: 16px; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  max-width: 100vw;
}
/* Universal: no element should ever push horizontal overflow */
img, video, iframe, table, pre, code { max-width: 100%; }

input, textarea, select, button { font: inherit; color: inherit; }
input, textarea, select { font-size: 16px; }   /* prevent iOS zoom */
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
em { font-style: italic; font-family: var(--serif); }

h1, h2, h3, h4 { font-family: var(--serif); margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 28px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.lbl { display:block; font-size:11px; font-weight:600; letter-spacing:0.06em; text-transform:uppercase; color:var(--muted); margin: 12px 0 6px; }

/* =========================================================================
   AUTH SCREEN
   ========================================================================= */
.auth-screen {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #1a1714 0%, #2a2520 100%);
  padding: 20px;
}
.auth-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 28px 24px;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.auth-logo {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; display: grid; place-items: center;
  font-family: var(--serif); font-size: 24px; font-weight: 600;
}
.auth-title { font-family: var(--serif); font-size: 22px; font-weight: 600; }
.auth-sub { color: var(--muted); font-size: 13px; }
.auth-form input {
  width: 100%; padding: 11px 13px;
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--bg-2);
  margin-bottom: 4px;
}
.auth-form input:focus { outline: none; border-color: var(--accent); }
.auth-actions { display: flex; gap: 8px; margin-top: 14px; }
.auth-actions .btn { flex: 1; }
.auth-msg { font-size: 13px; margin-top: 12px; min-height: 18px; }
.auth-msg.error { color: var(--urgent); }
.auth-msg.success { color: var(--success); }

/* =========================================================================
   SHELL · TOPBAR · SIDEBAR
   ========================================================================= */
.shell { min-height: 100vh; display: grid; grid-template-rows: var(--topbar-h) 1fr; max-width: 100vw; overflow-x: hidden; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  background: rgba(247,243,236,0.92);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; display: grid; place-items: center;
  font-family: var(--serif); font-size: 17px; font-weight: 600;
}
.brand-text { font-family: var(--serif); font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.brand-text em { font-weight: 400; color: var(--accent); }

.topbar-right { display: flex; gap: 6px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-2);
  display: grid; place-items: center; color: var(--ink-2);
  transition: all 150ms;
}
.icon-btn:hover { background: var(--surface); border-color: var(--line-2); }
.icon-btn:active { transform: scale(0.96); }
.user-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-color: transparent; font-weight: 600;
}

/* Sidebar — mobile drawer */
.sidebar {
  position: fixed; left: 0; top: var(--topbar-h);
  width: var(--sidebar-w); height: calc(100vh - var(--topbar-h));
  background: var(--bg-2); border-right: 1px solid var(--line);
  transform: translateX(-100%);
  transition: transform 240ms cubic-bezier(.2,.7,.2,1);
  z-index: 40;
  overflow-y: auto;
  padding: 12px 0 60px;
}
.sidebar.open { transform: translateX(0); }
.sidebar-overlay {
  position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(0,0,0,0.3);
  z-index: 35; opacity: 0; pointer-events: none;
  transition: opacity 200ms;
}
.sidebar-overlay.open { opacity: 1; pointer-events: auto; }

.nav { display: flex; flex-direction: column; }
.nav-section {
  font-size: 10px; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--muted);
  padding: 14px 18px 6px;
}
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px;
  color: var(--ink-2); font-size: 14px; font-weight: 500;
  cursor: pointer;
  transition: background 120ms;
}
.nav-link:hover { background: rgba(184,137,90,0.08); color: var(--accent); }
.nav-link.active { background: rgba(184,137,90,0.14); color: var(--accent); border-right: 3px solid var(--accent); }
.nav-ic { width: 20px; text-align: center; opacity: 0.7; font-size: 14px; }

/* Main */
.main {
  padding: 16px 14px 80px;
  min-height: calc(100vh - var(--topbar-h));
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  min-width: 0;
  overflow-x: hidden;
}
.main > * { max-width: 100%; min-width: 0; }
.loading { padding: 60px 20px; text-align: center; color: var(--muted); }

/* Tablet+: sidebar persistent */
@media (min-width: 900px) {
  .menu-btn { display: none; }
  .sidebar { transform: translateX(0); }
  .sidebar-overlay { display: none; }
  .main {
    margin-left: var(--sidebar-w);
    padding: 24px 28px 80px;
    max-width: calc(100vw - var(--sidebar-w));
    width: calc(100vw - var(--sidebar-w));
  }
}

/* =========================================================================
   COMPONENTS
   ========================================================================= */

/* Buttons */
.btn {
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 14px;
  border-radius: var(--r);
  font-size: 14px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all 150ms;
  text-decoration: none;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover { background: var(--ink-2); }
.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-accent:hover { background: var(--accent-2); }
.btn-soft { background: var(--bg-2); color: var(--ink-2); border-color: var(--line); }
.btn-ghost { background: transparent; color: var(--ink-2); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg-2); }
.btn-danger { background: transparent; color: var(--urgent); border-color: var(--urgent); }
.btn-danger:hover { background: var(--urgent); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-lg { padding: 13px 20px; font-size: 15px; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; gap: 10px; flex-wrap: wrap; }
.card-title { font-family: var(--serif); font-size: 17px; font-weight: 600; }

/* Inputs */
.field { margin-bottom: 12px; }
.field input, .field textarea, .field select,
input.input, textarea.textarea, select.select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 10px 12px;
  border-radius: var(--r);
  font-size: 16px;
  transition: border 150ms, box-shadow 150ms;
}
.field input:focus, .field textarea:focus, .field select:focus,
input.input:focus, textarea.textarea:focus, select.select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(184,137,90,0.15);
}
textarea.textarea { min-height: 90px; resize: vertical; font-family: var(--sans); }

/* Pills / status */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px;
  background: var(--bg-2); color: var(--ink-2);
  border: 1px solid var(--line);
}
.pill-inquiry  { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.pill-booked   { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.pill-shooting { background: #fce7f3; color: #9d174d; border-color: #fbcfe8; }
.pill-editing  { background: #ede9fe; color: #5b21b6; border-color: #ddd6fe; }
.pill-delivered{ background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.pill-archived { background: #f3f4f6; color: #4b5563; border-color: #e5e7eb; }
.pill-todo     { background: #f3f4f6; color: #4b5563; }
.pill-in_progress { background: #dbeafe; color: #1e40af; }
.pill-review   { background: #fef3c7; color: #92400e; }
.pill-done     { background: #d1fae5; color: #065f46; }
.pill-blocked  { background: #fee2e2; color: #991b1b; }
.pill-paid     { background: #d1fae5; color: #065f46; }
.pill-pending  { background: #fef3c7; color: #92400e; }
.pill-failed   { background: #fee2e2; color: #991b1b; }

/* Empty state */
.empty {
  padding: 40px 20px; text-align: center; color: var(--muted);
  border: 1.5px dashed var(--line); border-radius: var(--r-lg);
  background: var(--bg-2);
}
.empty h3 { font-family: var(--serif); font-size: 17px; color: var(--ink-2); margin-bottom: 6px; }

/* KPI tiles */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 12px 14px;
}
.kpi-label { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.kpi-value { font-family: var(--serif); font-size: 24px; font-weight: 600; margin-top: 4px; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Table-as-cards (mobile) */
.row-card { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); margin-bottom: 8px; }
.row-card:hover { border-color: var(--line-2); background: var(--bg-2); }
.row-title { font-weight: 600; font-size: 14px; }
.row-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Tabs */
.tabs {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  max-width: 100%;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent; border: 0; padding: 10px 14px; font-weight: 500;
  color: var(--muted); border-bottom: 2px solid transparent;
  white-space: nowrap;
  flex-shrink: 0;
}
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }

/* Line item rows on package tabs — should scroll inside their card, not push the page */
.line-row { min-width: 0; }
.line-row input { min-width: 0; max-width: 100%; }

/* Card widths */
.card { max-width: 100%; }
.card > * { max-width: 100%; min-width: 0; }

/* Row of buttons should wrap, not overflow */
.row { flex-wrap: wrap; min-width: 0; }
.row > * { min-width: 0; }

/* KPI grid: responsive without forcing overflow */
.kpi-grid { max-width: 100%; }
.kpi { min-width: 0; }
.kpi-value, .kpi-sub, .kpi-label { word-break: break-word; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(26,23,20,0.55); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; animation: fade-in 180ms ease;
}
.modal {
  background: var(--surface); border-radius: var(--r-lg);
  width: 100%; max-width: 540px; max-height: calc(100vh - 32px);
  overflow-y: auto; box-shadow: var(--shadow-lg);
  animation: slide-up 220ms cubic-bezier(.2,.7,.2,1);
}
.modal-head { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.modal-title { font-family: var(--serif); font-size: 18px; font-weight: 600; }
.modal-sub { color: var(--muted); font-size: 13px; }
.modal-body { padding: 16px 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: var(--bg-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.modal-close { background: transparent; border: 0; color: var(--muted); font-size: 22px; line-height: 1; }

/* Toast */
.toast-stack {
  position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px;
  z-index: 200; max-width: 380px;
  pointer-events: none;
}
.toast {
  background: var(--surface); border: 1px solid var(--line);
  border-left: 4px solid var(--info); border-radius: 10px;
  padding: 12px 14px; box-shadow: var(--shadow);
  animation: slide-in 280ms cubic-bezier(.2,.7,.2,1);
  pointer-events: auto;
}
.toast.success { border-left-color: var(--success); }
.toast.warn { border-left-color: var(--warn); }
.toast.error { border-left-color: var(--urgent); }
.toast-title { font-size: 13px; font-weight: 600; color: var(--ink); }
.toast-body { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Page header */
.page-head {
  display: flex; justify-content: space-between; align-items: baseline;
  flex-wrap: wrap; gap: 10px; margin-bottom: 18px;
  min-width: 0;
}
.page-head > * { min-width: 0; }
.page-head > div:first-child { flex: 1 1 auto; min-width: 0; }
.page-head .row { flex: 0 0 auto; flex-wrap: wrap; }
.page-title { font-family: var(--serif); font-size: 26px; font-weight: 600; letter-spacing: -0.01em; word-break: break-word; }
.page-title em { color: var(--accent); }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 4px; word-break: break-word; }

/* Chip cluster */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* Number bar (for line items) */
.line-row { display: grid; grid-template-columns: 1fr 60px 90px 90px 30px; gap: 6px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.line-row input { font-size: 14px; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line); }
.line-row .total { font-weight: 600; text-align: right; padding: 0 6px; }

/* Misc */
.row { display: flex; gap: 8px; align-items: center; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
@media (max-width: 600px) { .row-3 { grid-template-columns: 1fr; } }

.spacer { height: 12px; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }

@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slide-up { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* Mobile tighten */
@media (max-width: 600px) {
  h1 { font-size: 24px; }
  .page-title { font-size: 22px; }
  .main { padding: 14px 12px 80px; }
  .card { padding: 14px; }
  .modal { border-radius: 14px 14px 0 0; align-self: end; max-height: 92vh; }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .line-row { grid-template-columns: 1fr; gap: 4px; padding: 10px 0; }
  /* Stack page-head buttons under title on phones */
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head .row { width: 100%; }
}
