:root {
  --brand-green: #1f8a53;
  --brand-green-dark: #14603b;
  --brand-green-light: #e6f4ec;
  --brand-orange: #f2782f;
  --brand-orange-dark: #d9631f;
  --brand-orange-light: #fdeee3;
  --brand-white: #ffffff;
  --brand-ink: #1c2b22;
  --brand-muted: #5b6b61;
  --mobile-tabbar-height: 52px;
}

html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--brand-ink);
  background: linear-gradient(180deg, var(--brand-green-light) 0%, #ffffff 320px);
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem var(--brand-green);
}

/* Navbar */
.navbar {
  background: linear-gradient(90deg, var(--brand-green) 0%, var(--brand-green-dark) 100%) !important;
  box-shadow: 0 2px 10px rgba(20, 96, 59, 0.25);
}

.navbar-brand {
  color: var(--brand-white) !important;
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: 0.5px;
}

.navbar .btn-primary {
  background-color: var(--brand-orange);
  border-color: var(--brand-orange);
  font-weight: 600;
  padding: 0.5rem 1.5rem;
  border-radius: 2rem;
  box-shadow: 0 2px 8px rgba(217, 99, 31, 0.4);
}

.navbar .btn-primary:hover {
  background-color: var(--brand-orange-dark);
  border-color: var(--brand-orange-dark);
}

/* Pulls the nav links + logout icon together into one tightly-packed group
   at the right edge of the navbar (an auto margin absorbs all the free
   space before it, so justify-content-between on the container-fluid has
   nothing left to distribute past this point). */
.navbar-actions {
  margin-left: auto;
}

/* Buttons */
.btn-primary {
  background-color: var(--brand-orange);
  border-color: var(--brand-orange);
  font-weight: 600;
}

.btn-primary:hover, .btn-primary:focus {
  background-color: var(--brand-orange-dark);
  border-color: var(--brand-orange-dark);
}

.btn-outline-secondary {
  color: var(--brand-green-dark);
  border-color: var(--brand-green);
}

.btn-outline-secondary:hover {
  background-color: var(--brand-green);
  border-color: var(--brand-green);
  color: var(--brand-white);
}

.btn-outline-orange {
  color: var(--brand-orange-dark);
  border-color: var(--brand-orange);
}

.btn-outline-orange:hover {
  background-color: var(--brand-orange);
  border-color: var(--brand-orange);
  color: var(--brand-white);
}

/* Page heading */
.page-heading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}

.page-heading .icon-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  border-radius: 0.75rem;
  font-size: 1.5rem;
  color: var(--brand-white);
}

.icon-badge--green {
  background: linear-gradient(135deg, var(--brand-green) 0%, var(--brand-green-dark) 100%);
}

.icon-badge--orange {
  background: linear-gradient(135deg, var(--brand-orange) 0%, var(--brand-orange-dark) 100%);
}

/* Form cards */
.form-card {
  background: var(--brand-white);
  border: none;
  border-radius: 1rem;
  box-shadow: 0 10px 30px rgba(20, 96, 59, 0.08);
  padding: 2rem;
  border-top: 5px solid var(--brand-green);
}

.form-card--orange {
  border-top-color: var(--brand-orange);
}

.form-card .form-label {
  font-weight: 600;
  color: var(--brand-green-dark);
}

.form-card .form-control,
.form-card .form-select {
  border-radius: 0.5rem;
  border-color: #d7e5dc;
}

.form-card .form-control[readonly] {
  background-color: var(--brand-green-light);
  color: var(--brand-green-dark);
}

.form-card .form-control:focus,
.form-card .form-select:focus {
  border-color: var(--brand-green);
}

.form-card--orange .form-control:focus,
.form-card--orange .form-select:focus {
  border-color: var(--brand-orange);
}

.form-card--orange .form-label {
  color: var(--brand-orange-dark);
}

.form-text {
  color: var(--brand-muted);
}

/* Success card */
.card {
  border: none;
  border-radius: 1rem;
  box-shadow: 0 10px 30px rgba(20, 96, 59, 0.08);
}

.alert-success {
  background-color: var(--brand-green-light);
  border-color: var(--brand-green);
  color: var(--brand-green-dark);
  border-radius: 0.75rem;
  font-weight: 600;
}

