/* ============================================================
   8mm Quote Studio – Luxury Beige Theme
   Sleek · Minimal · Sophisticated
   ============================================================ */

:root {
  --bg:          #f9f6f1;
  --bg2:         #ffffff;
  --bg3:         #f2ede4;
  --border:      rgba(90, 70, 45, 0.10);
  --border2:     rgba(90, 70, 45, 0.18);
  --accent:      #d95f08;
  --accent2:     #e87420;
  --accent-glow: rgba(217, 95, 8, 0.12);
  --text:        #1a1208;
  --text2:       #7a6b58;
  --text3:       #b0a490;
  --red:         #c0392b;
  --green:       #1a8a4a;
  --card-r:      16px;
  --sidebar-w:   240px;
  font-family: 'Outfit', 'Inter', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); }

/* ============================================================
   LAYOUT
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ============================================================
   SIDEBAR – elegant, light
   ============================================================ */
.sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1.15rem;
  gap: 2rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-logo { padding: 0 0.25rem; }
.logo-img {
  width: 100%;
  max-width: 180px;
  height: auto;
  display: block;
}
.logo-sub {
  font-size: 0.68rem;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--accent);
  margin-top: 6px;
  font-weight: 600;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.15s ease;
  text-align: left;
}
.nav-btn svg { width: 17px; height: 17px; flex-shrink: 0; stroke-width: 1.8; }
.nav-btn:hover {
  background: var(--bg3);
  color: var(--text);
}
.nav-btn.active {
  background: var(--bg3);
  color: var(--accent);
  border-color: var(--border2);
  font-weight: 600;
}

.badge {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  min-width: 20px;
  text-align: center;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}
/* Sync Status */
.sync-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.25rem;
  margin-bottom: 0.75rem;
  font-size: 0.72rem;
  color: var(--text2);
  border-bottom: 1px solid var(--border);
}
.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #b0a490;
}
.sync-status.online .sync-dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.sync-status.error .sync-dot { background: var(--red); }
.sync-status.syncing .sync-dot { background: var(--accent); animation: pulse 1s infinite; }

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

.company-info {
  font-size: 0.72rem;
  color: var(--text3);
  line-height: 1.7;
}
.company-name {
  font-weight: 700;
  color: var(--text);
  font-size: 0.82rem;
  margin-bottom: 0.15rem;
}

/* ============================================================
   MAIN
   ============================================================ */
.main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  position: sticky;
  top: 0;
  z-index: 20;
  gap: 1rem;
}
.topbar-left { display: flex; align-items: center; gap: 0.75rem; }
.topbar-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}
.active-tpl-pill {
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 11px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.topbar-actions { display: flex; gap: 0.55rem; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.btn-primary svg { width: 15px; height: 15px; }
.btn-primary:hover { background: var(--accent2); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-ghost svg { width: 15px; height: 15px; }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text3);
  cursor: pointer;
  padding: 5px;
  transition: all 0.15s;
  font-family: inherit;
}
.btn-icon svg { width: 14px; height: 14px; }
.btn-icon:hover { color: var(--red); border-color: var(--red); }

/* ============================================================
   PANEL VIEWS
   ============================================================ */
.panel-view {
  display: none;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.5rem 2rem;
  flex: 1;
}
.panel-view.active { display: flex; }

/* ============================================================
   CARD
   ============================================================ */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--card-r);
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.card-header h2 {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text);
}
.card-header p {
  font-size: 0.8rem;
  color: var(--text2);
  margin-top: 2px;
}
.subtitle-text {
  font-size: 0.78rem;
  color: var(--text2);
  margin-top: 2px;
}
.subtitle-text strong { color: var(--accent); }

/* ============================================================
   FORMS
   ============================================================ */
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
  min-width: 140px;
}
.field.flex2 { flex: 2; }
.field span {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text3);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.field input,
.field textarea,
.field select {
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  transition: border-color 0.15s;
  width: 100%;
}
.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
}
.field textarea { resize: vertical; }

