/* ============================================================
   Xudov Garage — Layout
   V.0.28.7 — FAB konsisten X-axis (semua di kanan).
   Theme & help selalu di kanan-atas di semua breakpoint.
   ============================================================ */

/* 1. LOGIN */
.wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  width: 380px; max-width: 100%; background: var(--surface);
  border: var(--card-border); border-radius: var(--radius-lg);
  padding: 30px 28px; box-shadow: var(--shadow-md); text-align: center;
}
.login-card h1 { font-size: 26px; letter-spacing: .5px; }
.login-card h1 b { color: var(--accent); }
.tag-line { color: var(--muted); font-size: 12.5px; margin: 4px 0 24px; }

/* 2. PIN SCREEN */
.pin-screen { display: none; }
.pin-screen.active { display: flex; }
.back-btn {
  background: none; border: none; color: var(--muted);
  font-size: 13px; margin-bottom: 14px; padding: 0;
  cursor: pointer; transition: color .15s;
}
.back-btn:hover { color: var(--text); }

/* 3. APP SHELL */
.app-screen { display: none; }
.app-screen.active {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "sidebar topbar" "sidebar content";
  min-height: 100vh; max-width: none; padding: 0;
}

/* 4. SIDEBAR */
.sidebar {
  grid-area: sidebar; background: var(--surface);
  border-right: 1px solid var(--border); padding: 22px 14px;
  display: flex; flex-direction: column; position: sticky; top: 0;
  height: 100vh; overflow-y: auto; z-index: 30;
}
.sidebar .brand {
  font-family: var(--font-display); font-weight: 800; font-size: 18px;
  letter-spacing: -.4px; padding: 0 8px 18px; margin-bottom: 16px;
  border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 2px;
}
.sidebar .brand b { color: var(--accent); }

/* 5. SIDE NAV */
.side-nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.side-nav button {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px;
  text-align: left; color: var(--muted); font-weight: 600; font-size: 13.5px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  transition: all .15s; width: 100%; background: transparent;
}
.side-nav button:hover { background: var(--surface-2); color: var(--text); }
.side-nav button.active {
  background: var(--accent-soft); color: var(--accent); border-color: var(--accent);
}
.side-nav button .ic {
  width: 20px; height: 20px; display: inline-flex; align-items: center;
  justify-content: center; font-size: 0; overflow: visible; flex-shrink: 0; background: none;
}
.side-nav button .ic svg { width: 18px; height: 18px; stroke: currentColor; fill: none; }

/* 6. SIDE FOOTER */
.side-foot {
  margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
.side-user { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.side-user .av {
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-fg);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 800; font-size: 13px; flex-shrink: 0;
}
.side-user .nm { font-weight: 700; font-size: 13px; }
.side-user .rl { font-size: 10.5px; color: var(--muted); margin-top: 1px; }
.side-theme-btn, .side-logout {
  padding: 9px 12px; border-radius: var(--radius-sm); font-size: 12.5px;
  font-weight: 600; text-align: left; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); transition: all .15s;
}
.side-theme-btn:hover { border-color: var(--accent); color: var(--accent); }
.side-logout { color: var(--muted); background: transparent; }
.side-logout:hover { color: var(--danger); border-color: var(--danger); }

/* 7. TOPBAR */
.topbar {
  grid-area: topbar; background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px 14px 24px;
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 20; gap: 12px;
}
.topbar .hello {
  font-family: var(--font-display); font-weight: 800;
  font-size: 22px; letter-spacing: -.6px;
}
.topbar .hello b { color: var(--accent); }
.topbar .sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.topbar .clock {
  padding: 9px 16px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--border); font-weight: 600; font-size: 12.5px;
  font-family: var(--font-mono); letter-spacing: .5px; color: var(--text);
  white-space: nowrap; display: flex; align-items: center; gap: 10px;
}
.topbar .clock small { color: var(--muted); font-size: 11px; }
.topbar .who { display: none; align-items: center; gap: 10px; }
.topbar .who .av {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-fg);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 800; font-size: 13px;
}
.topbar .who .nm { font-size: 13.5px; font-weight: 700; }
.topbar .who .rl { font-size: 10.5px; color: var(--muted); }

/* 8. CONTENT */
.content {
  grid-area: content; padding: 20px; max-width: 1280px; width: 100%;
  margin: 0 auto; padding-bottom: 100px; min-width: 0;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* 9. PAGE HEAD */
.page-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 16px; flex-wrap: wrap; gap: 10px;
}
.page-head h2 { font-size: 23px; }
.page-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.row-actions { display: flex; gap: 5px; flex-wrap: wrap; }

