/* MyPolin -- app-shell CSS.
   Goal: feel like a native mobile app, not a scaled-down website --
   system font stack, fixed bottom tab bar with safe-area padding, large
   tap targets, card-based layout, no page-reload navigation. */

:root {
  --color-primary: #0b5ed7;
  --color-primary-dark: #084298;
  --color-bg: #f2f4f7;
  --color-surface: #ffffff;
  --color-text: #1b1f27;
  --color-text-muted: #6b7280;
  --color-border: #e5e7eb;
  --color-danger: #d92d20;
  --color-success: #12805c;
  --color-warning: #b54708;
  --color-warning-bg: #fffaeb;
  --color-info: #175cd3;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --topbar-height: 56px;
  --bottomnav-height: 60px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior-y: contain;
}

body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

button, input {
  font-family: inherit;
}

/* ---------- Splash ---------- */
.splash {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--color-primary);
  color: #fff;
  z-index: 100;
}
.splash img { width: 84px; height: 84px; border-radius: 20px; }
.splash .spinner { border-color: rgba(255,255,255,0.35); border-top-color: #fff; }
.splash[hidden] { display: none; }

/* ---------- Generic screen (login) ---------- */
.screen {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
}
.screen[hidden] { display: none; }

.login-card {
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
}
.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.login-logo img { width: 64px; height: 64px; border-radius: 16px; }
.login-logo h1 { font-size: 22px; margin: 0; }
.login-logo p { margin: 0; color: var(--color-text-muted); font-size: 14px; text-align: center; }

.field {
  margin-bottom: 16px;
}
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}
.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 16px; /* 16px avoids iOS Safari auto-zoom on focus */
  background: var(--color-surface);
  color: var(--color-text);
}
.field textarea { resize: vertical; }
.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(11, 94, 215, 0.15);
}
/* Red asterisk marking a mandatory field label (Input Solusi dialog,
   2026-07-31 -- "kedua input mandatory"), matches the screenshot behind
   that request. */
.required { color: var(--color-danger); }

/* Read-only "field" that displays a derived value instead of accepting
   input -- Update CPL CPMK sheet's CPL row (2026-08-01: CPL is derived
   from the chosen CPMK's tcpmk_cpl mapping, not picked directly). Same
   box shape as .field input/select, just non-interactive with a muted
   background so it visibly reads as "not editable". */