/* Footer */
.footer {
  background: var(--brand-green-dark);
  color: var(--brand-white) !important;
  padding: 1rem 0;
}

.footer a {
  color: var(--brand-orange-light);
}

.footer a:hover {
  color: var(--brand-orange);
}

/* "Show Invoices" link on Create Invoice page */
.show-invoices-link {
  font-weight: 600;
  color: var(--brand-green-dark);
  text-decoration: none;
  border-bottom: 2px solid var(--brand-green);
  padding-bottom: 0.1rem;
}

.show-invoices-link:hover {
  color: var(--brand-orange-dark);
  border-color: var(--brand-orange);
}

/* Previous / Next invoice navigation on the Tax Invoice page */
.invoice-nav-link {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--brand-green-dark);
  text-decoration: none;
}

.invoice-nav-link:hover {
  color: var(--brand-orange-dark);
  text-decoration: underline;
}

.invoice-nav-link--disabled {
  color: #b7c2bc;
  cursor: not-allowed;
}

/* Add / remove line item controls */
.btn-add-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--brand-green) 0%, var(--brand-green-dark) 100%);
  color: var(--brand-white);
  font-size: 1.5rem;
  line-height: 1;
  box-shadow: 0 4px 10px rgba(20, 96, 59, 0.3);
  transition: transform 0.15s ease;
}

.btn-add-item:hover {
  transform: scale(1.08);
  background: linear-gradient(135deg, var(--brand-green-dark) 0%, var(--brand-green-dark) 100%);
}

/* Tax rate toggle buttons */
.tax-rate-btn {
  flex: 1;
  padding: 0.6rem 0.5rem;
  border-radius: 0.5rem;
  border: 1.5px solid #d7e5dc;
  background: var(--brand-white);
  color: var(--brand-ink);
  font-weight: 600;
  transition: all 0.15s ease;
}

.tax-rate-btn:hover {
  border-color: var(--brand-green);
}

.tax-rate-btn.active {
  background: linear-gradient(135deg, var(--brand-green) 0%, var(--brand-green-dark) 100%);
  border-color: var(--brand-green-dark);
  color: var(--brand-white);
}

.btn-remove-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  border: 1px solid #f1c3c3;
  background: #fdecec;
  color: #c0392b;
  font-size: 0.85rem;
  line-height: 1;
}

.btn-remove-item:hover {
  background: #c0392b;
  color: var(--brand-white);
  border-color: #c0392b;
}

#itemsTable tbody tr:hover {
  background-color: var(--brand-green-light);
}

.amount-cell {
  font-weight: 600;
  color: var(--brand-green-dark);
}

/* Modal */
.modal-content {
  border: none;
  border-radius: 1rem;
  overflow: hidden;
}

.modal-header {
  background: linear-gradient(90deg, var(--brand-green) 0%, var(--brand-green-dark) 100%);
  color: var(--brand-white);
}

.modal-header .btn-close {
  filter: invert(1) grayscale(100%) brightness(200%);
}

.table-responsive {
  -webkit-overflow-scrolling: touch;
}

