/* ============================================================
   KARVELO PACKING SYSTEM — Main Stylesheet
   Design: Modern minimalis, biru #1b8ee8
   ============================================================ */

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:         #1b8ee8;
  --blue-dark:    #1472c4;
  --blue-light:   #d6edfb;
  --green:        #22c55e;
  --green-light:  #dcfce7;
  --red:          #ef4444;
  --red-light:    #fee2e2;
  --yellow:       #f59e0b;
  --yellow-light: #fef3c7;
  --gray-50:      #f8fafc;
  --gray-100:     #f1f5f9;
  --gray-200:     #e2e8f0;
  --gray-400:     #94a3b8;
  --gray-600:     #475569;
  --gray-800:     #1e293b;
  --white:        #ffffff;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.08);
  --shadow:       0 4px 12px rgba(0,0,0,.10);
  --shadow-lg:    0 10px 30px rgba(0,0,0,.14);
  --radius:       10px;
  --radius-lg:    16px;
  --font:         'Inter', 'Segoe UI', system-ui, sans-serif;
}

html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  font-size: 15px;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
input, button, select, textarea { font-family: inherit; }

/* ---- Layout ---- */
.app-wrapper { display: flex; min-height: 100vh; }

/* ---- Sidebar ---- */
.sidebar {
  width: 240px;
  background: var(--gray-800);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .2s ease;
}
.sidebar-logo {
  padding: 24px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo .logo-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--white);
  letter-spacing: -.3px;
}
.sidebar-logo .logo-sub {
  font-size: 11px;
  color: var(--gray-400);
  margin-top: 2px;
}
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: rgba(255,255,255,.7);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s ease;
  border-left: 3px solid transparent;
}
.nav-item:hover { color: var(--white); background: rgba(255,255,255,.06); text-decoration: none; }
.nav-item.active { color: var(--white); background: rgba(27,142,232,.25); border-left-color: var(--blue); }
.nav-item .nav-icon { font-size: 18px; width: 22px; text-align: center; }
.nav-section { padding: 16px 20px 6px; font-size: 10px; font-weight: 700; color: var(--gray-400); text-transform: uppercase; letter-spacing: 1px; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-user { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--blue); display: flex; align-items: center; justify-content: center; color: var(--white); font-weight: 700; font-size: 13px; flex-shrink: 0; }
.user-info .name { font-size: 13px; font-weight: 600; color: var(--white); }
.user-info .role { font-size: 11px; color: var(--gray-400); }
.btn-logout { margin-top: 10px; width: 100%; background: rgba(239,68,68,.15); color: #fca5a5; border: none; border-radius: var(--radius); padding: 8px; font-size: 13px; cursor: pointer; transition: background .15s; }
.btn-logout:hover { background: rgba(239,68,68,.3); }

/* ---- Main Content ---- */
.main-content {
  flex: 1;
  margin-left: 240px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.page-title { font-size: 20px; font-weight: 700; color: var(--gray-800); }
.page-subtitle { font-size: 13px; color: var(--gray-400); margin-top: 1px; }
.content { padding: 28px; flex: 1; }

/* ---- Cards ---- */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  padding: 24px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.card-title { font-size: 16px; font-weight: 700; color: var(--gray-800); }
.card-subtitle { font-size: 13px; color: var(--gray-400); }

/* ---- Stat Widgets ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  gap: 16px;
}
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.stat-icon.blue   { background: var(--blue-light); color: var(--blue); }
.stat-icon.green  { background: var(--green-light); color: var(--green); }
.stat-icon.red    { background: var(--red-light);   color: var(--red);  }
.stat-icon.yellow { background: var(--yellow-light); color: var(--yellow); }
.stat-value { font-size: 28px; font-weight: 800; color: var(--gray-800); line-height: 1; }
.stat-label { font-size: 12px; color: var(--gray-400); margin-top: 4px; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .15s ease;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--blue); color: var(--white); }
.btn-primary:hover { background: var(--blue-dark); color: var(--white); }
.btn-success { background: var(--green); color: var(--white); }
.btn-success:hover { background: #16a34a; color: var(--white); }
.btn-danger  { background: var(--red); color: var(--white); }
.btn-danger:hover  { background: #dc2626; color: var(--white); }
.btn-warning { background: var(--yellow); color: var(--white); }
.btn-warning:hover { background: #d97706; color: var(--white); }
.btn-outline { background: var(--white); color: var(--gray-600); border: 1.5px solid var(--gray-200); }
.btn-outline:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-light); }
.btn-lg { padding: 14px 28px; font-size: 16px; border-radius: 12px; }
.btn-xl { padding: 18px 36px; font-size: 18px; border-radius: 14px; }
.btn-sm { padding: 7px 14px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---- Badges ---- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-recording { background: rgba(34,197,94,.15); color: #15803d; }
.badge-completed { background: rgba(27,142,232,.15); color: #1472c4; }
.badge-failed    { background: rgba(239,68,68,.15);  color: #b91c1c; }
.badge-unknown   { background: var(--gray-100); color: var(--gray-600); }

/* ---- Table ---- */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-lg); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th { background: var(--gray-50); padding: 12px 16px; text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .7px; color: var(--gray-400); border-bottom: 1px solid var(--gray-200); white-space: nowrap; }
tbody td { padding: 14px 16px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--gray-50); }
.table-resi { font-family: 'Courier New', monospace; font-weight: 700; font-size: 13px; color: var(--gray-800); }

