:root {
  --bg: #0b0f14;
  --bg2: #121820;
  --card: #151c26;
  --border: #243041;
  --text: #e8eef6;
  --muted: #8b9bb0;
  --accent: #3b82f6;
  --success: #22c55e;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 12px;
  --font: 'Inter', system-ui, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }
button { font-family: inherit; cursor: pointer; border: none; }
input, textarea, select {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg2); color: var(--text);
  font-size: 0.95rem;
}
textarea { resize: vertical; }
label { display: block; margin-bottom: 6px; font-size: 0.85rem; color: var(--muted); }

.login-screen {
  min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(ellipse at center, #152030 0%, #0b0f14 70%);
}
.login-box {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 40px; width: 100%; max-width: 380px; text-align: center;
}
.login-brand { color: var(--accent); font-weight: 700; letter-spacing: 0.1em; margin-bottom: 8px; }
.login-box h1 { font-size: 1.5rem; margin-bottom: 4px; }
.login-sub { color: var(--muted); margin-bottom: 24px; font-size: 0.9rem; }
.login-box input { margin-bottom: 12px; text-align: center; }
.login-hint { margin-top: 16px; font-size: 0.8rem; color: var(--muted); }
.login-hint code { background: var(--bg2); padding: 2px 6px; border-radius: 4px; }

.btn-primary {
  background: var(--accent); color: #fff; padding: 10px 20px; border-radius: 10px;
  font-weight: 600; width: 100%;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary {
  background: var(--bg2); color: var(--text); padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--border); font-weight: 500;
}
.btn-danger { background: var(--danger); color: #fff; padding: 6px 12px; border-radius: 8px; font-size: 0.85rem; }
.btn-success { background: var(--success); color: #fff; padding: 6px 12px; border-radius: 8px; font-size: 0.85rem; }

.admin-app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: var(--bg2); border-right: 1px solid var(--border);
  padding: 20px 12px; display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-brand { font-weight: 700; padding: 8px 12px; margin-bottom: 20px; color: var(--accent); }
.nav-btn {
  display: block; width: 100%; text-align: left; padding: 10px 12px;
  border-radius: 8px; color: var(--muted); margin-bottom: 4px; background: none;
  font-size: 0.95rem;
}
.nav-btn:hover, .nav-btn.active { background: rgba(59,130,246,.15); color: var(--text); }
.btn-logout { margin-top: auto; color: var(--danger); padding: 10px; background: none; font-size: 0.9rem; }

.main { flex: 1; padding: 28px; overflow-y: auto; }
.tab { display: none; }
.tab.active { display: block; }
.tab h2 { margin-bottom: 8px; }
.hint { color: var(--muted); font-size: 0.9rem; margin-bottom: 20px; line-height: 1.5; }
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }

.form-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; max-width: 640px;
}
.form-group { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 0.8rem; }
tr:hover { background: rgba(255,255,255,.02); }
.actions { display: flex; gap: 6px; }

.order-row {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; margin-bottom: 10px;
}
.order-row-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.status-paid { color: var(--success); font-weight: 600; }
.status-unpaid { color: var(--warn); font-weight: 600; }

.modal {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6);
  z-index: 200; align-items: center; justify-content: center; padding: 16px;
}
.modal.active { display: flex; }
.modal-box {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-close { font-size: 1.2rem; color: var(--muted); background: none; }
.modal-body { padding: 20px; }

.export-preview {
  margin-top: 16px; background: var(--bg2); padding: 12px; border-radius: 8px;
  font-size: 0.75rem; max-height: 300px; overflow: auto; color: var(--muted);
}

@media (max-width: 768px) {
  .admin-app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; padding: 12px; }
  .btn-logout { margin-top: 0; }
  .form-row { grid-template-columns: 1fr; }
}

.status-bar { font-size: 0.85rem; color: var(--muted); margin-bottom: 12px; min-height: 1.2em; }
.form-card h3 { margin: 0 0 12px; font-size: 1rem; }
.login-error { color: #ef4444; font-size: 0.9rem; }

/* FIX: login never blocks clicks after hide */
.login-screen {
  position: fixed; inset: 0; z-index: 500;
}
.login-screen[style*="display: none"],
.login-screen.is-hidden {
  display: none !important;
  pointer-events: none !important;
  visibility: hidden !important;
}
.admin-app { position: relative; z-index: 1; }
.nav-btn, .btn-primary, .btn-secondary, .btn-logout, button {
  position: relative; z-index: 2; cursor: pointer !important;
  pointer-events: auto !important;
}
@media (max-width: 768px) {
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 4px; width: 100%; }
  .nav-btn { width: auto; flex: 1 1 auto; min-width: 100px; font-size: 0.8rem; padding: 8px; }
}

.ai-widget { position: fixed; right: 16px; bottom: 20px; z-index: 900; }
.ai-fab {
  width: 54px; height: 54px; border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: #fff; font-size: 1.4rem; border: none; cursor: pointer;
  box-shadow: 0 8px 24px rgba(59,130,246,.4);
}
.ai-panel {
  position: absolute; right: 0; bottom: 62px;
  width: min(340px, 92vw); height: 400px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; display: flex; flex-direction: column;
  box-shadow: 0 16px 40px rgba(0,0,0,.45);
}
.ai-panel-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.ai-messages { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.ai-msg { padding: 8px 10px; border-radius: 10px; font-size: 0.85rem; max-width: 95%; }
.ai-msg.bot { background: var(--bg2); align-self: flex-start; }
.ai-msg.user { background: var(--accent); color: #fff; align-self: flex-end; }
.ai-input-row { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--border); }
.ai-input-row input { flex: 1; }
