/* NovaPro Solutions LLC — brand palette only:
   orange #FE7003 | charcoal #414345 | light gray #F4F5F6 | white | medium gray #8A8D90 */
:root {
  --orange: #FE7003;
  --orange-dark: #d95f02;
  --charcoal: #414345;
  --bg: #F4F5F6;
  --white: #ffffff;
  --gray: #8A8D90;
  --gray-light: #A9ACAF;
  --border: #dfe2e4;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--charcoal);
  font-size: 15px;
  line-height: 1.5;
}

.hidden { display: none !important; }

h1, h2, h3 { color: var(--charcoal); margin: 0 0 12px; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p { margin: 0 0 10px; }
a { color: var(--orange); }

label { display: block; font-weight: 600; font-size: 13px; margin: 14px 0 5px; color: var(--charcoal); }

input[type="text"], input[type="email"], input[type="tel"], input[type="password"],
input[type="number"], input[type="date"], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  color: var(--charcoal);
  background: var(--white);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--orange);
  outline-offset: 0;
  border-color: var(--orange);
}
textarea { min-height: 74px; resize: vertical; }

.muted { color: var(--gray); }
.small { font-size: 13px; }
.error-text { color: #b3261e; font-weight: 600; margin-top: 10px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  background: var(--white);
  color: var(--charcoal);
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--orange); color: #fff; }
.btn-primary:hover { background: var(--orange-dark); }
.btn-secondary { border-color: var(--border); color: var(--charcoal); }
.btn-danger { background: var(--charcoal); color: #fff; }
.btn-ghost { background: transparent; color: var(--gray); }
.btn-block { width: 100%; margin-top: 16px; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 6px; }
.btn + .btn { margin-left: 8px; }

/* ---------- Login ---------- */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}
.login-card {
  background: var(--white);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(65, 67, 69, 0.12);
  padding: 36px 34px 30px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}
.login-logo { width: 100%; max-width: 300px; height: auto; }
.login-subtitle { color: var(--gray); font-weight: 600; letter-spacing: 2px; text-transform: uppercase; font-size: 13px; margin: 6px 0 18px; }
#login-form { text-align: left; }
.login-heading { font-size: 19px; font-weight: 700; color: var(--charcoal); margin: 0 0 14px; }
.login-toggle { margin: 16px 0 0; }
.link-btn { background: none; border: none; padding: 0; color: var(--orange); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; }
.link-btn:hover { color: #e56300; }
#login-cloud-note { margin-top: 14px; }
.remember-row { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--gray); margin-top: 14px; cursor: pointer; }
.remember-row input { width: auto; accent-color: var(--orange); }

