/* ===== Event Rental Manager — offline app styles ===== */
:root {
  --bg: #f4f6f9;
  --bg2: #ffffff;
  --bg3: #e9edf2;
  --border: #d5dce4;
  --text: #1d2633;
  --muted: #64748b;
  --accent: #e8921a;
  --accent-dim: #c47a10;
  --green: #1f9d55;
  --red: #d64545;
  --blue: #2b6cb0;
  --purple: #7450c8;
  --radius: 10px;
  --shadow: 0 8px 28px rgba(15,23,42,.14);
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
}
h1, h2, h3 { margin: 0 0 .5em; font-weight: 650; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- layout ---- */
#app { max-width: 1240px; margin: 0 auto; padding: 0 18px 40px; }
#topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 0 12px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 50;
  flex-wrap: nowrap;   /* nav never wraps — it compacts, then collapses to the drawer */
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex-shrink: 1; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #e2641e);
  color: #14100a; font-weight: 800; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: .5px;
}
.brand-name { font-weight: 700; font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#nav { display: flex; gap: 2px; flex: 1; flex-wrap: nowrap; min-width: 0; justify-content: center; }
#nav button {
  background: none; border: none; color: var(--muted);
  padding: 8px 9px; border-radius: 8px; cursor: pointer;
  font-size: .88rem; font-weight: 550; font-family: inherit;
  white-space: nowrap;
}
#nav button:hover { background: var(--bg3); color: var(--text); }
#nav button.active { background: var(--bg3); color: var(--accent); }
.topbar-right { display: flex; gap: 8px; }
#page { padding-top: 20px; min-height: 60vh; }
#appfooter { color: var(--muted); font-size: .75rem; padding: 26px 0 8px; border-top: 1px solid var(--border); margin-top: 32px; }