/* standalone inputs */
input[type="text"],
input[type="search"],
input[type="tel"],
input[type="date"],
input[type="url"],
input[type="number"] {
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  appearance: none;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* ============================================================
   TABLE
   ============================================================ */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
thead tr { border-bottom: 2px solid var(--border); }
th {
  padding: 0.55rem 0.75rem;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
td {
  padding: 0.7rem 0.75rem;
  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: rgba(217, 95, 8, 0.03); }

.col-sr      { width: 3%; text-align: center; font-weight: 600; color: var(--text3); }
.col-product { width: 55%; min-width: 250px; padding-right: 2rem; }
.col-qty     { width: 8%; text-align: center; }
.col-price   { width: 12%; text-align: center; }
.col-total   { width: 13%; text-align: right; font-weight: 700; color: var(--accent); }
.col-del     { width: 5%; text-align: center; }

.empty-row td {
  text-align: center;
  color: var(--text3);
  padding: 2.5rem;
  font-size: 0.88rem;
  font-style: italic;
}

/* inline table inputs */
.input-inline {
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  width: 100%;
  padding: 0;
  white-space: normal !important; /* Force multi-line */
  word-wrap: break-word;
}
.input-inline:focus {
  outline: 1px solid var(--accent);
  border-radius: 4px;
  padding: 2px 4px;
  background: #fff;
}
.input-inline.right { text-align: right; }
.input-inline.center { text-align: center; }

.item-cell { display: flex; align-items: flex-start; gap: 0.8rem; }
.item-thumb {
  width: 96px;
  height: 96px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--bg3);
}
.item-thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-info { flex: 1; display: flex; flex-direction: column; gap: 0.1rem; }
.item-name { 
  font-weight: 600; 
  white-space: normal !important;
  word-wrap: break-word;
  field-sizing: content; /* Modern CSS to auto-grow textarea */
  min-height: 1.5em;
  height: auto !important;
  overflow: visible !important;
}
.line-total { font-weight: 700; color: var(--accent); }

/* notes toggle */
.notes-shell { font-size: 0.8rem; }
.notes-toggle-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.7rem;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
}
.notes-shell textarea {
  display: none;
  width: 100%;
  margin-top: 3px;
}
.notes-shell.editing textarea { display: block; }
.notes-shell .notes-text { color: var(--text2); display: none; font-size: 0.78rem; }
.notes-shell.has-notes .notes-text { display: block; }

/* ============================================================
   ADD ITEM ACCORDION
   ============================================================ */
.add-item-accordion {
  border: 1px dashed var(--border2);
  border-radius: 10px;
  overflow: hidden;
}
.add-item-accordion summary {
  padding: 0.65rem 1rem;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
  user-select: none;
  transition: background 0.15s;
  letter-spacing: 0.03em;
}
.add-item-accordion summary:hover { background: rgba(217, 95, 8, 0.04); }
.add-item-accordion[open] summary { border-bottom: 1px dashed var(--border2); }
.add-item-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
}

/* ============================================================
   SUMMARY
   ============================================================ */