/* Responsive tweaks */
@media (max-width: 576px) {
  .navbar-brand {
    font-size: 1.25rem;
  }

  .navbar .btn-primary {
    padding: 0.4rem 1.1rem;
  }

  /* Nav links (Invoice / Quotation / Customers) become a fixed bottom tab
     bar on mobile, out of the header entirely - taking them out of normal
     flow means the order/flex-basis tricks used for the old inline layout
     no longer apply here. The logout icon stays in the header, pinned to
     the top-right corner next to the brand via its own auto margin. */
  .navbar-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1030;
    margin: 0;
    gap: 0;
    padding: 0.4rem max(0.5rem, env(safe-area-inset-right)) calc(0.4rem + env(safe-area-inset-bottom)) max(0.5rem, env(safe-area-inset-left));
    background: linear-gradient(90deg, var(--brand-green) 0%, var(--brand-green-dark) 100%);
    box-shadow: 0 -2px 10px rgba(20, 96, 59, 0.25);
    justify-content: space-around;
  }

  .navbar-actions .nav-link {
    flex: 1;
    text-align: center;
    padding: 0.4rem 0.25rem;
  }

  .nav-logout-icon-btn {
    order: 1;
    margin-left: auto;
  }

  /* Reserve space at the bottom of the page so the fixed tab bar never
     covers the footer or the last bit of page content when scrolled all
     the way down. */
  body {
    padding-bottom: calc(var(--mobile-tabbar-height) + env(safe-area-inset-bottom));
  }

  .page-heading {
    gap: 0.6rem;
  }

  .page-heading .icon-badge {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.15rem;
    border-radius: 0.6rem;
  }

  .page-heading h1 {
    font-size: 1.4rem;
  }

  .form-card {
    padding: 1.25rem 1rem;
    border-radius: 0.75rem;
  }

  .form-card button[type="submit"] {
    width: 100%;
  }

  /* All data tables, site-wide - Bootstrap's .table only draws a line under each
     row, which gets hard to read once cells are this narrow, so give every table
     a full grid of borders on mobile. table-borderless summaries (e.g. Product/
     Index's Tax Summary) opt out since those are meant to stay plain. */
  .table:not(.table-borderless) {
    border-collapse: collapse;
  }

  .table:not(.table-borderless) th,
  .table:not(.table-borderless) td {
    border: 1px solid rgba(0, 0, 0, 0.15);
  }

  /* Products page: customer details strip */
  .customer-details-row .text-uppercase {
    font-size: 0.68rem;
  }

  .customer-details-row .fw-semibold {
    font-size: 0.95rem;
  }

  /* Products page: line items table */
  #itemsTable {
    font-size: 0.82rem;
  }

  #itemsTable th,
  #itemsTable td {
    padding: 0.5rem 0.4rem;
    white-space: nowrap;
  }

  .btn-add-item {
    width: 2.25rem;
    height: 2.25rem;
    font-size: 1.25rem;
  }

  /* Products page: Calculate Tax / View Invoice actions */
  .product-actions .btn {
    width: 100%;
  }

  /* Add Line Item modal */
  .modal-body {
    padding: 1rem;
  }

  #taxRateGroup {
    flex-wrap: wrap;
  }

  .tax-rate-btn {
    min-width: calc(33.333% - 0.5rem);
  }

  /* Invoice view: line items table */
  .invoice-items-table {
    font-size: 0.82rem;
  }

  .invoice-items-table th,
  .invoice-items-table td {
    padding: 0.5rem 0.4rem;
    white-space: nowrap;
  }

  /* Invoice view: logo + invoice number/date top row (kept side-by-side on mobile) */
  .invoice-top-row {
    gap: 0.6rem !important;
  }

  .invoice-logo-wrap img {
    max-height: 56px !important;
  }

  .invoice-meta-wrap h5 {
    font-size: 1.05rem;
  }

  .invoice-meta-wrap p {
    font-size: 0.78rem;
  }

  /* Invoice view: Bill To section spacing when stacked under company info */
  .row.gy-4 .col-md-6.text-md-end {
    text-align: left !important;
  }

  /* Invoice view: Amount Paid inline controls */
  .amount-paid-controls {
    gap: 0.4rem !important;
  }

  .amount-paid-controls input#amountPaidInput {
    width: 72px !important;
  }

  .amount-paid-controls .btn {
    padding: 0.25rem 0.6rem;
  }

  /* Invoice view: Back to Products / Print / Email actions */
  .invoice-actions .btn {
    width: 100%;
  }

  /* Invoices list page */
  .invoice-list-table {
    font-size: 0.82rem;
  }

  .invoice-list-table th,
  .invoice-list-table td {
    padding: 0.5rem 0.4rem;
    white-space: nowrap;
  }

  .invoice-filter-bar .btn {
    flex: 1 1 auto;
  }

  .invoice-filter-bar form {
    width: 100%;
    margin-left: 0 !important;
  }

  /* Accounting report page */
  .accounting-table {
    font-size: 0.85rem;
  }

  .accounting-table th,
  .accounting-table td {
    padding: 0.5rem 0.4rem;
  }

  .accounting-share-row #accountingShareLink {
    flex: 1 1 100%;
    order: -1;
  }

  .accounting-share-row .btn {
    flex: 1 1 auto;
  }
}

