/* ──────────────────────────────────────────────
   BREWER QUOTE BUILDER — MAIN STYLESHEET
   ────────────────────────────────────────────── */
:root {
  --navy:        #1C1C2E;
  --navy-light:  #2a2a42;
  --red:         #C8102E;
  --red-hover:   #a80d27;
  --white:       #ffffff;
  --off-white:   #f8f9fb;
  --border:      #e2e6ea;
  --text:        #1a1a2e;
  --text-muted:  #6b7280;
  --success:     #16a34a;
  --warning:     #d97706;
  --danger:      #dc2626;
  --radius:      6px;
  --radius-lg:   10px;
  --shadow:      0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg:   0 8px 32px rgba(0,0,0,.16);
  --sidebar-w:   240px;
  --transition:  0.18s ease;
}

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

html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--off-white);
  color: var(--text);
  line-height: 1.5;
}

/* ── UTILITIES ─────────────────────────────── */
.hidden { display: none !important; }
.mt-4   { margin-top: 1.5rem; }
.text-muted { color: var(--text-muted); font-size: .9rem; }

/* ── SCREENS ───────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; }
#screen-app.active { display: flex; height: 100vh; overflow: hidden; }

/* ── LOGIN / AUTH SCREENS ──────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: var(--off-white);
}
.login-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}
.login-logo img { max-width: 200px; max-height: 80px; object-fit: contain; }
.login-title { font-size: 1.25rem; color: var(--navy); font-weight: 700; margin-top: .5rem; }
.login-card { width: 100%; max-width: 400px; }
.login-card h2 { font-size: 1.25rem; margin-bottom: 1.25rem; color: var(--navy); }

/* ── CARD ──────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

/* ── FORM FIELDS ───────────────────────────── */
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: .85rem; font-weight: 600; color: var(--text-muted); margin-bottom: .35rem; text-transform: uppercase; letter-spacing: .03em; }
.field-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="date"],
input[type="number"],
input[type="tel"],
select,
textarea {
  width: 100%;
  padding: .55rem .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition);
}

/* Remove WebKit native search input decoration (cancel button, magnifier) that
   can bleed outside the input's layout box in Safari/Chrome */
input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
}

/* Safety net: any input rendered as a direct child of body or #app
   (outside all proper containers) must never be visible */
body > input,
#app > input {
  visibility: hidden !important;
  pointer-events: none !important;
  position: fixed !important;
  width: 0 !important;
  height: 0 !important;
  opacity: 0 !important;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(28,28,46,.12);
}
textarea { resize: vertical; min-height: 80px; }

.input-sm {
  padding: .42rem .7rem;
  font-size: .875rem;
  max-width: 240px;
}

/* ── BUTTONS ───────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), box-shadow var(--transition), opacity var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary  { background: var(--red); color: #fff; border-color: var(--red); }
.btn-primary:hover:not(:disabled) { background: var(--red-hover); border-color: var(--red-hover); }

.btn-secondary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn-secondary:hover:not(:disabled) { background: var(--navy-light); }

.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--off-white); }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }

.btn-full { width: 100%; justify-content: center; }
.btn-sm   { padding: .35rem .75rem; font-size: .82rem; }
.btn-icon { padding: .35rem .6rem; font-size: 1.1rem; line-height: 1; }

.link-sm { display: block; text-align: center; margin-top: .75rem; font-size: .85rem; color: var(--navy); text-decoration: none; }
.link-sm:hover { text-decoration: underline; }

/* ── MESSAGES ──────────────────────────────── */
.error-msg { color: var(--danger); font-size: .875rem; margin-bottom: .75rem; padding: .5rem .75rem; background: #fef2f2; border-radius: var(--radius); border: 1px solid #fecaca; }
.msg       { font-size: .875rem; margin-bottom: .75rem; padding: .5rem .75rem; border-radius: var(--radius); }
.msg.success { background: #f0fdf4; border: 1px solid #bbf7d0; color: var(--success); }
.msg.error   { background: #fef2f2; border: 1px solid #fecaca; color: var(--danger); }

/* ── SIDEBAR ───────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--navy);
  color: var(--white);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar-logo img { max-width: 110px; max-height: 40px; object-fit: contain; filter: brightness(0) invert(1); }
.sidebar-app-name { font-size: .9rem; font-weight: 700; color: rgba(255,255,255,.85); letter-spacing: .02em; }
.nav-items { list-style: none; padding: .75rem 0; flex: 1; }
.nav-items li { padding: 0; }
.nav-section-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: rgba(255,255,255,.4); padding: 1rem 1rem .35rem; }
.nav-link {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .65rem 1rem;
  color: rgba(255,255,255,.75);
  text-decoration: none;
  font-size: .9rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
}
.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,.08);
  color: var(--white);
  border-left-color: var(--red);
}
.nav-link .icon { font-size: 1rem; opacity: .8; }
.sidebar-user {
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,.1);
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
#sidebar-user-name { font-size: .82rem; color: #ffffff !important; }
#btn-logout { color: #ffffff !important; border-color: rgba(255, 255, 255, 0.3) !important; }

/* ── MAIN CONTENT ──────────────────────────── */
#main-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem 2rem;
  display: flex;
  flex-direction: column;
}
.view { display: none; flex-direction: column; gap: 1.25rem; flex: 1; }
.view.active { display: flex; }

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.view-header h1 { font-size: 1.5rem; color: var(--navy); font-weight: 700; }
.view-header-left { display: flex; align-items: center; gap: 1rem; }
.view-header-actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }

.filters-row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }

/* ── TABLES ────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  font-size: .9rem;
}
thead tr { background: var(--navy); }
thead th { padding: .75rem 1rem; text-align: left; color: var(--white); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--off-white); }
tbody td { padding: .7rem 1rem; vertical-align: middle; }

.empty-state { text-align: center; color: var(--text-muted); padding: 3rem 1rem; background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow); }

/* ── BADGES ────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.badge-draft  { background: #f3f4f6; color: #6b7280; }
.badge-sent   { background: #dbeafe; color: #1d4ed8; }
.badge-active { background: #dcfce7; color: #16a34a; }
.badge-inactive { background: #f3f4f6; color: #6b7280; }
.badge-admin  { background: #fef3c7; color: #d97706; }
.badge-num    { background: var(--off-white); color: var(--navy); border: 1px solid var(--border); font-size: .85rem; padding: .3rem .8rem; border-radius: var(--radius); }

/* ── QUOTE EDITOR ──────────────────────────── */
.editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
@media (max-width: 900px) { .editor-grid { grid-template-columns: 1fr; } }

.editor-meta h3,
.editor-product-search h3 { font-size: 1rem; font-weight: 700; color: var(--navy); margin-bottom: 1rem; }

/* Problem A fix: contain the Add Products panel within its grid cell */
.editor-product-search {
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  box-sizing: border-box;
}

.search-controls { display: flex; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.search-controls input, .search-controls select { flex: 1; min-width: 120px; }

/* Problem A fix: prevent horizontal overflow from result rows */
.product-results { max-height: 320px; overflow-y: auto; overflow-x: hidden; }

/* Outer row: column direction so price-unavail-msg and color-selector-panel stack below */
.product-result-item {
  display: flex;
  flex-direction: column;
  padding: .55rem .75rem;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.product-result-item:last-child { border-bottom: none; }
.product-result-item:hover { background: var(--off-white); }

/* Problem B fix: flat single-row layout for desktop results */
.product-result-row {
  display: flex;
  align-items: center;
  width: 100%;
  overflow: hidden;
  gap: 12px;
}
.product-result-item-num {
  flex-shrink: 0;
  width: 120px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.product-result-description {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: .88rem;
  font-weight: 500;
}
.product-result-price-type {
  flex-shrink: 0;
  width: 130px;
  font-size: .82rem;
}
.product-result-shown-price {
  flex-shrink: 0;
  width: 72px;
  text-align: right;
  font-size: .85rem;
  font-weight: 600;
}
.product-result-freight-notes {
  flex: 1;
  min-width: 0;
  font-size: .83rem;
}
.product-result-add-btn {
  flex-shrink: 0;
  width: 60px;
  justify-content: center;
}
/* Inline unavailability message */
.product-price-unavail-msg {
  font-size: .78rem;
  color: #c0392b;
}
/* Inline color selector panel */
.color-selector-panel {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem;
  padding: .5rem .25rem .4rem;
  margin-top: .3rem;
  background: #f0f4ff;
  border-radius: 4px;
  border: 1px solid #c7d2fe;
}
.color-sel-label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--navy);
  white-space: nowrap;
}
.color-dropdown {
  font-size: .82rem;
  min-width: 180px;
}
.color-val-msg {
  font-size: .78rem;
  color: #c0392b;
  width: 100%;
}

/* Retained for mobile card layout (mobile branch still renders these classes) */
.product-info { flex: 1; min-width: 0; }
.product-info .item-num { font-size: .78rem; color: var(--text-muted); }
.product-info .item-desc { font-size: .88rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-prices { display: flex; gap: .5rem; align-items: center; flex-shrink: 0; }
.product-prices .price-lbl { font-size: .75rem; color: var(--text-muted); }
.product-prices .price-val { font-size: .88rem; font-weight: 600; }

.line-items-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.line-items-header h3 { font-size: 1rem; font-weight: 700; color: var(--navy); }
.subtotal-row { display: flex; justify-content: flex-end; gap: 1rem; align-items: center; padding: .75rem 1rem 0; font-size: 1rem; }
#quote-subtotal { font-size: 1.2rem; color: var(--navy); }

/* inline table inputs */
#line-items-table td input,
#line-items-table td select {
  padding: .3rem .5rem;
  font-size: .85rem;
  width: 100%;
  min-width: 60px;
}

/* ── PAGINATION ────────────────────────────── */
.pagination-row {
  display: flex;
  gap: .4rem;
  align-items: center;
  justify-content: center;
  padding: .75rem 0;
  flex-wrap: wrap;
}
.pagination-row button { min-width: 36px; justify-content: center; }
.pagination-row .page-info { font-size: .85rem; color: var(--text-muted); padding: 0 .5rem; }

/* ── PROGRESS BAR ──────────────────────────── */
.progress-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-bottom: .5rem; }
.progress-fill { height: 100%; background: var(--red); width: 0; transition: width .3s ease; }

