/* =====================================================================
   Global polish (Option 1 light facelift)
   Subtle improvements layered on top of Bootstrap defaults.
   ===================================================================== */

/* Modern system font stack — slightly tighter and more refined than
   Bootstrap's default; available on Windows / macOS / Linux out of the box. */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  color: #1f2937;
}

/* Soft gradient background app-wide (overrides Bootstrap's bg-light flat color). */
body.bg-light {
  background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%) !important;
  min-height: 100vh;
}

/* Navbar: slightly more breathing room and a subtle shadow. */
.navbar-dark.bg-dark {
  background: #1a202c !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Page headings: less heavy weight, more comfortable size. */
main h2 {
  font-weight: 600;
  letter-spacing: -0.01em;
  color: #111827;
}

/* Cards: softer corners, more subtle shadow, no harsh border. */
.card {
  border: none;
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
}
.card .card-header {
  background: #fafbfc;
  border-bottom: 1px solid #eef0f3;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  font-weight: 600;
  color: #374151;
}
.card .card-footer {
  background: #fafbfc;
  border-top: 1px solid #eef0f3;
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
}

/* Buttons: a bit more weight + nicer hover. */
.btn {
  font-weight: 500;
  border-radius: 8px;
  transition: transform 0.05s ease, box-shadow 0.15s ease;
}
.btn-primary {
  background: #2563eb;
  border-color: #2563eb;
}
.btn-primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}
.btn:active {
  transform: translateY(1px);
}

/* Form controls: slightly more height, softer focus ring. */
.form-control, .form-select {
  border-radius: 8px;
  border-color: #d1d5db;
  transition: border-color 0.1s ease, box-shadow 0.1s ease;
}
.form-control:focus, .form-select:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Tables: cleaner row dividers, no heavy borders. */
.table {
  --bs-table-border-color: #eef0f3;
}
.table thead th {
  font-weight: 600;
  color: #4b5563;
  font-size: 0.875rem;
  letter-spacing: 0.02em;
  text-transform: none;
  background: #fafbfc;
}

/* Alerts: gentler color palette. */
.alert {
  border-radius: 10px;
  border: 1px solid transparent;
}
.alert-info {
  background: #eff6ff;
  border-color: #dbeafe;
  color: #1e40af;
}
.alert-success {
  background: #ecfdf5;
  border-color: #d1fae5;
  color: #065f46;
}
.alert-warning {
  background: #fffbeb;
  border-color: #fef3c7;
  color: #92400e;
}
.alert-danger {
  background: #fef2f2;
  border-color: #fee2e2;
  color: #991b1b;
}

/* Status badges: keep existing colors but use the new font. */
.status-pill {
  font-weight: 600;
  border-radius: 999px;
}

/* Subtle link hover. */
a {
  color: #2563eb;
  text-decoration: none;
}
a:hover {
  color: #1d4ed8;
  text-decoration: underline;
}

