/* === Variables === */
:root {
  --primary: #8b7fc7;
  --primary-dark: #6b5fa7;
  --primary-light: rgba(139, 127, 199, 0.1);
  --bg: #f5f3fa;
  --bg-card: #ffffff;
  --text: #2d3748;
  --text-light: #718096;
  --border: #e8e4f0;
  --success: #48bb78;
  --warning: #ecc94b;
  --danger: #f56565;
  --info: #4299e1;
  --sidebar-w: 240px;
  --ai-panel-w: 380px;
  --radius: 12px;
  --radius-sm: 8px;
}

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

html {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

/* === Layout === */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--text);
  color: white;
  display: flex; flex-direction: column;
  z-index: 100;
  transition: transform 0.3s;
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 18px; font-weight: 700;
}

.logo i { color: var(--primary); font-size: 22px; }

.nav-links {
  list-style: none; flex: 1; padding: 12px 0;
}

.nav-links a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; color: rgba(255,255,255,0.7);
  text-decoration: none; font-weight: 500;
  transition: all 0.2s; border-left: 3px solid transparent;
}

.nav-links a:hover { color: white; background: rgba(255,255,255,0.05); }
.nav-links a.active {
  color: white; background: rgba(139, 127, 199, 0.15);
  border-left-color: var(--primary);
}

.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,0.1); }

.btn-ai-toggle {
  width: 100%; padding: 10px 16px;
  background: var(--primary); color: white;
  border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500;
  cursor: pointer; display: flex; align-items: center; gap: 8px;
  justify-content: center; transition: background 0.2s;
}
.btn-ai-toggle:hover { background: var(--primary-dark); }

.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  transition: margin-right 0.3s;
}

.main-content.ai-open { margin-right: var(--ai-panel-w); }

.top-bar {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}

.top-bar h1 { font-size: 18px; font-weight: 600; flex: 1; }
.btn-menu { display: none; background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text); }

.content { padding: 24px; }

/* === Cards & Components === */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px; margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex; align-items: center; gap: 16px;
}

.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}

.stat-icon.purple { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: rgba(72,187,120,0.1); color: var(--success); }
.stat-icon.yellow { background: rgba(236,201,75,0.1); color: #d69e2e; }
.stat-icon.red { background: rgba(245,101,101,0.1); color: var(--danger); }
.stat-icon.blue { background: rgba(66,153,225,0.1); color: var(--info); }

.stat-info h3 { font-size: 24px; font-weight: 700; line-height: 1.2; }
.stat-info p { font-size: 12px; color: var(--text-light); }

/* === Buttons === */
.btn {
  padding: 8px 16px; font-size: 13px; font-weight: 500;
  border-radius: var(--radius-sm); border: none;
  cursor: pointer; display: inline-flex;
  align-items: center; gap: 6px; transition: all 0.2s;
  text-decoration: none;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg-card); border: 1px solid var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #e53e3e; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { background: none; border: none; cursor: pointer; color: var(--text-light); font-size: 16px; padding: 4px; }
.btn-icon:hover { color: var(--text); }

/* === Tables === */
.table-container { overflow-x: auto; }

table {
  width: 100%; border-collapse: collapse;
}

th, td {
  padding: 10px 14px; text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-light); background: var(--bg);
}

tr:hover td { background: var(--primary-light); }

/* === Badges === */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}

