@import url('https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Spline+Sans+Mono:wght@400;500;600;700&display=swap');

:root {
  --background: 210 20% 98%;
  --foreground: 222 47% 11%;
  --border: 214 32% 91%;
  --input: 214 32% 91%;
  --ring: 24 98% 50%;
  --card: 0 0% 100%;
  --card-foreground: 222 47% 11%;
  --primary: 24 98% 50%;
  --primary-foreground: 0 0% 100%;
  --secondary: 222 47% 11%;
  --secondary-foreground: 0 0% 100%;
  --muted: 210 40% 96.1%;
  --muted-foreground: 215.4 16.3% 46.9%;
  --accent: 210 40% 96.1%;
  --accent-foreground: 222 47% 11%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 0 0% 100%;
  --font-sans: 'Geist', sans-serif;
  --font-mono: 'Spline Sans Mono', monospace;
  --radius: 0.5rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  -webkit-font-smoothing: antialiased;
}

.font-mono { font-family: var(--font-mono); }

a { color: inherit; }

.hidden { display: none !important; }

/* ── Layout helpers ─────────────────────────────────────────────── */
.min-h-screen { min-height: 100vh; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-1 { flex: 1 1 0%; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.gap-4 { gap: 1rem; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.w-full { width: 100%; }

/* ── Loader ─────────────────────────────────────────────────────── */
.spinner {
  width: 2rem; height: 2rem; border-radius: 50%;
  border: 3px solid hsl(var(--primary) / .25);
  border-top-color: hsl(var(--primary));
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .5rem;
  border-radius: calc(var(--radius) - 2px);
  font-size: .875rem; font-weight: 500;
  padding: .5rem 1rem; height: 2.5rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color .15s, color .15s, border-color .15s;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.btn-primary:hover:not(:disabled) { background: hsl(var(--primary) / .9); }
.btn-outline { background: hsl(var(--background)); border-color: hsl(var(--input)); color: hsl(var(--foreground)); }
.btn-outline:hover:not(:disabled) { background: hsl(var(--accent)); }
.btn-ghost { background: transparent; color: hsl(var(--foreground)); }
.btn-ghost:hover:not(:disabled) { background: hsl(var(--accent)); }
.btn-destructive { background: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); }
.btn-icon { width: 2.25rem; height: 2.25rem; padding: 0; }
.btn-sm { height: 2rem; padding: 0 .75rem; font-size: .8rem; }
.btn-block { width: 100%; }
.btn-lg { height: 3rem; font-size: 1.125rem; }

/* ── Inputs / Select ────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; }
.field label { font-size: .875rem; font-weight: 600; }
.input, select.input, textarea.input {
  height: 2.5rem; width: 100%;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid hsl(var(--input));
  background: hsl(var(--background));
  padding: 0 .75rem; font-size: .875rem;
  font-family: inherit;
  color: hsl(var(--foreground));
}
.input:focus, select.input:focus { outline: 2px solid hsl(var(--ring) / .4); border-color: hsl(var(--ring)); }
textarea.input { height: auto; padding: .5rem .75rem; }

/* ── Card ───────────────────────────────────────────────────────── */
.card {
  background: hsl(var(--card)); color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.card-header { padding: 1rem 1.25rem; }
.card-content { padding: 1.25rem; }
.card-title { font-size: 1.5rem; font-weight: 700; margin: 0; }
.card-desc { font-size: .8rem; color: hsl(var(--muted-foreground)); text-transform: uppercase; font-weight: 700; letter-spacing: .03em; }
.stat-card { border-bottom: 4px solid hsl(var(--primary)); }
.stat-value { font-family: var(--font-mono); font-size: 1.75rem; font-weight: 700; }

/* ── Table ──────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.data-table th.col-qty { width: 90px; }
table.data-table thead { background: hsl(var(--secondary) / .05); }
table.data-table th {
  text-align: left; padding: .65rem 1rem; font-size: .7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid hsl(var(--border));
}
table.data-table td { padding: .65rem 1rem; border-bottom: 1px solid hsl(var(--border)); }
table.data-table tbody tr:hover { background: hsl(var(--accent) / .5); }
.row-inactive { opacity: .5; }

/* ── Badge ──────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; border-radius: 9999px;
  border: 1px solid hsl(var(--border)); padding: .15rem .65rem;
  font-size: .7rem; font-weight: 600;
}
.badge-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); border-color: transparent; }
.badge-outline { background: transparent; }
.badge-green { border-color: #4ade80; color: #16a34a; }
.badge-solid-green { background: #22c55e; color: #fff; border-color: transparent; }
.badge-muted { color: hsl(var(--muted-foreground)); }

/* ── Tabs ───────────────────────────────────────────────────────── */
.tabs-list {
  display: flex; flex-wrap: wrap; gap: .5rem; background: hsl(var(--card));
  border: 1px solid hsl(var(--border)); border-radius: var(--radius);
  padding: .5rem; box-shadow: 0 1px 2px rgba(0,0,0,.04); overflow-x: auto;
}
.tab-trigger {
  border: none; background: transparent; cursor: pointer;
  padding: .75rem 1.25rem; border-radius: calc(var(--radius) - 2px);
  font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: hsl(var(--foreground));
  display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap;
}
.tab-trigger.active { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Modal / Dialog ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 50;
}
.modal {
  background: hsl(var(--card)); border-radius: var(--radius); width: 100%; max-width: 30rem;
  max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal > form {
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.modal-header { padding: 1.5rem 1.5rem .5rem; flex-shrink: 0; }
.modal-header h3 { margin: 0 0 .25rem; font-size: 1.15rem; font-weight: 700; }
.modal-header p { margin: 0; font-size: .85rem; color: hsl(var(--muted-foreground)); }
.modal-body { padding: 1rem 1.5rem; overflow-y: auto; flex: 1; min-height: 0; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid hsl(var(--border)); display: flex; justify-content: flex-end; gap: .5rem; flex-shrink: 0; }

/* ── Alert box ──────────────────────────────────────────────────── */
.alert-error {
  display: flex; align-items: flex-start; gap: .5rem; padding: .75rem;
  background: hsl(var(--destructive) / .1); border: 1px solid hsl(var(--destructive) / .3);
  border-radius: calc(var(--radius) - 2px); color: hsl(var(--destructive)); font-size: .875rem;
}

/* ── Toast ──────────────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; display: flex; flex-direction: column; gap: .5rem; z-index: 100; }
.toast {
  background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: var(--radius);
  padding: .85rem 1.1rem; box-shadow: 0 4px 12px rgba(0,0,0,.15); min-width: 260px; font-size: .875rem;
  animation: toast-in .15s ease-out;
}
.toast.toast-error { border-color: hsl(var(--destructive)); color: hsl(var(--destructive)); }
.toast.toast-success { border-color: #22c55e; color: #15803d; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Login page ─────────────────────────────────────────────────── */
.login-page { min-height: 100vh; display: flex; flex-direction: column; }
@media (min-width: 768px) { .login-page { flex-direction: row; } }
.login-hero {
  flex: 1; background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground));
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 2rem; position: relative; overflow: hidden;
  background-image: radial-gradient(rgba(255,255,255,.1) 1px, transparent 1px);
  background-size: 32px 32px;
}
.login-hero-icon {
  display: inline-flex; padding: .85rem; border-radius: 1rem;
  background: hsl(var(--primary) / .2); color: hsl(var(--primary)); margin-bottom: 1.5rem; font-size: 2.5rem;
}
.login-hero-icon img { display: block; width: 5.5rem; height: 5.5rem; border-radius: 50%; object-fit: cover; }
.login-hero h1 { font-size: 2.5rem; font-weight: 700; text-align: center; margin: 0 0 1rem; line-height: 1.15; }
.login-hero h1 span { color: hsl(var(--primary)); }
.login-hero p { text-align: center; color: hsl(var(--secondary-foreground) / .7); font-size: 1.1rem; max-width: 28rem; }
.login-form-side {
  flex: 1; background: hsl(var(--background)); display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 2rem; border-left: 1px solid hsl(var(--border));
}
.login-form-side form { width: 100%; max-width: 24rem; }
.login-form-side h2 { font-size: 1.75rem; font-weight: 700; margin: 0 0 .5rem; text-align: center; }
.login-form-side > form > p, .login-subtitle { text-align: center; color: hsl(var(--muted-foreground)); margin: 0 0 2rem; }

/* ── App header (dashboard / admin cockpit) ────────────────────── */
.app-header {
  background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground));
  border-bottom: 4px solid hsl(var(--primary)); position: sticky; top: 0; z-index: 20;
}
.app-header-inner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  padding: 1rem 1.5rem; gap: .75rem;
}
.app-header-left { display: flex; align-items: center; gap: 1rem; }
.app-header-icon { background: hsl(var(--primary) / .2); border: 1px solid hsl(var(--primary) / .3); padding: .35rem; border-radius: .5rem; font-size: 1.5rem; display: inline-flex; }
.app-header-icon img { display: block; width: 2.75rem; height: 2.75rem; border-radius: 50%; object-fit: cover; }
.app-header h1 { font-size: 1.5rem; font-weight: 700; text-transform: uppercase; margin: 0; line-height: 1; }
.app-header-meta { display: flex; align-items: center; gap: .5rem; margin-top: .25rem; flex-wrap: wrap; font-size: .85rem; }
.app-header-meta .sep { opacity: .5; font-size: .75rem; }
.role-pill { font-size: .7rem; padding: .1rem .5rem; border-radius: 9999px; background: hsl(var(--secondary-foreground) / .1); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.app-header-right { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.shift-chip { display: inline-flex; align-items: center; gap: .4rem; padding: .35rem .75rem; border-radius: .5rem; color: #fff; font-size: .7rem; font-weight: 700; }
.date-block { text-align: right; }
.date-block .label { font-size: .8rem; font-weight: 700; color: hsl(var(--secondary-foreground) / .8); text-transform: uppercase; letter-spacing: .05em; margin: 0; }
.date-block .value { font-family: var(--font-mono); color: hsl(var(--primary)); font-weight: 700; font-size: 1.1rem; margin: 0; }
.btn-logout { border-color: hsl(var(--secondary-foreground) / .2); background: hsl(var(--secondary) / .5); color: hsl(var(--secondary-foreground)); }
/* #logout-btn (id) needed so this beats .btn-outline:hover:not(:disabled)'s higher specificity */
#logout-btn.btn-logout:hover, #logout-btn.btn-logout:active,
.btn-logout:hover, .btn-logout:active { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); border-color: hsl(var(--primary)); }
#export-btn:hover:not(:disabled), #export-btn:active:not(:disabled) { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); border-color: hsl(var(--primary)); }

.app-main { flex: 1; padding: 1.5rem; max-width: 1600px; margin: 0 auto; width: 100%; }

/* ── Not found ──────────────────────────────────────────────────── */
.notfound { min-height: 100vh; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: .5rem; text-align: center; }
.notfound h1 { font-size: 4rem; margin: 0; color: hsl(var(--primary)); }

/* ── Responsive: tablet & mobile ──────────────────────────────────
   Layout is desktop-first with fluid/wrapping flex rows, so most
   sections already reflow. This section tightens spacing, scales
   type down, and stacks the header/date/actions so the app stays
   usable at phone widths (the operators mainly use this from the
   factory floor on phones/tablets, not just desktop). */
@media (max-width: 900px) {
  .app-main { padding: 1rem; }
  .card-header { padding: .85rem 1rem; }
  .card-content { padding: 1rem; }
  .modal { max-width: 100%; }
}

@media (max-width: 640px) {
  html { -webkit-text-size-adjust: 100%; }
  .app-header-inner { padding: .85rem 1rem; flex-direction: column; align-items: stretch; }
  .app-header-left { width: 100%; }
  .app-header h1 { font-size: 1.15rem; }
  .app-header-right { width: 100%; justify-content: space-between; gap: .5rem; }
  .app-header-right .btn { flex: 1; white-space: nowrap; padding: 0 .6rem; font-size: .78rem; }
  /* "Keluar Sesi" (and Export on admin) must stay a compact, text-fit
     button on phones instead of stretching via flex:1 — a full-width
     button here pushes/crowds the Shift and Tanggal Shift info next to
     it. Sized to fit its own label rather than a fixed px width so it
     still adapts if the label ever changes. */
  .app-header-right .btn-logout { flex: 0 0 auto; width: auto; min-width: 90px; max-width: 110px; padding: 0 .5rem; }
  /* Export Database punya label lebih panjang dari "Keluar Sesi" — pakai
     batas lebar sendiri (bukan 110px) supaya teksnya tidak terpotong. */
  .app-header-right #export-btn.btn-logout { flex: 0 0 auto; width: auto; min-width: 0; max-width: none; white-space: normal; text-align: center; line-height: 1.2; font-size: .72rem; padding: .4rem .6rem; }
  .date-block { text-align: left; }
  .app-main { padding: .75rem; }
  .tabs-list { padding: .35rem; gap: .35rem; -webkit-overflow-scrolling: touch; }
  .tab-trigger { padding: .6rem .85rem; font-size: .65rem; }
  .card-header { padding: .75rem .85rem; }
  .card-content { padding: .85rem; }
  .card-title { font-size: 1.2rem; }
  .stat-value { font-size: 1.4rem; }
  table.data-table { font-size: .78rem; }
  table.data-table th, table.data-table td { padding: .5rem .6rem; white-space: nowrap; }
  /* Tables scroll horizontally instead of squeezing columns unreadably
     thin — a subtle edge fade hints there's more content off-screen. */
  .table-wrap { -webkit-overflow-scrolling: touch; position: relative; }
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { max-width: 100%; width: 100%; border-radius: var(--radius) var(--radius) 0 0; max-height: 92vh; }
  .modal-header, .modal-body, .modal-footer { padding-left: 1rem; padding-right: 1rem; }
  .modal-footer { flex-wrap: wrap; }
  .modal-footer .btn { flex: 1; }
  .login-hero { padding: 1.5rem 1.25rem; }
  .login-hero h1 { font-size: 1.85rem; }
  .login-hero p { font-size: .95rem; }
  .login-form-side { padding: 1.5rem 1.25rem; border-left: none; }
  #toast-container { left: .75rem; right: .75rem; bottom: 1rem; }
  .toast { min-width: 0; width: 100%; }

  /* iOS Safari auto-zooms on focus of any input with font-size < 16px —
     jarring on a form-heavy app used mostly from phones on the floor. */
  .input, select.input, textarea.input { font-size: 1rem; }

  /* Icon-only buttons (edit/delete/toggle in tables) need a touch target
     close to the 44px accessibility minimum, not the desktop 36px. */
  .btn-icon { width: 2.75rem; height: 2.75rem; font-size: 1.05rem; }
}

/* Good/NG number inputs must stay wide enough to show larger figures
   (e.g. 1500+) in full on phones. The table already scrolls horizontally
   via .table-wrap, so widening these two columns doesn't need to shrink
   anything else — desktop (>=768px) keeps the original 90px column. */
@media (max-width: 767px) {
  table.data-table th.col-qty { width: 120px; }
  table.data-table .qty-good, table.data-table .qty-ng { min-width: 100px; }
}

/* ── Responsive: medium phones (321–480px) ──────────────────────── */
/* Breakpoint antara 640px (side-by-side) dan 400px (full stack):
   tombol Export + Keluar Sesi disusun vertikal agar tidak saling
   berdesakan dan teks Export tidak terpaksa wrap di tengah baris. */
@media (max-width: 480px) {
  .app-header-right {
    flex-direction: column;
    align-items: stretch;
    gap: .4rem;
  }
  .app-header-right .btn {
    width: 100% !important;
    max-width: none !important;
    flex: none !important;
    white-space: normal;
    height: auto;
    min-height: 2.5rem;
    padding: .5rem .75rem;
    line-height: 1.3;
    text-align: center;
  }

  /* Stat cards: 2 per baris pada layar ≤480px.
     !important diperlukan karena inline style pada elemen yang digenerate
     JS menggunakan min-width:130px / 160px / 200px secara langsung. */
  .stat-card {
    flex: 1 1 calc(50% - .5rem) !important;
    min-width: 0 !important;
  }

  /* Kartu ringkasan per-line di Admin: cukup 1 baris tapi jangan
     memaksa min-width yang terlalu lebar */
  .line-summary-card {
    flex: 1 1 100% !important;
    min-width: 0 !important;
  }
}

/* ── Responsive: small phones ───────────────────────────────────── */
@media (max-width: 400px) {
  .app-header-right { flex-direction: column; align-items: stretch; }
  .app-header-right .btn { width: 100%; }
  /* Keep "Keluar Sesi"/"Export" compact even in the stacked column
     layout at very small widths, instead of inheriting the 100% width
     above — it should stay right-aligned and text-sized, not span the
     row and crowd the Shift/Tanggal Shift info stacked above it. */
  .app-header-right .btn-logout { width: auto; align-self: flex-end; }
  .app-header-right #export-btn.btn-logout { width: 100%; align-self: stretch; }
  .tab-trigger { padding: .55rem .65rem; font-size: .62rem; }
  .stat-card { min-width: 100% !important; }
  .card-content.flex, div[style*="flex-wrap:wrap"] { row-gap: .5rem; }
}

/* Any pointer-based device (mouse) can keep smaller, denser touch targets;
   this only widens tap targets for actual touchscreens. */
@media (hover: none) and (pointer: coarse) {
  .btn-icon { width: 2.75rem; height: 2.75rem; }
  .tab-trigger { padding: .75rem 1rem; }
}

/* ── Calendar widget (Hari Libur / Kalender Leader) ─────────────────── */
.cal-widget { max-width: 480px; }
.cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.cal-title { font-weight: 700; font-size: 1.05rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: .3rem; }
.cal-grid-head { margin-bottom: .3rem; }
.cal-dow { text-align: center; font-size: .72rem; font-weight: 700; color: hsl(var(--muted-foreground)); text-transform: uppercase; }
.cal-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: .5rem;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  font-size: .8rem;
  cursor: default;
  gap: .15rem;
}
.cal-cell-empty { visibility: hidden; border: none; background: none; }
.cal-cell-today { border: 2px solid hsl(var(--primary)); }
.cal-cell-clickable { cursor: pointer; }
.cal-cell-clickable:hover { background: hsl(var(--primary) / .08); }
.cal-daynum { font-weight: 600; }
.cal-daylabel { font-size: .6rem; line-height: 1; }

/* Hari libur (semua leader off) — merah */
.cal-cell-holiday-off {
  background: hsl(var(--destructive) / .15);
  border-color: hsl(var(--destructive) / .5);
  color: hsl(var(--destructive));
}
.cal-cell-holiday-off .cal-daynum { color: hsl(var(--destructive)); }

/* Hari libur, tapi leader ini tetap masuk kerja — hitam */
.cal-cell-holiday-working {
  background: #1f2937;
  border-color: #111827;
  color: #fff;
}
.cal-cell-holiday-working .cal-daynum,
.cal-cell-holiday-working .cal-daylabel { color: #fff; }

.cal-legend { display: flex; gap: 1.25rem; flex-wrap: wrap; margin-top: .9rem; font-size: .8rem; }
.cal-legend-item { display: flex; align-items: center; gap: .4rem; }
.cal-legend-swatch { width: 1rem; height: 1rem; border-radius: .3rem; display: inline-block; }
