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

:root {
  --blue: #042069;
  --blue-dark: #021448;
  --blue-light: #e8ecf5;
  --gray: #6b7280;
  --gray-light: #f3f4f6;
  --border: #e5e7eb;
  --danger: #dc2626;
  --success: #16a34a;
  --text: #111827;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--gray-light);
  min-height: 100vh;
}

/* ── Auth ── */
#login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 40px;
  width: 360px;
  box-shadow: 0 4px 24px rgba(0,0,0,.1);
  text-align: center;
}
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-card p { color: var(--gray); margin-bottom: 24px; }

/* ── Layout ── */
#app { display: flex; min-height: 100vh; }
#sidebar {
  width: 220px;
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-brand {
  padding: 20px 16px 12px;
  font-size: 16px;
  font-weight: 700;
  color: var(--blue);
  border-bottom: 1px solid var(--border);
}
.sidebar-brand span { display: block; font-size: 11px; font-weight: 400; color: var(--gray); }
nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  color: var(--gray);
  text-decoration: none;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
}
nav a:hover { background: var(--gray-light); color: var(--text); }
nav a.active { background: var(--blue-light); color: var(--blue); border-left-color: var(--blue); font-weight: 600; }
.sidebar-footer { margin-top: auto; padding: 12px; border-top: 1px solid var(--border); }

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar h2 { font-size: 18px; }
.content { padding: 24px; flex: 1; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: opacity .15s;
}
.btn:hover { opacity: .85; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; border-radius: 4px; background: none; border: none; cursor: pointer; color: var(--gray); }
.btn-icon:hover { color: var(--blue); background: var(--blue-light); }

/* ── Cards / Tables ── */
.card {
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
}
.card-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header h3 { font-size: 15px; }

table { width: 100%; border-collapse: collapse; }
th {
  padding: 10px 12px;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray);
  background: var(--gray-light);
  border-bottom: 1px solid var(--border);
}
td { padding: 11px 12px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }

/* ── Forms ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 12px; font-weight: 600; color: var(--gray); text-transform: uppercase; letter-spacing: .04em; }
input, select, textarea {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  width: 100%;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(4,32,105,.1);
}
textarea { resize: vertical; min-height: 80px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: #fff;
  border-radius: 10px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: #fff;
}
.modal-header h3 { font-size: 16px; }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}
.badge-quote    { background: #fef3c7; color: #92400e; }
.badge-printing { background: #e0e6f5; color: #042069; }
.badge-done     { background: #d1fae5; color: #065f46; }
.badge-shipped  { background: #ede9fe; color: #5b21b6; }
.badge-cancelled{ background: #fee2e2; color: #991b1b; }
.badge-tax-exempt { background: #e0f2fe; color: #0369a1; }
.badge-fdm        { background: #e0e6f5; color: #042069; }
.badge-resin      { background: #ede9fe; color: #5b21b6; }
.badge-active     { background: #d1fae5; color: #065f46; }
.badge-inactive   { background: #f3f4f6; color: #6b7280; }
.badge-rush       { background: #fef3c7; color: #92400e; font-weight: 700; }

/* Low-stock row highlight */
tr.low-stock td { background: #fef9c3 !important; }
tr.low-stock:hover td { background: #fef08a !important; }

/* ── Misc ── */
.empty { padding: 40px; text-align: center; color: var(--gray); }
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 13px; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #d1fae5; color: #065f46; }

/* Line items / cost/quote tables */
.items-table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.items-table th, .items-table td { padding: 6px 8px; border: 1px solid var(--border); font-size: 13px; }
.items-table th { background: var(--gray-light); font-weight: 600; }
.items-table input, .items-table select { border: none; padding: 2px 4px; }

/* Two-section line editor */
.line-section { margin-top: 20px; }
.line-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.line-section-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
}
.internal-badge { background: #fef3c7; color: #92400e; }
.quote-badge    { background: #d1fae5; color: #065f46; }

/* Wide modal for order form */
.modal-xl { max-width: 880px; }
.modal-lg { max-width: 680px; }

.pdf-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Settings page */
.settings-card { padding: 24px; margin-bottom: 20px; }
.settings-section-header {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: .05em;
  padding-bottom: 12px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
/* City / State / ZIP three-column row inside form-grid */
.form-row-3 {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 12px;
}

/* ── Kanban Board ── */
.pipeline-summary {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.pipeline-stat {
  font-size: 28px;
  font-weight: 700;
  color: var(--blue);
  margin-top: 2px;
}
.kanban-board {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 16px;
  align-items: flex-start;
  /* contain scroll to board only */
  min-width: 0;
}
.kanban-column {
  flex: 0 0 200px;
  min-width: 200px;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 170px);
}
.kanban-col-header {
  padding: 10px 12px 0;
  flex-shrink: 0;
}
.kanban-col-bar {
  height: 4px;
  margin-top: 8px;
  border-radius: 0;
}
.kanban-col-title {
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text);
}
.kanban-col-count {
  font-size: 11px;
  color: var(--gray);
  float: right;
  font-weight: 600;
}
.kanban-cards {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex: 1;
}
.kanban-card {
  background: var(--gray-light);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s;
}
.kanban-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
  border-color: #c0c9e0;
}
.kanban-card-paid {
  background: #f0fdf4;
  border-color: #bbf7d0;
}
.kanban-card-paid:hover {
  border-color: #86efac;
  box-shadow: 0 2px 8px rgba(22,163,74,.15);
}
.kanban-card-job {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  font-weight: 700;
  color: var(--blue);
}
.kanban-card-customer {
  font-size: 12px;
  font-weight: 600;
  margin: 3px 0 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kanban-card-desc {
  font-size: 11px;
  color: var(--gray);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 6px;
}
.kanban-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 4px;
}
.kanban-card-amount {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}
.kanban-card-due { font-size: 10px; }
.kanban-margin   { font-size: 10px; color: var(--gray); }
.due-normal  { color: var(--gray); }
.due-warning { color: #d97706; font-weight: 600; }
.due-overdue { color: var(--danger); font-weight: 600; }

/* ── Unpaid Invoices ── */
tr.inv-overdue td   { background: #fee2e2 !important; }
tr.inv-warning td   { background: #fef3c7 !important; }
tr.inv-overdue:hover td { background: #fca5a5 !important; }
tr.inv-warning:hover td { background: #fde68a !important; }

/* ── Job Summary ── */
.job-summary-box {
  background: var(--gray-light);
  border-radius: 6px;
  padding: 12px 16px;
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.job-summary-box .sum-item {
  display: flex;
  flex-direction: column;
}
.job-summary-box .sum-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray);
  margin-bottom: 2px;
}
.job-summary-box .sum-value {
  font-size: 18px;
  font-weight: 700;
}

/* ── Schedule C Report ── */
.sc-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
}
.sc-part {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
  overflow: hidden;
}
.sc-part-header {
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  padding: 10px 16px;
}
.sc-part-body {
  padding: 16px;
}
.sc-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.sc-stat-row:last-child { border-bottom: none; }
.sc-stat-value {
  font-weight: 700;
  font-size: 15px;
  color: var(--blue);
}
.sc-line-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
}
.sc-line-row:hover { background: var(--gray-light); }
.sc-line-num {
  display: inline-block;
  min-width: 52px;
  padding: 2px 6px;
  background: var(--blue-light);
  color: var(--blue);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
}
.sc-line-label { font-size: 13px; font-weight: 600; }
.sc-toggle-icon { color: var(--gray); font-size: 10px; }
.sc-sub-table {
  padding: 10px 16px 14px;
  background: var(--gray-light);
  border-bottom: 1px solid var(--border);
}
.sc-sub-table table { width: 100%; border-collapse: collapse; }
.sc-sub-table th {
  padding: 6px 8px; text-align: left; font-size: 11px;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--gray); background: #e9ebf0; border-bottom: 1px solid var(--border);
}
.sc-sub-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); font-size: 13px; }
.sc-sub-table tr:last-child td { border-bottom: none; }
.sc-kv-label { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--gray); margin-bottom: 3px; }
.sc-kv-value { font-size: 20px; font-weight: 700; color: var(--text); }
.sc-summary-box {
  background: #fff;
  border: 2px solid var(--blue);
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 32px;
}
.sc-summary-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--blue);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 14px;
}
.sc-summary-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 24px;
  font-size: 14px;
}
.sc-summary-grid span:nth-child(even) { text-align: right; font-weight: 700; }
.sc-summary-divider {
  height: 1px;
  background: var(--blue);
  margin: 12px 0;
  opacity: .3;
}
.sc-summary-net {
  display: grid;
  grid-template-columns: 1fr auto;
  font-size: 17px;
  font-weight: 700;
}

/* ── Dashboard ── */
.dash-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.dash-stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
}
.dash-stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray);
  margin-bottom: 6px;
}
.dash-stat-value {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.1;
}
.dash-stat-sub {
  font-size: 12px;
  color: var(--gray);
  margin-top: 4px;
}
.dash-charts-row {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}
.dash-tables-row {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}
.dash-charts-row .card,
.dash-tables-row .card {
  min-width: 0;
}

/* ── Expense Summary Bar ── */
.expense-summary-bar {
  display: flex;
  align-items: center;
  gap: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 20px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.expense-summary-item {
  flex: 1;
  min-width: 100px;
}
.expense-summary-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--gray);
  margin-bottom: 4px;
}
.expense-summary-value {
  font-size: 20px;
  font-weight: 700;
}
.expense-summary-divider {
  width: 1px;
  height: 40px;
  background: var(--border);
  margin: 0 20px;
  flex-shrink: 0;
}

/* Responsive */
@media (max-width: 640px) {
  #sidebar { display: none; }
  .form-grid { grid-template-columns: 1fr; }
}
