/* app.css — CRC Billing shared styles. Calm, precise "ledger" look. */

/* Remove number input spinners */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type=number] { -moz-appearance: textfield; }
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #14202c;
  --muted: #647387;
  --line: #e4e9ee;
  --line-strong: #d3dbe3;
  --accent: #235a97;
  --accent-ink: #1a4779;
  --accent-soft: #eaf1f9;
  --pos: #1f7a43;   /* they owe us / in stock */
  --neg: #bb2d2d;   /* we owe them / negative */
  --shadow: 0 1px 2px rgba(16,24,40,.06);
  --radius: 11px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 15px; line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
.num { font-variant-numeric: tabular-nums; }

/* ---- Header / nav ---- */
header.nav {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.nav-inner {
  max-width: 880px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 18px; height: 56px;
}
.brand {
  font-weight: 680; letter-spacing: -.01em; font-size: 16px;
  color: var(--ink); text-decoration: none; white-space: nowrap;
  display: flex; align-items: center; gap: 8px;
}
.brand .mark {
  width: 22px; height: 22px; border-radius: 5px;
  background: linear-gradient(150deg, var(--accent), #3b78b8);
}
.nav-links { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; }
.nav-links a {
  text-decoration: none; color: var(--muted); font-size: 14px; font-weight: 550;
  padding: 7px 11px; border-radius: 8px; white-space: nowrap;
}
.nav-links a:hover { background: var(--bg); color: var(--ink); }
.nav-links a.active { background: var(--accent-soft); color: var(--accent-ink); }
.nav-badge {
  display:inline-flex; align-items:center; justify-content:center;
  min-width:16px; height:16px; padding:0 4px; margin-left:5px;
  border-radius:999px; background:var(--neg); color:#fff;
  font-size:10px; font-weight:700; line-height:1; vertical-align:middle;
}

/* ---- Page ---- */
main { max-width: 880px; margin: 0 auto; padding: 22px 16px 80px; }
.page-head {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.page-head h1 { font-size: 20px; font-weight: 680; letter-spacing: -.02em; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 13px; }
.spacer { margin-left: auto; }

/* ---- Filter chips ---- */
.chips { display: flex; gap: 6px; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--muted); font-size: 13px; font-weight: 550;
  padding: 6px 13px; border-radius: 999px; cursor: pointer;
}
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---- List rows ---- */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 13px 15px; display: flex; align-items: center; gap: 12px;
  cursor: pointer;
}
.row:hover { border-color: var(--line-strong); }
/* Keyboard row navigation (item 8: Up/Down + Enter + Escape) */
.kb-highlight { outline: 2px solid var(--accent) !important; background: var(--accent-soft) !important; }
.row .main { min-width: 0; }
.row .name { font-weight: 600; letter-spacing: -.01em; }
.row .meta { color: var(--muted); font-size: 12.5px; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .right { margin-left: auto; text-align: right; white-space: nowrap; }
.row .amt { font-weight: 640; }
.row .amt.pos { color: var(--pos); }
.row .amt.neg { color: var(--neg); }
.row .amt.zero { color: var(--muted); }
.row .tag { color: var(--muted); font-size: 11.5px; margin-top: 2px; }

.empty {
  text-align: center; color: var(--muted); padding: 48px 20px;
  border: 1px dashed var(--line-strong); border-radius: var(--radius);
  background: var(--surface);
}
.empty b { color: var(--ink); display: block; margin-bottom: 4px; font-weight: 600; }

/* ---- Buttons ---- */
.btn {
  font: inherit; font-weight: 600; font-size: 14px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  padding: 9px 15px; border-radius: 9px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.danger { color: var(--neg); border-color: #e9cccc; }
.btn.danger:hover { background: #fbf0f0; }

/* ---- Dialog / form ---- */
dialog {
  border: none; border-radius: 14px; padding: 0; width: min(460px, calc(100vw - 24px));
  box-shadow: 0 18px 50px rgba(16,24,40,.22); color: var(--ink);
}
dialog::backdrop { background: rgba(16,24,40,.42); }
.dlg-head { padding: 18px 20px 0; }
.dlg-head h2 { margin: 0; font-size: 17px; font-weight: 680; letter-spacing: -.01em; }
form.body { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 13px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  font: inherit; padding: 10px 11px; border: 1px solid var(--line-strong);
  border-radius: 9px; background: #fff; color: var(--ink); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent-soft); border-color: var(--accent);
}
.field textarea { resize: vertical; min-height: 52px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.dlg-foot .spacer { margin-left: 0; margin-right: auto; }
.err { color: var(--neg); font-size: 13px; min-height: 0; }

/* ---- Inline field validation ---- */
.field label .req { color: var(--neg); margin-left: 2px; }
.field.invalid input, .field.invalid select, .field.invalid textarea {
  border-color: var(--neg); background: #fff5f5;
}
.field.valid input, .field.valid select, .field.valid textarea {
  border-color: var(--pos);
}
.field-error {
  display: none; color: var(--neg); font-size: 12px; margin-top: -1px;
}
.field.invalid .field-error { display: block; }
.field-check {
  display: none; color: var(--pos); font-size: 12px; font-weight: 700;
}
.field.valid .field-check { display: inline; }

/* ---- Skeleton loading placeholders ---- */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
  height: 20px;
  margin: 4px 0;
}
.skeleton-row { display: flex; gap: 10px; align-items: center; padding: 13px 15px; }
.skeleton-row .skeleton { flex: 1; }
.skeleton-row .skeleton.short { flex: 0 0 60px; }
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---- Dashboard cards ---- */
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.stat .k { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }

/* ---- Toast (stacked, typed: success / error / warning / info) ---- */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 16px;
  border-radius: 8px;
  color: white;
  font-size: 14px;
  min-width: 250px;
  max-width: 350px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  animation: slideIn 0.3s ease;
}
.toast.toast-out { animation: slideOut 0.25s ease forwards; }
.toast.success { background: #16a34a; }
.toast.error { background: #dc2626; }
.toast.warning { background: #d97706; }
.toast.info { background: #2563eb; }
.toast-icon { flex: none; font-weight: 700; }
.toast-msg  { flex: 1; line-height: 1.4; }
.toast-close {
  flex: none; background: none; border: none; color: #fff; opacity: .8;
  cursor: pointer; font-size: 16px; line-height: 1; padding: 0;
}
.toast-close:hover { opacity: 1; }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOut {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

/* ---- Mobile-friendly tables (Phase 2, item 8) ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; position: relative; }
.table-wrap.scrollable::after {
  content: '\2190 scroll \2192';
  display: block; text-align: center; font-size: 11px; color: var(--muted);
  padding: 4px 0 0;
}

/* ---- Mobile ---- */
@media (max-width: 560px) {
  body { font-size: 16px; }
  .cards { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .nav-inner { gap: 10px; }
  .row { padding: 14px; }
  .btn { padding: 11px 16px; }   /* bigger tap targets on phones */

  /* Title + action buttons wrap onto their own row instead of clipping */
  .page-head { flex-wrap: wrap; }
  .page-head .spacer { flex-basis: 100%; height: 0; margin: 0; }

  /* Filter chip rows scroll horizontally instead of overflowing the page */
  .chips { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  .chips .chip { flex: none; white-space: nowrap; }
}

/* ---- Mobile — larger tap targets (Phase 2) ---- */
@media (max-width: 768px) {
  /* Larger buttons */
  button, .btn, .chip {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 16px;
    font-size: 15px;
  }

  /* Larger input fields */
  input, select, textarea {
    min-height: 44px;
    font-size: 16px; /* prevents iOS zoom on focus */
    padding: 10px 12px;
  }

  /* Larger table rows */
  td, th {
    padding: 12px 8px;
    font-size: 14px;
  }

  /* Full width cards */
  .card, .panel {
    margin: 8px 0;
    border-radius: 8px;
  }

  /* Bigger badge text */
  .badge, .k-badge {
    font-size: 12px;
    padding: 4px 8px;
  }

  /* Stack form rows vertically */
  .form-row {
    flex-direction: column;
  }

  /* Full width dialogs */
  dialog, .dlg {
    width: 95vw;
    max-width: 95vw;
    margin: 10px auto;
    max-height: 90vh;
    overflow-y: auto;
  }
}

/* ---- Print (global — applies on every page) ---- */
@media print {
  .no-print, header.nav, .fab, .btn-actions, .quick-actions,
  .bottom-nav, .search-overlay, #global-search-btn, #theme-toggle-btn { display: none !important; }
  body { font-size: 11px; color: #000; background: #fff; }
  table { border-collapse: collapse; width: 100%; }
  td, th { border: 1px solid #ccc; padding: 6px; }
  .page-break { page-break-after: always; }
  a { text-decoration: none; color: #000; }
}

/* ---- Dark mode ---- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --ink: #f1f5f9;
    --muted: #94a3b8;
    --line: #334155;
    --line-strong: #475569;
    --accent: #3b82f6;
    --accent-ink: #93c5fd;
    --accent-soft: #1e3a5f;
  }
}
body.dark {
  --bg: #0f172a;
  --surface: #1e293b;
  --ink: #f1f5f9;
  --muted: #94a3b8;
  --line: #334155;
  --line-strong: #475569;
  --accent: #3b82f6;
  --accent-ink: #93c5fd;
  --accent-soft: #1e3a5f;
}
/* Explicit light override — wins even when the OS prefers dark */
body.light {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #14202c;
  --muted: #647387;
  --line: #e4e9ee;
  --line-strong: #d3dbe3;
  --accent: #235a97;
  --accent-ink: #1a4779;
  --accent-soft: #eaf1f9;
}
