/* Shared design system for admin + user-facing pages. */

:root {
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-light: #eff6ff;
  --ink: #1f2937;
  --muted: #6b7280;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --border: #e5e7eb;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --ok: #16a34a;
  --ok-light: #f0fdf4;
  --warn: #d97706;
  --warn-light: #fffbeb;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 4px; font-weight: 700; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
p.lead { color: var(--muted); margin-top: 0; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
}

label { display: block; font-weight: 600; font-size: 13px; margin: 14px 0 6px; }
label.inline { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }

input[type=text], input[type=email], input[type=tel], input[type=password],
input[type=url], input[type=number], input[type=date], input[type=search],
select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

button, .btn {
  display: inline-block;
  padding: 10px 16px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}
button:hover, .btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f9fafb; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-block { display: block; width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 13px; }

.alert { padding: 12px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 16px; }
.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid #fecaca; }
.alert-ok { background: var(--ok-light); color: var(--ok); border: 1px solid #bbf7d0; }
.alert-warn { background: var(--warn-light); color: var(--warn); border: 1px solid #fde68a; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
table th, table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
table tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-active { background: var(--ok-light); color: var(--ok); }
.badge-pending { background: var(--warn-light); color: var(--warn); }
.badge-disabled { background: #f3f4f6; color: var(--muted); }
.badge-removed { background: var(--danger-light); color: var(--danger); }
.badge-admin { background: var(--brand-light); color: var(--brand); }
.badge-in { background: var(--ok-light); color: var(--ok); }
.badge-out { background: #f3f4f6; color: var(--muted); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.stat-card .value { font-size: 26px; font-weight: 700; }
.stat-card .label { color: var(--muted); font-size: 13px; margin-top: 2px; }

.flex { display: flex; align-items: center; flex-wrap: wrap; }
.flex-between { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-0 { margin-top: 0; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.muted { color: var(--muted); }
.text-center { text-align: center; }

/* ---- Admin shell (sidebar layout) ---- */
.admin-shell { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #111827;
  color: #d1d5db;
  padding: 20px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.admin-sidebar .brand { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 0 20px 20px; }
.admin-sidebar .brand .logo { width: 32px; height: 32px; border-radius: 8px; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.admin-sidebar .brand img.logo { width: 100px; height: 100px; max-width: 100%; background: transparent; object-fit: contain; border-radius: 0; }
.admin-sidebar .brand span { font-weight: 600; color: #fff; font-size: 14px; }
.admin-sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; color: #9ca3af; font-size: 14px; font-weight: 500;
  text-decoration: none; border-left: 3px solid transparent;
}
.admin-sidebar nav a:hover { color: #fff; background: rgba(255,255,255,.04); }
.admin-sidebar nav a.active { color: #fff; background: rgba(37,99,235,.15); border-left-color: var(--brand); }
.admin-sidebar .sidebar-foot { padding: 16px 20px 0; margin-top: 16px; border-top: 1px solid rgba(255,255,255,.08); }
.admin-main { flex: 1; min-width: 0; }
.admin-topbar { display: flex; align-items: center; justify-content: space-between; padding: 16px 28px; background: #fff; border-bottom: 1px solid var(--border); }
.admin-content { padding: 28px; max-width: 1100px; }

/* ---- Toggle switch ---- */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .switch-track { position: absolute; inset: 0; background: #d1d5db; transition: background .15s; border-radius: 24px; cursor: pointer; }
.switch .switch-track::before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px; background: #fff; transition: transform .15s; border-radius: 50%; }
.switch input:checked + .switch-track { background: var(--brand); }
.switch input:checked + .switch-track::before { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--brand); outline-offset: 2px; }
.switch-row { display: flex; align-items: center; gap: 10px; }

/* ---- Stats charts (admin/supply-stats.php) ---- */
.chart-card { margin-bottom: 24px; }
.chart-title { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.chart-subtitle { color: var(--muted); font-size: 12px; margin-bottom: 14px; }

.hbar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.hbar-label { width: 150px; flex-shrink: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { flex: 1; background: #f3f3f1; border-radius: 4px; height: 16px; }
.hbar-fill { height: 100%; border-radius: 4px; min-width: 3px; }
.hbar-value { width: 56px; flex-shrink: 0; text-align: right; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.vbar-chart { display: flex; align-items: flex-end; gap: 8px; height: 160px; border-bottom: 1px solid var(--border); padding-top: 20px; }
.vbar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.vbar-value { font-size: 11px; color: var(--muted); margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.vbar-bar { width: 100%; max-width: 28px; border-radius: 4px 4px 0 0; min-height: 2px; }
.vbar-label { margin-top: 6px; font-size: 11px; color: var(--muted); text-align: center; }

.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; font-size: 12px; color: var(--ink); }
.chart-legend-item { display: flex; align-items: center; gap: 6px; }
.chart-legend-swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; flex-shrink: 0; }

.grouped-row { margin-bottom: 14px; }
.grouped-row-label { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.grouped-bars { display: flex; flex-direction: column; gap: 3px; }
.grouped-bar-line { display: flex; align-items: center; gap: 8px; }
.grouped-bar-track { flex: 1; background: #f3f3f1; border-radius: 3px; height: 12px; }
.grouped-bar-fill { height: 100%; border-radius: 3px; min-width: 2px; }
.grouped-bar-value { width: 48px; flex-shrink: 0; text-align: right; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

.stats-table { width: 100%; font-size: 13px; }

/* ---- Training: progress meters + video embed (admin/training.php, app/training*.php) ---- */
.progress-track { background: var(--brand-light); border-radius: 999px; height: 10px; overflow: hidden; }
.progress-track.lg { height: 14px; }
.progress-fill { height: 100%; background: var(--brand); border-radius: 999px; min-width: 2%; transition: width .2s; }
.training-video-row { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--border); text-decoration: none; color: inherit; }
.training-video-row:last-child { border-bottom: none; }
.training-video-row:hover { text-decoration: none; }
.training-video-row .thumb { position: relative; flex-shrink: 0; width: 96px; height: 54px; border-radius: 6px; overflow: hidden; background: var(--brand-light); }
.training-video-row .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.training-video-row .thumb::before { content: ""; position: absolute; inset: 0; margin: auto; width: 28px; height: 28px; border-radius: 50%; background: rgba(0, 0, 0, .55); }
.training-video-row .thumb::after { content: ""; position: absolute; top: 50%; left: 50%; transform: translate(-38%, -50%); border-style: solid; border-width: 6px 0 6px 10px; border-color: transparent transparent transparent #fff; }
.training-video-row .info { flex: 1; min-width: 0; }
.training-video-row .title { font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.training-video-row .meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.training-video-row .meta .progress-track { flex: 1; min-width: 60px; }
.training-video-row .duration { flex-shrink: 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.video-embed-wrap { position: relative; width: 100%; padding-top: 56.25%; background: #000; border-radius: var(--radius); overflow: hidden; }
.video-embed-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.closet-jump-nav { display: flex; flex-wrap: wrap; gap: 8px; }
.closet-jump-nav a { background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: 5px 12px; font-size: 12px; color: var(--ink); text-decoration: none; }
.closet-jump-nav a:hover { background: var(--brand-light); text-decoration: none; }

/* ---- Drag-to-reorder rows (e.g. admin/supplies.php) ---- */
.drag-handle { cursor: grab; color: var(--muted); font-size: 15px; user-select: none; touch-action: none; }
.drag-handle:active { cursor: grabbing; }
tr.dragging { opacity: .4; background: var(--brand-light); }

/* ---- Auth screens (centered card) ---- */
.auth-wrap { max-width: 420px; margin: 0 auto; padding: 64px 20px; }
.auth-wrap .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; justify-content: center; }
.auth-wrap .brand .logo { width: 36px; height: 36px; border-radius: 8px; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.auth-wrap .brand img.logo { width: 100px; height: 100px; max-width: 100%; background: transparent; object-fit: contain; border-radius: 0; }
.auth-wrap .brand span { font-weight: 700; font-size: 16px; }
/* Bigger logo on the two login screens only (admin/login.php, app/login.php) */
.auth-wrap .brand .logo.logo-lg { width: 150px; height: 150px; font-size: 42px; }

/* ---- User app shell ---- */
.app-shell { max-width: 480px; margin: 0 auto; padding: 0 0 40px; }
.app-topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.app-topbar .brand-link { display: block; line-height: 0; }
.app-topbar img.topbar-logo { width: 50px; height: 50px; max-width: 50px; background: transparent; object-fit: contain; border-radius: 0; display: block; }
.app-topbar div.topbar-logo { width: 50px; height: 50px; border-radius: 8px; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }

/* ---- Employee app: mobile drawer menu (replaces a horizontal link row) ---- */
#app-menu-toggle {
  background: none; border: none; padding: 8px; margin: -8px; cursor: pointer;
  font-size: 22px; line-height: 1; color: var(--ink);
}
#app-menu-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
#app-menu-overlay.open { display: block; }
#app-menu {
  position: fixed; top: 0; right: -260px; width: 240px; max-width: 78vw; height: 100vh;
  background: #fff; box-shadow: -2px 0 16px rgba(0,0,0,.18); z-index: 21;
  display: flex; flex-direction: column; padding: 8px 0 20px;
  transition: right .2s ease; overflow-y: auto;
}
#app-menu.open { right: 0; }
#app-menu-close { align-self: flex-end; background: none; border: none; font-size: 24px; line-height: 1; color: var(--muted); padding: 12px 16px; cursor: pointer; }
#app-menu a { padding: 14px 22px; color: var(--ink); text-decoration: none; font-size: 15px; font-weight: 500; border-left: 3px solid transparent; }
#app-menu a:hover { background: #f9fafb; text-decoration: none; }
#app-menu a.active { color: var(--brand); border-left-color: var(--brand); background: var(--brand-light); font-weight: 700; }
.app-menu-divider { margin: 8px 22px; border-top: 1px solid var(--border); }

.app-content { padding: 20px; }
.clock-card { text-align: center; padding: 32px 24px; }
.clock-status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot-in-range { background: var(--ok); }
.dot-out-range { background: var(--danger); }
.dot-checking { background: var(--warn); }
.clock-time { font-size: 42px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 8px 0; }
.clock-btn {
  width: 160px; height: 160px; border-radius: 50%; border: none; font-size: 17px; font-weight: 700;
  color: #fff; cursor: pointer; margin: 20px auto; display: flex; align-items: center; justify-content: center;
}
.clock-btn.clock-in { background: var(--ok); }
.clock-btn.clock-in:hover { background: #15803d; }
.clock-btn.clock-out { background: var(--danger); }
.clock-btn.clock-out:hover { background: #b91c1c; }
.clock-btn:disabled { background: #d1d5db; cursor: not-allowed; }

.history-item { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.history-item:last-child { border-bottom: none; }

/* Two-column layout (calendar grid + day panel) — its own class instead of
   an inline style, so the mobile override below can actually win: an
   inline style always beats a stylesheet rule, media query or not. */
.calendar-layout { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; align-items: start; }

#sidebar-toggle { display: none; }
#sidebar-overlay { display: none; }

@media (max-width: 720px) {
  .admin-sidebar { position: fixed; left: -240px; top: 0; z-index: 21; transition: left .2s; box-shadow: 2px 0 12px rgba(0,0,0,.2); }
  .admin-sidebar.open { left: 0; }
  #sidebar-toggle { display: inline-block; }
  #sidebar-overlay.open {
    display: block; position: fixed; inset: 0; z-index: 20;
    background: rgba(0,0,0,.4);
  }
  .admin-topbar { padding: 14px 16px; }
  .admin-content { padding: 16px; }
  .row2, .row3, .calendar-layout { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
  .clock-btn { width: 140px; height: 140px; }
  .clock-time { font-size: 34px; }
}

@media (max-width: 380px) {
  .card { padding: 18px; }
  .admin-content { padding: 12px; }
  .app-content { padding: 14px; }
}