/* ============================================================
   10-12. FAB BASE STYLE
   Posisi diatur HANYA di section 21.
   ============================================================ */
.fab {
  position: fixed; width: 56px; height: 56px; border-radius: 18px;
  background: var(--accent); color: var(--accent-fg);
  font-size: 26px; font-weight: 700; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  border: none; cursor: pointer; box-shadow: var(--shadow-orange);
  z-index: 60; transition: transform .15s;
}
.fab:active { transform: scale(.92); }
.fab.open { transform: rotate(45deg); }
.fab-menu {
  position: fixed; display: none; flex-direction: column; gap: 8px;
  z-index: 60; align-items: flex-end;
}
.fab-menu.open { display: flex; }
.fab-menu button {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: var(--card-border); color: var(--text);
  padding: 11px 16px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow-md);
  cursor: pointer; white-space: nowrap;
  transition: border-color .15s, background .15s;
}
.fab-menu button:active { background: var(--surface-2); border-color: var(--accent); }

.help-fab {
  position: fixed; width: 44px; height: 44px; border-radius: 14px;
  background: var(--surface); border: var(--card-border); color: var(--text);
  font-size: 18px; font-weight: 700; font-family: var(--font-display);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md); z-index: 55; cursor: pointer;
  opacity: .7; transition: opacity .2s, transform .15s;
}
.help-fab:hover { opacity: 1; }
.help-fab:active { transform: scale(.92); }
.help-fab.on {
  background: var(--accent); color: var(--accent-fg);
  border-color: var(--accent); opacity: 1;
}
.help-tip {
  position: fixed; max-width: min(290px, calc(100vw - 110px));
  background: var(--surface); border: 1px solid var(--accent);
  border-radius: var(--radius-sm); padding: 14px 34px 14px 14px;
  font-size: 12.5px; line-height: 1.65; color: var(--text);
  box-shadow: var(--shadow-md); z-index: 60; display: none;
  pointer-events: auto; animation: helpTipIn .2s cubic-bezier(.32,.72,0,1);
}
@keyframes helpTipIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.help-tip.open { display: block; }
.help-tip .close-tip {
  position: absolute; top: 6px; right: 8px;
  background: none; border: none; color: var(--muted);
  font-size: 18px; cursor: pointer; padding: 0 4px; line-height: 1;
}
.help-tip .close-tip:hover { color: var(--text); }
.help-tip .tip-title {
  font-weight: 700; color: var(--accent); font-size: 12px;
  margin-bottom: 5px; text-transform: uppercase; letter-spacing: .4px;
}
.help-tip b { color: var(--text); font-weight: 700; }

.theme-fab {
  position: fixed; width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: var(--accent-fg);
  font-size: 20px; display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-orange); border: none; cursor: pointer;
  z-index: 90; transition: transform .15s;
}
.theme-fab:active { transform: scale(.92); }

/* 13. THEME DRAWER */
.theme-drawer {
  position: fixed; inset: 0; z-index: 250;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: none; align-items: flex-end; justify-content: flex-end; padding: 16px;
}
.theme-drawer.open { display: flex; }
.theme-drawer-inner {
  background: var(--surface); border: var(--card-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  width: 100%; max-width: 440px; max-height: 92vh; overflow-y: auto; padding: 22px;
  animation: slideUp .28s cubic-bezier(.32,.72,0,1);
}
@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.theme-drawer h3 {
  font-family: var(--font-display); font-size: 18px; font-weight: 800; margin-bottom: 4px;
}
.theme-drawer .desc { font-size: 12px; color: var(--muted); margin-bottom: 20px; }
.theme-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.theme-item {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  background: var(--surface-2); border: 2px solid transparent;
  border-radius: var(--radius-sm); text-align: left; transition: all .15s;
  width: 100%; cursor: pointer;
}
.theme-item:hover { border-color: var(--accent); }
.theme-item.active { border-color: var(--accent); background: var(--accent-soft); }
.theme-prev {
  width: 40px; height: 40px; border-radius: var(--radius-sm); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.theme-item .meta .t { font-weight: 700; font-size: 13px; display: block; }
.theme-item .meta .d {
  font-size: 10.5px; color: var(--muted); margin-top: 1px; display: block;
}

/* 14. BOTTOM NAV */
.bottom-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  grid-template-columns: repeat(5, 1fr); gap: 2px;
}
.bottom-nav button {
  padding: 8px 4px; display: flex; flex-direction: column; align-items: center;
  gap: 3px; color: var(--muted); font-size: 10.5px; font-weight: 700;
  border-radius: var(--radius-sm); transition: all .15s;
  border: none; background: transparent;
}
.bottom-nav button .ic {
  width: 22px; height: 22px; display: inline-flex; align-items: center;
  justify-content: center; font-size: 0; background: none; overflow: visible;
}
.bottom-nav button .ic svg { width: 20px; height: 20px; stroke: currentColor; fill: none; }
.bottom-nav button.active { color: var(--accent) !important; background: var(--accent-soft); }

/* 15. SYNC BADGE */
#syncBadge {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%);
  font-size: 11px; padding: 5px 12px; border-radius: 20px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--muted); z-index: 50; display: none; font-weight: 600;
  font-family: var(--font-mono); white-space: nowrap; max-width: 90vw;
  overflow: hidden; text-overflow: ellipsis;
}
#syncBadge.on { display: block; }
#syncBadge.saving { border-color: var(--warning); color: var(--warning); }
#syncBadge.error { border-color: var(--danger); color: var(--danger); }
#syncBadge.synced { border-color: var(--success); color: var(--success); }