/* ---------- App shell ---------- */
#app { display: flex; min-height: 100vh; }
#sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--charcoal);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand { padding: 6px 8px 18px; border-bottom: 1px solid rgba(255, 255, 255, 0.15); }
.sidebar-logo { width: 100%; height: auto; display: block; padding: 4px 8px; }
#main-nav { display: flex; flex-direction: column; gap: 4px; margin-top: 18px; flex: 1; }
.nav-item {
  text-align: left;
  background: transparent;
  border: none;
  color: #cfd2d4;
  font-size: 15px;
  font-weight: 600;
  padding: 11px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-item.active { background: var(--orange); color: #fff; }
.sidebar-logout { color: #cfd2d4; text-align: left; padding: 10px 12px; }
.sidebar-logout:hover { color: #fff; }
.sync-status { font-size: 12px; color: #9aa0a3; padding: 8px 12px 2px; }
.sync-status[data-state="synced"] { color: #7bc47f; }
.sync-status[data-state="offline"] { color: #e0a03c; }

#main { flex: 1; min-width: 0; padding: 26px 30px 40px; }
#view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
#view-header h1 { margin: 0; }

/* ---------- Cards / dashboard ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: 0 1px 4px rgba(65, 67, 69, 0.08);
}
.stat-card .stat-label { font-size: 13px; font-weight: 600; color: var(--gray); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--charcoal); margin-top: 4px; }
.stat-card .stat-value.orange { color: var(--orange); }

.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 1px 4px rgba(65, 67, 69, 0.08);
  padding: 20px 22px;
  margin-bottom: 20px;
}
.card h2 { margin-bottom: 4px; }
.card .card-sub { color: var(--gray); font-size: 13px; margin-bottom: 14px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--gray); background: var(--bg); }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; }
.row-actions { white-space: nowrap; }
.row-actions .btn { margin: 2px 2px 2px 0; }
.empty-row td { text-align: center; color: var(--gray); padding: 26px; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  text-transform: capitalize;
  border: 1px solid var(--gray);
  color: var(--gray);
  background: var(--white);
}
.badge-draft { border-color: var(--gray); color: var(--gray); }
.badge-sent { border-color: var(--orange); color: var(--orange); }
.badge-paid, .badge-accepted { background: var(--orange); border-color: var(--orange); color: #fff; }
.badge-void, .badge-declined { background: var(--charcoal); border-color: var(--charcoal); color: #fff; }
.badge-overdue { background: var(--charcoal); border-color: var(--charcoal); color: #fff; }

/* ---------- Filters ---------- */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  align-items: center;
}
.filter-bar input[type="text"], .filter-bar select { width: auto; flex: 1; min-width: 180px; }
.filter-bar select { flex: 0 0 170px; }

/* ---------- Forms / editor ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.form-grid .full { grid-column: 1 / -1; }
.totals-box {
  margin-left: auto;
  width: 320px;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  background: var(--bg);
}
.totals-row { display: flex; justify-content: space-between; padding: 4px 0; }
.totals-row.grand { font-size: 18px; font-weight: 700; border-top: 2px solid var(--charcoal); margin-top: 8px; padding-top: 10px; }
.totals-row.grand span:last-child { color: var(--orange); }
.editor-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.editor-actions .spacer { flex: 1; }
.tax-input { display: flex; align-items: center; gap: 8px; }
.tax-input input { width: 90px; }
.inline-add {
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-top: 10px;
}
.inline-add h3 { margin-bottom: 4px; }

/* ---------- Settings ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.danger-zone { border: 2px solid var(--charcoal); }
.danger-zone h2 { color: var(--charcoal); }

/* ---------- Document preview / print ---------- */
#preview-modal {
  position: fixed;
  inset: 0;
  background: rgba(65, 67, 69, 0.75);
  overflow-y: auto;
  z-index: 100;
}
.modal-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--charcoal);
  color: #fff;
  padding: 12px 20px;
}
.modal-title { font-weight: 700; font-size: 15px; }
#preview-body { padding: 28px 16px 48px; display: flex; justify-content: center; }
/* While a document preview is open, the mobile tab bar stays hidden. */
body.preview-open #bottom-nav,
body.preview-open #more-sheet,
body.preview-open #more-backdrop { display: none !important; }

.doc-page {
  width: 800px;
  max-width: 100%;
  background: #fff;
  color: var(--charcoal);
  padding: 48px 52px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
  font-size: 14px;
}
.doc-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding-bottom: 20px; border-bottom: 3px solid var(--orange); }
.doc-logo { height: 74px; width: auto; max-width: 320px; object-fit: contain; }
.doc-company { text-align: right; font-size: 13px; color: var(--charcoal); line-height: 1.6; }
.doc-company strong { font-size: 15px; }
.doc-title-row { display: flex; justify-content: space-between; align-items: flex-end; margin: 26px 0 6px; }
.doc-title { font-size: 32px; font-weight: 800; letter-spacing: 2px; color: var(--charcoal); margin: 0; }
.doc-title.orange { color: var(--orange); }
.doc-meta { text-align: right; font-size: 13px; line-height: 1.7; }
.doc-meta strong { color: var(--charcoal); }
.doc-billto { margin: 18px 0 22px; }
.doc-billto h4 { margin: 0 0 4px; font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--gray); }
.doc-billto .billto-name { font-size: 16px; font-weight: 700; }
.doc-items { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.doc-items th { background: var(--charcoal); color: #fff; }
.doc-items td, .doc-items th { padding: 9px 12px; }
.doc-totals { margin-left: auto; width: 280px; margin-top: 10px; }
.doc-totals .totals-row { padding: 3px 0; }
.doc-notes { margin-top: 22px; font-size: 13px; }
.doc-notes h4 { margin: 0 0 4px; font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--gray); }
.doc-terms-list { margin: 4px 0 0; padding-left: 20px; }
.doc-terms-list li { margin: 3px 0; }
/* Terms & Conditions sit quiet at the bottom: smaller and lighter gray. */
.doc-terms { font-size: 11px; color: var(--gray-light); }
.doc-terms h4 { color: var(--gray-light); }
.doc-footer { margin-top: 34px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--gray); text-align: center; }
.doc-footer .thanks { font-size: 14px; font-weight: 700; color: var(--orange); margin-bottom: 4px; }

/* ---------- Bottom tab bar (mobile only) ---------- */
#bottom-nav { display: none; }
#more-sheet, #more-backdrop { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  html, body { overflow-x: hidden; }
  #app { flex-direction: column; }
  /* Slim top bar: logo only. The full nav moves to the bottom tab bar. */
  #sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    padding: 10px 14px;
  }
  .sidebar-brand { padding: 0; border-bottom: none; width: 150px; }
  .sidebar-logo { padding: 4px; }
  #main-nav, .sidebar-logout { display: none; }
  #main { padding: 18px 14px 104px; }
  .form-grid { grid-template-columns: 1fr; }
  .doc-page { padding: 28px 22px; }
  .doc-header { flex-direction: column; }
  .doc-company { text-align: left; }
  .doc-title-row { flex-direction: column; align-items: flex-start; gap: 6px; }
  .doc-meta { text-align: left; }
  .totals-box { width: 100%; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
  #ed-items input[type="number"] { min-width: 84px; }
  .filter-bar select { flex: 1 1 100%; }

  /* Bottom tab bar */
  #bottom-nav {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 90;
    background: var(--white);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 12px rgba(65, 67, 69, 0.08);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .tab-item {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    padding: 8px 2px 7px;
    font-size: 11px;
    font-weight: 600;
    color: var(--gray);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    font-family: inherit;
  }
  .tab-item svg { width: 22px; height: 22px; }
  .tab-item.active { color: var(--orange); }
  .tab-item span { white-space: nowrap; }

  /* "More" sheet above the tab bar */
  #more-sheet {
    position: fixed;
    left: 12px; right: 12px;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    background: var(--white);
    border-radius: 14px;
    box-shadow: 0 8px 30px rgba(65, 67, 69, 0.28);
    z-index: 96;
    padding: 6px;
  }
  #more-sheet:not(.hidden), #more-backdrop:not(.hidden) { display: block; }
  .more-item {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    padding: 13px 14px;
    font-size: 15px;
    font-weight: 600;
    color: var(--charcoal);
    border-radius: 9px;
    cursor: pointer;
    font-family: inherit;
  }
  .more-item:hover { background: var(--bg); }
  .more-item:last-child { color: #b3261e; }
  #more-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(65, 67, 69, 0.35);
    z-index: 95;
  }
}
@media (max-width: 480px) {
  #view-header h1 { font-size: 22px; }
  .stat-grid { gap: 10px; }
  .stat-card { padding: 14px 16px; }
  .stat-card .stat-value { font-size: 24px; }
  #main { padding: 16px 12px 104px; }
  .card { padding: 16px; }
  .btn { padding: 10px 14px; }
  .modal-card { padding: 18px; }
  #pay-modal { padding: 16px 12px; }
}