/* Custom styles on top of Bootstrap. */
.status-pill {
  font-size: 0.75rem;
  padding: 0.25em 0.6em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.status-draft     { background:#6c757d; color:#fff; }
.status-submitted { background:#0d6efd; color:#fff; }
.status-exported  { background:#6610f2; color:#fff; }
.status-posted    { background:#198754; color:#fff; }
.status-rejected  { background:#dc3545; color:#fff; }

table.lines tbody tr.line-row td { vertical-align: middle; }
table.lines tfoot td { font-weight: 600; }

.csv-preview {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  white-space: pre;
  background: #f4f4f8;
  padding: 1rem;
  border-radius: 0.4rem;
  overflow-x: auto;
}

.receipt-thumb {
  max-height: 60px;
  border-radius: 4px;
  border: 1px solid #ddd;
}

/* Visually-readonly select (used for the GL dropdown when a Job is picked).
   <select readonly> isn't a thing, so we mimic it: grey background, no
   pointer events, no keyboard focus. The value still submits with the form. */
select.gl-readonly,
select.gl-readonly:focus {
  background-color: #e9ecef;
  pointer-events: none;
  border-color: #ced4da;
  color: #495057;
  cursor: not-allowed;
}

/* Auto-fill indicator: GL was populated from the selected Category. Subtle
   left border + a small hint text below the dropdown. */
.gl-auto-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.gl-auto-hint {
  font-size: 0.7rem;
  color: #198754;
  line-height: 1;
  visibility: hidden;
  user-select: none;
}
.gl-auto-hint.visible { visibility: visible; }
.gl-auto-hint::before { content: "✓ "; }

/* Fallback warning shown when neither the Category nor the Cost Code has a
   Cost_Account set in Sage. GL field unlocks so the user isn't stuck, but
   this warning makes the situation explicit. AP should fix the Sage data. */
.gl-fallback-warn {
  font-size: 0.7rem;
  color: #b54708;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 3px;
  padding: 2px 5px;
  line-height: 1.2;
  display: none;
}
.gl-fallback-warn.visible { display: block; }

/* Form-validation feedback (Bootstrap-style red border on invalid inputs
   after the user has tried to submit). */
.was-validated .form-control:invalid,
.was-validated .form-select:invalid,
.was-validated select.gl-readonly:invalid {
  border-color: #dc3545;
  box-shadow: 0 0 0 0.15rem rgba(220, 53, 69, 0.18);
}
.validation-error-banner {
  display: none;
  margin-bottom: 0.75rem;
}
.was-validated .validation-error-banner.has-errors { display: block; }


/* =====================================================================
   MOBILE: convert the line-items table into a stacked card view
   ===================================================================== */
@media (max-width: 767.98px) {
  /* Tighten outer card padding so cells use the full width */
  .card-body { padding: 0.75rem; }

  /* Hide the column headers; we'll show per-field labels via ::before */
  table.lines thead { display: none; }

  /* Each line row becomes a self-contained card */
  table.lines,
  table.lines tbody,
  table.lines tr,
  table.lines td {
    display: block;
    width: 100%;
  }
  table.lines tr.line-row {
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem 0.75rem;
    background: #fff;
    position: relative;
  }
  /* Drop the original cell borders; we have a card border */
  table.lines td {
    border: none !important;
    padding: 0.4rem 0;
  }
  /* Inject the column label above each field on mobile */
  table.lines td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.15rem;
  }
  /* Bigger touch targets — inputs/selects 44px tall min */
  table.lines td .form-control,
  table.lines td .form-select {
    min-height: 44px;
    font-size: 1rem;
  }
  /* Remove button: absolute-positioned in the top-right of the card */
  table.lines td:last-child {
    position: absolute;
    top: 0.4rem;
    right: 0.5rem;
    padding: 0;
    width: auto;
  }
  table.lines td:last-child::before { display: none; }
  table.lines td:last-child .remove-line {
    min-width: 36px;
    min-height: 36px;
  }
  /* GL auto-hint stays useful on mobile */
  .gl-auto-wrap { display: flex; flex-direction: column; gap: 4px; }

  /* Footer total: own line, big and clear */
  table.lines tfoot tr {
    background: #f8f9fa;
    border-radius: 0.5rem;
    padding: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
  }
  table.lines tfoot td { padding: 0; border: none; }

  /* Form action buttons stack and go full-width on mobile */
  form .d-flex.justify-content-between { flex-direction: column; gap: 0.5rem; }
  form .d-flex.justify-content-between > div { display: flex; flex-direction: column; gap: 0.5rem; }
  form .d-flex.justify-content-between > div .btn { width: 100%; }

  /* Add-line button: full-width, more prominent */
  #addLineBtn { width: 100%; padding: 0.6rem; font-size: 1rem; }

  /* "My Reports" list and AP queue: keep horizontal scroll behavior on
     the wrapped table so the user can swipe to see all columns. The Edit
     button stays right-aligned and tappable. */
  .table-responsive table { font-size: 0.9rem; }
  .table-responsive table .btn { white-space: nowrap; }

  /* Detail screens (view_report, ap_review): dl horizontal pairs stack */
  dl.row dt { margin-bottom: 0; }
  dl.row dd { margin-bottom: 0.5rem; }

  /* Page headings: lighter and stack the right-side button group below */
  main h2 { font-size: 1.4rem; }
  main > div.d-flex.justify-content-between.align-items-center {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.5rem;
  }
}