/* Floating reload button (bottom-right) on every page */
.fab-btn {
  position: fixed;
  z-index: 1040;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background-color: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  color: var(--brand-green-dark);
  cursor: pointer;
  padding: 0;
  transition: background-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.fab-btn svg {
  width: 20px;
  height: 20px;
}

.fab-btn:hover,
.fab-btn:focus {
  background-color: var(--brand-green-light);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  color: var(--brand-green-dark);
  transform: translateY(-1px);
}

.fab-reload {
  bottom: 16px;
  right: 16px;
}

@media (max-width: 576px) {
  .fab-btn {
    width: 40px;
    height: 40px;
  }

  .fab-btn svg {
    width: 18px;
    height: 18px;
  }

  .fab-reload {
    /* Sits above the fixed bottom tab bar (.navbar-actions) instead of at
       the very bottom edge, so the two don't overlap. */
    bottom: calc(var(--mobile-tabbar-height) + env(safe-area-inset-bottom) + 10px);
    right: 10px;
  }
}

/* Back button, inline in the navbar next to the "EBill" brand (top-left of the page) */
.nav-back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background-color: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  color: var(--brand-green-dark);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.nav-back-btn svg {
  width: 18px;
  height: 18px;
}

.nav-back-btn:hover,
.nav-back-btn:focus {
  background-color: var(--brand-green-light);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

/* Logout icon button - icon only, no text label, at every breakpoint. On
   desktop it sits at the far right of the nav-links group (see
   .navbar-actions' margin-left: auto above); on mobile it's reordered to
   sit next to the brand instead (see the mobile override below). */
.nav-logout-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-orange) 0%, var(--brand-orange-dark) 100%);
  color: var(--brand-white) !important;
  box-shadow: 0 2px 8px rgba(217, 99, 31, 0.4);
  flex-shrink: 0;
}

.nav-logout-icon-btn svg {
  width: 18px;
  height: 18px;
}

.nav-logout-icon-btn:hover,
.nav-logout-icon-btn:focus {
  background: linear-gradient(135deg, var(--brand-orange-dark) 0%, var(--brand-orange-dark) 100%);
  color: var(--brand-white) !important;
}

.accounting-share-row {
  max-width: 640px;
}

.accounting-share-row #accountingShareLink {
  min-width: 0;
  flex: 1 1 260px;
  font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.8rem;
}

/* Print */
.print-only {
  display: none;
}

@media print {
  header, footer, .no-print {
    display: none !important;
  }

  .print-only {
    display: inline !important;
  }

  html {
    font-size: 11px;
  }

  body {
    background: #fff !important;
  }

  .container {
    width: 100% !important;
    max-width: 100% !important;
  }

  .form-card {
    box-shadow: none !important;
    border: 1px solid #ddd;
    padding: 1rem !important;
    border-radius: 0 !important;
  }

  .table-responsive {
    overflow: visible !important;
  }

  .table th,
  .table td {
    padding: 0.35rem 0.5rem !important;
    white-space: normal !important;
  }

  /* Bootstrap's col-md-6 only goes side-by-side above a 768px viewport, which
     print previews don't satisfy, so force the two-column layout explicitly. */
  .row {
    display: flex !important;
    flex-wrap: wrap !important;
  }

  .row > .col-md-6 {
    flex: 0 0 50% !important;
    max-width: 50% !important;
  }

  /* text-md-end (Bill To) relies on the same 768px breakpoint check, which the
     print page box doesn't reliably satisfy, so force it explicitly here. */
  .text-md-end {
    text-align: right !important;
  }

  .invoice-top-row {
    align-items: flex-start !important;
  }

  /* A non-zero @page margin leaves Chrome/Edge room to print their own
     header/footer (page title, URL, date, page number). Set it to 0 so
     nothing prints there, and restore the spacing as body padding instead. */
  @page {
    size: auto;
    margin: 0;
  }

  body {
    padding: 12mm !important;
  }
}