/* ---- Forms ---- */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-600); margin-bottom: 6px; }
.form-control {
  display: block; width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--gray-800);
  background: var(--white);
  transition: border-color .15s;
  outline: none;
}
.form-control:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(27,142,232,.1); }
.form-control::placeholder { color: var(--gray-400); }

/* ---- Search Bar ---- */
.search-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search-input { flex: 1; min-width: 200px; }
.filter-select { min-width: 140px; }

/* ---- Alert ---- */
.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 14px; margin-bottom: 16px; display: flex; align-items: flex-start; gap: 10px; }
.alert-success { background: var(--green-light); color: #15803d; border: 1px solid #bbf7d0; }
.alert-error   { background: var(--red-light);   color: #b91c1c; border: 1px solid #fecaca; }
.alert-warning { background: var(--yellow-light); color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: var(--blue-light);  color: #1472c4; border: 1px solid #bae0fd; }

/* ---- Login Page ---- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--gray-800) 0%, #0f172a 100%); padding: 20px; }
.login-card { background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 44px 40px; width: 100%; max-width: 420px; }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo .logo-icon { font-size: 48px; margin-bottom: 10px; }
.login-logo h1 { font-size: 24px; font-weight: 800; color: var(--gray-800); }
.login-logo p { font-size: 14px; color: var(--gray-400); margin-top: 4px; }
.btn-login { width: 100%; padding: 13px; font-size: 15px; margin-top: 6px; }
.login-footer { text-align: center; margin-top: 20px; font-size: 12px; color: var(--gray-400); }

/* ============================================================
   SCANNER PAGE
   ============================================================ */
.scanner-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: #0a0e1a;
  color: var(--white);
  overflow: hidden;
}
.scanner-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: rgba(255,255,255,.04);
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.scanner-topbar .logo { font-size: 16px; font-weight: 700; color: var(--white); }
.scanner-topbar .status-bar { display: flex; align-items: center; gap: 16px; }
.scanner-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 360px;
  overflow: hidden;
}
.camera-panel {
  position: relative;
  background: #000;
  overflow: hidden;
}
.camera-panel video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.qr-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.qr-frame {
  width: 220px; height: 220px;
  border: 3px solid var(--blue);
  border-radius: 16px;
  box-shadow: 0 0 0 4000px rgba(0,0,0,.45);
  position: relative;
  animation: pulse-frame 2s ease-in-out infinite;
}
.qr-frame::before, .qr-frame::after,
.qr-frame .corner-br, .qr-frame .corner-bl {
  content: '';
  position: absolute;
  width: 28px; height: 28px;
  border-color: var(--blue);
  border-style: solid;
}
.qr-frame::before  { top: -4px;  left: -4px;  border-width: 5px 0 0 5px; border-radius: 4px 0 0 0; }
.qr-frame::after   { top: -4px;  right: -4px; border-width: 5px 5px 0 0; border-radius: 0 4px 0 0; }
.qr-frame .corner-br { bottom: -4px; right: -4px; border-width: 0 5px 5px 0; border-radius: 0 0 4px 0; }
.qr-frame .corner-bl { bottom: -4px; left: -4px;  border-width: 0 0 5px 5px; border-radius: 0 0 0 4px; }
@keyframes pulse-frame { 0%,100%{box-shadow:0 0 0 4000px rgba(0,0,0,.45),0 0 12px rgba(27,142,232,.6)} 50%{box-shadow:0 0 0 4000px rgba(0,0,0,.5),0 0 28px rgba(27,142,232,1)} }
.scan-line {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--blue), transparent);
  animation: scan 2s ease-in-out infinite;
  top: 0;
}
@keyframes scan { 0%{top:0} 100%{top:100%} }

