:root {
  --ink: #1c1914;
  --muted: #6b6458;
  --paper: #f4efe6;
  --paper-2: #ebe4d6;
  --card: #fffaf2;
  --line: #d8cfc0;
  --navy: #1f2a36;
  --navy-2: #2a3848;
  --copper: #b8612b;
  --copper-2: #9a4d20;
  --sage: #3f6b54;
  --danger: #9b2c2c;
  --shadow: 0 10px 30px rgba(28, 25, 20, 0.08);
  --sidebar: 232px;
  --font: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
  min-height: 100dvh;
}
a { color: var(--copper-2); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: var(--ink); }

.layout { display: flex; min-height: 100vh; min-height: 100dvh; }
.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  background: var(--navy);
  color: #e8dfd2;
  padding: 22px 16px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
.brand {
  font-family: var(--serif);
  font-size: 22px;
  letter-spacing: 0.02em;
  color: #f4efe6;
  margin: 0 0 4px;
  padding-bottom: 10px;
  border-bottom: 3px solid var(--copper);
}
.brand span { color: #e0a070; }
.brand-sub { color: #9aa7b5; font-size: 12px; margin: 10px 0 20px; letter-spacing: .04em; text-transform: uppercase; }
.nav a {
  display: block;
  color: #d5dde6;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 4px;
  text-decoration: none;
  font-weight: 600;
  min-height: 40px;
}
.nav a:hover, .nav a.active { background: var(--navy-2); color: #fff; text-decoration: none; }
.sidebar-foot { margin-top: 12px; font-size: 13px; color: #9aa7b5; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.12); }
.sidebar-foot .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 8px; }
.sidebar-foot a { color: #e0a070; font-weight: 600; }

.app-top {
  display: none;
  background: #fff;
  color: var(--ink);
  padding: 10px 16px;
  justify-content: flex-start;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.app-top-title { font-weight: 600; font-size: 20px; font-family: var(--serif); flex: 1; }
.menu-btn { display: none; }
.nav-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 35, 64, .45);
  z-index: 14;
}

.main { flex: 1; padding: 28px 36px 48px; max-width: 1280px; width: 100%; }
.topbar { display: flex; justify-content: space-between; gap: 16px; align-items: flex-end; margin-bottom: 22px; flex-wrap: wrap; }
h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 600;
  margin: 0;
}
h1 { font-size: 32px; }
h2 { font-size: 22px; margin: 28px 0 12px; }
.muted { color: var(--muted); }
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(4, 1fr); }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.stat-value { font-size: 28px; margin-top: 6px; font-family: var(--serif); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
input, select, textarea {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
}
textarea { width: 100%; min-height: 90px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; font-weight: 600; }
.field { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  color: #f4efe6;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
}
.btn:hover { background: var(--navy-2); text-decoration: none; color: #fff; }
.btn.secondary { background: #fff; color: var(--navy); border: 1px solid var(--line); }
.btn.copper { background: var(--copper); color: #fff; }
.btn.copper:hover { background: var(--copper-2); }
.btn.small { padding: 6px 10px; min-height: 36px; font-size: 13px; }

.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  background: var(--paper-2);
  color: var(--ink);
}
.badge.won, .badge.completed { background: #dceadf; color: var(--sage); }
.badge.lost { background: #f3d6d6; color: var(--danger); }
.badge.active, .badge.customer { background: #dceadf; }
.badge.lead, .badge.prospect { background: #efe3cf; }
.pipeline { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.pipe-col { background: var(--paper-2); border-radius: 12px; padding: 10px; min-height: 180px; }
.pipe-col h3 { font-size: 15px; margin-bottom: 4px; }
.pipe-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin-top: 8px;
}
.pipe-card strong { display: block; margin-bottom: 4px; }
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 20% 20%, #3a4b5e 0, transparent 40%),
    var(--navy);
}
.login-card { width: min(380px, 100%); }
.login-card h1 { color: var(--ink); margin-bottom: 6px; }
.login-card input { width: 100%; font-size: 16px; }
.error { background: #f8e3e3; color: var(--danger); padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.meta { font-size: 14px; color: var(--muted); }
.split { display: grid; grid-template-columns: 1.4fr 0.8fr; gap: 18px; }
.activity { border-bottom: 1px solid var(--line); padding: 10px 0; }

@media (max-width: 900px) {
  .layout { display: block; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 15;
    box-sizing: border-box;
    width: min(280px, 86vw);
    flex-basis: auto;
    height: 100dvh;
    max-height: 100dvh;
    transform: translateX(-100%);
    transition: transform .2s ease;
    padding-top: calc(18px + env(safe-area-inset-top));
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }
  .sidebar.open { transform: none; }
  .sidebar > .nav { overflow: visible; flex: none; min-height: auto; }
  .app-top {
    display: flex;
    padding-top: calc(10px + env(safe-area-inset-top));
  }
  .menu-btn { display: inline-flex; }
  .nav-scrim { display: block; }
  .nav-scrim[hidden] { display: none; }
  body.nav-open { overflow: hidden; }
  .stats, .split, .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .main { padding: 16px 16px calc(48px + env(safe-area-inset-bottom)); }
  .topbar { align-items: stretch; }
  .topbar .btn { width: 100%; }
  h1 { font-size: 26px; }
  input, select, textarea { font-size: 16px; }
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .pipeline { grid-template-columns: 1fr; }
  .toolbar input, .toolbar select { min-height: 44px; flex: 1 1 160px; }
}

@media (min-width: 901px) and (max-width: 1100px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .main { padding: 22px 22px 40px; }
}

@page { size: letter; margin: 0.5in; }
@media print {
  .sidebar, .app-top, .menu-btn, .toolbar, .btn, .nav-scrim, .no-print { display: none !important; }
  .main { padding: 0 !important; max-width: none; }
  .layout, .workspace { display: block; width: auto; }
  body { background: #fff; }
  .bid-doc { max-width: none; width: auto; margin: 0; padding: 0; }
}

.bid-doc {
  background: #fff;
  color: #111;
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 28px 48px;
  font-family: "Times New Roman", Times, serif;
}
.qb-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.qb-logo { height: 64px; width: auto; }
.qb-head-text { flex: 1; }
.qb-form-name { font-size: 20px; font-weight: 700; }
.qb-tag { font-size: 12px; color: #333; }
.qb-estnum { border: 1px solid #222; padding: 8px 12px; min-width: 120px; text-align: right; }
.qb-grid { display: grid; grid-template-columns: 1fr 220px; gap: 12px; margin-bottom: 16px; }
.qb-box { border: 1px solid #222; padding: 8px 10px; min-height: 120px; }
.qb-box .lbl, .qb-estnum .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: #444; }
.qb-lines { width: 100%; border-collapse: collapse; margin-top: 8px; }
.qb-lines th, .qb-lines td { border: 1px solid #222; padding: 5px 6px; font-size: 13px; }
.qb-lines .right, .bid-doc .right { text-align: right; }
.qb-totals { margin-top: 10px; width: 260px; margin-left: auto; font-size: 14px; }
.qb-totals div { display: flex; justify-content: space-between; border-bottom: 1px solid #ccc; padding: 3px 0; }
.qb-totals .grand { font-weight: 700; }
.bid-doc .terms { font-size: 11px; line-height: 1.35; margin-top: 18px; }
.bid-lines select.item-pick { max-width: 11rem; width: 100%; }
.bid-lines input[name="qty"], .bid-lines input[name="rate"] { width: 100%; max-width: 5.5rem; }