.banner {
  background: #fff6de; border: 1px solid #e8cf8a; color: #7a5b00;
  padding: 9px 14px; border-radius: 8px; margin-top: 12px; font-size: .86rem;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.banner .btn { flex-shrink: 0; }
.hidden { display: none !important; }

/* ---- page chrome ---- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- cards / KPIs ---- */
.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px;
}
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px;
}
.kpi .kpi-label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi .kpi-value { font-size: 1.35rem; font-weight: 700; margin-top: 2px; }
.kpi .kpi-sub { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.kpi.accent .kpi-value { color: var(--accent); }
.kpi.green .kpi-value { color: var(--green); }
.kpi.red .kpi-value { color: var(--red); }
.kpi.blue .kpi-value { color: var(--blue); }

/* ---- buttons ---- */
.btn {
  background: var(--bg3); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 14px; font-size: .88rem; font-weight: 550;
  cursor: pointer; font-family: inherit; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #14100a; }
.btn-primary:hover { background: #ffb739; border-color: #ffb739; }
.btn-danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: rgba(224,92,92,.12); }
.btn-green { background: var(--green); border-color: var(--green); color: #0a1a10; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: .8rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
button { font-family: inherit; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg2); }
table.data { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.data th {
  text-align: left; padding: 10px 12px; color: var(--muted); font-weight: 600;
  font-size: .74rem; text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border); background: var(--bg3);
  white-space: nowrap;
}
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: rgba(15,23,42,.035); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tfoot td { font-weight: 700; background: var(--bg3); }
.muted { color: var(--muted); }
.small { font-size: .78rem; }
.strong { font-weight: 650; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.empty-state { padding: 46px 20px; text-align: center; color: var(--muted); }
.empty-state .big { font-size: 2rem; margin-bottom: 8px; }

/* ---- badges ---- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: .72rem; font-weight: 650; letter-spacing: .02em; white-space: nowrap;
}
.badge-grey  { background: #e2e8f0; color: #475569; }
.badge-green { background: #d8f1e1; color: #1b7a43; }
.badge-red   { background: #fadede; color: #b03a3a; }
.badge-amber { background: #fdecc8; color: #96660c; }
.badge-blue  { background: #dcebfb; color: #2b6cb0; }
.badge-purple{ background: #e9e1fa; color: #6443ad; }

/* ---- forms ---- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px 14px; }
.form-grid .span2 { grid-column: span 2; }
.field label { display: block; font-size: .74rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: .9rem; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent-dim); }
.field textarea { resize: vertical; min-height: 64px; }
.field .hint { font-size: .72rem; color: var(--muted); margin-top: 3px; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); transform: scale(1.1); }
.check-row { display: flex; align-items: center; gap: 8px; font-size: .88rem; }
.filter-bar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.filter-bar input[type="search"], .filter-bar input[type="text"] {
  background: var(--bg2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 12px; min-width: 220px; font-size: .9rem; font-family: inherit;
}
.filter-bar select {
  background: var(--bg2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: .88rem; font-family: inherit;
}

/* ---- modal ---- */
#modalRoot .overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.42); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 16px; overflow-y: auto;
}
.modal {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); width: 100%; max-width: 760px;
  animation: pop .14s ease-out;
}
.modal.modal-lg { max-width: 980px; }
.modal.modal-sm { max-width: 460px; }
@keyframes pop { from { transform: translateY(8px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 1.3rem; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 18px; max-height: 72vh; overflow-y: auto; }
.modal-foot { padding: 13px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---- toast ---- */
#toastRoot { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg3); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  color: var(--text); padding: 11px 16px; border-radius: 8px; box-shadow: var(--shadow);
  font-size: .88rem; max-width: 360px; animation: pop .15s ease-out;
}
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }

/* ---- invoice editor specifics ---- */
.totals-panel { background: var(--bg3); border-radius: var(--radius); padding: 14px 16px; font-size: .9rem; }
.totals-panel .trow { display: flex; justify-content: space-between; padding: 3px 0; }
.totals-panel .trow.grand { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; font-size: 1.05rem; font-weight: 700; }
.totals-panel .trow.grand .val { color: var(--accent); }
.line-grid td { padding: 4px 6px !important; }
.line-grid input, .line-grid select {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; font-size: .85rem; font-family: inherit;
}
.line-grid input.num { text-align: right; font-variant-numeric: tabular-nums; }
.avail-ok { color: var(--green); font-size: .74rem; }
.avail-bad { color: var(--red); font-size: .74rem; font-weight: 700; }

.two-col { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }

/* ---- hamburger (hidden on desktop) ---- */
.menu-btn { display: none; background: none; border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; cursor: pointer; }
.menu-btn span { display: block; width: 20px; height: 2.5px; border-radius: 2px; background: var(--text); margin: 4px 0; }
#navOverlay { display: none; }
.drawer-backup { display: none; }

/* ============ NAV, mid-size windows (1024–1279px) ============
   11 pages at full size need ~1280px; in this band the row compacts
   (tighter buttons, tagline hidden) so it still fits on ONE line. */
@media (max-width: 1279px) and (min-width: 1120px) {
  #topbar { gap: 10px; }
  #nav button { padding: 7px 7px; font-size: .84rem; }
  .brand-sub { display: none; }
  .brand-name { max-width: 150px; }
}

/* ============ NAV COLLAPSE (phones, tablets, narrow windows <1120px) ======
   Below 1120px even the compact row can't fit all pages, so the nav becomes
   the same glass drawer the phone app uses (hamburger in the top bar). */
@media (max-width: 1119px) {
  #topbar { flex-wrap: nowrap; gap: 10px; }
  .brand { flex: 1; min-width: 0; }
  .brand-name { font-size: .95rem; }
  .menu-btn { display: block; flex-shrink: 0; }
  #backupBtn { display: none; }           /* lives inside the drawer */

  /* nav becomes a right-side drawer — Apple "liquid glass" treatment */
  #nav {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 95;
    width: min(78vw, 300px);
    background: rgba(255, 255, 255, .55);
    -webkit-backdrop-filter: blur(26px) saturate(180%);
    backdrop-filter: blur(26px) saturate(180%);
    border-left: 1px solid rgba(255, 255, 255, .65);
    border-radius: 18px 0 0 18px;
    box-shadow: inset 1px 0 0 rgba(255, 255, 255, .7), -18px 0 44px rgba(15, 23, 42, .25);
    display: flex; flex-direction: column; gap: 4px;
    padding: 64px 14px 20px;
    transform: translateX(105%);
    transition: transform .22s ease-out;
    overflow-y: auto;
  }
  /* solid fallback where backdrop-filter is unavailable */
  @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    #nav { background: var(--bg2); }
  }
  body.nav-open #nav { transform: none; }
  #nav button:hover { background: rgba(255, 255, 255, .5); }
  #nav button.active { background: rgba(255, 255, 255, .78); color: var(--accent); }
  #nav .drawer-backup { background: rgba(255, 255, 255, .45); }
  /* #nav lives inside the sticky topbar's stacking context (z 50), which would
     trap the drawer beneath the z-90 overlay — lift the topbar while open */
  body.nav-open #topbar { z-index: 96; }
  #nav button { display: block; width: 100%; text-align: left; padding: 13px 14px; font-size: 1rem; border-radius: 10px; }
  #nav button.active { background: var(--bg3); }
  #nav .drawer-backup { display: block; margin-top: auto; border: 1px solid var(--border); text-align: center; }
  body.nav-open #navOverlay { display: block; position: fixed; inset: 0; z-index: 90; background: rgba(15,23,42,.28); }
}