/* Recording indicator on camera */
.rec-indicator {
  position: absolute;
  top: 16px; left: 16px;
  background: rgba(0,0,0,.6);
  border-radius: 8px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
}
.rec-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--red);
  animation: blink 1s step-end infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }
.rec-timer { font-variant-numeric: tabular-nums; }

/* Right panel */
.scanner-panel {
  background: #0f1525;
  border-left: 1px solid rgba(255,255,255,.06);
  display: flex;
  flex-direction: column;
  padding: 24px;
  gap: 20px;
  overflow-y: auto;
}
.panel-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,.35);
  margin-bottom: 10px;
}

/* Status box */
.status-box {
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
  transition: all .3s ease;
}
.status-box.idle     { background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.08); }
.status-box.rec      { background: rgba(239,68,68,.12);   border: 1px solid rgba(239,68,68,.3); }
.status-box.done     { background: rgba(34,197,94,.12);   border: 1px solid rgba(34,197,94,.3); }
.status-box.uploading{ background: rgba(27,142,232,.12);  border: 1px solid rgba(27,142,232,.3); }
.status-emoji { font-size: 40px; margin-bottom: 8px; }
.status-title { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.status-desc  { font-size: 13px; color: rgba(255,255,255,.55); }

/* Current resi display */
.resi-display {
  background: rgba(27,142,232,.1);
  border: 1px solid rgba(27,142,232,.3);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.resi-label { font-size: 11px; color: rgba(255,255,255,.4); text-transform: uppercase; letter-spacing: .8px; font-weight: 600; margin-bottom: 4px; }
.resi-value { font-size: 20px; font-weight: 800; font-family: 'Courier New', monospace; color: var(--blue); letter-spacing: 1px; word-break: break-all; }

/* Manual input */
.manual-input-area input {
  background: rgba(255,255,255,.06);
  border: 1.5px solid rgba(255,255,255,.12);
  color: var(--white);
  border-radius: var(--radius);
  padding: 11px 14px;
  width: 100%;
  font-size: 14px;
  outline: none;
}
.manual-input-area input:focus { border-color: var(--blue); }
.manual-input-area input::placeholder { color: rgba(255,255,255,.3); }

/* Recent scans list */
.recent-list { display: flex; flex-direction: column; gap: 8px; max-height: 220px; overflow-y: auto; }
.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,.04);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  border-left: 3px solid transparent;
}
.recent-item.completed   { border-left-color: var(--blue); }
.recent-item.recording   { border-left-color: var(--green); }
.recent-item.upload_failed { border-left-color: var(--red); }
.recent-item .r-resi   { font-weight: 700; color: var(--white); font-family: monospace; }
.recent-item .r-status { font-size: 11px; }
.recent-item .r-time   { font-size: 11px; color: rgba(255,255,255,.3); }

