:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

#loginScreen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #111827 0%, #1e3a8a 100%);
  padding: 16px;
}
body.logged-in #loginScreen { display: none; }
body:not(.logged-in) .app { display: none; }

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  text-align: center;
}
.login-card .login-logo { font-size: 40px; margin-bottom: 6px; }
.login-card h2 { margin: 0 0 4px; }
.login-card .login-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
.login-card label { display: block; text-align: left; font-size: 12px; color: var(--text-muted); margin: 14px 0 4px; }
.login-card input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px;
}
.login-card .btn-primary { width: 100%; margin-top: 22px; padding: 12px; font-size: 15px; }
.login-card .login-hint { margin-top: 16px; font-size: 12px; color: var(--text-muted); }
.login-card .login-error { margin-top: 14px; font-size: 12px; color: var(--danger); min-height: 14px; }

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px; background: #111827; color: #fff;
  display: flex; flex-direction: column; padding: 20px 14px; flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 30px; padding: 0 8px; }
.brand-logo { font-size: 26px; }
.brand-name { font-weight: 700; font-size: 18px; }
.btn-toggle-menu {
  display: none; margin-left: auto; background: transparent; border: none;
  color: #fff; font-size: 22px; cursor: pointer; padding: 4px 8px;
}
.sidebar-menu { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.nav-item {
  background: transparent; border: none; color: #cbd5e1;
  text-align: left; padding: 12px 14px; border-radius: var(--radius);
  cursor: pointer; font-size: 15px; transition: 0.15s;
}
.nav-item:hover { background: #1f2937; color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }

.sidebar-footer { margin-top: 20px; }
.user-box { background: #1f2937; border-radius: var(--radius); padding: 12px; }
.user-box .user-nama { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-box .user-actions { display: flex; gap: 6px; margin-top: 10px; }
.btn-sidebar-kecil {
  flex: 1; background: #374151; color: #e2e8f0; border: none; border-radius: 6px;
  padding: 7px 6px; font-size: 11px; cursor: pointer;
}
.btn-sidebar-kecil:hover { background: #4b5563; }

.role-badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px;
  margin-top: 4px;
}
.role-badge.admin { background: #1d4ed8; color: #dbeafe; }
.role-badge.kasir { background: #374151; color: #cbd5e1; }

.role-badge-table { background: #dbeafe; color: #1d4ed8; }
.role-badge-table.kasir { background: #e2e8f0; color: #475569; }

.status-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.status-badge.aktif { background: #dcfce7; color: #16a34a; }
.status-badge.nonaktif { background: #fee2e2; color: #dc2626; }

.main { flex: 1; padding: 24px; overflow-x: hidden; }
.tab-content { display: none; }
.tab-content.active { display: block; }

.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.panel-header h2 { margin: 0; }
.header-actions { display: flex; gap: 10px; flex-wrap: wrap; }

input, select, button { font-family: inherit; font-size: 14px; }
input[type=text], input[type=number], input[type=date], input[type=password], select {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text); width: 100%;
}
input[type=file] { padding: 8px 0; width: 100%; }

.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 14px 0 4px; }
.checkbox-row input[type=checkbox] { width: 16px; height: 16px; }
.checkbox-row label { margin: 0; font-size: 13px; color: var(--text); }

.kasir-grid { display: grid; grid-template-columns: 1fr 360px; gap: 18px; align-items: start; }
.produk-panel, .cart-panel { background: var(--card); border-radius: var(--radius); padding: 16px; border: 1px solid var(--border); }
.produk-panel .panel-header { gap: 10px; margin-bottom: 14px; }
#searchProduk { flex: 1; min-width: 160px; }
#filterKategori { max-width: 180px; }

.produk-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px;
  max-height: 65vh; overflow-y: auto; padding-right: 4px;
}
.produk-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; cursor: pointer; transition: 0.15s; background: #fafbfc; text-align: left; }
.produk-card:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(37,99,235,0.15); }
.produk-card.habis { opacity: 0.5; cursor: not-allowed; }
.produk-card .p-nama { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.produk-card .p-kategori { font-size: 11px; color: var(--text-muted); margin-bottom: 8px; }
.produk-card .p-harga { color: var(--primary); font-weight: 700; }
.produk-card .p-stok { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.p-gambar { width: 100%; height: 90px; object-fit: cover; border-radius: 8px; margin-bottom: 8px; background: #eef2f7; display: block; }
.p-gambar-placeholder { display: flex; align-items: center; justify-content: center; font-size: 26px; }

.cart-panel h3 { margin-top: 0; }
.cart-list { max-height: 38vh; overflow-y: auto; margin-bottom: 12px; }
.empty-msg { color: var(--text-muted); font-size: 14px; text-align: center; padding: 20px 0; }
.cart-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); gap: 8px; }
.cart-item .ci-info { flex: 1; min-width: 0; }
.cart-item .ci-nama { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-item .ci-harga { font-size: 12px; color: var(--text-muted); }
.qty-control { display: flex; align-items: center; gap: 6px; }
.qty-control button { width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--border); background: #fff; cursor: pointer; font-weight: 700; }
.qty-control span { min-width: 20px; text-align: center; font-size: 13px; }
.ci-remove { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 16px; }

.cart-summary { border-top: 1px solid var(--border); padding-top: 12px; }
.cart-summary .row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 15px; }
.cart-summary label { font-size: 12px; color: var(--text-muted); display: block; margin-bottom: 4px; }
.cart-summary input, .cart-summary select { margin-bottom: 12px; }

.btn-primary, .btn-secondary { padding: 11px 16px; border-radius: 8px; border: none; cursor: pointer; font-weight: 600; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-block { width: 100%; margin-top: 8px; }

.table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
.table th { background: #f1f5f9; font-weight: 600; color: var(--text-muted); }
.table td button { margin-right: 6px; padding: 6px 10px; border-radius: 6px; border: none; cursor: pointer; font-size: 12px; }
.btn-edit { background: #dbeafe; color: var(--primary-dark); }
.btn-hapus { background: #fee2e2; color: var(--danger); }
.btn-lihat { background: #e0f2fe; color: #0369a1; }

.thumb-produk { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); display: block; }
.thumb-placeholder { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; background: #f1f5f9; border-radius: 6px; font-size: 18px; }

.ringkasan-cards { display: flex; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.card-ringkasan { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; min-width: 180px; }
.card-ringkasan .label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.card-ringkasan .value { font-size: 22px; font-weight: 700; color: var(--primary); }

.filter-laporan { display: flex; align-items: end; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-laporan label { font-size: 12px; color: var(--text-muted); }
.filter-laporan input { width: auto; }

.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.5); align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.modal-overlay.active { display: flex; }
.modal { background: #fff; border-radius: var(--radius); padding: 22px; width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto; }
.modal h3 { margin-top: 0; }
.modal label { display: block; font-size: 12px; color: var(--text-muted); margin: 10px 0 4px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.hint-text { display: block; font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.upload-gambar { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; border: 1px dashed var(--border); border-radius: var(--radius); padding: 10px; }
.preview-gambar { width: 100%; max-width: 200px; height: 140px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }

.struk { font-family: 'Courier New', monospace; font-size: 13px; }
.struk h4 { text-align: center; margin: 0 0 4px; }
.struk .center { text-align: center; }
.struk hr { border: none; border-top: 1px dashed #999; margin: 8px 0; }
.struk .struk-row { display: flex; justify-content: space-between; }
.struk .struk-total { font-weight: 700; font-size: 15px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1e293b; color: #fff; padding: 12px 20px; border-radius: 8px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: 0.25s; z-index: 2000;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

.loading-overlay { display: none; position: fixed; inset: 0; background: rgba(255,255,255,0.6); align-items: center; justify-content: center; z-index: 3000; }
.loading-overlay.active { display: flex; }
.spinner { width: 40px; height: 40px; border: 4px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal-lg { max-width: 520px; }
.cetak-barcode-list { max-height: 50vh; overflow-y: auto; margin: 10px 0; }
.cetak-barcode-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.cetak-barcode-row:last-child { border-bottom: none; }
.cetak-barcode-row .cb-info { flex: 1; min-width: 0; }
.cetak-barcode-row .cb-nama { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cetak-barcode-row .cb-kode { font-size: 12px; color: var(--text-muted); }
.cetak-barcode-row .cb-qty { width: 70px; text-align: center; }

.chk-produk, #checkAllProduk { width: 16px; height: 16px; cursor: pointer; }

.print-barcode-area { display: none; }
.print-struk-area { display: none; }

@media print {
  body * { visibility: hidden; }

  .print-barcode-area, .print-barcode-area * { visibility: visible; }
  .print-barcode-area {
    display: grid !important; position: absolute; left: 0; top: 0; width: 100%;
    grid-template-columns: repeat(3, 1fr); gap: 6mm;
  }
  .label-barcode { border: 1px dashed #999; padding: 3mm; text-align: center; page-break-inside: avoid; }
  .label-barcode .lb-nama { font-size: 10px; font-weight: 700; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .label-barcode .lb-harga { font-size: 10px; margin-bottom: 2px; }
  .label-barcode svg { width: 100%; height: auto; }

  .print-struk-area, .print-struk-area * { visibility: visible; }
  .print-struk-area {
    display: block !important; position: absolute; left: 0; top: 0; width: 80mm;
    font-family: 'Courier New', monospace; font-size: 12px; padding: 4mm;
  }
  .print-struk-area h4 { text-align: center; margin: 0 0 4px; font-size: 14px; }
  .print-struk-area .center { text-align: center; }
  .print-struk-area hr { border: none; border-top: 1px dashed #000; margin: 6px 0; }
  .print-struk-area .struk-row { display: flex; justify-content: space-between; }
  .print-struk-area .struk-total { font-weight: 700; font-size: 13px; }

  @page { margin: 8mm; }
}

@media (max-width: 900px) {
  .app { flex-direction: column; }

  .sidebar {
    width: 100%; flex-direction: column; padding: 12px 16px;
    position: sticky; top: 0; z-index: 50;
  }
  .brand { margin-bottom: 0; }
  .btn-toggle-menu { display: block; }

  /* Menu (nav + info user) disembunyikan by default, jadi dropdown saat toggle dibuka */
  .sidebar-menu {
    max-height: 0; overflow: hidden; opacity: 0;
    transition: max-height 0.2s ease, opacity 0.2s ease, margin-top 0.2s ease;
    margin-top: 0;
  }
  .sidebar-menu.open {
    max-height: 70vh; overflow-y: auto; opacity: 1; margin-top: 14px;
  }
  .nav { flex-direction: column; }
  .sidebar-footer { margin-top: 14px; }

  .kasir-grid { grid-template-columns: 1fr; }
  .main { padding: 16px; }
  .produk-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); max-height: none; }
  .cart-list { max-height: none; }
}

@media (max-width: 480px) {
  .panel-header { flex-direction: column; align-items: stretch; }
  .header-actions { width: 100%; }
  .header-actions button { flex: 1; }
}