/* ===================== MOBILE (phones / Android app) ===================== */
@media (max-width: 760px) {
  #topbar { padding: 10px 0; }

  /* layout polish */
  #app { padding: 0 12px 32px; }
  h1 { font-size: 1.25rem; }
  .page-head { gap: 10px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: auto; }
  .filter-bar input[type="search"], .filter-bar input[type="text"] { min-width: 0; flex: 1 1 160px; }
  .filter-bar select { flex: 1 1 120px; }
  .kpi-row { grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 9px; }
  .kpi { padding: 11px 13px; }
  .kpi .kpi-value { font-size: 1.15rem; }
  table.data { font-size: .82rem; }
  table.data th, table.data td { padding: 8px 9px; }
  table.line-grid { min-width: 620px; }   /* line editors scroll sideways instead of crushing inputs */
  .line-grid input.num { min-width: 58px; }
  #modalRoot .overlay { padding: 2vh 8px; }
  .modal-body { padding: 14px; max-height: 76vh; }
  .modal-head { padding: 12px 14px; }
  .modal-foot { padding: 11px 14px; flex-wrap: wrap; }
  .doc-sheet { padding: 18px 16px; }
  .totals-panel { font-size: .85rem; }
}

/* ===================== PRINT ===================== */
.print-area { display: none; }
@media print {
  body { background: #fff; }
  #app, #modalRoot, #toastRoot { display: none !important; }
  .print-area { display: block !important; }
}
/* On-screen preview of print doc (inside modal) */
.doc-sheet {
  background: #ffffff; color: #141820;
  width: 100%; max-width: 820px; margin: 0 auto;
  padding: 34px 40px; font-size: 13px; line-height: 1.42;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
.doc-sheet * { color: inherit; }
.doc-sheet .doc-top { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2.5px solid #141820; padding-bottom: 14px; }
.doc-sheet .doc-co-name { font-size: 21px; font-weight: 800; letter-spacing: .01em; }
.doc-sheet .doc-co-sub { font-size: 11.5px; color: #4a5260; white-space: pre-line; margin-top: 3px; }
.doc-sheet .doc-type { font-size: 17px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; text-align: right; }
.doc-sheet .doc-meta { font-size: 12px; text-align: right; margin-top: 6px; }
.doc-sheet .doc-meta div { margin-bottom: 2px; }
.doc-sheet .doc-parties { display: flex; justify-content: space-between; gap: 24px; margin: 14px 0; }
.doc-sheet .doc-party h4 { margin: 0 0 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #6a7280; }
.doc-sheet table.doc-lines { width: 100%; border-collapse: collapse; margin: 6px 0 10px; }
.doc-sheet table.doc-lines th {
  background: #f0f2f5; border: 1px solid #c9cfd8; padding: 6px 8px;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; text-align: left;
}
.doc-sheet table.doc-lines td { border: 1px solid #c9cfd8; padding: 6px 8px; font-size: 12px; }
.doc-sheet table.doc-lines td.num, .doc-sheet table.doc-lines th.num { text-align: right; font-variant-numeric: tabular-nums; }
.doc-sheet .doc-bottom { display: flex; gap: 24px; justify-content: space-between; margin-top: 8px; }
.doc-sheet .doc-totals { margin-left: auto; min-width: 270px; }
.doc-sheet .doc-totals .trow { display: flex; justify-content: space-between; padding: 2.5px 0; font-size: 12.5px; }
.doc-sheet .doc-totals .trow.grand { border-top: 2px solid #141820; margin-top: 5px; padding-top: 6px; font-weight: 800; font-size: 14.5px; }
.doc-sheet .doc-words { font-size: 11.5px; font-style: italic; margin: 8px 0 12px; }
.doc-sheet .doc-bank { font-size: 11.5px; background: #f6f7f9; border: 1px solid #d7dce3; border-radius: 6px; padding: 10px 12px; }
.doc-sheet .doc-bank h4, .doc-sheet .doc-terms h4 { margin: 0 0 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #6a7280; }
.doc-sheet .doc-terms { font-size: 10.8px; color: #4a5260; white-space: pre-line; margin-top: 12px; }
.doc-sheet .doc-sign { margin-top: 36px; text-align: right; font-size: 12px; }
.doc-sheet .doc-sign .sig-line { margin-top: 44px; border-top: 1px solid #141820; display: inline-block; padding-top: 4px; min-width: 220px; text-align: center; }
.doc-sheet .doc-foot { margin-top: 18px; padding-top: 8px; border-top: 1px solid #d7dce3; font-size: 10px; color: #8a93a0; text-align: center; }
.doc-sheet .proforma-note { background: #fff6e4; border: 1px solid #e8cf96; padding: 7px 10px; font-size: 11px; border-radius: 6px; margin: 10px 0; }
@media print {
  .doc-sheet { max-width: none; padding: 0; font-size: 12.5px; }
  @page { margin: 14mm 12mm; }
}

/* ---- PIN gate (v2.0) ---- */
#pinGate {
  position: fixed; inset: 0; z-index: 500;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
#pinGate .pin-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 16px;
  padding: 30px 28px; width: min(86vw, 340px); text-align: center;
  box-shadow: var(--shadow);
}
#pinGate h2 { margin-bottom: 14px; }
#pinGate input {
  width: 100%; text-align: center; font-size: 1.5rem; letter-spacing: .4em;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px;
}

/* ---- calendar page (v2.0) ---- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head { font-size: .7rem; color: var(--muted); text-transform: uppercase; text-align: center; padding: 4px 0; }
.cal-cell {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 8px;
  min-height: 86px; padding: 4px 5px; cursor: pointer; overflow: hidden;
}
.cal-cell.cal-out { opacity: .38; }
.cal-cell.cal-today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cal-cell.cal-sel { background: #fff6e0; }
.cal-day { font-size: .72rem; font-weight: 700; color: var(--muted); margin-bottom: 3px; }
.cal-chip {
  display: block; font-size: .66rem; border-radius: 5px; padding: 1px 5px;
  margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer;
}
.cal-chip.st-enquiry  { background: #e2e8f0; color: #475569; }
.cal-chip.st-confirmed{ background: #dcebfb; color: #2b6cb0; }
.cal-chip.st-out      { background: #fdecc8; color: #96660c; }
@media (max-width: 760px) {
  .cal-cell { min-height: 56px; padding: 3px 4px; }
  .cal-chip { font-size: .6rem; }
}

/* ---- QR label sheet (v2.0, print) ---- */
.qr-sheet { display: flex; flex-wrap: wrap; gap: 6px; }
.qr-label {
  width: 170px; border: 1px dashed #9aa3af; border-radius: 6px; padding: 7px;
  display: flex; gap: 8px; align-items: center; background: #fff; color: #141820;
}
.qr-label img { width: 62px; height: 62px; image-rendering: pixelated; }
.qr-label .qr-txt { font-size: 10px; line-height: 1.25; overflow: hidden; }
.qr-label .qr-txt b { font-size: 10.5px; }

/* ---- dashboard alerts (v2.0) ---- */
.alert-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 4px;
  border-bottom: 1px solid var(--border); font-size: .86rem; flex-wrap: wrap;
}
.alert-row:last-child { border-bottom: none; }
.alert-row .grow { flex: 1; min-width: 160px; }

/* ============ INSTALLED HOME-SCREEN APP (iPhone/Android PWA) ============
   Only matches when launched from the home screen (display-mode:
   standalone) — the browser tab, Android APK WebView and Mac DMG all
   report 'browser' and are untouched. env() clears the notch/home bar. */
@media (display-mode: standalone) {
  #topbar { padding-top: calc(14px + env(safe-area-inset-top)); }
  body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
  #app { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
  #toastRoot { bottom: calc(22px + env(safe-area-inset-bottom)); }
}
@media (display-mode: standalone) and (max-width: 1119px) {
  /* the glass drawer slides under the notch otherwise */
  #nav { padding-top: calc(64px + env(safe-area-inset-top)); }
}
@media (display-mode: standalone) and (max-width: 760px) {
  /* match the phone block's tighter paddings, inset-added */
  #topbar { padding-top: calc(10px + env(safe-area-inset-top)); }
  #app { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
}