/* ---------- Print: only the document prints ---------- */
@media print {
  body { background: #fff; }
  #login-screen, #app, .modal-bar,
  /* The bottom tab bar, More sheet and backdrop live OUTSIDE #app, so
     hiding #app alone does not hide them — they printed at the foot
     of the page on mobile. Hide them explicitly. */
  #bottom-nav, #more-sheet, #more-backdrop, #sidebar, #view-header { display: none !important; }
  #preview-modal {
    position: static;
    display: block !important;
    background: none;
    overflow: visible;
  }
  #preview-body { padding: 0; display: block; }
  .doc-page { box-shadow: none; width: 100%; max-width: none; padding: 0; }
  @page { size: letter; margin: 18mm; }
}

/* ---------- Dashboard charts, search, tax rates (2026-11-26) ---------- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.chart-bars { display: flex; gap: 10px; align-items: stretch; height: 150px; padding-top: 6px; }
.chart-col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; }
.chart-pair { flex: 1; display: flex; align-items: flex-end; gap: 4px; width: 100%; max-width: 56px; min-height: 0; }
.chart-bar { flex: 1; border-radius: 4px 4px 0 0; min-height: 0; }
.chart-bar-inv { background: var(--orange); }
.chart-bar-paid { background: var(--charcoal); }
.chart-value { font-size: 11px; font-weight: 700; color: var(--charcoal); margin-top: 6px; white-space: nowrap; }
.chart-label { font-size: 12px; color: var(--gray); font-weight: 600; }
.chart-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; }
.top-client-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.top-client-row:last-child { border-bottom: none; }
.search-hit { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.search-hit:last-child { border-bottom: none; }
.search-hit-label { flex: 1; min-width: 0; }
.tax-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tax-row .tax-state { width: 74px; flex-shrink: 0; }
.tax-row .tax-rate { width: 110px; }
.tax-row .tax-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .chart-bars { height: 130px; }
  .chart-value { font-size: 10px; }
  .search-hit { flex-wrap: wrap; }
  .search-hit-label { flex: 1 1 100%; }
}

/* ---------- New badges ---------- */
.badge-partial, .badge-applied { background: var(--orange); border-color: var(--orange); color: #fff; }

/* ---------- Sidebar attention badge ---------- */
.nav-badge {
  background: var(--orange);
  color: #fff;
  border-radius: 12px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
  margin-left: 6px;
  vertical-align: middle;
}

/* ---------- Payment modal ---------- */
#pay-modal {
  position: fixed;
  inset: 0;
  background: rgba(65, 67, 69, 0.75);
  overflow-y: auto;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
}
.modal-card {
  background: var(--white);
  border-radius: 12px;
  width: 560px;
  max-width: 100%;
  padding: 22px 24px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}