/* 16. TOAST */
#toastContainer {
  position: fixed; top: calc(16px + env(safe-area-inset-top, 0px));
  left: 50%; transform: translateX(-50%); z-index: 300;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
  width: calc(100% - 32px); max-width: 400px; align-items: center;
}

/* ============================================================
   17. RESPONSIVE — 1024px
   ============================================================ */
@media (max-width: 1024px) {
  .bento { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-card.hero { grid-column: span 2; }
  .chart-row { grid-template-columns: 1fr; }
}

/* ============================================================
   18. RESPONSIVE — 900px (layout shell only, no FAB)
   ============================================================ */
@media (max-width: 900px) {
  .app-screen.active {
    grid-template-columns: 1fr;
    grid-template-areas: "topbar" "content";
  }
  .sidebar { display: none; }
  body.app-active .bottom-nav { display: grid; }
  .content { padding: 14px; padding-bottom: 120px; }
  .topbar { padding: 12px 14px; }
  .topbar .who { display: flex !important; }
  .topbar .hello, .topbar .sub { display: none; }
  .topbar .clock { padding: 7px 12px; font-size: 11.5px; }

  .kasir-layout { grid-template-columns: 1fr; }
  .cart-box { position: static; }
  .form-grid { grid-template-columns: 1fr; }
  .perm-grid { grid-template-columns: 1fr; }

  .bento { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-card.hero { grid-column: 1 / -1; }

  .produk-grid {
    grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
    max-height: none;
  }
  .list-row { flex-wrap: wrap; }

  .log-row { grid-template-columns: auto 1fr; gap: 8px; }
  .log-row .time { grid-column: 2; text-align: left; }

  .user-admin-row { flex-wrap: wrap; }
  .user-admin-actions {
    width: 100%; justify-content: flex-start; margin-top: 8px;
  }

  .help-tip { max-width: calc(100% - 40px); }
  .theme-list { grid-template-columns: 1fr; }

  .page-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .page-head .row-actions {
    display: flex; flex-wrap: wrap; gap: 8px;
    width: 100%; overflow: visible;
  }
  .page-head .row-actions .btn-secondary {
    flex: 0 0 auto; white-space: nowrap; font-size: 12px; padding: 8px 12px;
  }

  body, .content, .tab-panel { max-width: 100vw; overflow-x: hidden; }
  *, *::before, *::after { min-width: 0; }

  .page-head h2 { font-size: 20px; }
  .topbar .clock { font-size: 10.5px; padding: 6px 10px; }
  .topbar .clock small { display: none; }
}

/* ============================================================
   19. SAFE AREA
   ============================================================ */
@supports (padding: env(safe-area-inset-bottom)) {
  .bottom-nav { padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .content { padding-bottom: calc(120px + env(safe-area-inset-bottom)); }
}

/* ============================================================
   20. FORCE MOBILE — layout shell only
   ============================================================ */
body.force-mobile .app-screen.active {
  grid-template-columns: 1fr;
  grid-template-areas: "topbar" "content";
}
body.force-mobile .sidebar { display: none; }
body.force-mobile.app-active .bottom-nav { display: grid; }
body.force-mobile .content { padding: 14px; padding-bottom: 120px; }
body.force-mobile .topbar { padding: 12px 14px; }
body.force-mobile .topbar .who { display: flex !important; }
body.force-mobile .topbar .hello,
body.force-mobile .topbar .sub { display: none; }
body.force-mobile .topbar .clock { padding: 7px 12px; font-size: 11.5px; }
body.force-mobile .topbar #btnToggleMode { flex-shrink: 0; }
body.force-mobile .kasir-layout { grid-template-columns: 1fr; }
body.force-mobile .cart-box { position: static; }
body.force-mobile .form-grid,
body.force-mobile .perm-grid { grid-template-columns: 1fr; }
body.force-mobile .bento { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
body.force-mobile .stat-card.hero { grid-column: 1 / -1 !important; }
body.force-mobile .page-head { flex-direction: column; align-items: stretch; gap: 12px; }
body.force-mobile .page-head .row-actions {
  display: flex; flex-wrap: wrap; gap: 8px; width: 100%; overflow: visible;
}
body.force-mobile .page-head .row-actions .btn-secondary {
  flex: 0 0 auto; white-space: nowrap; font-size: 12px; padding: 8px 12px;
}
body.force-mobile, body.force-mobile .content, body.force-mobile .tab-panel {
  max-width: 100vw; overflow-x: hidden;
}
body.force-mobile *, body.force-mobile *::before, body.force-mobile *::after {
  min-width: 0;
}

/* ============================================================
   21. FAB POSITIONING — SINGLE SOURCE OF TRUTH
   Semua di KANAN. Theme & help selalu di kanan-ATAS.
   Gak ada pergeseran horizontal saat resize.
   ============================================================ */

/* Base: default top-right (berlaku semua breakpoint) */
.theme-fab {
  top: calc(16px + env(safe-area-inset-top, 0px)) !important;
  bottom: auto !important;
  left: auto !important;
  right: 16px !important;
}
.help-fab {
  top: calc(72px + env(safe-area-inset-top, 0px)) !important;
  bottom: auto !important;
  left: auto !important;
  right: 16px !important;
}
.help-tip {
  top: calc(128px + env(safe-area-inset-top, 0px)) !important;
  bottom: auto !important;
  left: auto !important;
  right: 16px !important;
}
.topbar { padding-right: 76px !important; }

/* FAB kasir — desktop: pojok kanan bawah */
.fab {
  top: auto !important;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px)) !important;
  right: calc(24px + env(safe-area-inset-right, 0px)) !important;
  left: auto !important;
}
.fab-menu {
  top: auto !important;
  bottom: calc(90px + env(safe-area-inset-bottom, 0px)) !important;
  right: calc(20px + env(safe-area-inset-right, 0px)) !important;
  left: auto !important;
}

/* Mobile ≤900px — FAB kasir naik dikit, theme & help tetap atas */
@media (max-width: 900px) {
  .theme-fab {
    top: calc(16px + env(safe-area-inset-top, 0px)) !important;
    right: 14px !important;
  }
  .help-fab {
    top: calc(72px + env(safe-area-inset-top, 0px)) !important;
    right: 14px !important;
  }
  .help-tip {
    top: calc(128px + env(safe-area-inset-top, 0px)) !important;
    right: 14px !important;
  }
  .fab {
    bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
    right: 14px !important;
  }
  .fab-menu {
    bottom: calc(144px + env(safe-area-inset-bottom, 0px)) !important;
    right: 14px !important;
  }
}

/* Force-mobile — sama kayak mobile ≤900px */
body.force-mobile .theme-fab {
  top: calc(16px + env(safe-area-inset-top, 0px)) !important;
  bottom: auto !important;
  left: auto !important;
  right: 14px !important;
}
body.force-mobile .help-fab {
  top: calc(72px + env(safe-area-inset-top, 0px)) !important;
  bottom: auto !important;
  left: auto !important;
  right: 14px !important;
}
body.force-mobile .help-tip {
  top: calc(128px + env(safe-area-inset-top, 0px)) !important;
  bottom: auto !important;
  left: auto !important;
  right: 14px !important;
}
body.force-mobile .topbar { padding-right: 76px !important; }
body.force-mobile .fab {
  top: auto !important;
  bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
  right: 14px !important;
  left: auto !important;
}
body.force-mobile .fab-menu {
  top: auto !important;
  bottom: calc(144px + env(safe-area-inset-bottom, 0px)) !important;
  right: 14px !important;
  left: auto !important;
}

/* ============================================================
   22. PORTRAIT MOBILE COMPACT (typography only)
   ============================================================ */
@media (max-width: 600px) and (orientation: portrait) {
  .content { padding: 10px 10px 112px; }
  .topbar { gap: 6px; padding: 10px; }
  .topbar .who { flex: 1; min-width: 0; }
  .topbar .who > div:last-child { min-width: 0; }
  .topbar .who .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .clock { padding: 6px 8px; font-size: 10px; }
  .page-head { gap: 8px; }
  .page-head h2 { font-size: 18px; }
  .page-head .sub { font-size: 11px; }
  .page-head .row-actions { gap: 6px; padding-bottom: 2px; }
  .page-head .row-actions .btn-secondary { padding: 8px 10px; font-size: 12px; }
  body.force-mobile .content { padding: 10px 10px 112px; }
}