:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --border: #e3e7ef;
  --text: #1c2333;
  --muted: #6b7489;
  --primary: #5b3df5;
  --primary-hover: #4a2ee0;
  --danger: #dc2626;
  --sidebar: #141a2b;
  --radius: 12px;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 18px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
input, textarea, select, button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: .88rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.center-screen { min-height: 100vh; display: grid; place-items: center; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: var(--sidebar); color: #cfd5e4; display: flex; flex-direction: column; padding: 20px 14px; position: fixed; inset: 0 auto 0 0; z-index: 30; transition: transform .2s; }
.brand { font-weight: 800; font-size: 1.1rem; color: #fff; padding: 0 10px 22px; }
.brand span { font-size: .7rem; background: var(--primary); padding: 2px 7px; border-radius: 6px; vertical-align: middle; margin-left: 4px; }
.brand-lg { color: var(--text); font-size: 1.4rem; text-align: center; padding-bottom: 24px; }
.brand-lg span { color: #fff; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar nav a { color: #cfd5e4; padding: 10px 12px; border-radius: 8px; display: flex; gap: 10px; }
.sidebar nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar-store { color: #9aa3b8; padding: 10px 12px; font-size: .9rem; }
.content { flex: 1; margin-left: 240px; min-width: 0; }
.topbar { height: 60px; background: var(--card); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 10; }
.topbar-right { display: flex; align-items: center; gap: 14px; margin-left: auto; font-size: .9rem; }
.menu-btn { display: none; background: none; border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; cursor: pointer; font-size: 1.1rem; }
.page { padding: 26px 24px 60px; max-width: 1300px; }
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 25; }

/* Elements */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.card-head, .page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h1 { margin: 0; }
.page-head { margin-bottom: 18px; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); cursor: pointer; font-weight: 500; font-size: .92rem; color: var(--text); }
.btn:hover { border-color: #c5ccdb; text-decoration: none; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: .82rem; }
.btn-block { width: 100%; justify-content: center; padding: 11px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > span { font-size: .85rem; color: var(--muted); font-weight: 500; }
.input, .field input:not([type='color']):not([type='checkbox']), .field textarea { border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; background: #fff; outline: none; width: 100%; }
.input:focus, .field input:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(91, 61, 245, .12); }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0; cursor: pointer; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
.form-grid .card { margin-bottom: 18px; }
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type='color'] { width: 44px; height: 38px; border: 1px solid var(--border); border-radius: 8px; padding: 2px; background: #fff; }

.alert { padding: 11px 14px; border-radius: 8px; margin: 12px 0; font-size: .9rem; }
.alert-error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; padding: 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fafbfe; }
.detail-row td { background: #f8f9fd; }
.edit-table { margin-bottom: 12px; }
.edit-table td { padding: 6px; vertical-align: middle; }
.product-cell { display: flex; gap: 10px; align-items: center; }
.swatch { width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0; }
.filter { max-width: 340px; margin-bottom: 12px; }

.badge, .status-select { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; border: none; }
.status-select { cursor: pointer; padding: 5px 8px; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-paid { background: #dbeafe; color: #1e40af; }
.badge-processing { background: #e0e7ff; color: #3730a3; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-failed, .badge-cancelled { background: #fee2e2; color: #991b1b; }

.switch { width: 40px; height: 22px; border-radius: 999px; border: none; background: #cbd2e0; position: relative; cursor: pointer; transition: .15s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .15s; }
.switch.on { background: #22c55e; }
.switch.on::after { left: 21px; }

.toolbar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .tabs { margin: 0; }
.tabs button { background: none; border: 1px solid transparent; padding: 7px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tabs button:hover { background: #eef0f6; }
.tabs button.active { background: #ece8ff; color: var(--primary); }
.inline-form { display: flex; gap: 8px; }
.inline-form .input { min-width: 260px; }

.order-detail { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; padding: 6px; }
.order-detail dl { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin: 0; font-size: .88rem; }
.order-detail dt { color: var(--muted); }
.order-detail dd { margin: 0; }

/* Dashboard */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { display: flex; flex-direction: column; gap: 4px; margin: 0; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat strong { font-size: 1.5rem; }
.stat small { color: var(--muted); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.status-list { list-style: none; padding: 0; margin: 0; }
.status-list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.bars { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.bar-label { display: flex; justify-content: space-between; font-size: .88rem; margin-bottom: 4px; }
.bar { height: 8px; background: #eef0f6; border-radius: 99px; overflow: hidden; }
.bar div { height: 100%; background: var(--primary); border-radius: 99px; }

/* Messages */
.message-list { display: flex; flex-direction: column; }
.message.unread { border-left: 4px solid var(--primary); }
.message-head { display: flex; justify-content: space-between; gap: 12px; }
.message-body { white-space: pre-wrap; margin: 12px 0; }

/* Login */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, #141a2b, #2a1f6b); }
.login-card { width: 100%; max-width: 380px; padding: 32px; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .content { margin-left: 0; }
  .menu-btn { display: block; }
  .form-grid, .two-col, .order-detail { grid-template-columns: 1fr; }
  .page { padding: 20px 16px 60px; }
  .topbar { padding: 0 16px; }
}
@media (max-width: 600px) {
  .grid-2 { grid-template-columns: 1fr; }
  .inline-form { width: 100%; }
  .inline-form .input { min-width: 0; }
  .topbar-right .muted { display: none; }
}

/* Realtime (Pusher) */
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: #eef0f6; color: var(--muted); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #cbd2e0; }
.live-connected { background: #dcfce7; color: #166534; }
.live-connected .live-dot { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .25); animation: pulse 2s infinite; }
.live-unavailable { background: #fee2e2; color: #991b1b; }
.live-unavailable .live-dot { background: var(--danger); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); } }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: calc(100vw - 32px); width: 340px; }
.toast { display: flex; flex-direction: column; gap: 2px; background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 10px; padding: 12px 14px; box-shadow: 0 10px 30px rgba(20, 26, 43, .15); color: var(--text); font-size: .88rem; animation: toast-in .2s ease-out; }
.toast:hover { text-decoration: none; border-color: #c5ccdb; }
.toast-success { border-left-color: #22c55e; }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }
tr.flash td { animation: flash 2.5s ease-out; }
@keyframes flash { from { background: #fef9c3; } }
.stat.flash { animation: flash 2.5s ease-out; }
.live-disabled { background: #fef3c7; color: #92400e; }
.live-disabled .live-dot { background: #f59e0b; }
.live { cursor: help; }

/* Digiflazz */
.brand-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.brand-chip { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); cursor: pointer; text-align: left; }
.brand-chip:hover { border-color: #c5ccdb; }
.brand-chip.active { border-color: var(--primary); background: #f3f0ff; }
tr.muted td { color: var(--muted); }
.text-danger { color: var(--danger); }
.supplier-box { grid-column: 1 / -1; border-top: 1px dashed var(--border); padding-top: 12px; }
.supplier-box dl { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin: 0 0 10px; font-size: .88rem; }
.supplier-box dt { color: var(--muted); }
.supplier-box dd { margin: 0; }
.margin-ok { color: #166534; }
.margin-bad { color: var(--danger); font-weight: 600; }

/* Store mode */
.mode-badge { font-size: .75rem; font-weight: 800; letter-spacing: .06em; padding: 4px 10px; border-radius: 6px; }
.mode-badge:hover { text-decoration: none; filter: brightness(.95); }
.mode-development { background: #fef3c7; color: #92400e; }
.mode-production { background: #dcfce7; color: #166534; }
.mode-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--card); }
.mode-switch button { border: none; background: none; padding: 8px 16px; cursor: pointer; font-weight: 600; color: var(--muted); }
.mode-switch button + button { border-left: 1px solid var(--border); }
.mode-switch button.active { background: var(--primary); color: #fff; }
.mode-switch button:disabled:not(.active) { opacity: .5; cursor: not-allowed; }
.small-switch button { padding: 6px 12px; font-size: .85rem; }
.mode-card { border-left: 4px solid #f59e0b; }
.mode-card-production { border-left-color: #22c55e; }
.keys-table { max-width: 520px; margin: 6px 0 10px; }
.mode-tag { display: inline-block; margin-left: 6px; font-size: .68rem; font-weight: 800; letter-spacing: .05em; padding: 1px 6px; border-radius: 4px; background: #fef3c7; color: #92400e; vertical-align: middle; font-family: inherit; }
.mode-select { width: auto; min-width: 140px; }

/* Digiflazz balance & deposit */
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.balance-refresh { align-self: flex-start; margin-top: 6px; }
.deposit-ticket { margin-top: 16px; padding: 16px; border: 1px dashed var(--primary); border-radius: 10px; background: #f8f6ff; }
.deposit-ticket h3 { margin-top: 0; }
.deposit-ticket dl { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 0 0 8px; align-items: center; }
.deposit-ticket dt { color: var(--muted); font-size: .88rem; }
.deposit-ticket dd { margin: 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.deposit-ticket .big { font-size: 1.3rem; color: var(--primary); }
.stat-warn { border-color: #fcd34d; background: #fffbeb; }
@media (max-width: 700px) { .grid-3 { grid-template-columns: 1fr; } }