/* Toast notification */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 1000; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.toast {
  background: var(--gray-800);
  color: var(--white);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  max-width: 340px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-left: 4px solid var(--blue);
  animation: slide-in .2s ease;
}
.toast.success { border-left-color: var(--green); }
.toast.error   { border-left-color: var(--red); }
.toast.warning { border-left-color: var(--yellow); }
@keyframes slide-in { from{transform:translateX(100%);opacity:0} to{transform:translateX(0);opacity:1} }

/* Progress bar */
.progress-bar { height: 4px; background: rgba(255,255,255,.1); border-radius: 2px; overflow: hidden; margin-top: 10px; }
.progress-fill { height: 100%; background: var(--blue); border-radius: 2px; transition: width .3s; }

/* Webcam error overlay */
.camera-error {
  position: absolute;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px;
  text-align: center;
}
.camera-error .err-icon { font-size: 64px; }
.camera-error h3 { font-size: 18px; font-weight: 700; }
.camera-error p  { font-size: 14px; color: rgba(255,255,255,.5); max-width: 300px; }

/* ---- Shipments Table Page ---- */
.page-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.pagination { display: flex; align-items: center; gap: 6px; margin-top: 16px; justify-content: center; }
.page-btn { width: 36px; height: 36px; border: 1.5px solid var(--gray-200); border-radius: 8px; background: var(--white); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; color: var(--gray-600); transition: all .15s; }
.page-btn:hover { border-color: var(--blue); color: var(--blue); }
.page-btn.active { background: var(--blue); border-color: var(--blue); color: var(--white); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---- Detail Page ---- */
.detail-grid { display: grid; grid-template-columns: 1fr 340px; gap: 24px; }
.video-player-wrap { background: #000; border-radius: var(--radius-lg); overflow: hidden; aspect-ratio: 16/9; display: flex; align-items: center; justify-content: center; }
.video-player-wrap video { width: 100%; height: 100%; }
.no-video-placeholder { text-align: center; color: rgba(255,255,255,.4); font-size: 14px; }
.no-video-placeholder .icon { font-size: 48px; margin-bottom: 12px; }
.info-row { display: flex; justify-content: space-between; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--gray-100); font-size: 14px; }
.info-row:last-child { border-bottom: none; }
.info-key { color: var(--gray-400); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.info-val { color: var(--gray-800); font-weight: 600; text-align: right; max-width: 220px; word-break: break-all; }
.log-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.log-item { display: flex; gap: 10px; font-size: 12px; }
.log-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--blue); flex-shrink: 0; margin-top: 4px; }
.log-action { font-weight: 700; color: var(--gray-800); }
.log-desc { color: var(--gray-400); }
.log-time { color: var(--gray-400); font-size: 11px; white-space: nowrap; }

/* ---- Modals ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 500; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 480px; padding: 28px; }
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }

/* ---- Loading Overlay ---- */
.loading-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 900; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; color: var(--white); }
.spinner { width: 48px; height: 48px; border: 4px solid rgba(255,255,255,.2); border-top-color: var(--blue); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to{transform:rotate(360deg)} }
.loading-text { font-size: 15px; font-weight: 600; }

/* ---- Chart placeholder ---- */
.chart-container { height: 200px; display: flex; align-items: flex-end; gap: 8px; padding: 0 4px; }
.bar { flex: 1; background: var(--blue); border-radius: 4px 4px 0 0; min-height: 4px; transition: height .4s ease; position: relative; }
.bar-label { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--gray-400); white-space: nowrap; }
.bar-value { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--gray-600); font-weight: 700; }

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .scanner-body { grid-template-columns: 1fr; }
  .scanner-panel { max-height: 260px; }
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .content { padding: 16px; }
  .login-card { padding: 28px 20px; }
}