.field .value {
  padding: 13px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 15px;
  background: var(--color-bg, #f4f5f7);
  color: var(--color-text);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:active { background: var(--color-primary-dark); }
.btn-primary:disabled { opacity: 0.6; }
.btn-outline-danger {
  background: transparent;
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
}
.btn-success { background: var(--color-success); color: #fff; }
.btn-success:active { filter: brightness(0.9); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:active { filter: brightness(0.9); }
/* Pause (queue-item, Running status, 2026-07-30 follow-up) -- amber, sits
   between success (Start, now removed) and danger visually. */
.btn-warning { background: #f79009; color: #fff; }
.btn-warning:active { filter: brightness(0.9); }
/* Finish (queue-item, Running status, 2026-07-30 follow-up) -- blue,
   distinct from --color-primary so it doesn't read as the default/primary
   action among three same-weight buttons. */
.btn-info { background: var(--color-info); color: #fff; }
.btn-info:active { filter: brightness(0.9); }
.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:active { background: var(--color-border); }
.btn:disabled { opacity: 0.6; cursor: default; }

/* Compact side-by-side buttons inside a card, e.g. queue-item's
   Pause/Finish/Trouble (Home > Produksi > Production (Scan), 2026-07-30),
   and the confirm dialog's Batal/Ya pair below. */
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row .btn { width: auto; flex: 1; padding: 10px 12px; font-size: 14px; }

/* ---------- Confirmation dialog (standard, 2026-07-30) ----------
   See js/confirm.js -- MyPolinConfirm.show() is the one place any button
   in this app should go through when it needs a confirm-before-proceeding
   step, instead of the browser's native confirm(). */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(16, 24, 40, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.confirm-overlay[hidden] { display: none; }

.confirm-dialog {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 20px;
  width: 100%;
  max-width: 340px;
}
.confirm-dialog h3 { margin: 0 0 8px; font-size: 17px; }
.confirm-dialog p { margin: 0; color: var(--color-text-muted); font-size: 14px; line-height: 1.4; }
.confirm-dialog .btn-row { margin-top: 18px; }

/* ---------- Bottom-sheet dialog ("Input Solusi", Home > Maintenance >
   Machine Trouble, 2026-07-31) ---------- anchored to the bottom of the
   viewport with a rounded top edge + drag-handle bar, distinct from
   .confirm-dialog's centered card -- matches the screenshot behind the
   request. z-index sits ABOVE .scanner-overlay/.machine-trouble-overlay
   (200, this sheet opens from inside that overlay) but BELOW
   .confirm-overlay (300, Simpan still triggers the standard confirm
   dialog on top of this sheet). */
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(16, 24, 40, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet-overlay[hidden] { display: none; }

.sheet-dialog {
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-card);
  padding: 12px 20px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 480px;
}
.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--color-border);
  margin: 0 auto 16px;
}
.sheet-dialog h3 { margin: 0 0 16px; font-size: 17px; }

.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
}
.alert-danger { background: #fef3f2; color: var(--color-danger); border: 1px solid #fda29b; }
.alert[hidden] { display: none; }

.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(0,0,0,0.15);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: 0 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- App shell ---------- */
.app-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.app-shell[hidden] { display: none; }

.topbar {
  flex: 0 0 auto;
  height: calc(var(--topbar-height) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary);
  color: #fff;
  position: relative;
}
.topbar h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
}
.topbar .topbar-action {
  position: absolute;
  right: 12px;
  top: calc(env(safe-area-inset-top) + 8px);
  background: transparent;
  border: none;
  color: #fff;
  padding: 8px;
  display: flex;
}

.view-container {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
}
.view { animation: fade-in 0.18s ease-out; }
.view[hidden] { display: none; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.bottom-nav {
  flex: 0 0 auto;
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: var(--bottomnav-height);
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.nav-item svg { width: 24px; height: 24px; stroke: currentColor; }
.nav-item.active { color: var(--color-primary); }

/* ---------- Cards / content ---------- */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px;
  margin-bottom: 14px;
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 14px;
}
.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  flex: 0 0 auto;
  object-fit: cover;
}
.profile-header h2 { margin: 0 0 2px; font-size: 17px; }
.profile-header p { margin: 0; color: var(--color-text-muted); font-size: 13px; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  margin: 20px 2px 10px;
}
.section-title:first-child { margin-top: 0; }

.info-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 14px;
}
.info-row:last-child { border-bottom: none; }
.info-row .label { color: var(--color-text-muted); flex: 0 0 42%; }
.info-row .value { text-align: right; font-weight: 500; flex: 1; }

.empty-state {
  text-align: center;
  color: var(--color-text-muted);
  padding: 40px 16px;
  font-size: 14px;
}

/* ---------- Menu tiles (Home > Produksi, 2026-07-30) ---------- */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}
.menu-tile {
  position: relative; /* anchors .menu-tile-badge, see Maintenance section 2026-07-31 */
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  border: none;
  padding: 16px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.menu-tile:active { background: var(--color-bg); }
.menu-tile-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.menu-tile-icon svg { width: 22px; height: 22px; }
/* Balon/badge on a menu tile (Home > Maintenance > Machine Trouble,
   2026-07-31 request: "tampilkan baloon pada menu tersebut dengan isi
   angka jumlah record") -- generic enough for any future tile that
   needs a count badge, not Machine Trouble-specific by name. Hidden via
   the [hidden] attribute (not display:none in a class) when the count
   is 0, see js/app.js's refreshMachineTroubleBadge(). */
.menu-tile-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--color-danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.menu-tile-badge[hidden] { display: none; }
.menu-tile-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-primary);
  text-align: center;
  line-height: 1.3;
}

/* ---------- QR scanner overlay (Home > Produksi > Production (Scan)) ---------- */
.scanner-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #000;
}
.scanner-overlay[hidden] { display: none; }