.summary-cols {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.5rem;
  align-items: flex-start;
}
.summary-left {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.totals-block {
  background: var(--bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
}
.total-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.total-line:last-child { border-bottom: none; }
.total-line span { color: var(--text2); font-size: 0.82rem; }
.total-line strong { font-weight: 600; }
.total-line.grand-total {
  background: var(--text);
  color: #fff;
}
.total-line.grand-total span { color: rgba(255,255,255,0.7); font-weight: 600; }
.total-line.grand-total strong { font-size: 1.2rem; color: #fff; }
.total-line.discount-line strong { color: var(--green); }

.discount-field {
  border: 1px dashed var(--border2);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  background: var(--bg3);
  display: none;
}
.discount-field.visible { display: block; }

.discount-toggle-btn {
  background: none;
  border: 1px dashed var(--border2);
  border-radius: 8px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
  text-align: center;
  letter-spacing: 0.03em;
}
.discount-toggle-btn:hover { background: rgba(217, 95, 8, 0.05); }

.save-tpl-row { display: flex; gap: 0.5rem; }
.save-tpl-row input { flex: 1; }

/* ============================================================
   TERMS GRID
   ============================================================ */
.terms-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
}
.terms-box {
  background: var(--bg);
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 0.85rem 1rem;
}
.terms-box h3 {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 0.5rem;
}
.terms-box ul {
  padding-left: 1rem;
  color: var(--text2);
  font-size: 0.78rem;
  line-height: 1.6;
}
.terms-box p {
  color: var(--text2);
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.55;
}

/* ============================================================
   PRODUCT LIBRARY
   ============================================================ */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.85rem;
}
.product-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, transform 0.15s;
}
.product-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.product-card img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  background: var(--bg3);
}
.product-card-body {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}
.product-card-body h3 { font-size: 0.88rem; font-weight: 700; }
.product-card-body p { font-size: 0.76rem; color: var(--text2); line-height: 1.5; flex: 1; }
.product-card-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.78rem;
}
.product-price { font-weight: 700; color: var(--accent); }
.product-brand { color: var(--text3); font-size: 0.72rem; }
.product-card-footer {
  padding: 0.6rem 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.45rem;
  align-items: center;
}
.product-card-footer input {
  width: 50px;
  text-align: center;
  padding: 0.35rem 0.25rem;
  font-size: 0.85rem;
}
.product-card-footer .btn-primary {
  flex: 1;
  justify-content: center;
  padding: 0.4rem 0.5rem;
  font-size: 0.78rem;
}

/* ============================================================
   TEMPLATES
   ============================================================ */
.tpl-search-row { display: flex; gap: 0.75rem; align-items: center; }
.tpl-search-row input { flex: 1; }
.badge-lg { font-size: 0.78rem; color: var(--text2); white-space: nowrap; }
.badge-lg span { font-weight: 700; color: var(--accent); }

.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 0.75rem;
}
.template-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  transition: border-color 0.15s;
}
.template-card:hover { border-color: var(--accent); }
.template-card.active-template {
  border-color: var(--accent);
  background: rgba(217, 95, 8, 0.04);
}
.template-card h3 { font-size: 0.92rem; font-weight: 700; }
.template-card p { font-size: 0.78rem; color: var(--text2); }
.tpl-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text3);
  margin-top: 2px;
}
.tpl-actions { display: flex; gap: 0.35rem; margin-top: 0.4rem; }
.tpl-load-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: 6px;
  padding: 0.4rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  flex: 1;
  justify-content: center;
}
.tpl-load-btn:hover { background: var(--accent2); }
.tpl-del-btn {
  display: inline-flex;
  align-items: center;
  background: transparent;
  border: 1px solid rgba(192, 57, 43, 0.2);
  color: var(--red);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}
.tpl-del-btn:hover { background: rgba(192, 57, 43, 0.06); }

.helper-text { font-size: 0.72rem; color: var(--text3); }

/* ============================================================
   PRINT
   ============================================================ */
.print-header { display: none; }

