/* ══════════════════════════════════════════════
   MINI E-COMMERCE — Admin CSS
   Modern, Responsive, Mobile-First
══════════════════════════════════════════════ */

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

/* ── TOKENS ──────────────────────────────────── */
:root {
  --sidebar-w:      240px;
  --sidebar-bg:     #0f0e0c;
  --sidebar-border: rgba(255,255,255,.07);
  --sidebar-text:   rgba(255,255,255,.55);
  --sidebar-hover:  rgba(255,255,255,.07);
  --sidebar-active: rgba(255,255,255,.1);
  --topbar-h:       56px;
  --bottom-nav-h:   60px;
  --bg:             #f4f2ee;
  --surface:        #ffffff;
  --border:         #e8e3db;
  --ink:            #0f0e0c;
  --muted:          #7a7060;
  --gold:           #c9a84c;
  --rust:           #c44b2b;
  --sage:           #3d6b4f;
  --sky:            #2563a8;
  --r:              12px;
  --shadow-sm:      0 1px 3px rgba(15,14,12,.06);
  --shadow-md:      0 4px 16px rgba(15,14,12,.08);
  --shadow-lg:      0 12px 40px rgba(15,14,12,.12);
  --font: 'Plus Jakarta Sans', 'Segoe UI', sans-serif;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

/* ── RESET ───────────────────────────────────── */
*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  font-size: 14px;
  line-height: 1.6;
  overflow-x: hidden;
}
a { text-decoration: none; color: inherit; }
img { max-width: 100%; display: block; }
button, a, input, select, textarea {
  -webkit-tap-highlight-color: transparent;
}

/* ── SIDEBAR ─────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  height: 100vh;
  position: fixed;
  top: 0; left: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 200;
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--sidebar-border);
  min-height: 70px; flex-shrink: 0;
}
.sidebar-logo-img {
  width: 38px; height: 38px; border-radius: 10px;
  object-fit: cover; border: 1.5px solid rgba(255,255,255,.12); flex-shrink: 0;
}
.sidebar-logo-fallback {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 800; color: #fff;
  border: 1.5px solid rgba(255,255,255,.12);
}
.sidebar-store-name {
  font-size: 13px; font-weight: 700;
  color: rgba(255,255,255,.9); line-height: 1.3; word-break: break-word;
}
.sidebar-logo {
  font-size: 13px; font-weight: 700;
  padding: 20px 18px;
  border-bottom: 1px solid var(--sidebar-border);
  color: var(--gold); text-transform: uppercase; letter-spacing: .06em;
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar-logo small { font-size: 10px; color: rgba(255,255,255,.3); letter-spacing: .1em; font-weight: 500; }

.sidebar nav { padding: 10px 0; flex: 1; display: flex; flex-direction: column; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 18px;
  color: var(--sidebar-text);
  font-size: 13.5px; font-weight: 500;
  transition: all .2s;
  position: relative;
  margin: 1px 8px; border-radius: 8px;
  min-height: 44px;
}
.sidebar nav a:hover { background: var(--sidebar-hover); color: rgba(255,255,255,.9); }
.sidebar nav a.active { background: var(--sidebar-active); color: #fff; }
.sidebar nav a.active::before {
  content: '';
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; background: var(--gold);
  border-radius: 0 4px 4px 0; margin-left: -8px;
}
.sidebar nav a.nav-logout { margin-top: auto; color: rgba(255,255,255,.3); }
.sidebar nav a.nav-logout:hover { background: rgba(196,75,43,.15); color: #f87171; }

/* ── MOBILE TOGGLE — ada di dalam topbar ──────── */
.sidebar-toggle {
  display: none;
  position: static;
  width: 44px; height: 44px;
  background: transparent;
  border: none; border-radius: 10px;
  cursor: pointer;
  flex-direction: column; align-items: center;
  justify-content: center; gap: 5px;
  flex-shrink: 0; padding: 0;
}
.sidebar-toggle span {
  display: block; width: 20px; height: 2px;
  background: var(--ink); border-radius: 2px; transition: all .3s;
}
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.4); z-index: 190; backdrop-filter: blur(2px);
}

/* ── MAIN CONTENT ────────────────────────────── */
.main-content { margin-left: var(--sidebar-w); flex: 1; min-height: 100vh; display: flex; flex-direction: column; min-width: 0; max-width: 100%; }