.badge-planning { background: rgba(66,153,225,0.1); color: var(--info); }
.badge-brewing { background: rgba(236,201,75,0.15); color: #b7791f; }
.badge-fermenting { background: rgba(139,127,199,0.15); color: var(--primary-dark); }
.badge-ready { background: rgba(72,187,120,0.1); color: #2f855a; }
.badge-ok { background: rgba(72,187,120,0.1); color: #2f855a; }
.badge-low { background: rgba(236,201,75,0.15); color: #b7791f; }
.badge-critical { background: rgba(245,101,101,0.1); color: var(--danger); }

/* === Forms === */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text-light); margin-bottom: 4px;
  text-transform: uppercase; letter-spacing: 0.3px;
}

input, select, textarea {
  padding: 9px 12px; font-size: 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  width: 100%; font-family: inherit;
  background: var(--bg-card);
}

input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

textarea { resize: vertical; min-height: 80px; }

.form-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}

.form-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* === Stock Bar === */
.stock-bar {
  width: 100%; height: 6px; background: var(--border);
  border-radius: 3px; overflow: hidden;
}

.stock-bar-fill {
  height: 100%; border-radius: 3px;
  transition: width 0.3s;
}

.stock-bar-fill.ok { background: var(--success); }
.stock-bar-fill.low { background: var(--warning); }
.stock-bar-fill.critical { background: var(--danger); }

/* === AI Panel === */
.ai-panel {
  position: fixed; right: -400px; top: 0; bottom: 0;
  width: var(--ai-panel-w);
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 200; transition: right 0.3s;
  box-shadow: -4px 0 20px rgba(0,0,0,0.05);
}

.ai-panel.open { right: 0; }

.ai-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--primary-light);
}

.ai-panel-header h3 {
  font-size: 15px; display: flex; align-items: center; gap: 8px;
  color: var(--primary-dark);
}

.ai-messages {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}

.ai-message {
  display: flex; gap: 10px; max-width: 95%;
}

.ai-message.ai-user { align-self: flex-end; flex-direction: row-reverse; }

.ai-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0;
}

.ai-bot .ai-avatar { background: var(--primary-light); color: var(--primary); }
.ai-user .ai-avatar { background: var(--bg); color: var(--text-light); }

.ai-bubble {
  padding: 10px 14px; border-radius: 12px;
  font-size: 13px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}

.ai-bot .ai-bubble { background: var(--bg); color: var(--text); }
.ai-user .ai-bubble { background: var(--primary); color: white; }

.ai-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.ai-status {
  font-size: 12px; color: var(--primary);
  min-height: 18px; padding: 0 4px;
}

.ai-form {
  display: flex; gap: 8px;
}

.ai-form input {
  flex: 1; padding: 10px 14px;
}

.btn-send {
  padding: 10px 14px; background: var(--primary);
  color: white; border: none; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 14px;
}

.btn-send:hover { background: var(--primary-dark); }

/* === Modal === */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: none; align-items: center; justify-content: center;
  z-index: 300;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 90%; max-width: 560px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 16px; }
.modal-body { padding: 24px; }

/* === Empty state === */
.empty-state {
  text-align: center; padding: 48px 24px;
  color: var(--text-light);
}

.empty-state i { font-size: 48px; margin-bottom: 16px; opacity: 0.3; }
.empty-state h3 { font-size: 16px; margin-bottom: 8px; color: var(--text); }

/* === Alerts list === */
.alert-list { display: flex; flex-direction: column; gap: 8px; }

.alert-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 13px;
}

.alert-item.warning { background: rgba(236,201,75,0.1); border-left: 3px solid var(--warning); }
.alert-item.danger { background: rgba(245,101,101,0.08); border-left: 3px solid var(--danger); }
.alert-item i { font-size: 16px; }
.alert-item.warning i { color: #d69e2e; }
.alert-item.danger i { color: var(--danger); }

/* === Section headers === */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}

.section-header h2 { font-size: 16px; font-weight: 600; }

.filter-bar {
  display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap;
}

.filter-bar select, .filter-bar input {
  width: auto; min-width: 160px;
}

/* === Responsive === */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .btn-menu { display: block; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .ai-panel { width: 100%; right: -100%; }
  .main-content.ai-open { margin-right: 0; }
}

/* === Loading spinner === */
.loading {
  display: flex; align-items: center; justify-content: center;
  padding: 48px; color: var(--text-light);
}

.loading::after {
  content: ''; width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* === Detail grid === */
.detail-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; margin-bottom: 20px;
}

.detail-item label {
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.3px; color: var(--text-light);
  font-weight: 600;
}

.detail-item p {
  font-size: 14px; font-weight: 500; margin-top: 2px;
}

.ingredients-list {
  display: flex; flex-direction: column; gap: 6px;
}

.ingredient-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--bg);
  border-radius: var(--radius-sm); font-size: 13px;
}

.ingredient-row .qty { font-weight: 600; color: var(--primary-dark); }
