* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #0a0a0f; --card: rgba(255,255,255,0.05); --border: rgba(255,255,255,0.1);
  --text: #fff; --text2: rgba(255,255,255,0.6); --primary: #8b5cf6; --success: #22c55e;
  --warning: #f59e0b; --danger: #ef4444; --radius: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
html { height: 100%; }
body { 
  min-height: 100%; width: 100%; overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.4;
  -webkit-font-smoothing: antialiased; padding-bottom: calc(var(--safe-bottom) + 20px);
}

/* Error Screen */
.error-screen {
  display: none; flex-direction: column; align-items: center; justify-content: center;
  height: 100vh; padding: 24px; text-align: center; position: fixed; inset: 0;
  background: var(--bg); z-index: 9999;
}
.error-screen.show { display: flex; }
.error-icon { font-size: 56px; margin-bottom: 16px; }
.error-screen h2 { font-size: 18px; margin-bottom: 8px; color: var(--danger); }
.error-screen p { color: var(--text2); margin-bottom: 24px; max-width: 280px; white-space: pre-line; font-size: 13px; }

/* Loading */
.loading { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; gap: 12px; position: fixed; inset: 0; background: var(--bg); z-index: 9998; }
.loading.hide { display: none; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading p { font-size: 13px; color: var(--text2); }

/* Content */
.content { display: none; padding: 12px; padding-top: calc(var(--safe-top) + 12px); max-width: 100%; }
.content.show { display: block; }
.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; padding: 0 4px; }
.header h1 { font-size: 16px; font-weight: 700; }
.user-badge { font-size: 10px; color: var(--text); background: var(--primary); padding: 4px 10px; border-radius: 12px; font-weight: 600; }