/* ── TOPBAR ──────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow-sm);
  gap: 10px;
}
.topbar h1 { font-size: 15px; font-weight: 700; letter-spacing: -.01em; color: var(--ink); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.topbar-user { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 500; white-space: nowrap; }

/* ── CONTENT ─────────────────────────────────── */
.content { padding: 20px 24px; flex: 1; min-width: 0; overflow-x: hidden; }

/* ── ALERT ───────────────────────────────────── */
.alert {
  padding: 12px 16px; border-radius: var(--r);
  margin: 12px 24px 0; font-size: 13.5px; font-weight: 500;
  display: flex; align-items: center; gap: 8px;
}
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* ── STATS GRID ──────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px; margin-bottom: 20px;
}
.stat-card {
  background: var(--surface); border-radius: 16px; padding: 18px;
  border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  transition: transform .2s, box-shadow .2s;
  position: relative; overflow: hidden;
}
.stat-card::after {
  content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 3px;
  background: var(--gold); transform: scaleX(0); transform-origin: left; transition: transform .3s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card:hover::after { transform: scaleX(1); }
.stat-icon { font-size: 24px; margin-bottom: 8px; }
.stat-label { font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; }
.stat-value { font-size: 20px; font-weight: 800; letter-spacing: -.02em; color: var(--ink); line-height: 1.2; }

/* ── SECTION ─────────────────────────────────── */
.section {
  background: var(--surface); border-radius: 16px; padding: 20px;
  border: 1px solid var(--border); box-shadow: var(--shadow-sm); margin-bottom: 20px;
}
.section h2 { font-size: 15px; font-weight: 700; margin-bottom: 16px; color: var(--ink); letter-spacing: -.01em; }

/* ── TABLE WRAPPER ───────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 12px; }

/* ── TABLE ───────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 480px; }
.table th {
  background: #faf8f4; padding: 10px 14px;
  text-align: left; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid #f4f2ee; vertical-align: middle; color: var(--ink); }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #faf8f4; }

/* ── BADGES ──────────────────────────────────── */
.badge {
  padding: 3px 10px; border-radius: 100px;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; display: inline-block; white-space: nowrap;
}
.badge-pending  { background: #fef3c7; color: #d97706; }
.badge-proses   { background: #dbeafe; color: #2563eb; }
.badge-selesai  { background: #d1fae5; color: #059669; }
.badge-batal    { background: #fee2e2; color: #dc2626; }
.badge-active   { background: #d1fae5; color: #059669; }
.badge-inactive { background: #f1f5f9; color: #64748b; }
.badge-superadmin { background: #fef3c7; color: #92400e; }
.badge-owner    { background: #ede9fe; color: #6d28d9; }
.badge-kasir    { background: #dbeafe; color: #1e40af; }
.superadmin-badge { background: #fef3c7; color: #92400e; padding:3px 10px; border-radius:100px; font-size:11px; font-weight:700; }

/* ── BUTTONS ─────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 16px; border-radius: 8px;
  border: 1.5px solid var(--border); background: var(--surface);
  cursor: pointer; font-family: var(--font);
  font-size: 13px; font-weight: 600; color: var(--ink);
  text-decoration: none; transition: all .2s; white-space: nowrap;
  min-height: 44px;
}
.btn:hover { background: #f4f2ee; border-color: #d0c8b8; }
.btn-primary { background: var(--ink); color: #faf8f4; border-color: var(--ink); }
.btn-primary:hover { background: var(--rust); border-color: var(--rust); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(196,75,43,.25); }
.btn-danger  { background: #ef4444; color: #fff; border-color: #ef4444; }
.btn-danger:hover { background: #dc2626; border-color: #dc2626; }
.btn-success { background: var(--sage); color: #fff; border-color: var(--sage); }
.btn-success:hover { background: #2d5a3d; }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 7px; min-height: 36px; }
.btn-block { width: 100%; justify-content: center; }

/* ── PAGE HEADER ─────────────────────────────── */
.page-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; flex-wrap: wrap; gap: 10px;
}
.page-header h2 { font-size: 17px; font-weight: 800; letter-spacing: -.02em; }

/* ── FORMS ───────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 12px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 6px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%; padding: 12px 14px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-family: var(--font);
  font-size: 16px; /* 16px cegah zoom iOS */
  color: var(--ink);
  background: #faf8f4; transition: border-color .2s, box-shadow .2s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none; border-color: var(--gold); background: #fff;
  box-shadow: 0 0 0 3px rgba(201,168,76,.12);
}
.form-group textarea { resize: vertical; min-height: 90px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

/* ── FILTER BOX ──────────────────────────────── */
.filter-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px; margin-bottom: 16px;
}
.filter-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px; align-items: flex-end;
}

/* ── MODAL ───────────────────────────────────── */
.modal {
  position: fixed; z-index: 500; inset: 0;
  background: rgba(0,0,0,.45); display: flex;
  align-items: center; justify-content: center; padding: 16px;
}
.modal-content {
  background: var(--surface); border-radius: 16px;
  padding: 28px; width: 100%; max-width: 440px;
  box-shadow: var(--shadow-lg); position: relative;
  max-height: 90vh; overflow-y: auto;
}
.modal-content h2 { font-size: 17px; font-weight: 700; margin-bottom: 20px; }
.close {
  position: absolute; top: 16px; right: 20px;
  font-size: 22px; color: var(--muted); cursor: pointer;
  background: none; border: none; line-height: 1;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
}
.close:hover { color: var(--ink); }

/* ── CARD SECTION ────────────────────────────── */
.card {
  background: var(--surface); border-radius: 14px;
  border: 1px solid var(--border); padding: 20px;
  box-shadow: var(--shadow-sm);
}

/* ── AUTH PAGE ───────────────────────────────── */
body.auth-page {
  display: flex; justify-content: center; align-items: center;
  background: #f0ede8; min-height: 100vh;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.auth-box {
  background: var(--surface); padding: 40px; border-radius: 20px;
  width: 100%; max-width: 400px; box-shadow: var(--shadow-lg);
}
.auth-box h2 { font-size: 20px; margin-bottom: 24px; text-align: center; }

/* ── PRINT ───────────────────────────────────── */
@media print {
  .sidebar, .topbar, .page-header .btn, .sidebar-toggle,
  .filter-box, .no-print, .bottom-nav, .pwa-install-banner { display: none !important; }
  .main-content { margin-left: 0 !important; }
  body { background: white; }
}

/* ── TABLET (900px) ──────────────────────────── */
@media (max-width: 900px) {
  :root { --sidebar-w: 220px; }
}

/* ── MOBILE (768px) ──────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-overlay.open { display: block; }

  /* Toggle masuk ke dalam topbar */
  .sidebar-toggle { display: flex; }

  .main-content { margin-left: 0; }

  /* Topbar: safe area atas untuk notch/dynamic island */
  .topbar {
    height: auto;
    min-height: var(--topbar-h);
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: 8px;
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    gap: 8px;
  }
  .topbar h1 { font-size: 14px; }
  .topbar-user { font-size: 11px; }

  .alert { margin: 10px 12px 0; font-size: 12.5px; }

  /* Content: beri ruang untuk bottom nav */
  .content {
    padding: 12px;
    padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 12px);
  }

  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
  .stat-value { font-size: 17px; }
  .stat-card { padding: 14px; }
  .stat-icon { font-size: 20px; }
  .stat-label { font-size: 9px; }
  .form-row { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .section { padding: 14px; border-radius: 12px; }
  .page-header { flex-direction: row; }
  .form-actions { justify-content: stretch; }
  .form-actions .btn { flex: 1; justify-content: center; }
  .table { min-width: 540px; }
  .table-wrap { margin: 0 -2px; }

  /* Modal jadi bottom sheet */
  .modal { align-items: flex-end; padding: 0; }
  .modal-content {
    border-radius: 20px 20px 0 0;
    padding: 24px 20px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    max-width: 100%;
    max-height: 85vh;
  }
}

/* ── SMALL MOBILE (480px) ────────────────────── */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .filter-grid { grid-template-columns: 1fr; }
  .topbar-user span.superadmin-badge,
  .topbar-user span.role-badge { display: none; }
  .stat-value { font-size: 16px; }
  .table th, .table td { padding: 9px 10px; font-size: 12.5px; }
  .section { padding: 12px; }
  .content {
    padding: 10px;
    padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 10px);
  }
}

/* ── DESKTOP WIDE (1280px) ───────────────────── */
@media (min-width: 1280px) {
  :root { --sidebar-w: 256px; }
  .content { padding: 24px 28px; }
}
