* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f0f2f5;
  --sidebar-w: 230px;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: var(--text); }

/* ── App layout ── */
.app-layout { display: flex; min-height: 100vh; background: var(--bg); }

.sidebar {
  width: var(--sidebar-w); background: #1e1b4b; color: #c7d2fe;
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; z-index: 100;
}
.sidebar-logo { padding: 20px 20px 12px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,.08); }
.logo-icon { font-size: 1.6rem; color: #818cf8; }
.logo-icon.large { font-size: 3rem; display: block; }
.logo-text { font-size: 1rem; font-weight: 700; color: #e0e7ff; letter-spacing: .5px; }

.nav-menu { list-style: none; padding: 12px 0; flex: 1; overflow-y: auto; }
.nav-item a { display: flex; align-items: center; gap: 10px; padding: 10px 20px; color: #a5b4fc; text-decoration: none; font-size: .9rem; border-radius: 0; transition: all .15s; }
.nav-item a:hover { color: #fff; background: rgba(255,255,255,.07); }
.nav-item.active a { color: #fff; background: rgba(99,102,241,.35); border-left: 3px solid #818cf8; }
.nav-icon { font-size: 1rem; width: 18px; text-align: center; }
.nav-divider { height: 1px; background: rgba(255,255,255,.08); margin: 8px 16px; }

.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.08); font-size: .8rem; }
.user-role { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: .7rem; font-weight: 600; text-transform: uppercase; margin-bottom: 4px; }
.user-role.admin { background: #7c3aed; color: #fff; }
.user-role.manager { background: #0284c7; color: #fff; }
.user-role.cashier { background: #059669; color: #fff; }
.user-name { display: block; color: #e0e7ff; font-weight: 600; margin-bottom: 8px; }
.btn-logout { color: #a5b4fc; font-size: .8rem; text-decoration: none; }
.btn-logout:hover { color: #fff; }

.main-content { margin-left: var(--sidebar-w); flex: 1; min-width: 0; }
.page-content { padding: 32px; max-width: 1200px; }

/* ── Login page ── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%); }
.login-card { background: #fff; border-radius: 16px; box-shadow: 0 8px 40px rgba(0,0,0,.25); padding: 40px; width: 100%; max-width: 400px; }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 1.4rem; color: #1e1b4b; margin: 10px 0 4px; }
.login-logo p { color: var(--text-muted); font-size: .9rem; }

/* ── Page header ── */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; gap: 16px; flex-wrap: wrap; }
h1 { font-size: 1.6rem; color: #111827; }
.subtitle { color: var(--text-muted); font-size: .9rem; margin-top: 2px; }

/* ── Cards ── */
.card { background: #fff; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.06); padding: 24px; margin-bottom: 20px; }
.card-title { font-size: 1rem; font-weight: 600; color: #374151; margin-bottom: 16px; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }

/* ── Stats ── */
.stats-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: #fff; border-radius: 12px; padding: 20px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.stat-value { font-size: 1.8rem; font-weight: 800; color: var(--primary); }
.stat-label { font-size: .8rem; color: var(--text-muted); margin-top: 4px; }

/* ── Buttons ── */
.btn-generate { width: 100%; padding: 12px; background: var(--primary); color: #fff; border: none; border-radius: 10px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: background .2s; }
.btn-generate:hover:not(:disabled) { background: var(--primary-dark); }
.btn-generate:disabled { background: #9ca3af; cursor: not-allowed; }
.btn-back { text-decoration: none; color: var(--primary); font-size: .9rem; font-weight: 600; white-space: nowrap; padding: 8px 14px; border: 1.5px solid var(--primary); border-radius: 8px; transition: all .2s; }
.btn-back:hover { background: var(--primary); color: #fff; }
.btn-download { display: inline-block; padding: 10px 24px; background: var(--success); color: #fff; border: none; border-radius: 8px; font-size: .95rem; font-weight: 600; cursor: pointer; transition: background .2s; margin-bottom: 14px; }
.btn-download:hover { background: #059669; }
.btn-sm { padding: 5px 12px; border: 1px solid var(--border); background: #fff; border-radius: 6px; font-size: .8rem; cursor: pointer; transition: all .15s; }
.btn-sm:hover { background: var(--bg); }
.btn-danger { border-color: #fca5a5; color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-success { border-color: #6ee7b7; color: var(--success); }
.btn-success:hover { background: #f0fdf4; }

/* ── Export buttons ── */
.export-btns { display: flex; gap: 4px; }
.btn-export-sm { padding: 4px 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 5px; font-size: .75rem; font-weight: 600; text-decoration: none; color: #374151; transition: all .15s; }
.btn-export-sm:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Badges ── */
.badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: .75rem; font-weight: 600; }
.badge-active { background: #d1fae5; color: #065f46; }
.badge-used { background: #dbeafe; color: #1e40af; }
.badge-expired { background: #fee2e2; color: #991b1b; }
.badge-disabled { background: #f3f4f6; color: #6b7280; }
.badge-admin { background: #ede9fe; color: #5b21b6; }
.badge-manager { background: #dbeafe; color: #1d4ed8; }
.badge-cashier { background: #d1fae5; color: #065f46; }
.badge-tier { background: #fef3c7; color: #92400e; }

/* ── Tables ── */
.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table thead tr { background: #f9fafb; }
.data-table th { padding: 10px 14px; text-align: left; font-weight: 600; color: #374151; border-bottom: 1.5px solid var(--border); white-space: nowrap; }
.data-table td { padding: 10px 14px; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }
.data-table tbody tr:hover { background: #fafafa; }
.table-toolbar { margin-bottom: 12px; }

/* ── Progress ── */
.progress-mini { height: 6px; background: #e5e7eb; border-radius: 3px; margin-bottom: 4px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 3px; transition: width .3s; }

/* ── Pagination ── */
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; padding-top: 16px; font-size: .875rem; color: var(--text-muted); }
.page-btn { color: var(--primary); text-decoration: none; font-weight: 600; }

/* ── Alerts ── */
.alert { padding: 10px 16px; border-radius: 8px; margin-bottom: 16px; font-size: .9rem; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

/* ── Form fields ── */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: .875rem; font-weight: 600; color: #374151; margin-bottom: 6px; }
.field .hint { font-size: .75rem; color: var(--text-muted); font-weight: 400; }
.field .required { color: var(--danger); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: .95rem; color: var(--text); background: #fafafa; outline: none; transition: border-color .2s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); background: #fff; }
.field textarea { resize: vertical; }
.field.checkbox label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 400; color: #555; }

/* ── QR result ── */
.result { margin-top: 24px; text-align: center; }
.result.hidden { display: none; }
.qr-wrapper { display: inline-block; padding: 16px; border: 1.5px solid var(--border); border-radius: 12px; background: #fff; margin-bottom: 16px; }
.qr-wrapper img { display: block; width: 220px; height: 220px; }
#qr-content-label { font-size: .82rem; color: #9ca3af; word-break: break-all; }
.error { padding: 12px 16px; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; color: var(--danger); font-size: .9rem; margin-top: 12px; }
.error.hidden { display: none; }

/* ── Tabs (QR single) ── */
.tabs { display: flex; gap: 8px; margin-bottom: 24px; background: var(--bg); padding: 4px; border-radius: 10px; }
.tab { flex: 1; padding: 8px 12px; border: none; background: transparent; border-radius: 8px; cursor: pointer; font-size: .9rem; color: #666; font-weight: 500; transition: all .2s; }
.tab:hover { color: #333; }
.tab.active { background: #fff; color: var(--primary); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.form-panel { display: none; }
.form-panel.active { display: block; }

/* ── Bulk table ── */
.bulk-container { max-width: 100%; }
.bulk-table-wrap { overflow-x: auto; border: 1.5px solid var(--border); border-radius: 10px; }
.bulk-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.bulk-table thead tr { background: #f9fafb; }
.bulk-table th { padding: 10px 12px; text-align: left; font-weight: 600; color: #374151; border-bottom: 1.5px solid var(--border); white-space: nowrap; }
.bulk-table td { padding: 6px 8px; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }
.bulk-table tbody tr:last-child td { border-bottom: none; }
.cell-input { width: 100%; padding: 7px 10px; border: 1.5px solid var(--border); border-radius: 6px; font-size: .875rem; color: var(--text); background: #fafafa; outline: none; transition: border-color .15s; }
.cell-input:focus { border-color: var(--primary); background: #fff; }
.cell-sm { width: 90px; }
.cell-mono { font-family: 'Courier New', monospace; letter-spacing: .03em; }
.btn-del { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 1rem; padding: 4px 8px; border-radius: 4px; transition: background .15s; }
.btn-del:hover { background: #fee2e2; }
.bulk-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; flex-wrap: wrap; gap: 10px; }
.btn-add { padding: 8px 16px; background: var(--bg); border: 1.5px dashed #9ca3af; border-radius: 8px; color: #374151; font-size: .9rem; font-weight: 600; cursor: pointer; transition: all .2s; }
.btn-add:hover { border-color: var(--primary); color: var(--primary); background: #eef2ff; }
.total-info { font-size: .9rem; color: var(--text-muted); display: flex; align-items: center; gap: 10px; }
.total-info strong { color: var(--text); font-size: 1rem; }
.warn { color: var(--warning); font-size: .82rem; }
.warn.hidden { display: none; }
.btn-export { margin-top: 20px; }
.code-preview { font-size: .82rem; color: var(--text-muted); margin-top: -8px; margin-bottom: 8px; font-family: monospace; }

/* ── Landing page ── */
.landing-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #f0f2f5; padding: 20px; }
.landing-card { background: #fff; border-radius: 20px; box-shadow: 0 8px 40px rgba(0,0,0,.12); padding: 36px 32px; text-align: center; max-width: 380px; width: 100%; }
.landing-logo { width: 80px; height: 80px; object-fit: contain; border-radius: 12px; margin-bottom: 12px; }
.landing-logo-placeholder { width: 80px; height: 80px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: 700; color: #fff; margin: 0 auto 12px; }
.landing-store { font-size: 1.4rem; color: #111827; margin-bottom: 12px; }
.landing-badge { display: inline-block; padding: 10px 28px; border-radius: 50px; color: #fff; font-size: 2rem; font-weight: 900; margin: 8px 0; }
.landing-tier { color: var(--text-muted); margin: 8px 0 16px; }
.landing-code-box { background: #f9fafb; border: 1.5px dashed var(--border); border-radius: 12px; padding: 14px; margin: 12px 0; }
.landing-code-label { display: block; font-size: .75rem; color: var(--text-muted); margin-bottom: 4px; }
.landing-code { font-family: monospace; font-size: 1.3rem; font-weight: 700; letter-spacing: 2px; color: var(--text); }
.landing-expiry { color: var(--text-muted); font-size: .875rem; margin-bottom: 20px; }
.btn-confirm { width: 100%; padding: 14px; color: #fff; border: none; border-radius: 12px; font-size: 1.1rem; font-weight: 700; cursor: pointer; transition: opacity .2s; }
.btn-confirm:hover { opacity: .9; }
.btn-confirm:disabled { opacity: .5; cursor: not-allowed; }
.landing-note { font-size: .8rem; color: var(--text-muted); margin-top: 8px; }
.success-icon { width: 64px; height: 64px; background: var(--success); color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: 700; margin: 0 auto 16px; }
.success-msg { color: #065f46; font-weight: 600; font-size: 1.05rem; }
.error-icon { width: 64px; height: 64px; background: var(--danger); color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: 700; margin: 0 auto 16px; }

/* ── Analytics / AI ── */
.ai-panel { }
.ai-type-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.ai-tab { padding: 6px 14px; border: 1.5px solid var(--border); background: #fff; border-radius: 20px; font-size: .85rem; cursor: pointer; color: #374151; transition: all .15s; }
.ai-tab:hover { border-color: var(--primary); color: var(--primary); }
.ai-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.ai-loading { color: var(--text-muted); font-style: italic; padding: 16px 0; }
.ai-result { background: #f9fafb; border: 1.5px solid var(--border); border-radius: 10px; padding: 20px; font-size: .9rem; line-height: 1.7; color: var(--text); white-space: pre-wrap; }

/* ── Stores ── */
.store-card { position: relative; overflow: hidden; text-align: center; }
.store-color-bar { height: 6px; position: absolute; top: 0; left: 0; right: 0; }
.store-logo-img { width: 60px; height: 60px; object-fit: contain; border-radius: 8px; margin: 20px auto 10px; display: block; }
.store-logo-placeholder { width: 60px; height: 60px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.8rem; font-weight: 700; color: #fff; margin: 20px auto 10px; }
.store-color-label { font-size: .8rem; color: var(--text-muted); margin: 4px 0; }
.store-card h3 { font-size: 1rem; }

/* ── Modal ── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 999; }
.modal.hidden { display: none; }
.modal-box { background: #fff; border-radius: 16px; padding: 32px; width: 100%; max-width: 480px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal-box h3 { font-size: 1.2rem; margin-bottom: 20px; }

/* ── Helpers ── */
.hidden { display: none !important; }
.link { color: var(--primary); text-decoration: none; font-weight: 500; }
.link:hover { text-decoration: underline; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-center { text-align: center; }
