/* ── Google Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&family=Inter:wght@400;500;600&display=swap');

/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: #f5f2ed;
  color: #2a2a2a;
  line-height: 1.5;
}

main {
  padding: 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

/* ── Alerts ── */
.alert {
  padding: 0.6rem 1rem;
  border-radius: 4px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-danger  { background: #fef5f3; color: #a0293d; border: 1px solid #f5c6c6; }
.alert-success { background: #f0f7f2; color: #2d6a4f; border: 1px solid #c3dfc9; }
.alert-warning { background: #fdf6e3; color: #7d5a00; border: 1px solid #edd5a0; }
.alert-info    { background: #eff5fd; color: #2a5fa8; border: 1px solid #b8d4f5; }

/* ── Navbar ── */
.navbar {
  background: #3f3f3c;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 70px;
  border-bottom: 1px solid #2f2f2c;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.navbar-brand {
  color: #c8a96e;
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 1.2rem;
  margin-right: 1.5rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.navbar-left  { display: flex; align-items: center; gap: 0.25rem; }
.navbar-logo  { height: 44px; vertical-align: middle; margin-right: 0.5rem; }
.navbar-right { display: flex; align-items: center; gap: 1rem; }
.navbar a {
  color: rgba(255,255,255,0.55);
  text-decoration: none;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 0.5rem 0.9rem;
  border-radius: 4px;
  transition: color 0.15s;
}
.navbar a:hover  { color: #a0c4e0; }
.navbar a.active { color: #a0c4e0; }
.navbar-user     { color: rgba(255,255,255,0.45); font-size: 0.8rem; }
.navbar-logout   { font-size: 0.8rem !important; }
.navbar-links    { display: flex; align-items: center; gap: 0.25rem; flex: 1; }
.navbar-right    { display: flex; align-items: center; gap: 1rem; margin-left: auto; }
.navbar-hamburger {
  display: none;
  background: none; border: none;
  color: rgba(255,255,255,0.75); font-size: 1.5rem;
  cursor: pointer; padding: 0.25rem 0.5rem; line-height: 1;
}

/* ── Role badges in nav ── */
.badge-role {
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: 0.3rem;
}
.badge-role.admin { background: rgba(200,169,110,0.25); color: #c8a96e; }
.badge-role.staff { background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.6); }

/* ── Page header ── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
}
.page-header h1 {
  font-family: 'Montserrat', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: #1a1a1a;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.page-header-left    { display: flex; flex-direction: column; gap: 0.25rem; }
.page-header-actions { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.back-link           { font-size: 0.8rem; color: #8a8078; text-decoration: none; }
.back-link:hover     { color: #c8a96e; }

/* ── Toolbar / search ── */
.toolbar     { margin-bottom: 1rem; }
.search-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.search-input {
  padding: 0.45rem 0.75rem;
  border: 1px solid #c8b99a;
  border-radius: 4px;
  font-size: 0.9rem;
  background: #fff;
  color: #2a2a2a;
  width: 260px;
}
.filter-select {
  padding: 0.45rem 0.6rem;
  border: 1px solid #c8b99a;
  border-radius: 4px;
  font-size: 0.9rem;
  background: #fff;
  color: #2a2a2a;
  cursor: pointer;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.9rem;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn-primary         { background: #4a6b8a; color: #ffffff; border-color: #4a6b8a; }
.btn-primary:hover   { background: #3a5a78; border-color: #3a5a78; }
.btn-secondary       { background: #fff; color: #2a2a2a; border-color: #c8b99a; }
.btn-secondary:hover { background: #faf7f3; border-color: #b8a08a; }
.btn-ghost           { background: transparent; color: #6b6560; border-color: #ddd8ce; }
.btn-ghost:hover     { background: #faf7f3; color: #2a2a2a; border-color: #c8b99a; }
.btn-danger {
  background: #c0392b; color: #fff; border: none;
  padding: 0.45rem 1rem; border-radius: 4px; font-size: 0.875rem;
  font-weight: 500; cursor: pointer; text-decoration: none; display: inline-block;
}
.btn-danger:hover { background: #a93226; }
.btn-sm   { font-size: 0.8rem; padding: 0.3rem 0.65rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Cards ── */
.card {
  background: #fff;
  border: 1px solid #e8e2d9;
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 2px 8px rgba(180,160,130,0.12);
}
.table-card { padding: 0; overflow: hidden; }

/* ── Data table ── */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th {
  background: #f0ece6;
  padding: 0.65rem 1rem;
  text-align: left;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #5a5550;
  border-bottom: 1px solid #e8e2d9;
  white-space: nowrap;
}
.data-table td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid #f0ece6;
  vertical-align: middle;
  color: #2a2a2a;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td      { background: #faf7f3; }
.table-link       { color: #8a6d3e; text-decoration: none; font-weight: 500; }
.table-link:hover { text-decoration: underline; color: #c8a96e; }

/* ── Status / estimate badges ── */
.badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 12px;
  font-weight: 500;
}
.badge-active   { background: #eef7f0; color: #2d6a4f; }
.badge-inactive { background: #f5f3f0; color: #8a8078; }
.badge-draft    { background: #eef3fb; color: #3a6ea8; }
.badge-sent     { background: #fdf4e3; color: #8a6d3e; }
.badge-won      { background: #eef7f0; color: #2d6a4f; }
.badge-lost     { background: #f5f3f0; color: #8a8078; }
.badge-approved { background: #eef7f0; color: #2d6a4f; }
.badge-declined { background: #fdeef0; color: #a0293d; }

/* ── Pipeline stage badges (customer cards / index table) ── */
.badge-pipeline          { background: #f5f3f0;              color: #8a8078; }
.badge-pipeline-lead     { background: rgba(90,140,190,0.12); color: #3d6e9e; }
.badge-pipeline-quoted   { background: rgba(200,169,110,0.15); color: #8a6d3e; }
.badge-pipeline-followup { background: rgba(210,140,30,0.12); color: #8a6010; }
.badge-pipeline-won      { background: rgba(50,130,80,0.12);  color: #2d6a4f; }
.badge-pipeline-lost     { background: rgba(100,100,100,0.1); color: #8a8078; }

/* ── Forms ── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem 1.5rem;
}
.field        { display: flex; flex-direction: column; gap: 0.25rem; }
.field-wide   { grid-column: span 2; }
.field-full   { grid-column: span 2; }
.field-narrow { grid-column: span 1; }
.field label  { font-size: 0.82rem; font-weight: 500; color: #6b6560; }
.field input,
.field select,
.field textarea {
  padding: 0.45rem 0.7rem;
  border: 1px solid #c8b99a;
  border-radius: 4px;
  font-size: 0.9rem;
  font-family: inherit;
  background: #fff;
  color: #2a2a2a;
  width: 100%;
  transition: border-color 0.15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus { outline: none; border-color: #4a6b8a; }
.field textarea { resize: vertical; }
.required       { color: #c0392b; }
.form-actions   { margin-top: 1.5rem; display: flex; gap: 0.75rem; }

/* ── Profile card ── */
.profile-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #e8e2d9;
}
.profile-since { font-size: 0.82rem; color: #8a8078; }
.detail-grid {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 0.5rem 1rem;
  font-size: 0.9rem;
}
.detail-grid dt { color: #8a8078; font-weight: 500; align-self: start; padding-top: 0.1rem; }
.detail-grid dd { color: #2a2a2a; }

/* ── Content sections ── */
.content-section { margin-top: 2rem; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.content-section h2 {
  font-family: 'Montserrat', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: #3a3530;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

/* ── Activity log ── */
.activity-log { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.activity-entry {
  display: flex;
  gap: 1rem;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  background: #faf7f3;
  border: 1px solid #ede8e0;
  border-radius: 6px;
}
.activity-time   { color: #b0a898; white-space: nowrap; flex-shrink: 0; }
.activity-user   { font-weight: 500; color: #8a6d3e; flex-shrink: 0; }
.activity-detail { color: #5a5550; }

/* ── Misc ── */
.empty-state {
  padding: 2.5rem;
  text-align: center;
  color: #8a8078;
  background: #faf7f3;
  border: 1px dashed #ddd8ce;
  border-radius: 8px;
}
.empty-state a { color: #c8a96e; }
.muted { color: #8a8078; font-size: 0.875rem; }

/* ── Login page ── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: #f5f2ed;
}
.login-card {
  background: #fff;
  border: 1px solid #e8e2d9;
  border-radius: 10px;
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 4px 24px rgba(180,160,130,0.18);
}
.login-brand { text-align: center; margin-bottom: 2rem; }
.login-logo-placeholder {
  width: 64px;
  height: 64px;
  background: #c8a96e;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 0.75rem;
}
.login-brand h1 {
  font-family: 'Montserrat', sans-serif;
  font-size: 1.5rem;
  color: #c8a96e;
  text-transform: uppercase;
  letter-spacing: 2px;
}
.login-brand p { font-size: 0.82rem; color: #8a8078; margin-top: 0.2rem; }

/* ── Catalog-specific ── */
.mono         { font-family: monospace; font-size: 0.85rem; color: #6b6560; white-space: nowrap; }
.field-hint   { font-size: 0.75rem; color: #8a8078; font-weight: 400; }
.margin-value { font-weight: 600; }
.margin-good  { color: #2d6a4f; }
.margin-ok    { color: #8a6010; }
.margin-low   { color: #c0392b; }
.row-actions  { display: flex; gap: 0.25rem; }

/* ── Line items table (create/edit form) ── */
/* overflow must NOT be set here — it would clip the absolutely-positioned
   catalog autocomplete dropdown regardless of z-index value. */
.table-responsive { overflow: visible; }
.line-items-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; min-width: 800px; }
.line-items-table th {
  background: #f0ece6;
  padding: 0.5rem 0.6rem;
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #5a5550;
  border-bottom: 2px solid #e8e2d9;
  white-space: nowrap;
}
.line-items-table td { padding: 0.35rem 0.4rem; border-bottom: 1px solid #f0ece6; vertical-align: middle; }
.line-input {
  padding: 0.35rem 0.5rem;
  border: 1px solid #c8b99a;
  border-radius: 3px;
  font-size: 0.875rem;
  font-family: inherit;
  background: #fff;
  color: #2a2a2a;
  width: 100%;
}
.line-input:focus { outline: none; border-color: #4a6b8a; }

.col-catalog { width: 170px; }
.col-desc    { min-width: 190px; }
.col-qty     { width: 68px; }
.col-price   { width: 100px; }
.col-cost    { width: 100px; }
.col-margin  { width: 68px; text-align: right; }
.col-total   { width: 90px; text-align: right; white-space: nowrap; }
.col-remove  { width: 38px; }

/* ── Catalog autocomplete dropdown ── */
.catalog-wrap     { position: relative; }
.catalog-dropdown {
  position: absolute; top: calc(100% + 2px); left: 0;
  background: #fff; border: 1px solid #c8b99a; border-radius: 4px;
  box-shadow: 0 4px 14px rgba(180,160,130,0.2);
  min-width: 270px; max-height: 210px; overflow-y: auto;
  display: none; z-index: 1000;
}
.catalog-dropdown.open { display: block; }
.catalog-option {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.45rem 0.75rem; cursor: pointer; font-size: 0.85rem;
  border-bottom: 1px solid #f0ece6; color: #2a2a2a;
}
.catalog-option:last-child { border-bottom: none; }
.catalog-option:hover      { background: #faf7f3; }
.catalog-empty { color: #b0a898; cursor: default; }
.option-name   { font-weight: 500; }
.option-meta   { color: #8a8078; font-size: 0.8rem; margin-left: 0.5rem; white-space: nowrap; }

.line-total  { font-weight: 500; font-size: 0.875rem; }
.line-margin { font-size: 0.8rem; font-weight: 600; }

/* ── Markup control ── */
.markup-control { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.markup-control label { color: #6b6560; white-space: nowrap; }
.markup-control input {
  width: 72px; padding: 0.3rem 0.5rem; border: 1px solid #c8b99a;
  border-radius: 4px; font-size: 0.85rem; background: #fff; color: #2a2a2a;
}

/* ── Estimate totals box ── */
.estimate-totals { display: flex; justify-content: flex-end; margin: 0.75rem 0 1.5rem; }
.totals-box {
  background: #fff; border: 1px solid #e8e2d9; border-radius: 6px;
  padding: 1rem 1.25rem; min-width: 260px;
  box-shadow: 0 2px 8px rgba(180,160,130,0.12);
}
.totals-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.3rem 0; font-size: 0.9rem; color: #5a5550;
}
.totals-row + .totals-row { border-top: 1px solid #f0ece6; }
.totals-grand {
  font-weight: 700; font-size: 1rem; color: #1a1a1a;
  border-top: 2px solid #e8e2d9 !important;
  margin-top: 0.2rem; padding-top: 0.5rem !important;
}
.totals-admin {
  border-top: 2px dashed #edd5a0 !important;
  margin-top: 0.4rem; padding-top: 0.4rem !important;
  font-size: 0.82rem; color: #8a6d3e;
}

/* ── Estimate meta strip (detail page) ── */
.estimate-meta {
  display: flex; gap: 1.5rem; flex-wrap: wrap;
  margin-bottom: 1.25rem; padding-bottom: 1rem; border-bottom: 1px solid #e8e2d9;
}
.estimate-meta-item { display: flex; flex-direction: column; gap: 0.15rem; }
.estimate-meta-item dt {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.4px; color: #b0a898;
}
.estimate-meta-item dd { font-size: 0.9rem; color: #2a2a2a; }
.status-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ── PDF section bar ── */
.pdf-section {
  background: #faf7f3; border: 1px solid #e8e2d9; border-radius: 6px;
  padding: 0.85rem 1.1rem; display: flex; align-items: center;
  justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem;
}
.pdf-section-info         { font-size: 0.875rem; color: #6b6560; }
.pdf-section-info strong  { color: #2a2a2a; }

/* ── Delete confirmation box ── */
.delete-confirm-box {
  background: #fef5f3;
  border: 1px solid #f5c6c6;
  border-left: 4px solid #c0392b;
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}
.delete-confirm-box p { font-size: 0.9rem; color: #3a2020; margin-bottom: 0.85rem; }
.delete-confirm-actions { display: flex; gap: 0.75rem; align-items: center; }

/* ── User management ── */
.badge-you {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  background: rgba(200,169,110,0.18);
  color: #8a6d3e;
  margin-left: 0.35rem;
  vertical-align: middle;
}
.badge-status { display: inline-block; padding: 0.2rem 0.55rem; border-radius: 4px; font-size: 0.75rem; font-weight: 600; }
.badge-status.active   { background: #eef7f0; color: #2d6a4f; }
.badge-status.inactive { background: #f5f3f0; color: #8a8078; }
.form-card {
  background: #fff;
  border: 1px solid #e8e2d9;
  border-radius: 8px;
  padding: 1.5rem;
  max-width: 500px;
  box-shadow: 0 2px 8px rgba(180,160,130,0.12);
}
.form-group { margin-bottom: 1.1rem; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.35rem; color: #6b6560; }
.form-control {
  width: 100%;
  padding: 0.45rem 0.65rem;
  border: 1px solid #c8b99a;
  border-radius: 4px;
  font-size: 0.9rem;
  font-family: inherit;
  background: #fff;
  color: #2a2a2a;
}
.form-control:focus    { outline: none; border-color: #4a6b8a; }
.form-control:disabled { background: #f5f2ed; color: #b0a898; cursor: not-allowed; }
.form-hint     { font-size: 0.78rem; color: #8a8078; margin-top: 0.25rem; display: block; }
.form-optional { font-size: 0.78rem; color: #b0a898; font-weight: 400; }
.table-actions { white-space: nowrap; }

/* ── Responsive ── */
@media (max-width: 768px) {
  /* ── Navbar hamburger ── */
  .navbar           { height: 56px; }
  .navbar-logo      { height: 32px; }
  .navbar-hamburger { display: flex; align-items: center; }
  .navbar-links {
    display: none;
    position: absolute; top: 56px; left: 0; right: 0;
    background: #3f3f3c;
    border-bottom: 1px solid #2f2f2c;
    flex-direction: column;
    gap: 0;
    padding: 0.25rem 0;
    z-index: 200;
  }
  .navbar-links.open { display: flex; }
  .navbar-links > a {
    padding: 0.7rem 1.5rem;
    border-radius: 0;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    font-size: 0.85rem;
  }
  .navbar-right {
    margin-left: 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
    padding: 0.6rem 1.5rem 0.75rem;
    border-top: 1px solid rgba(255,255,255,0.12);
    width: 100%;
  }

  /* ── Layout ── */
  main { padding: 1rem; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header-actions { flex-wrap: wrap; }

  /* ── Tables ── */
  .table-card       { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ── Cards ── */
  .card { min-width: 0; }

  /* ── Forms ── */
  .form-grid { grid-template-columns: 1fr; }
  .field-wide, .field-full { grid-column: span 1; }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; justify-content: center; }

  /* ── Typography ── */
  .page-header h1 { font-size: 1.2rem; }
  .navbar-brand   { font-size: 0.95rem; }

  /* ── Line item column widths ── */
  .col-catalog { width: 120px; }
  .col-desc    { min-width: 130px; }
  .col-qty     { width: 50px; }
  .col-price   { width: 75px; }
  .col-cost    { width: 75px; }

  /* ── Login ── */
  .login-card { padding: 1.75rem 1.25rem; }

  /* ── Estimates ── */
  .line-items-table { font-size: 0.8rem; }
  .estimate-meta    { gap: 1rem; }
  .pdf-section      { flex-direction: column; align-items: flex-start; }
  .status-actions   { flex-wrap: wrap; }
  .totals-box       { min-width: 0; width: 100%; }
  .estimate-totals  { justify-content: stretch; }
}