/* ── MODAL ─────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal-box {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.05rem; font-weight: 700; color: var(--navy); }
.modal-body { padding: 1.25rem; overflow-y: auto; flex: 1; }
.modal-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; gap: .6rem; justify-content: flex-end; }

/* ── TOAST ─────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  z-index: 2000;
}
.toast {
  padding: .75rem 1.25rem;
  border-radius: var(--radius);
  color: #fff;
  font-size: .9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideIn .2s ease;
  max-width: 340px;
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--navy); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── RESPONSIVE ────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  #sidebar { position: fixed; left: -240px; width: 240px; transition: left .25s ease; z-index: 100; }
  #sidebar.open { left: 0; }
  #main-content { padding: 1rem; }
  .field-grid-2 { grid-template-columns: 1fr; }
  .view-header-actions { gap: .4rem; }
}

/* ── ADMIN QUOTES DASHBOARD ─────────────────── */
#rep-quotes-view { display: flex; flex-direction: column; gap: 1.25rem; flex: 1; }
#admin-quotes-dashboard {
  display: none;
  flex-direction: column;
  gap: 1.25rem;
  flex: 1;
}

.admin-dashboard { width: 100%; padding: 24px; box-sizing: border-box; }
.admin-notice { width: 100%; background: #fff8e6; border-left: 4px solid #e8c84a; border-radius: 4px; padding: 10px 16px; font-size: 13px; color: #7a5c00; margin-bottom: 20px; display: flex; align-items: center; gap: 8px; box-sizing: border-box; }
.admin-metrics-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.admin-metric-card { background: #fff; border: 1px solid #e2e2e8; border-radius: 8px; padding: 16px 20px; box-sizing: border-box; }
.admin-metric-label { font-size: 11px; color: #6b7280; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.admin-metric-value { font-size: 24px; font-weight: 600; color: #1a1a2e; margin-bottom: 2px; }
.admin-metric-sub { font-size: 11px; color: #6b7280; }
.admin-two-col { display: grid; grid-template-columns: 1fr 280px; gap: 20px; align-items: start; }
.admin-main-panel { background: #fff; border: 1px solid #e2e2e8; border-radius: 8px; overflow: hidden; }
.admin-panel-header { padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #e2e2e8; }
.admin-panel-title { font-size: 13px; font-weight: 500; color: #1a1a2e; }
.admin-filter-bar { padding: 10px 16px; display: flex; gap: 8px; flex-wrap: wrap; border-bottom: 1px solid #e2e2e8; background: #f9f9fb; }
.admin-filter-bar select, .admin-filter-bar input[type="date"] { background: #fff; border: 1px solid #e2e2e8; border-radius: 6px; padding: 5px 10px; font-size: 12px; color: #1a1a2e; width: auto; }
.admin-sidebar { display: flex; flex-direction: column; gap: 16px; }
.admin-sidebar-panel { background: #fff; border: 1px solid #e2e2e8; border-radius: 8px; overflow: hidden; }
.admin-sidebar-header { padding: 10px 14px; border-bottom: 1px solid #e2e2e8; font-size: 11px; font-weight: 600; color: #6b7280; text-transform: uppercase; letter-spacing: 1px; }
.admin-sidebar-row { padding: 8px 14px; border-bottom: 1px solid #f0f0f4; font-size: 12px; display: flex; align-items: center; gap: 8px; }
.admin-sidebar-row:last-child { border-bottom: none; }
.rep-dot { width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 500; color: #fff; flex-shrink: 0; }
.btn-export-csv { background: transparent; border: 1px solid #e2e2e8; border-radius: 6px; padding: 5px 12px; font-size: 12px; color: #1a1a2e; cursor: pointer; }
.btn-export-csv:hover { background: #f4f5f7; }
.btn-add-freight { border: 1px solid #1C1C2E; background: transparent; color: #1C1C2E; padding: 8px 16px; border-radius: 6px; font-size: .875rem; cursor: pointer; margin: .5rem 0; display: inline-block; }
.btn-add-freight:hover:not(:disabled) { background: rgba(28,28,46,.06); }
.btn-add-freight:disabled { opacity: 0.5; cursor: not-allowed; }


/* Mobile overrides */
@media (max-width: 767px) {
  .admin-metrics-row { grid-template-columns: repeat(2, 1fr); }
  .admin-two-col { grid-template-columns: 1fr; }
  .admin-dashboard { padding: 16px; }
}

/* Suppress focus ring on hidden file input so it never appears as a stray visible element */
#upload-price-list:focus {
  outline: none !important;
  box-shadow: none !important;
  border-color: transparent !important;
}