.scanner-camera {
  position: relative;
  height: 100%;
  width: 100%;
  overflow: hidden;
}
.scanner-camera[hidden] { display: none; }
.scanner-camera video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scanner-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(68vw, 280px);
  height: min(68vw, 280px);
  transform: translate(-50%, -50%);
  border: 3px solid rgba(255, 255, 255, 0.85);
  border-radius: var(--radius-lg);
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.scanner-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(48px + env(safe-area-inset-bottom));
  text-align: center;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  padding: 0 24px;
}
.scanner-close {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.scanner-result {
  position: absolute;
  inset: 0;
  background: var(--color-bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(64px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}
.scanner-result[hidden] { display: none; }
.scanner-result .scanner-close { background: rgba(0, 0, 0, 0.15); color: var(--color-text); }

.queue-item { margin-bottom: 10px; }
/* Running-status card -- 2026-07-30: originally a pale green tint, then
   2026-07-31 explicitly requested as LIME. First lime attempt (#ecfccb
   bg / #bef264 border) was too pale/desaturated -- read as near-yellow
   next to .queue-item-pause's yellow, defeating the point of using two
   different colors. Bumped up a shade (Tailwind lime-200/lime-500) for a
   background that's unambiguously green-leaning, not yellow-leaning. */
.queue-item-running {
  background: #d9f99d;
  border: 1px solid #84cc16;
}
/* Pause-status card -- 2026-07-31: originally a pale amber tint (barely
   distinguishable from white), then explicitly requested as YELLOW
   ("ubah background card jadi kuning untuk status pause") -- a clearly
   yellow background/border, distinct from .queue-item-running's green. */
.queue-item-pause {
  background: #fef9c3;
  border: 1px solid #fde047;
}
/* Machine Trouble-status card (2026-07-31, "ubah background card jadi
   red untuk status Machine trouble") -- clearly red, distinct from the
   lime Running card and yellow Pause card. This status also never shows
   any buttons (see js/scanner.js's renderQueueItemHtml/
   renderQueueListHtml -- Machine Trouble suppresses buttons on EVERY
   card in the queue, not just its own), so the red card is the only
   visual cue that this machine is out of action. */
.queue-item-trouble {
  background: #fecaca;
  border: 1px solid #ef4444;
}
.queue-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.queue-item-part { font-size: 14px; font-weight: 600; }

.chip {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  color: var(--color-primary);
  background: rgba(11, 94, 215, 0.1);
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
/* Running-status chip (matches .queue-item-running's green theme) --
   see 2026-07-30 Running/Pause/Finish/Trouble request. */
.chip-running {
  color: var(--color-success);
  background: rgba(18, 128, 92, 0.12);
}
/* Pause-status chip (matches .queue-item-pause's amber theme, 2026-07-31
   follow-up). */
.chip-pause {
  color: var(--color-warning);
  background: rgba(247, 144, 9, 0.14);
}
/* Machine Trouble-status chip (matches .queue-item-trouble's red theme,
   2026-07-31 follow-up). */
.chip-trouble {
  color: var(--color-danger);
  background: rgba(217, 45, 32, 0.14);
}
/* "submit" chip on a Machine Trouble ticket card (Home > Maintenance >
   Machine Trouble, 2026-07-31) -- light blue, matching --color-info
   (distinct from the danger-red used for the Machine Trouble QUEUE-ITEM
   card itself -- this chip is about the repair TICKET's own status,
   which starts as 'Submit', not about the piece's production status). */
.chip-submit {
  color: var(--color-info);
  background: rgba(23, 92, 211, 0.12);
}

/* ---------- Machine Trouble ticket card (Home > Maintenance > Machine
   Trouble, 2026-07-31) ---------- */
.mt-ticket { margin-bottom: 10px; }
/* On Progress / Part Purchase-status ticket card (2026-07-31 follow-up:
   "jika statusnya on progress, background card warna biru", extended
   same-day to Part Purchase via "lakukan hal yang sama untuk status part
   purchase" -- same class, not a second color, per that request's exact
   wording). Blue, distinct from the default white .mt-ticket and from
   the queue-item status colors (lime/yellow/red) above, since this is a
   different kind of card (repair TICKET, not production queue item). */
.mt-ticket-progress {
  background: #dbeafe;
  border: 1px solid #3b82f6;
}

.skeleton {
  background: linear-gradient(90deg, #e9ecf1 25%, #f4f6f8 37%, #e9ecf1 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-loading {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}