@media print {
  :root {
    --bg: #fff; --bg2: #fff; --bg3: #f7f4f0;
    --text: #111; --text2: #555; --text3: #888;
    --border: #ddd; --border2: #ccc;
    --accent: #d95f08; --accent2: #e87420;
  }

  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  html, body { height: auto; min-height: 0; background: #fff; color: #111; margin: 0; padding: 0; }

  .app { display: block !important; min-height: 0 !important; height: auto !important; padding: 0 !important; }
  .main { display: block !important; min-height: 0 !important; height: auto !important; }

  /* Hide all UI chrome */
  .sidebar, .topbar,
  .add-item-accordion, .tpl-search-row, .templates-grid,
  .helper-text, .product-grid, .save-tpl-row,
  .discount-field, .discount-toggle-btn,
  .col-del, .btn-ghost, .btn-primary, .btn-icon,
  #panel-library, #panel-templates,
  .notes-toggle-btn, .notes-shell textarea, .subtitle-text,
  .quick-search-section, #editor-search-results {
    display: none !important;
    height: 0 !important; overflow: hidden !important;
    margin: 0 !important; padding: 0 !important;
  }

  .panel-view { display: none !important; height: 0 !important; overflow: hidden !important; }
  #panel-editor { display: block !important; height: auto !important; overflow: visible !important; padding: 0.4rem !important; }

  .card {
    display: block !important;
    border: none;
    border-radius: 0;
    padding: 0.5rem 0;
    margin-bottom: 0.3rem;
    box-shadow: none;
    break-inside: auto;
  }
  .client-card .form-row label:first-child { display: none !important; } /* Hides "Quote Title" specifically */
  .summary-card { page-break-before: avoid; }
  .items-card { border-bottom: 1px solid #ddd; padding-bottom: 0.5rem; }

  /* Print header — static, page 1 only */
  .print-header {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 3px solid var(--accent);
    margin-bottom: 1.5rem;
  }
  .print-brand { display: flex; align-items: center; gap: 1rem; }
  .print-logo-img { height: 52px; width: auto; }
  .print-brand-info { font-size: 0.72rem; color: #555; line-height: 1.55; }
  .print-meta { font-size: 0.78rem; text-align: right; color: #333; line-height: 1.5; }

  /* Table */
  .table-wrap { overflow: visible; }
  table { table-layout: fixed; }
  .col-sr      { width: 4%; text-align: center; }
  .col-product { width: 65%; padding-right: 2rem; }
  .col-brand   { width: 13%; }
  .col-qty     { width: 8%; text-align: center; }
  .col-total   { width: 10%; text-align: right; }
  th { font-size: 0.7rem; padding: 0.35rem 0.5rem; border-bottom: 2px solid #ddd; }
  td { padding: 0.35rem 0.5rem; font-size: 0.82rem; border-bottom: 1px solid #eee; }

  .input-inline { border: none !important; outline: none !important; background: transparent !important; color: #111 !important; padding: 0 !important; }

  /* Summary — tight flow */
  .summary-cols { display: grid !important; grid-template-columns: 240px 1fr; gap: 0.6rem; }
  .summary-left { display: flex !important; flex-direction: column; gap: 0.4rem; }
  .totals-block { display: block !important; border: 1px solid #ddd; border-radius: 6px; }
  .total-line { display: flex !important; justify-content: space-between; padding: 0.35rem 0.6rem; font-size: 0.82rem; border-bottom: 1px solid #eee; }
  .total-line.grand-total { background: #1a1208; color: #fff; border-radius: 0 0 6px 6px; }
  .total-line.grand-total span { color: rgba(255,255,255,0.7); }
  .total-line.grand-total strong { color: #fff; }
  #discount-row[hidden] { display: none !important; }

  .terms-grid { display: grid !important; grid-template-columns: 1fr 1fr; gap: 0.4rem; }
  .terms-box { display: block !important; border-radius: 4px; padding: 0.5rem 0.6rem; border: 1px solid #eee; }
  .terms-box h3 { font-size: 0.65rem; margin-bottom: 0.25rem; color: #d95f08; }
  .terms-box ul, .terms-box p { font-size: 0.72rem; line-height: 1.45; }

  .item-thumb { 
    width: 100px; 
    height: 100px; 
    border-radius: 6px; 
    border: 1px solid #eee;
  }
  .item-cell { 
    display: flex !important;
    flex-direction: row-reverse; 
    justify-content: flex-end;
    gap: 2rem; 
    align-items: flex-start; 
  }
  .item-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100px;
  }
  .item-name {
    font-size: 1.1rem !important;
    font-weight: 700 !important;
    color: #000 !important;
    margin-bottom: 0.25rem;
  }
  .notes-text { 
    font-size: 0.8rem; 
    line-height: 1.5;
    color: #555;
  }
  .card-header { display: block !important; }
  .card-header h2 { font-size: 0.75rem; color: #888; margin-bottom: 0.3rem; }
  .form-row { display: flex !important; gap: 0.5rem; }
  .field span { font-size: 0.65rem; }
  .field input { border: none; font-size: 0.85rem; font-weight: 600; padding: 0; background: transparent; }
}

@media (max-width: 900px) {
  .app { 
    display: flex;
    flex-direction: column;
    grid-template-columns: 1fr; 
  }
  
  .sidebar {
    position: fixed;
    bottom: 0;
    top: auto;
    left: 0;
    right: 0;
    height: 65px;
    width: 100%;
    flex-direction: row;
    padding: 0;
    border-right: none;
    border-top: 1px solid var(--border);
    z-index: 1000;
    gap: 0;
    background: var(--bg2);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
  }

  .sidebar-logo, .sidebar-footer { display: none; }

  .sidebar-nav {
    flex-direction: row;
    height: 100%;
    width: 100%;
    justify-content: space-around;
    padding: 0 0.5rem;
  }
  .sidebar-nav hr { display: none; }

  .nav-btn {
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    padding: 6px 0;
    flex: 1;
    border-radius: 0;
    text-align: center;
    font-size: 0.62rem;
    height: 100%;
    position: relative;
    border: none !important;
  }
  .nav-btn svg { width: 18px; height: 18px; margin-bottom: 1px; }
  .nav-btn.active { color: var(--accent); }
  .nav-btn.active::after {
    content: '';
    position: absolute;
    top: 0;
    left: 15%;
    right: 15%;
    height: 3px;
    background: var(--accent);
    border-radius: 0 0 4px 4px;
  }

  .badge {
    position: absolute;
    top: 4px;
    left: 55%;
    margin-left: 0;
    transform: scale(0.8);
    pointer-events: none;
    z-index: 2;
  }

  .main {
    padding-bottom: 70px; /* Space for bottom nav */
    min-height: calc(100vh - 70px);
  }

  .topbar {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .topbar-actions {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .topbar-actions::-webkit-scrollbar { display: none; }
  
  .card { padding: 1rem; }
  .form-row { flex-direction: column; gap: 1rem; }
  
  .product-grid {
    grid-template-columns: 1fr;
  }
  
  .summary-cols { grid-template-columns: 1fr; }
  .terms-grid { grid-template-columns: 1fr; }

  /* --- PROFESSIONAL MOBILE CARD EDITOR --- */
  .items-card { padding: 0.75rem 0.5rem; }
  .items-table thead { display: none; } /* Hide headers */
  .items-table, .items-table tbody, .items-table tr, .items-table td {
    display: block;
    width: 100%;
  }
  .items-table tr {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 1rem;
    padding: 0.75rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    position: relative;
  }
  .items-table td {
    border: none;
    padding: 0.4rem 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
  }
  /* Labels for mobile cards */
  .items-table td::before {
    content: attr(data-label);
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .col-product { display: block !important; }
  .col-product::before { display: block; margin-bottom: 0.5rem; }
  .item-cell { flex-direction: row; gap: 0.75rem; align-items: center; }
  .item-thumb { width: 44px; height: 44px; flex-shrink: 0; }
  .item-name { font-size: 0.95rem !important; font-weight: 700 !important; }

  .col-qty, .col-price {
    background: var(--bg3);
    margin: 0.25rem 0;
    padding: 0.6rem 0.75rem !important;
    border-radius: 8px;
  }
  .col-qty .input-inline, .col-price .input-inline {
    width: 80px;
    text-align: right;
    font-weight: 700;
    font-size: 1rem;
    color: var(--accent);
    padding: 4px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 4px;
  }
  
  .col-total {
    border-top: 1px dashed var(--border);
    margin-top: 0.5rem;
    padding-top: 0.75rem !important;
    font-size: 1.1rem;
  }
  
  .col-del {
    position: absolute;
    top: 8px;
    right: 8px;
    width: auto;
  }
  .col-sr { display: none; }

  /* Misc Mobile Fixes */
  .sidebar-footer .sync-status { display: none; }
}

/* ============================================================
   BULK ACTIONS & CHECKBOXES
   ============================================================ */
.bulk-actions-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  animation: slideInDown 0.25s ease-out;
}
@keyframes slideInDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

.bulk-info {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}
.bulk-btns { display: flex; gap: 0.5rem; }

.btn-danger {
  background: var(--red);
  color: #fff;
  border: none;
  padding: 0.45rem 1rem;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-danger:hover { background: #a93226; transform: translateY(-1px); }

.product-card { position: relative; }

.product-card-selection {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 10;
  width: 22px;
  height: 22px;
  cursor: pointer;
  accent-color: var(--accent);
  opacity: 0.3;
  transition: opacity 0.15s, transform 0.15s;
  border: 2px solid #fff;
  border-radius: 4px;
}
.product-card:hover .product-card-selection,
.product-card-selection:checked {
  opacity: 1;
  transform: scale(1.1);
}

.product-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}


/* ============================================================
   SEARCH & QUICK ADD STYLES
   ============================================================ */
.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}
.search-icon {
  position: absolute;
  left: 0.85rem;
  width: 16px;
  height: 16px;
  color: var(--text3);
  pointer-events: none;
}
.search-input-wrapper input {
  padding-left: 2.35rem !important;
  padding-right: 2.35rem !important; /* Space for clear button */
  width: 100%;
}

.clear-search-btn {
  position: absolute;
  right: 0.85rem;
  background: none;
  border: none;
  color: var(--text3);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}
.clear-search-btn:hover { color: var(--accent); }
.clear-search-btn[hidden] { display: none; }


.lib-search-row {
  margin-bottom: 1.25rem;
}

.quick-search-section {
  position: relative;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

/* ============================================================
   LOGIN OVERLAY
   ============================================================ */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg2);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.login-card {
  background: #fff;
  padding: 2.5rem;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.1);
  width: 100%;
  max-width: 400px;
  text-align: center;
  border: 1px solid var(--border);
}
.login-logo { width: 100px; margin-bottom: 1.5rem; }
.login-card h2 { font-size: 1.5rem; margin-bottom: 0.5rem; color: var(--text); }
.login-card p { color: var(--text3); font-size: 0.9rem; margin-bottom: 2rem; }
.login-card input {
  width: 100%;
  padding: 0.8rem 1rem;
  border: 1px solid var(--border2);
  border-radius: 10px;
  margin-bottom: 1rem;
  font-family: inherit;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
.login-card input:focus { border-color: var(--accent); }
.login-error {
  color: #ff4d4f;
  background: #fff2f0;
  border: 1px solid #ffccc7;
  padding: 0.6rem;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

@media (max-width: 900px) {
  .login-overlay { padding: 1rem; }
  .login-card { padding: 2rem 1.5rem; }
}

.search-results-dropdown {
  position: absolute;
  bottom: 100%; /* Drop up instead of down because it's at the bottom of the card usually */
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 12px;
  margin-bottom: 0.6rem;
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
  max-height: 350px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.search-results-dropdown:empty { border: none; box-shadow: none; }

.search-result-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: all 0.15s;
  border-bottom: 1px solid var(--border);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg3); }

.search-result-thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg3);
  border: 1px solid var(--border);
}
.search-result-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.search-result-name { font-size: 0.88rem; font-weight: 600; color: var(--text); }
.search-result-meta { font-size: 0.72rem; color: var(--text3); }
.search-result-price { font-weight: 700; color: var(--accent); font-size: 0.85rem; }

/* Custom Scrollbar */
.search-results-dropdown::-webkit-scrollbar { width: 6px; }
.search-results-dropdown::-webkit-scrollbar-track { background: transparent; }
.search-results-dropdown::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 10px; }

