:root {
    --bg: #f0f2f5;
    --surface: #ffffff;
    --surface2: #f5f6f8;
    --border: #e2e5ea;
    --accent: #1a56ff;
    --accent-light: #e8eeff;
    --green: #00a86b;
    --green-light: #e6f7f1;
    --red: #e5293a;
    --red-light: #fdeaec;
    --amber: #f59e0b;
    --amber-light: #fef3e2;
    --blue: #1a56ff;
    --text: #0f1623;
    --muted: #8a93a6;
    --radius: 12px;
    --font-head: 'DM Sans', sans-serif;
    --font-body: 'DM Sans', sans-serif;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.05);
    --shadow-md: 0 4px 16px rgba(0,0,0,.1), 0 1px 4px rgba(0,0,0,.06);
  }
  body.dark {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #22263a;
    --border: #2e3347;
    --text: #f0f2ff;
    --muted: #7a84a0;
    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.2);
    --shadow-md: 0 4px 16px rgba(0,0,0,.4);
    --accent-light: #1a2a5e;
    --green-light: #0a2e1f;
    --red-light: #2e0f12;
    --amber-light: #2e1f00;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
  }

  /* NAV */
  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 100;
    box-shadow: 0 1px 0 var(--border);
  }
  .topbar-logo { font-family: var(--font-body); font-size: 20px; font-weight: 800; letter-spacing: -0.5px; color: var(--text); }
  .topbar-logo span { color: var(--accent); }
  .topbar-biz { font-size: 11px; color: var(--muted); font-weight: 500; margin-top: 1px; }

  .bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex; z-index: 100;
    box-shadow: 0 -2px 12px rgba(0,0,0,.06);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .nav-btn {
    flex: 1; padding: 10px 4px 12px; border: none; background: none;
    color: var(--muted); font-size: 10px; font-family: var(--font-body); font-weight: 600;
    cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px;
    transition: color .15s;
  }
  .nav-btn svg { width: 22px; height: 22px; }
  .nav-btn.active { color: var(--accent); }
  .nav-btn.active svg path, .nav-btn.active svg rect, .nav-btn.active svg circle { stroke: var(--accent); }

  /* PAGES */
  .page { display: none; padding: 18px 16px 100px; animation: fadeUp .25s ease; }
  .page.active { display: block; }
  @keyframes fadeUp { from { opacity:0; transform: translateY(10px); } to { opacity:1; transform:translateY(0); } }

  /* CARDS & UI */
  .card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; margin-bottom: 10px;
    box-shadow: var(--shadow);
  }
  .section-title {
    font-family: var(--font-body); font-size: 17px; font-weight: 800;
    margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between;
    color: var(--text); letter-spacing: -0.3px;
  }
  .badge {
    font-size: 11px; font-family: var(--font-body); font-weight: 700;
    padding: 3px 10px; border-radius: 20px; background: var(--surface2);
    text-transform: uppercase; letter-spacing: .4px;
  }
  .badge.green { background: var(--green-light); color: var(--green); }
  .badge.red { background: var(--red-light); color: var(--red); }
  .badge.amber { background: var(--amber-light); color: var(--amber); }
  .badge.blue { background: var(--accent-light); color: var(--blue); }

  /* BUTTONS */
  .btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 11px 18px; border-radius: 10px; border: none;
    font-family: var(--font-body); font-size: 14px; font-weight: 600;
    cursor: pointer; transition: all .15s; letter-spacing: -.1px;
  }
  .btn:active { transform: scale(.97); opacity: .9; }
  .btn-primary { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(26,86,255,.25); }
  .btn-secondary { background: var(--surface); color: var(--text); border: 1.5px solid var(--border); }
  .btn-danger { background: var(--red-light); color: var(--red); border: 1.5px solid #fbd0d3; }
  .btn-green { background: var(--green-light); color: var(--green); border: 1.5px solid #b3e8d5; }
  .btn-blue { background: var(--accent-light); color: var(--blue); border: 1.5px solid #c5d4ff; }
  .btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }
  .btn-full { width: 100%; justify-content: center; }

  /* FORM */
  .form-group { margin-bottom: 14px; }
  label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; letter-spacing: .3px; }
  input, select, textarea {
    width: 100%; background: var(--surface); border: 1.5px solid var(--border);
    border-radius: 10px; padding: 11px 14px; color: var(--text);
    font-family: var(--font-body); font-size: 14px; outline: none;
    transition: border-color .2s; box-shadow: 0 1px 2px rgba(0,0,0,.04);
  }
  input:focus, select:focus, textarea:focus { border-color: var(--accent); }
  #doc-discount-val::-webkit-inner-spin-button,
  #doc-discount-val::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
  #doc-discount-val { -moz-appearance: textfield; }
  textarea { resize: vertical; min-height: 80px; }
  select option { background: var(--surface2); }
  .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

  /* LIST ITEMS */
  .list-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 0; border-bottom: 1px solid var(--border);
  }
  .list-item:last-child { border-bottom: none; }
  .list-item-info h4 { font-size: 14px; font-weight: 500; margin-bottom: 3px; }
  .list-item-info p { font-size: 12px; color: var(--muted); }
  .list-item-right { text-align: right; }
  .list-item-right .amount { font-family: var(--font-body); font-size: 16px; font-weight: 700; }
  .list-item-actions { display: flex; gap: 6px; margin-top: 6px; justify-content: flex-end; }

  /* MODAL */
  .modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.75);
    z-index: 200; display: none; align-items: flex-end;
    animation: fadeIn .2s ease;
  }
  .modal-overlay.open { display: flex; }
  @keyframes fadeIn { from {opacity:0} to {opacity:1} }
  .modal {
    background: var(--surface); border-radius: 20px 20px 0 0;
    width: 100%; max-height: 90vh; overflow-y: auto;
    padding: 20px 16px 40px;
    animation: slideUp .25s ease;
    box-shadow: 0 -4px 30px rgba(0,0,0,.12);
  }
  @keyframes slideUp { from {transform:translateY(40px)} to {transform:translateY(0)} }
  .modal-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 0 auto 20px; }
  .modal-title { font-family: var(--font-body); font-size: 18px; font-weight: 800; margin-bottom: 20px; letter-spacing: -.3px; }

  /* DASHBOARD STATS */
  .stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; width: 100%; box-sizing: border-box; }
  .stat-card { min-width: 0; }
  .stat-card {
    background: var(--surface); border: 1.5px solid var(--border);
    border-radius: var(--radius); padding: 16px;
    box-shadow: var(--shadow);
  }
  .stat-label { font-size: 11px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .6px; font-weight: 600; }
  .stat-value { font-family: var(--font-body); font-size: 24px; font-weight: 800; letter-spacing: -.5px; }
  .stat-value.green { color: var(--green); }
  .stat-value.amber { color: var(--amber); }
  .stat-value.blue { color: var(--blue); }
  .stat-value.red { color: var(--red); }

  /* SHARE BUTTONS */
  .share-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
  .share-btn {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    padding: 16px 14px; border-radius: 12px; border: 1.5px solid var(--border);
    background: var(--surface); color: var(--text); cursor: pointer;
    font-family: var(--font-body); font-size: 13px; font-weight: 600;
    transition: all .15s; box-shadow: var(--shadow);
  }
  .share-btn:hover { background: var(--surface2); border-color: var(--accent); }
  .share-btn svg { width: 28px; height: 28px; }

  /* QUOTE LINE ITEMS */
  .line-items { margin-bottom: 14px; }
  .line-item-row {
    display: grid; grid-template-columns: 1fr 72px 88px 28px;
    gap: 6px; align-items: start; margin-bottom: 8px;
  }
  .line-item-row input { padding: 8px 10px; font-size: 13px; }
  .remove-line { background: var(--red-light); border: none; color: var(--red); cursor: pointer; font-size: 16px; padding: 5px 7px; border-radius: 6px; }
  .toggle-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; background: var(--surface2); border-radius: 10px;
    font-size: 14px; font-weight: 500; cursor: pointer;
  }
  .toggle-row input[type=checkbox] { display: none; }
  .switch {
    width: 44px; height: 24px; border-radius: 12px; background: var(--border);
    position: relative; transition: background .2s; flex-shrink: 0;
  }
  .switch::after {
    content: ''; position: absolute; top: 3px; left: 3px;
    width: 18px; height: 18px; border-radius: 50%; background: #fff;
    transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
  }
  .toggle-row input:checked + .switch { background: var(--accent); }
  .toggle-row input:checked + .switch::after { transform: translateX(20px); }
  .drag-handle { cursor: grab; color: var(--muted); font-size: 18px; margin-right: 10px; user-select: none; }
  .cdetail-row { display: flex; align-items: flex-start; gap: 10px; padding: 6px 0; font-size: 14px; }
  .cdetail-icon { flex-shrink: 0; width: 20px; text-align: center; margin-top: 1px; }
  .section-order-item {
    display: flex; align-items: center; padding: 12px 14px;
    background: var(--surface2); border-radius: 10px; font-size: 14px; font-weight: 500;
    border: 1.5px solid var(--border);
  }
  .section-order-item.dragging { opacity: .4; }

  .search-chip {
    padding: 6px 4px; border-radius: 20px; border: 1.5px solid var(--border);
    background: var(--surface); color: var(--muted); font-family: var(--font-body);
    font-size: 13px; font-weight: 600; cursor: pointer; transition: all .15s; text-align: center;
  }
  .search-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

  /* SEARCH */
  .search-bar {
    display: flex; align-items: center; gap: 10px;
    background: var(--surface); border: 1.5px solid var(--border);
    border-radius: 10px; padding: 10px 14px; margin-bottom: 16px;
    box-shadow: var(--shadow);
  }
  .search-bar input { background: none; border: none; padding: 0; flex: 1; font-size: 14px; box-shadow: none; }
  .search-bar svg { color: var(--muted); flex-shrink: 0; }

  /* TOAST */
  .toast {
    position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px);
    background: var(--text); color: #fff; border-radius: 10px;
    padding: 10px 20px; font-size: 13px; font-weight: 600; opacity: 0;
    transition: all .3s; z-index: 300; white-space: nowrap;
    box-shadow: 0 4px 20px rgba(0,0,0,.2);
  }
  .toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

  /* EMPTY STATE */
  .empty-state { text-align: center; padding: 40px 20px; color: var(--muted); font-weight: 500; }
  .empty-state svg { margin-bottom: 12px; opacity: .4; }
  .empty-state p { font-size: 14px; }

  .divider { height: 1.5px; background: var(--border); margin: 16px 0; }
  .total-row { display: flex; justify-content: space-between; align-items: center; }
  .total-row .label { font-size: 14px; color: var(--muted); }
  .total-row .value { font-family: var(--font-body); font-size: 16px; font-weight: 700; }
  .total-row.grand .value { font-size: 22px; color: var(--accent); font-family: var(--font-body); font-weight: 800; }