/* ──────────────────────────────────────────────
   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"],
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);
}
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: rgba(255,255,255,.6); }

/* ── 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; }

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

.product-results { max-height: 320px; overflow-y: auto; }
.product-result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .55rem .75rem;
  border-bottom: 1px solid var(--border);
  gap: .5rem;
  flex-wrap: wrap;
  transition: background var(--transition);
}
.product-result-item:last-child { border-bottom: none; }
.product-result-item:hover { background: var(--off-white); }
.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; }
}
