/* styles.css — Custom design layer on top of Tailwind (CDN, no build step,
   so this file is written in plain CSS rather than @apply). */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Playfair+Display:ital,wght@1,500&display=swap');

:root {
  --wg-navy: #10172a;
  --wg-navy-light: #1b2540;
  --wg-indigo: #4338ca;
  --wg-amber: #b45309;
  --wg-bg: #f6f7fb;
}

html, body { font-family: 'Inter', system-ui, sans-serif; background: var(--wg-bg); }
.font-signature { font-family: 'Playfair Display', serif; }

/* ---------- Layout ---------- */
#sidebar {
  background: linear-gradient(180deg, var(--wg-navy) 0%, var(--wg-navy-light) 100%);
}

.sidebar-link {
  width: 100%; display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 0.75rem; border-radius: 0.5rem;
  font-size: 0.875rem; font-weight: 500; color: #cbd5e1;
  background: transparent; border: none; cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
.sidebar-link:hover { background: rgba(255,255,255,0.1); color: #fff; }
.sidebar-link[data-active="true"] { background: rgba(255,255,255,0.15); color: #fff; }

/* ---------- Cards & form controls ---------- */
.card {
  background: #fff; border-radius: 1rem; border: 1px solid #f1f5f9;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04); padding: 1.25rem;
}
.card-title {
  font-size: 0.8rem; font-weight: 600; color: #1e293b; margin-bottom: 0.75rem;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.field-label {
  display: block; font-size: 0.72rem; font-weight: 500; color: #64748b; margin-bottom: 0.25rem;
}
.input {
  width: 100%; border-radius: 0.5rem; border: 1px solid #e2e8f0;
  padding: 0.5rem 0.75rem; font-size: 0.875rem; color: #1e293b; background: #fff;
  transition: box-shadow .15s ease, border-color .15s ease;
}
.input:focus { outline: none; border-color: #818cf8; box-shadow: 0 0 0 3px rgba(99,102,241,0.18); }
.input-sm {
  width: 100%; border-radius: 0.375rem; border: 1px solid #e2e8f0;
  padding: 0.35rem 0.5rem; font-size: 0.875rem;
}
.input-sm:focus { outline: none; box-shadow: 0 0 0 3px rgba(99,102,241,0.18); }

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  background: #4f46e5; color: #fff; font-size: 0.875rem; font-weight: 600;
  padding: 0.6rem 1rem; border-radius: 0.5rem; border: none; cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06); transition: background-color .15s ease, transform .1s ease;
}
.btn-primary:hover { background: #4338ca; }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  background: #fff; color: #334155; font-size: 0.85rem; font-weight: 500;
  padding: 0.6rem 1rem; border-radius: 0.5rem; border: 1px solid #e2e8f0; cursor: pointer;
  transition: background-color .15s ease, transform .1s ease;
}
.btn-secondary:hover { background: #f8fafc; }
.btn-secondary:active { transform: scale(0.98); }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  padding: 0.3rem 0.4rem; border-radius: 0.375rem; color: #64748b; background: transparent; border: none; cursor: pointer;
}
.icon-btn:hover { background: #f1f5f9; }

/* ---------- Loading skeleton ---------- */
.skeleton { background: #e2e8f0; border-radius: 0.5rem; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }

/* ---------- Toasts ---------- */
#toast-host { position: fixed; bottom: 1.25rem; right: 1.25rem; z-index: 200; display: flex; flex-direction: column; gap: 0.5rem; }
.toast-item { opacity: 0; transform: translateY(8px); transition: all .25s ease; }
.toast-show { opacity: 1; transform: translateY(0); }

/* ---------- Dialog pop animation ---------- */
@keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
.anim-pop { animation: pop .18s ease-out; }

/* ---------- A4 invoice sheet ---------- */
.a4-sheet {
  width: 794px;
  min-height: 1123px;
  background: #fff;
  padding: 32px 40px;
  margin: 0 auto;
  color: #1e293b;
  box-sizing: border-box;
}
.b-cell { border: 1px solid #cbd5e1; padding: 6px 8px; }

/* ---------- Dark mode ---------- */
.dark body { background: #0b1120; }
.dark .card { background: #0f172a; border-color: #1e293b; }
.dark .card-title { color: #e2e8f0; }
.dark .input, .dark .input-sm { background: #1e293b; border-color: #334155; color: #e2e8f0; }
.dark .btn-secondary { background: #1e293b; border-color: #334155; color: #e2e8f0; }
.dark .btn-secondary:hover { background: #273449; }
.dark table { color: #cbd5e1; }
.dark #page-root, .dark main { color: #e2e8f0; }
.dark .field-label { color: #94a3b8; }

/* ---------- Print ---------- */
@media print {
  body * { visibility: hidden; }
  .a4-sheet, .a4-sheet * { visibility: visible; }
  .a4-sheet { position: absolute; left: 0; top: 0; width: 100%; box-shadow: none; }
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }

/* =====================================================================
   MOBILE LAYER — the app is operated mostly from a phone, so every
   data-entry surface has to work at ~380px without pinch-zooming.
   ===================================================================== */

/* Phones auto-zoom into any focused control whose font is under 16px, which
   shifts the whole layout mid-typing. Keep controls at 16px on small screens. */
@media (max-width: 1023px) {
  .input, .input-sm, input, select, textarea { font-size: 16px; }
  .input { padding: 0.6rem 0.75rem; border-radius: 0.6rem; }
  .input-sm { padding: 0.55rem 0.6rem; border-radius: 0.6rem; }
  .btn-primary, .btn-secondary { min-height: 44px; padding: 0.65rem 1rem; }
  .icon-btn { min-width: 40px; min-height: 40px; font-size: 1.05rem; }
  .card { padding: 0.9rem; border-radius: 0.85rem; }
  .field-label { font-size: 0.78rem; }
}

/* Wide read-only tables keep their natural width and scroll sideways rather
   than crushing every column into an unreadable sliver. */
@media (max-width: 767px) {
  .overflow-x-auto > table:not(.rtable) { min-width: 620px; }
}

/* ---------- .rtable — list table that becomes a card stack on phones ------- */
@media (max-width: 767px) {
  table.rtable, table.rtable tbody, table.rtable tr, table.rtable td { display: block; width: 100%; }
  table.rtable thead { display: none; }
  table.rtable tr {
    border: 1px solid #e2e8f0; border-radius: 0.75rem;
    padding: 0.6rem 0.8rem; margin-bottom: 0.6rem; background: #fff;
  }
  table.rtable td {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    border: 0; padding: 0.3rem 0 !important; text-align: right !important;
  }
  table.rtable td::before {
    content: attr(data-label);
    font-size: 0.68rem; font-weight: 600; letter-spacing: 0.04em;
    text-transform: uppercase; color: #94a3b8; text-align: left; flex: none;
  }
  table.rtable td[data-label=""]::before { content: none; }
  table.rtable td.rt-primary { font-size: 1rem; font-weight: 700; }
  table.rtable td.rt-actions { justify-content: flex-end; gap: 0.25rem; padding-top: 0.5rem !important; margin-top: 0.35rem; border-top: 1px solid #f1f5f9 !important; }
}

/* ---------- Line items — cards on phone, table-like grid on desktop -------- */
.items-head { display: none; }
.item-row {
  position: relative;
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.55rem 0.6rem;
  border: 1px solid #e2e8f0; border-radius: 0.8rem;
  padding: 0.7rem 0.75rem; margin-bottom: 0.65rem; background: #fff;
}
.item-row .cell { min-width: 0; }
.item-row .cell-head { grid-column: 1 / -1; padding-right: 2.25rem; }
.item-row .cell-prod, .item-row .cell-gd { grid-column: 1 / -1; }
.item-row .cell-del { position: absolute; top: 0.45rem; right: 0.5rem; }
.item-idx { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: #94a3b8; }
.cell-label {
  display: block; font-size: 0.68rem; font-weight: 600; letter-spacing: 0.03em;
  text-transform: uppercase; color: #94a3b8; margin-bottom: 0.22rem;
}
.item-row .d-amt { display: block; padding: 0.5rem 0 0; font-weight: 700; font-size: 1rem; color: #0f172a; }

@media (min-width: 1024px) {
  .items-head {
    display: grid; gap: 0.5rem; padding: 0 0.5rem 0.45rem;
    font-size: 0.68rem; font-weight: 600; letter-spacing: 0.04em;
    text-transform: uppercase; color: #94a3b8; border-bottom: 1px solid #e2e8f0;
  }
  .item-row {
    display: grid; gap: 0.5rem; align-items: center;
    border: 0; border-bottom: 1px solid #f1f5f9; border-radius: 0;
    padding: 0.45rem 0.5rem; margin: 0; background: transparent;
  }
  .item-row .cell-head, .cell-label { display: none; }
  .item-row .cell-prod, .item-row .cell-gd { grid-column: auto; }
  .item-row .cell-del { position: static; text-align: right; }
  .item-row .d-amt { padding: 0; font-size: 0.875rem; font-weight: 600; }
  .items-head .h-qty, .items-head .h-rate, .items-head .h-gst, .items-head .h-amt { text-align: right; }
  .item-row .cell-amt { text-align: right; }
  .items-wrap[data-gd="1"] .items-head,
  .items-wrap[data-gd="1"] .item-row { grid-template-columns: minmax(0,2.6fr) minmax(0,1.3fr) 82px 108px 82px 116px 36px; }
  .items-wrap[data-gd="0"] .items-head,
  .items-wrap[data-gd="0"] .item-row { grid-template-columns: minmax(0,3fr) 82px 108px 82px 116px 36px; }
}

/* ---------- Sticky save bar (phone only) ---------- */
.save-bar {
  position: sticky; bottom: 0; z-index: 40;
  display: flex; align-items: center; gap: 0.75rem;
  margin-top: 0.9rem; padding: 0.7rem 0.85rem;
  background: rgba(255,255,255,0.97);
  border: 1px solid #e2e8f0; border-radius: 0.9rem;
  box-shadow: 0 -6px 18px rgba(15,23,42,0.08);
}
.save-bar .sb-label { font-size: 0.68rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: #94a3b8; display: block; }
.save-bar .sb-total { font-size: 1.15rem; font-weight: 800; color: #0f172a; }
.save-bar .btn-primary { margin-left: auto; }

/* ---------- Search picker menu: thumb-friendly rows ---------- */
.ps-menu { max-height: 52vh; }
@media (max-width: 1023px) {
  .ps-menu button { padding: 0.7rem 0.85rem; font-size: 0.9rem; }
}

/* ---------- A4 preview sheet scales down instead of overflowing ---------- */
@media (max-width: 900px) {
  .a4-sheet { width: 100%; min-height: 0; padding: 18px 14px; }
}

/* ---------- Dark mode for the new surfaces ---------- */
.dark .item-row { background: #0f172a; border-color: #1e293b; }
.dark .item-row .d-amt { color: #e2e8f0; }
.dark table.rtable tr { background: #0f172a; border-color: #1e293b; }
.dark .save-bar { background: rgba(15,23,42,0.97); border-color: #1e293b; }
.dark .save-bar .sb-total { color: #e2e8f0; }
.dark .ps-menu { background: #0f172a; border-color: #1e293b; color: #e2e8f0; }