/* Number inputs without the browser's up/down spinner arrows. */
input.no-spinner::-webkit-outer-spin-button,
input.no-spinner::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input.no-spinner[type=number] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* Invoice footprint: editor + printed footer */
.footprint-toolbar .fp-btn { min-width: 36px; }
#footprintEditor:focus { outline: 0; border-color: #86b7fe; box-shadow: 0 0 0 .25rem rgba(13,110,253,.25); }
#footprintEditor p { margin-bottom: .5rem; }
.invoice-footprint { max-width: 45%; font-size: .75rem; line-height: 1.4; }
.invoice-footprint p { margin-bottom: .25rem; }
.invoice-footprint ul, .invoice-footprint ol { padding-left: 1.1rem; margin-bottom: .25rem; }
#footprintEditor:empty::before { content: "e.g. Thank you for your business. Payment due within 15 days."; color: #6c757d; }
#footprintEditor .fp-sm, .invoice-footprint .fp-sm { font-size: .8em; }
#footprintEditor .fp-lg, .invoice-footprint .fp-lg { font-size: 1.3em; }
#footprintEditor .fp-xl, .invoice-footprint .fp-xl { font-size: 1.7em; }

/* Post-login selection cards (Ledger / Invoice) */
.dash-wrap { max-width: 640px; margin: 2rem auto; text-align: center; }
.dash-title { font-size: 1.25rem; font-weight: 600; margin-bottom: 1.5rem; }
.dash-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.dash-card {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .75rem;
    padding: 2rem 1rem; background: #fff; border: 1px solid #dee2e6; border-radius: 1rem;
    color: #212529; text-decoration: none; box-shadow: 0 2px 8px rgba(0,0,0,.06);
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.dash-card:hover, .dash-card:focus-visible { transform: translateY(-3px); border-color: #1f8a53; box-shadow: 0 6px 16px rgba(31,138,83,.18); color: #1f8a53; }
.dash-icon { width: 64px; height: 64px; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: #e8f5ee; color: #1f8a53; }
.dash-icon svg { width: 34px; height: 34px; }
.dash-name { font-size: 1.15rem; font-weight: 600; }

/* ---- Ledger pages + general mobile polish ---- */
.ledger-big { font-size: 2.25rem; line-height: 1.2; }
.ledger-date-form .form-control { min-width: 0; }
img, iframe, video { max-width: 100%; }

@media (max-width: 576px) {
  /* iOS zooms the page when a focused input has a font size under 16px. */
  .form-control, .form-select, .form-control-sm, .form-select-sm {
    font-size: 16px;
  }

  /* Non-admin users have no header; their logout icon is pinned top-right, so keep
     page content clear of it. */
  main.has-fixed-logout {
    padding-top: 2.75rem;
  }

  /* Total / Credited / Debited cards: Total Balance on its own full-width row, the
     other two side by side. */
  .ledger-stats {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem !important;
    width: 100%;
  }

  .ledger-stats > .form-card {
    min-width: 0;
    padding: 0.6rem 0.75rem !important;
  }

  .ledger-stats .ledger-stat--main {
    grid-column: 1 / -1;
  }

  .ledger-stats .fs-4 {
    font-size: 1.1rem !important;
  }

  .ledger-stats .ledger-stat--main .fs-4,
  .ledger-stats .ledger-big {
    font-size: 1.75rem !important;
  }

  /* Calculation page: date filter and Calculate buttons use the full width. */
  .ledger-date-form {
    width: 100%;
  }

  .ledger-date-form > div {
    flex: 1 1 100%;
  }

  .ledger-toolbar > form {
    width: 100%;
  }

  /* Today's Ledger / Ledger Pending tabs scroll sideways instead of wrapping. */
  .nav-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .nav-tabs .nav-link {
    padding: 0.5rem 0.75rem;
  }

  /* Ledger search box + admin button */
  .input-group {
    max-width: 100% !important;
  }

  /* Tap-friendly small buttons in tables */
  .table .btn-sm {
    padding: 0.35rem 0.6rem;
  }

  /* Settings user table: keep the Delete button from wrapping */
  .table-sm td .btn {
    white-space: nowrap;
  }
}

@media (max-width: 360px) {
  .dash-cards {
    grid-template-columns: 1fr;
  }

  .dash-wrap {
    margin: 1rem auto;
  }
}