/* Tabs */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; background: var(--card); padding: 4px; border-radius: var(--radius); }
.tab { flex: 1; padding: 10px 8px; border: none; background: transparent; color: var(--text2); font-size: 16px; border-radius: 8px; cursor: pointer; transition: all 0.15s; }
.tab.active { background: var(--primary); color: var(--text); }

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.2s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Alerts */
.alerts { margin-bottom: 12px; }
.alert { padding: 10px 12px; border-radius: var(--radius); margin-bottom: 6px; font-size: 13px; font-weight: 500; }
.alert.danger { background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.3); color: #fca5a5; }
.alert.warning { background: rgba(245,158,11,0.15); border: 1px solid rgba(245,158,11,0.3); color: #fcd34d; }

/* Stats Grid */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 16px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.stat-label { font-size: 10px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; display: block; margin-bottom: 4px; }
.stat-value { font-size: 18px; font-weight: 700; color: var(--success); display: block; }
.stat-sub { font-size: 11px; color: var(--text2); display: block; margin-top: 2px; }

h3 { font-size: 12px; color: var(--text2); margin: 14px 0 8px; text-transform: uppercase; letter-spacing: 0.5px; }
h4 { font-size: 12px; color: var(--text2); margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }

/* Lists */
.list { display: flex; flex-direction: column; gap: 6px; }
.list-item {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; display: flex; justify-content: space-between; align-items: center;
  cursor: pointer; transition: all 0.15s; -webkit-user-select: none; user-select: none;
}
.list-item:active { transform: scale(0.98); background: rgba(255,255,255,0.08); }
.item-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.item-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-details { font-size: 11px; color: var(--text2); }
.item-value { font-weight: 700; font-size: 14px; margin-left: 8px; flex-shrink: 0; }
.item-value.green { color: var(--success); }
.item-value.yellow { color: var(--warning); }
.item-value.orange { color: #f97316; }
.item-value.red { color: var(--danger); }

/* Products */
.products-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.products-header h3 { margin: 0; }
.filter-row { display: flex; gap: 6px; margin-bottom: 10px; }
.filter-row input, .filter-row select { 
  flex: 1; padding: 10px; background: var(--card); border: 1px solid var(--border); 
  border-radius: 8px; color: var(--text); font-size: 13px; 
}
.filter-row select { max-width: 70px; }

/* Orders */
.order-item { flex-direction: column; align-items: flex-start !important; gap: 6px; cursor: default !important; }
.order-item:active { transform: none !important; }
.order-header { display: flex; justify-content: space-between; width: 100%; align-items: center; }
.order-id { font-weight: 600; font-size: 13px; }
.order-status { font-size: 10px; padding: 3px 8px; border-radius: 4px; text-transform: uppercase; font-weight: 600; }
.order-status.delivered, .order-status.pickedup { background: rgba(34,197,94,0.2); color: var(--success); }
.order-status.pending, .order-status.confirmed, .order-status.preparing, .order-status.ready { background: rgba(245,158,11,0.2); color: var(--warning); }
.order-status.cancelled, .order-status.refused { background: rgba(239,68,68,0.2); color: var(--danger); }
.order-details { font-size: 11px; color: var(--text2); }

/* Buttons */
.btn-small { padding: 8px 12px; background: var(--primary); border: none; border-radius: 8px; color: var(--text); font-size: 12px; cursor: pointer; }
.btn-tiny { padding: 4px 8px; background: var(--card); border: 1px solid var(--border); border-radius: 6px; color: var(--text2); font-size: 11px; cursor: pointer; }
.btn-primary { padding: 10px 14px; background: var(--primary); border: none; border-radius: 8px; color: var(--text); font-size: 13px; cursor: pointer; font-weight: 500; }
.btn-success { padding: 10px 14px; background: var(--success); border: none; border-radius: 8px; color: var(--text); font-size: 13px; cursor: pointer; }
.btn-danger { padding: 10px 14px; background: var(--danger); border: none; border-radius: 8px; color: var(--text); font-size: 13px; cursor: pointer; margin-top: 8px; }
.btn-toggle { width: 100%; padding: 12px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 13px; cursor: pointer; margin-top: 12px; }
.full-width { width: 100%; margin-top: 8px; }

/* Modal */
.modal { 
  display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; 
  background: rgba(0,0,0,0.85); z-index: 1000; padding: 16px; overflow-y: auto;
  padding-top: calc(var(--safe-top) + 24px); padding-bottom: calc(var(--safe-bottom) + 16px);
}
.modal.active { display: flex; align-items: flex-start; justify-content: center; }
.modal-content { background: #151520; border-radius: 14px; width: 100%; max-width: 360px; max-height: calc(100vh - 60px); overflow-y: auto; }
.modal-content.small { max-width: 300px; }
.modal-header { 
  display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; 
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: #151520; z-index: 1; 
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text2); font-size: 18px; cursor: pointer; padding: 4px; }
.modal-body { padding: 14px 16px; }

.section { margin-bottom: 18px; }
.section .hint { font-size: 10px; color: var(--text2); margin: 4px 0 0 0; }

/* Chart */
.chart-container { background: var(--card); border-radius: 12px; padding: 12px; margin-bottom: 16px; height: 180px; }
#chartCanvas { width: 100% !important; height: 100% !important; }

/* Admin */
.admin-section { padding: 4px 0; }
.admin-list { margin-bottom: 16px; }
.admin-item { display: flex; justify-content: space-between; align-items: center; padding: 12px; background: var(--card); border-radius: 8px; margin-bottom: 8px; }
.admin-item .admin-info { display: flex; flex-direction: column; gap: 2px; }
.admin-item .admin-role { font-size: 10px; color: var(--text2); }
.admin-item .admin-id { font-size: 12px; color: var(--text2); }
.admin-item .btn-remove { background: var(--danger); color: white; border: none; padding: 6px 12px; border-radius: 6px; font-size: 12px; }
.add-admin { background: var(--card); padding: 12px; border-radius: 10px; }
.add-admin h4 { margin: 0 0 10px 0; font-size: 13px; }

/* Debug Panel */
.debug-btn { position: fixed; bottom: 80px; right: 16px; width: 40px; height: 40px; border-radius: 50%; background: #ff6b6b; border: none; font-size: 18px; z-index: 999; box-shadow: 0 2px 10px rgba(0,0,0,0.3); }
.debug-panel { position: fixed; bottom: 0; left: 0; right: 0; max-height: 50vh; background: #1a1a2e; border-top: 2px solid #ff6b6b; z-index: 1000; display: none; flex-direction: column; }
.debug-panel.show { display: flex; }
.debug-header { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: #16213e; color: #ff6b6b; font-weight: bold; }
.debug-header button { background: none; border: none; color: white; font-size: 16px; }
.debug-content { flex: 1; overflow-y: auto; padding: 8px; font-family: monospace; font-size: 11px; color: #0f0; white-space: pre-wrap; word-break: break-all; }

/* Action Row */
.action-row { display: flex; gap: 8px; margin: 12px 0; }
.btn-action { flex: 1; padding: 10px; border-radius: 8px; background: var(--card); border: 1px solid var(--border); color: var(--text); font-size: 12px; cursor: pointer; }
.btn-action:active { background: var(--accent); }
.product-info { background: var(--card); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; font-size: 12px; }
.product-info div { margin-bottom: 3px; }

.hint { font-size: 11px; color: var(--text2); margin-bottom: 10px; }
.current-value { font-size: 12px; color: var(--text2); margin-bottom: 10px; }

.input-row { display: flex; gap: 6px; margin-bottom: 6px; }
.input-row input { flex: 1; padding: 10px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 13px; min-width: 0; }
.input-row input::placeholder { color: var(--text2); }
.full-input { width: 100%; padding: 10px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 13px; margin-bottom: 6px; }

.variants-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.variant-item { display: flex; justify-content: space-between; align-items: center; background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.variant-info { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.variant-type { font-size: 12px; }
.variant-name { font-weight: 600; font-size: 12px; }
.variant-price { font-weight: 700; color: var(--success); font-size: 13px; }
.variant-ppg { font-size: 10px; color: var(--text2); margin-left: 6px; }
.variant-edit { background: none; border: none; color: var(--text2); font-size: 14px; cursor: pointer; padding: 4px; }

.type-selector { display: flex; gap: 4px; margin-bottom: 6px; }
.type-selector.cost-type, .type-selector.stock-type { margin-bottom: 8px; }
.type-btn { padding: 6px 10px; background: var(--card); border: 1px solid var(--border); border-radius: 6px; color: var(--text2); font-size: 11px; cursor: pointer; }
.type-btn.active { background: var(--primary); color: var(--text); border-color: var(--primary); }

.add-variant { background: rgba(139,92,246,0.08); border: 1px dashed rgba(139,92,246,0.3); border-radius: 8px; padding: 10px; }

/* Entries */
.entries-list { display: flex; flex-direction: column; gap: 6px; }
.entry-item { display: flex; justify-content: space-between; align-items: center; background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; cursor: pointer; }
.entry-item:active { background: rgba(255,255,255,0.08); }
.entry-info { flex: 1; }
.entry-qty { font-weight: 700; font-size: 14px; color: var(--success); }
.entry-details { font-size: 11px; color: var(--text2); margin-top: 2px; }
.entry-edit { font-size: 14px; color: var(--text2); }

/* Toast */
.toast { 
  position: fixed; bottom: calc(var(--safe-bottom) + 16px); left: 50%; transform: translateX(-50%); 
  background: #333; color: var(--text); padding: 10px 16px; border-radius: 8px; font-size: 13px; 
  opacity: 0; transition: opacity 0.2s; z-index: 2000; max-width: calc(100% - 32px); text-align: center;
  pointer-events: none;
}
.toast.show { opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
