:root {
  --brand: #0f766e;
  --brand-dark: #115e59;
  --bg: #f8fafc;
  --text: #0f172a;
  --border: #e2e8f0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  max-width: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1100px; margin: 0 auto; padding: 0 1rem; }

/* Layout: sidebar on desktop, top bar on mobile. Built mobile-first this
   time (single flex-column stack) so it can never repeat the QuotePro bug
   where a wide screen layout broke apart on a narrow one. */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
@media (min-width: 768px) {
  .app-shell { flex-direction: row; }
}

.sidebar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
@media (min-width: 768px) {
  .sidebar {
    width: 220px;
    flex-shrink: 0;
    border-bottom: none;
    border-right: 1px solid var(--border);
    flex-direction: column;
    align-items: stretch;
    padding: 1.25rem 1rem;
  }
}

.sidebar-brand { font-weight: 700; font-size: 1.1rem; color: var(--brand); }
.sidebar-nav { display: flex; flex-wrap: wrap; gap: 0.25rem; }
@media (min-width: 768px) {
  .sidebar-nav { flex-direction: column; margin-top: 1.5rem; gap: 0.15rem; }
}
.sidebar-nav a {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  color: #334155;
  font-size: 0.9rem;
  font-weight: 500;
}
.sidebar-nav a:hover, .sidebar-nav a.active {
  background: #f0fdfa;
  color: var(--brand-dark);
  text-decoration: none;
}

.main { flex: 1; min-width: 0; width: 100%; padding: 1.25rem 1rem; }
@media (min-width: 768px) { .main { padding: 2rem; } }

h1 { font-size: 1.4rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
.subtitle { color: #64748b; margin: 0 0 1.25rem; }

.card { background: white; border: 1px solid var(--border); border-radius: 0.75rem; padding: 1.25rem; margin-bottom: 1.25rem; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border-radius: 0.5rem;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.btn-primary { background: var(--brand); color: white; }
.btn-primary:hover { background: var(--brand-dark); text-decoration: none; }
.btn-secondary { background: white; color: #334155; border-color: var(--border); }
.btn-secondary:hover { background: #f1f5f9; text-decoration: none; }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-danger:hover { background: #fecaca; text-decoration: none; }

.actions-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 1rem; }

.form-group { margin-bottom: 1rem; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 640px) { .form-grid.cols-2 { grid-template-columns: 1fr 1fr; } }

label { display: block; font-size: 0.8rem; font-weight: 600; color: #475569; margin-bottom: 0.3rem; }
input, select, textarea {
  width: 100%;
  border-radius: 0.5rem;
  border: 1px solid #cbd5e1;
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  font-family: inherit;
  background: white;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }

.alert { padding: 0.75rem 1rem; border-radius: 0.5rem; margin-bottom: 1rem; font-size: 0.9rem; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

/* Tables: become stacked cards on narrow screens instead of scrolling
   sideways, using the same data-label pattern that fixed QuotePro. */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
th { color: #64748b; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.02em; }

@media (max-width: 700px) {
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive thead { display: none; }
  table.responsive tr { border: 1px solid var(--border); border-radius: 0.65rem; margin-bottom: 0.75rem; padding: 0.6rem 0.8rem; background: white; }
  table.responsive td { display: flex; justify-content: space-between; gap: 0.75rem; border: none; padding: 0.35rem 0; text-align: right; }
  table.responsive td::before { content: attr(data-label); font-weight: 600; color: #64748b; font-size: 0.7rem; text-transform: uppercase; text-align: left; }
}

.badge { display: inline-flex; align-items: center; border-radius: 9999px; padding: 0.15rem 0.65rem; font-size: 0.72rem; font-weight: 700; }
.badge-draft { background: #f1f5f9; color: #475569; }
.badge-sent { background: #eff6ff; color: #1d4ed8; }
.badge-accepted { background: #f0fdf4; color: #166534; }
.badge-rejected { background: #fef2f2; color: #b91c1c; }

.text-right { text-align: right; }
.text-muted { color: #64748b; }

.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 380px; }

.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 3.4rem; }
.pw-toggle {
  position: absolute;
  right: 0.4rem;
  top: 50%;
  transform: translateY(-50%);
  background: #f1f5f9;
  border: none;
  border-radius: 0.35rem;
  color: #475569;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 0.3rem 0.55rem;
  cursor: pointer;
}
.pw-toggle:hover { background: #e2e8f0; }

/* Dashboard KPI cards + choice tiles */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi-card { background: white; border: 1px solid var(--border); border-radius: 0.75rem; padding: 1.1rem 1.25rem; }
.kpi-card .kpi-label { font-size: 0.78rem; color: #64748b; margin-bottom: 0.35rem; }
.kpi-card .kpi-value { font-size: 1.5rem; font-weight: 700; }
.kpi-card .kpi-sub { font-size: 0.75rem; color: #94a3b8; margin-top: 0.2rem; }

.create-choice { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.create-choice a {
  display: block;
  background: white;
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  padding: 1.25rem;
  color: var(--text);
}
.create-choice a:hover { border-color: var(--brand); text-decoration: none; box-shadow: 0 2px 10px rgba(15,118,110,0.08); }
.create-choice .cc-icon { font-size: 1.6rem; margin-bottom: 0.4rem; }
.create-choice .cc-title { font-weight: 700; margin-bottom: 0.2rem; }
.create-choice .cc-desc { font-size: 0.82rem; color: #64748b; }

.chart-card canvas { max-width: 100%; }

.section-block { border: 1px solid var(--border); border-radius: 0.65rem; padding: 1rem; margin-bottom: 1rem; background: #fbfdfd; }
.section-block .section-head { display: flex; gap: 0.75rem; align-items: flex-end; margin-bottom: 0.75rem; flex-wrap: wrap; }
.section-block .section-head input[type="text"] { font-weight: 700; }
.section-subtotal { text-align: right; font-weight: 700; margin-top: 0.5rem; font-size: 0.9rem; }

.discount-row { display: flex; gap: 0.5rem; }
.discount-row select { max-width: 110px; flex-shrink: 0; }

@media print {
  .pw-toggle { display: none; }
}

.line-items-table input { text-align: right; }
.line-items-table td:first-child input { text-align: left; }

.totals-box { max-width: 320px; margin-left: auto; }
.totals-box .row { display: flex; justify-content: space-between; padding: 0.3rem 0; font-size: 0.9rem; }
.totals-box .row.total { font-weight: 700; font-size: 1.05rem; border-top: 1px solid var(--border); margin-top: 0.4rem; padding-top: 0.6rem; }

@media print {
  .no-print { display: none !important; }
  .app-shell { display: block; }
  .main { padding: 0; }
}