.modal-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.modal-card-head h3 { margin: 0; }
#pay-list { margin: 12px 0 6px; }

/* ---------- Product picker inside line items ---------- */
.item-product { margin-bottom: 6px; font-size: 13px; padding: 6px 8px; }

/* ---------- Needs attention list ---------- */
.attention-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.attention-item:last-child { border-bottom: none; }
.attention-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--orange);
  white-space: nowrap;
}

/* ---------- Mobile polish: fields, buttons, sizes (2026-11-26) ---------- */
@media (max-width: 860px) {
  /* iOS Safari zooms in on any field under 16px when tapped. Keep them 16px. */
  input[type="text"], input[type="email"], input[type="tel"], input[type="password"],
  input[type="number"], input[type="date"], select, textarea {
    font-size: 16px;
    padding: 11px 12px;
  }
  .item-product { font-size: 16px; padding: 9px 10px; }

  /* Touch-sized buttons: 44px minimum tap height. */
  .btn { min-height: 44px; padding: 11px 18px; font-size: 15px; }
  .btn-sm { min-height: 40px; padding: 9px 12px; font-size: 14px; }
  .row-actions .btn { min-height: 40px; }

  /* Primary actions stack full-width so nothing is a tiny tap target. */
  .editor-actions .btn { flex: 1 1 100%; margin-left: 0; }
  .editor-actions .spacer { display: none; }
  #view-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  #view-actions .btn { flex: 1 1 auto; min-width: 120px; margin-left: 0; }
  #pay-form .btn { width: 100%; margin: 8px 0 0; }
  .filter-bar input[type="text"], .filter-bar select { flex: 1 1 100%; min-width: 0; }

  /* Line-item table: fixed usable columns, scrolls sideways cleanly. */
  .items-wrap table { min-width: 640px; }
  #ed-items input[type="number"] { min-width: 76px; }

  /* Login: less padding, smaller logo on small screens. */
  .login-card { padding: 28px 20px 24px; }
  .login-logo { max-width: 240px; }

  /* Payment modal: less top padding on phones. */
  #pay-modal { padding: 16px 12px; }
  .modal-card { padding: 20px 18px; }
}
@media (max-width: 480px) {
  .doc-title { font-size: 28px; }
  #view-actions .btn { flex: 1 1 100%; }
}

/* ---------- Print: force the desktop document layout (2026-11-26) ----------
   iOS Safari prints with the mobile viewport, so the max-width:860px rules
   would otherwise stack the header, left-align the totals and shift every
   margin. These overrides restore the desktop layout in the PDF, and
   print-color-adjust keeps the charcoal header and orange accents visible
   (iOS drops backgrounds in print by default). */
@media print {
  .doc-page { width: 100% !important; max-width: none !important; padding: 0 !important; font-size: 14px !important; }
  .doc-header { flex-direction: row !important; align-items: flex-start !important; gap: 20px !important; padding-bottom: 20px !important; }
  .doc-logo { height: 74px !important; max-width: 320px !important; }
  .doc-company { text-align: right !important; }
  .doc-title-row { flex-direction: row !important; align-items: flex-end !important; }
  .doc-title { font-size: 32px !important; }
  .doc-meta { text-align: right !important; }
  .doc-totals { width: 280px !important; margin-left: auto !important; margin-top: 10px !important; }
  .doc-items th, .doc-items td { padding: 9px 12px !important; }
  .doc-page, .doc-page * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  @page { size: letter; margin: 18mm; }
}
