/* ===================================================
   PaintLab AI — Design System + Dark Theme
=================================================== */
:root {
  /* Brand — Induscolor */
  --primary: #144196;
  --primary-dark: #0d2e6e;
  --primary-light: #eaf0fb;
  --secondary: #c9a400;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --info: #0891b2;
  --info-light: #ecfeff;

  /* Light theme tokens */
  --bg: #f3f4f6;
  --bg-card: #ffffff;
  --bg-sidebar: #0a1e42;
  --bg-topbar: #ffffff;
  --bg-hover: #f9fafb;
  --bg-input: #ffffff;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --text: #111827;
  --text-sub: #374151;
  --text-muted: #6b7280;
  --text-xmuted: #9ca3af;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1), 0 4px 10px rgba(0,0,0,0.05);

  /* Sidebar */
  --sidebar-nav-text: #9ca3af;
  --sidebar-nav-hover: rgba(255,255,255,0.07);
  --sidebar-section-label: #4b5563;
  --sidebar-border: rgba(255,255,255,0.08);

  /* Phase colors */
  --phase-a: #144196;
  --phase-b: #f59e0b;
  --phase-c: #10b981;

  --sidebar-w: 260px;
  --topbar-h: 64px;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --font: 'Inter', sans-serif;
  color-scheme: light;
}

/* =========================================================
   DARK THEME
========================================================= */
[data-theme="dark"] {
  /* Faz os controles nativos (popup de <select>, etc.) renderizarem
     em modo escuro, senão o navegador usa o tema claro do sistema
     operacional e o texto fica ilegível sobre o fundo escuro do app. */
  color-scheme: dark;
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #071530;
  --bg-topbar: #1e293b;
  --bg-hover: #273349;
  --bg-input: #273349;
  --border: #334155;
  --border-light: #1e293b;
  --text: #f1f5f9;
  --text-sub: #cbd5e1;
  --text-muted: #94a3b8;
  --text-xmuted: #64748b;
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.4);

  --primary-light: rgba(20,65,150,0.18);
  --success-light: rgba(22,163,74,0.15);
  --warning-light: rgba(217,119,6,0.15);
  --danger-light: rgba(220,38,38,0.15);
  --info-light: rgba(8,145,178,0.15);

  --sidebar-nav-text: #94a3b8;
  --sidebar-nav-hover: rgba(255,255,255,0.06);
  --sidebar-section-label: #475569;
  --sidebar-border: rgba(255,255,255,0.06);
}

/* =========================================================
   BASE
========================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  transition: background .25s, color .25s;
}

/* =========================================================
   LOGIN SCREEN
========================================================= */
.login-screen {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
}

.login-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 20% 50%, rgba(20,65,150,0.15) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(201,164,0,0.15) 0%, transparent 40%),
    radial-gradient(circle at 60% 80%, rgba(16,185,129,0.08) 0%, transparent 40%);
}

.login-card {
  position: relative; z-index: 1;
  background: rgba(30,41,59,0.95);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 40px;
  width: 100%; max-width: 420px;
  box-shadow: 0 25px 60px rgba(0,0,0,0.5);
}

.login-logo {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 32px;
}

.login-logo-icon {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, #144196, #0a2554);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: white;
  box-shadow: 0 8px 24px rgba(20,65,150,0.4);
  flex-shrink: 0;
}

.login-logo-name {
  font-size: 22px; font-weight: 800; color: #f1f5f9;
}
.login-logo-name span {
  background: linear-gradient(90deg, #4d7fd4, #fff000);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.login-logo-sub { font-size: 11px; color: #94a3b8; margin-top: 2px; }

.login-card label { color: #94a3b8; }
.login-card .form-control {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.1);
  color: #f1f5f9;
  padding-left: 38px;
}
.login-card .form-control:focus {
  background: rgba(255,255,255,0.1);
  border-color: #144196;
  box-shadow: 0 0 0 3px rgba(20,65,150,0.25);
}
.login-card .form-control::placeholder { color: #475569; }

.input-icon-wrap { position: relative; }
.input-icon-wrap > i {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: #64748b; font-size: 13px; pointer-events: none;
}
.btn-eye {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer;
  color: #64748b; font-size: 13px; padding: 4px;
}
.btn-eye:hover { color: #94a3b8; }

.btn-login {
  width: 100%; margin-top: 8px; padding: 12px;
  font-size: 15px; font-weight: 700;
  background: linear-gradient(135deg, #144196, #0a2554);
  border: none; box-shadow: 0 4px 16px rgba(20,65,150,0.4);
}
.btn-login:hover { box-shadow: 0 6px 24px rgba(20,65,150,0.5); transform: translateY(-1px); }

.login-error {
  background: rgba(220,38,38,0.15); border: 1px solid rgba(220,38,38,0.3);
  color: #fca5a5; border-radius: 8px; padding: 10px 14px;
  font-size: 13px; margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}

.login-hint {
  text-align: center; margin-top: 16px;
  font-size: 12px; color: #475569;
}
.login-hint code { background: rgba(255,255,255,0.08); padding: 2px 6px; border-radius: 4px; color: #94a3b8; }

/* =========================================================
   APP WRAPPER
========================================================= */
#app-wrapper { display: flex; width: 100%; min-height: 100vh; }

/* =========================================================
   SIDEBAR
========================================================= */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  height: 100vh; position: fixed; left: 0; top: 0;
  display: flex; flex-direction: column;
  z-index: 100; overflow-y: auto;
  transition: transform .3s ease;
}

[data-theme="dark"] .sidebar { border-right: 1px solid var(--sidebar-border); }

.sidebar-logo {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-logo-img { width: 100%; max-width: 172px; height: auto; display: block; }

.sidebar-app-name {
  font-size: 10.5px; font-weight: 800; letter-spacing: 2px; text-transform: uppercase;
  background: linear-gradient(90deg, #f8fafc, var(--secondary));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-nav { flex: 1; padding: 12px 10px; }

.nav-section-label {
  font-size: 10px; font-weight: 600; letter-spacing: 1px;
  color: var(--sidebar-section-label); text-transform: uppercase;
  padding: 12px 8px 6px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--sidebar-nav-text); text-decoration: none;
  font-size: 13px; font-weight: 500;
  transition: all .15s; margin-bottom: 2px;
}
.nav-item:hover { background: var(--sidebar-nav-hover); color: #f1f5f9; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item i { width: 18px; text-align: center; font-size: 13px; }

/* =========================================================
   SIDEBAR FOOTER
========================================================= */
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--sidebar-border);
}

.sidebar-user-info {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; border-radius: 8px; margin-bottom: 8px;
  cursor: default;
}

.sidebar-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: white; flex-shrink: 0;
}

.sidebar-user-name { font-size: 13px; font-weight: 600; color: #e2e8f0; }
.sidebar-user-role { font-size: 11px; color: var(--sidebar-section-label); }

.sidebar-footer-btns { display: flex; gap: 6px; }

.sidebar-icon-btn {
  flex: 1; padding: 8px; background: var(--sidebar-nav-hover);
  border: 1px solid var(--sidebar-border); border-radius: 8px;
  cursor: pointer; color: var(--sidebar-nav-text); font-size: 14px;
  transition: all .2s;
}
.sidebar-icon-btn:hover { background: rgba(255,255,255,0.12); color: #f1f5f9; }

/* =========================================================
   MOBILE TOGGLE
========================================================= */
.mobile-toggle {
  display: none; position: fixed; top: 14px; left: 14px; z-index: 200;
  background: var(--primary); color: white; border: none; border-radius: 8px;
  width: 38px; height: 38px; cursor: pointer; font-size: 15px;
  align-items: center; justify-content: center;
}

/* =========================================================
   MAIN CONTENT
========================================================= */
.main-content { margin-left: var(--sidebar-w); flex: 1; min-height: 100vh; display: flex; flex-direction: column; }

/* =========================================================
   TOPBAR
========================================================= */
.topbar {
  height: var(--topbar-h); background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; position: sticky; top: 0; z-index: 50;
  transition: background .25s, border-color .25s;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-menu-btn {
  display: none; background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 18px; padding: 4px;
}
.topbar-left h1 { font-size: 18px; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: 11px; color: var(--text-muted); display: block; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.ai-badge {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white; padding: 4px 12px; border-radius: 20px;
  font-size: 11px; font-weight: 700;
}

.btn-icon {
  width: 34px; height: 34px; background: none;
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
  color: var(--text-muted); font-size: 14px; transition: all .2s;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }

.date-badge { font-size: 11px; color: var(--text-muted); background: var(--bg-hover); padding: 4px 10px; border-radius: 6px; }

.topbar-user {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; padding: 4px 8px; border-radius: 8px;
  transition: background .15s;
}
.topbar-user:hover { background: var(--bg-hover); }

.topbar-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: white;
  background: var(--primary);
}

#topbar-username { font-size: 12px; font-weight: 600; color: var(--text-muted); }

/* =========================================================
   PAGES
========================================================= */
.page { display: none; padding: 20px 24px; flex: 1; }
.page.active { display: block; }

/* =========================================================
   CARDS
========================================================= */
.card {
  background: var(--bg-card); border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  overflow: hidden; transition: background .25s, border-color .25s;
}

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

.card-header h3 {
  font-size: 14px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.card-header h3 i { color: var(--primary); }

/* =========================================================
   STATS GRID
========================================================= */
.stats-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; margin-bottom: 20px; }

.stat-card {
  background: var(--bg-card); border-radius: var(--radius);
  padding: 18px; display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
  border-left: 4px solid transparent; transition: background .25s;
}
.stat-blue { border-left-color: var(--primary); }
.stat-green { border-left-color: var(--success); }
.stat-orange { border-left-color: var(--warning); }
.stat-purple { border-left-color: var(--secondary); }

.stat-icon { width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 19px; }
.stat-blue .stat-icon { background: var(--primary-light); color: var(--primary); }
.stat-green .stat-icon { background: var(--success-light); color: var(--success); }
.stat-orange .stat-icon { background: var(--warning-light); color: var(--warning); }
.stat-purple .stat-icon { background: rgba(201,164,0,0.12); color: var(--secondary); }

.stat-value { font-size: 26px; font-weight: 800; color: var(--text); display: block; }
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; display: block; }

/* =========================================================
   DASHBOARD GRID
========================================================= */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.chart-card canvas { padding: 16px; }

/* =========================================================
   FORMULA LIST & GRID
========================================================= */
.formula-list {}
.formula-row {
  display: flex; align-items: center; padding: 11px 20px;
  border-bottom: 1px solid var(--border-light); cursor: pointer;
  transition: background .12s; gap: 12px;
}
.formula-row:hover { background: var(--bg-hover); }
.formula-row:last-child { border-bottom: none; }
.formula-row-code { font-size: 11px; font-weight: 600; color: var(--primary); min-width: 110px; }
.formula-row-name { flex: 1; font-weight: 500; color: var(--text); }
.formula-row-type { font-size: 11px; color: var(--text-muted); min-width: 120px; }

.formulas-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(300px,1fr)); gap: 16px; }

.formula-card {
  background: var(--bg-card); border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  overflow: hidden; cursor: pointer; transition: transform .2s, box-shadow .2s, background .25s;
}
.formula-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.formula-card-header {
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--primary-light), rgba(201,164,0,0.08));
  border-bottom: 1px solid var(--border);
}
.formula-card-code { font-size: 10px; font-weight: 700; color: var(--primary); }
.formula-card-name { font-size: 14px; font-weight: 700; color: var(--text); margin: 3px 0; }
.formula-card-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.formula-card-body { padding: 10px 14px; }
.formula-card-props { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.fc-prop { background: var(--bg-hover); border-radius: 6px; padding: 6px 10px; }
.fc-prop-label { font-size: 9px; color: var(--text-muted); text-transform: uppercase; font-weight: 700; }
.fc-prop-value { font-size: 14px; font-weight: 700; color: var(--text); }

.formula-card-actions { display: flex; gap: 6px; padding: 10px 14px; border-top: 1px solid var(--border); }

/* =========================================================
   TOOLBAR
========================================================= */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; flex: 1; max-width: 360px;
  transition: background .25s;
}
.search-box i { color: var(--text-muted); }
.search-box input { border: none; outline: none; flex: 1; font-family: var(--font); font-size: 13px; color: var(--text); background: transparent; }

.search-input {
  display: block; width: 100%; max-width: 360px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px;
  font-family: var(--font); font-size: 13px; color: var(--text);
  outline: none; transition: border-color .15s;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-color: var(--primary); }

/* =========================================================
   BUTTONS
========================================================= */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; font-family: var(--font);
  font-size: 13px; font-weight: 600; cursor: pointer; border: none;
  transition: all .15s; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--secondary); color: white; }
.btn-secondary:hover { background: #a58800; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #b45309; }
.btn-info { background: var(--info); color: white; }
.btn-info:hover { background: #0e7490; }
.btn-outline { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg-hover); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 11px; }

/* =========================================================
   FORMS
========================================================= */
.form-row { display: flex; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.form-group { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 150px; }
.form-group.full-width { flex: none; width: 100%; }
label { font-size: 12px; font-weight: 600; color: var(--text-muted); }

.form-control {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-family: var(--font); font-size: 13px;
  color: var(--text); outline: none; background: var(--bg-input);
  transition: border .15s, background .25s;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(20,65,150,0.12); }
.form-control-lg { font-size: 15px; padding: 11px 14px; }
.form-control::placeholder { color: var(--text-xmuted); }

.form-select {
  padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-family: var(--font); font-size: 13px;
  color: var(--text); background: var(--bg-input); cursor: pointer;
  outline: none; min-width: 120px; transition: border .15s, background .25s;
}
.form-select:focus { border-color: var(--primary); }
textarea.form-control { resize: vertical; }

/* =========================================================
   TABLES
========================================================= */
.table-wrapper { overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  background: var(--bg-hover); padding: 9px 14px;
  text-align: left; font-size: 10px; font-weight: 700;
  color: var(--text-muted); text-transform: uppercase;
  border-bottom: 1px solid var(--border); white-space: nowrap;
  transition: background .25s;
}
.data-table td { padding: 9px 14px; border-bottom: 1px solid var(--border-light); color: var(--text-sub); }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* Formula tables */
.formula-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.formula-table th {
  background: var(--bg-hover); padding: 8px 10px;
  text-align: left; font-size: 9px; font-weight: 700;
  color: var(--text-muted); text-transform: uppercase;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.formula-table td { padding: 5px 7px; border-bottom: 1px solid var(--border-light); }
.formula-table td input, .formula-table td select {
  width: 100%; border: 1px solid transparent;
  background: transparent; padding: 4px 6px; border-radius: 4px;
  font-size: 12px; font-family: var(--font); color: var(--text); outline: none;
  transition: border .15s;
}
.formula-table td input:focus, .formula-table td select:focus {
  border-color: var(--primary); background: var(--primary-light);
}
.formula-table td.number-cell { text-align: right; font-weight: 600; color: var(--text); }
.formula-table tbody tr:hover td { background: var(--bg-hover); }

/* Autocomplete de matéria-prima por código ou nome */
.rm-combo-list {
  display: none; position: fixed; z-index: 9999;
  max-height: 260px; overflow-y: auto;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.rm-combo-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  font-size: 12px; color: var(--text); cursor: pointer; white-space: nowrap;
}
.rm-combo-item:hover { background: var(--primary); color: #fff; }
.rm-combo-item-code { font-weight: 700; color: var(--primary); min-width: 52px; flex-shrink: 0; }
.rm-combo-item:hover .rm-combo-item-code { color: #fff; }
.rm-combo-item-name { overflow: hidden; text-overflow: ellipsis; }
.rm-combo-empty { padding: 10px; font-size: 12px; color: var(--text-muted); text-align: center; }

/* =========================================================
   PHASE SECTIONS
========================================================= */
.phase-section {}
.phase-header {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 20px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px;
}
.phase-a .phase-header { background: rgba(59,130,246,0.08); color: var(--phase-a); border-bottom: 2px solid rgba(59,130,246,0.2); }
.phase-b .phase-header { background: rgba(245,158,11,0.08); color: var(--phase-b); border-bottom: 2px solid rgba(245,158,11,0.2); }
.phase-c .phase-header { background: rgba(16,185,129,0.08); color: var(--phase-c); border-bottom: 2px solid rgba(16,185,129,0.2); }
.phase-a td:first-child { border-left: 3px solid var(--phase-a); }
.phase-b td:first-child { border-left: 3px solid var(--phase-b); }
.phase-c td:first-child { border-left: 3px solid var(--phase-c); }

/* =========================================================
   TOTALS BAR
========================================================= */
.totals-bar {
  display: flex; gap: 0;
  background: #1e293b;
  padding: 12px 20px;
}
[data-theme="dark"] .totals-bar { background: #0f172a; }
.total-item { flex: 1; text-align: center; }
.total-label { display: block; font-size: 9px; color: #94a3b8; text-transform: uppercase; font-weight: 700; }
.total-value { display: block; font-size: 15px; font-weight: 800; color: #fff; }

/* =========================================================
   PROPERTIES GRID
========================================================= */
.props-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; padding: 16px; }
.prop-item {
  background: var(--bg-hover); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px; text-align: center;
  transition: background .25s;
}
.prop-label { display: block; font-size: 10px; color: var(--text-muted); font-weight: 600; margin-bottom: 6px; }
.prop-label i { margin-right: 4px; color: var(--primary); }
.prop-value { display: block; font-size: 17px; font-weight: 800; color: var(--text); }

/* =========================================================
   AI CHAT
========================================================= */
.ai-analysis-layout .card { max-width: 900px; margin: 0 auto; }
.ai-chat-container {
  height: 420px; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
  background: var(--bg); transition: background .25s;
}
.ai-welcome-msg { display: flex; gap: 12px; align-items: flex-start; }
.ai-avatar {
  width: 36px; height: 36px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: white; font-size: 16px;
}
.ai-msg-bubble {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px 12px 12px 0; padding: 12px 16px; flex: 1;
  box-shadow: var(--shadow); transition: background .25s;
}
.ai-msg-bubble strong { display: block; color: var(--primary); font-size: 11px; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 1px; }
.ai-msg-bubble p { color: var(--text-sub); margin-bottom: 6px; font-size: 13px; }
.ai-msg-bubble ul { padding-left: 4px; list-style: none; }
.ai-msg-bubble ul li { font-size: 13px; color: var(--text-sub); padding: 2px 0; }
.user-msg-bubble {
  background: var(--primary); color: white;
  border-radius: 12px 12px 0 12px; padding: 10px 14px;
  margin-left: auto; max-width: 75%;
  font-size: 13px; box-shadow: var(--shadow);
}
.ai-input-area { padding: 14px; border-top: 1px solid var(--border); background: var(--bg-card); transition: background .25s; }
.quick-prompts { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.quick-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 11px; border-radius: 20px;
  background: var(--bg-hover); border: 1px solid var(--border);
  font-size: 11px; font-weight: 600; cursor: pointer;
  color: var(--text-muted); transition: all .15s; font-family: var(--font);
}
.quick-btn:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }
.ai-input-row { display: flex; gap: 8px; align-items: flex-end; }
.ai-input-row textarea { flex: 1; min-height: 56px; }
.btn-ai-send { padding: 10px 14px; align-self: flex-end; height: 56px; border-radius: 10px; }
.ai-badge-sm { background: var(--primary-light); color: var(--primary); padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }

.ai-suggestion { background: var(--warning-light); border: 1px solid rgba(217,119,6,0.25); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.ai-suggestion-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.severity { padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; }
.severity-high { background: rgba(220,38,38,0.15); color: #dc2626; }
.severity-medium { background: rgba(217,119,6,0.15); color: #d97706; }
.severity-low { background: rgba(22,163,74,0.15); color: #16a34a; }
.ai-suggestion-title { font-weight: 700; font-size: 13px; color: var(--text); }
.ai-suggestion-cause { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.ai-suggestion-text { font-size: 13px; color: var(--text-sub); margin-bottom: 4px; }
.ai-suggestion-impact { font-size: 12px; color: var(--success); font-weight: 600; }

/* typing */
.typing-indicator { display: flex; gap: 4px; align-items: center; padding: 10px 14px; background: var(--bg-card); border-radius: 12px; width: fit-content; border: 1px solid var(--border); }
.typing-dot { width: 7px; height: 7px; background: var(--text-muted); border-radius: 50%; animation: typingBounce .8s infinite; }
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes typingBounce { 0%,60%,100% { transform:translateY(0); } 30% { transform:translateY(-5px); background:var(--primary); } }

/* =========================================================
   BADGES
========================================================= */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 10px; font-weight: 700; }
.badge-blue { background: var(--primary-light); color: var(--primary); }
.badge-green { background: var(--success-light); color: var(--success); }
.badge-gray { background: var(--bg-hover); color: var(--text-muted); }
.badge-orange { background: var(--warning-light); color: var(--warning); }
.badge-red { background: var(--danger-light); color: var(--danger); }
.badge-group { display: flex; gap: 6px; }

.type-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 9px; font-weight: 700; text-transform: uppercase; }
.type-esmalte_sintetico { background: var(--primary-light); color: var(--primary); }
.type-epoxy { background: var(--warning-light); color: var(--warning); }
.type-primer { background: var(--danger-light); color: var(--danger); }
.type-pu_acrilico { background: rgba(201,164,0,0.12); color: var(--secondary); }
.type-pu_poliester { background: rgba(168,136,0,0.12); color: #a58800; }
.type-base_agua { background: var(--info-light); color: var(--info); }
.type-piso { background: var(--success-light); color: var(--success); }
.type-metal { background: var(--bg-hover); color: var(--text-muted); }
.type-verniz { background: var(--warning-light); color: var(--warning); }
.type-telha { background: rgba(219,39,119,0.1); color: #db2777; }

/* =========================================================
   MODALS
========================================================= */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
  backdrop-filter: blur(3px);
}
.modal-box {
  background: var(--bg-card); border-radius: var(--radius-lg);
  width: 100%; max-width: 680px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg); border: 1px solid var(--border);
  transition: background .25s;
}
.modal-xl { max-width: 900px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-card); z-index: 1; transition: background .25s;
}
.modal-header h3 { font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 8px; color: var(--text); }
.modal-header h3 i { color: var(--primary); }
.modal-close { width: 30px; height: 30px; background: none; border: none; cursor: pointer; color: var(--text-muted); border-radius: 6px; font-size: 13px; transition: all .15s; }
.modal-close:hover { background: var(--bg-hover); color: var(--text); }
.modal-body { padding: 18px 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }

/* =========================================================
   TOASTS
========================================================= */
.toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 2000; }
.toast {
  display: flex; align-items: center; gap: 10px;
  background: #1e293b; color: #f1f5f9;
  padding: 11px 16px; border-radius: 10px;
  min-width: 260px; max-width: 380px;
  box-shadow: var(--shadow-lg); animation: slideIn .25s ease;
  font-size: 13px; font-weight: 500;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }
.toast-info { background: var(--primary); }
.toast i { font-size: 15px; }
@keyframes slideIn { from { transform: translateX(80px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* =========================================================
   COMPARE
========================================================= */
.compare-select-row { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.compare-picker { flex: 1; padding: 14px; }
.compare-picker .form-select { width: 100%; margin-top: 8px; }
.compare-vs { font-size: 22px; color: var(--text-muted); flex-shrink: 0; width: 40px; text-align: center; }
.compare-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.compare-table th, .compare-table td { padding: 9px 13px; border: 1px solid var(--border); text-align: center; color: var(--text); }
.compare-table th { background: var(--bg-hover); font-size: 11px; font-weight: 700; }
.compare-table .col-label { text-align: left; font-weight: 600; color: var(--text-sub); }
.compare-better { color: var(--success); font-weight: 700; }
.compare-worse { color: var(--danger); }

/* =========================================================
   OCR
========================================================= */
.ocr-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 36px 20px; text-align: center; cursor: pointer;
  margin: 14px 18px; transition: all .2s; background: var(--bg-hover);
}
.upload-zone:hover { border-color: var(--primary); background: var(--primary-light); }
.upload-zone i { font-size: 36px; color: var(--text-xmuted); margin-bottom: 10px; display: block; }
.upload-zone p { color: var(--text-muted); font-size: 13px; }
.upload-hint { font-size: 11px; color: var(--text-xmuted); margin-top: 6px; }
.ocr-mode-tabs { display: flex; gap: 6px; padding: 0 18px; margin-top: 10px; }
.tab-btn { flex: 1; padding: 8px; border: 1px solid var(--border); background: var(--bg-hover); border-radius: 8px; cursor: pointer; font-size: 11px; font-weight: 600; color: var(--text-muted); transition: all .15s; font-family: var(--font); display: flex; align-items: center; justify-content: center; gap: 5px; }
.tab-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.tab-btn:hover:not(.active) { background: var(--primary-light); color: var(--primary); }

/* =========================================================
   BARCODE & CAMERA
========================================================= */
.barcode-layout { display: flex; flex-direction: column; gap: 16px; }
.barcode-input-area { padding: 18px; }
.barcode-search-row { display: flex; gap: 8px; margin-bottom: 8px; }
.hint-text { font-size: 11px; color: var(--text-muted); }
.barcode-result { padding: 18px; }
.barcode-formula-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 16px; }
.barcode-formula-header h2 { color: var(--text); }
.barcode-actions { display: flex; gap: 8px; }
.barcode-display { text-align: center; padding: 16px; background: var(--bg-hover); border-radius: var(--radius); border: 1px solid var(--border); }
.barcode-list-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(190px,1fr)); gap: 10px; padding: 14px; }
.barcode-list-item { background: var(--bg-hover); border: 1px solid var(--border); border-radius: 8px; padding: 10px; text-align: center; cursor: pointer; transition: all .15s; }
.barcode-list-item:hover { background: var(--primary-light); border-color: var(--primary); }
.barcode-list-item svg { max-width: 100%; height: 48px; }
.barcode-list-name { font-size: 10px; font-weight: 600; margin-top: 5px; color: var(--text-sub); }
.barcode-list-code { font-size: 9px; color: var(--text-muted); }

/* Camera Scanner */
.camera-scanner-area {
  margin: 0 18px 16px; border-radius: var(--radius);
  border: 2px solid var(--primary); background: var(--bg-hover);
  overflow: hidden;
}
.camera-scanner-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: var(--primary); color: white;
  font-size: 13px; font-weight: 600;
}
.camera-viewport {
  position: relative; background: #000;
  display: flex; align-items: center; justify-content: center;
  min-height: 280px; overflow: hidden;
}
.camera-viewport video {
  width: 100%; max-height: 380px;
  object-fit: cover; display: block;
}
.camera-overlay {
  position: absolute; inset: 0; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
}
.scan-line {
  position: absolute; left: 10%; right: 10%;
  height: 2px; background: linear-gradient(90deg, transparent, rgba(20,65,150,0.8), transparent);
  animation: scanMove 2s ease-in-out infinite;
  box-shadow: 0 0 8px rgba(20,65,150,0.6);
}
@keyframes scanMove {
  0% { top: 20%; }
  50% { top: 80%; }
  100% { top: 20%; }
}
.scan-corners { position: absolute; inset: 16px; }
.corner {
  position: absolute; width: 24px; height: 24px;
  border-color: var(--primary); border-style: solid;
}
.corner.tl { top: 0; left: 0; border-width: 3px 0 0 3px; border-radius: 4px 0 0 0; }
.corner.tr { top: 0; right: 0; border-width: 3px 3px 0 0; border-radius: 0 4px 0 0; }
.corner.bl { bottom: 0; left: 0; border-width: 0 0 3px 3px; border-radius: 0 0 0 4px; }
.corner.br { bottom: 0; right: 0; border-width: 0 3px 3px 0; border-radius: 0 0 4px 0; }

.camera-select-row { display: flex; align-items: center; gap: 8px; padding: 10px 14px; font-size: 12px; color: var(--text-muted); }
.camera-select-row .form-select { flex: 1; font-size: 12px; padding: 6px 10px; }
.camera-hint { font-size: 12px; color: var(--text-muted); text-align: center; padding: 0 14px 10px; }

.camera-scan-result {
  margin: 0 14px 14px; padding: 10px 14px; border-radius: 8px;
  background: var(--success-light); color: var(--success);
  font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
  border: 1px solid rgba(22,163,74,0.3);
  transition: all .3s;
}
.scan-success { animation: scanPulse .5s ease; }
@keyframes scanPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.02); } }

.camera-error-msg {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px; padding: 40px 20px;
  color: var(--text-muted); text-align: center;
  background: var(--bg-hover);
}
.camera-error-msg i { font-size: 40px; color: var(--warning); }
.camera-error-msg p { font-size: 13px; max-width: 280px; }

/* =========================================================
   REPORTS
========================================================= */
.reports-layout { display: flex; flex-direction: column; gap: 16px; }
.report-options { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; padding: 16px; }
.report-type-card {
  background: var(--bg-hover); border: 2px solid var(--border);
  border-radius: var(--radius); padding: 18px; text-align: center;
  cursor: pointer; transition: all .15s;
}
.report-type-card:hover { border-color: var(--primary); background: var(--primary-light); }
.report-type-card i { font-size: 26px; color: var(--primary); margin-bottom: 8px; display: block; }
.report-type-card h4 { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.report-type-card p { font-size: 11px; color: var(--text-muted); }

/* =========================================================
   CONSTANTS
========================================================= */
.constants-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(230px,1fr)); gap: 12px; }
.constant-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); transition: background .25s; }
.constant-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.constant-card-category { font-size: 9px; font-weight: 700; text-transform: uppercase; padding: 2px 8px; border-radius: 4px; background: var(--primary-light); color: var(--primary); }
.constant-card-value { font-size: 26px; font-weight: 800; color: var(--text); }
.constant-card-unit { font-size: 12px; color: var(--text-muted); margin-left: 3px; }
.constant-card-name { font-size: 12px; font-weight: 600; color: var(--text-sub); margin-bottom: 3px; }
.constant-card-notes { font-size: 11px; color: var(--text-muted); }

/* =========================================================
   USERS
========================================================= */
.users-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(300px,1fr)); gap: 16px; }

.user-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; transition: background .25s, box-shadow .15s;
}
.user-card:hover { box-shadow: var(--shadow-md); }
.user-inactive { opacity: .6; }

.user-card-header {
  display: flex; align-items: center; gap: 14px;
  padding: 16px; border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--primary-light), rgba(201,164,0,0.06));
}

.user-avatar-lg {
  width: 52px; height: 52px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 800; color: white;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.user-card-name { font-size: 14px; font-weight: 700; color: var(--text); }
.user-card-username { font-size: 12px; color: var(--primary); font-weight: 600; }
.user-card-email { font-size: 11px; color: var(--text-muted); }

.user-card-body { padding: 12px 16px; }
.user-card-meta { display: flex; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.user-last-login { font-size: 11px; color: var(--text-muted); }
.user-last-login i { margin-right: 4px; }

.user-card-actions { display: flex; gap: 6px; padding: 10px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }

.role-badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 10px; font-weight: 700; }
.role-admin { background: rgba(220,38,38,0.12); color: #dc2626; }
.role-quimico { background: var(--primary-light); color: var(--primary); }
.role-viewer { background: var(--bg-hover); color: var(--text-muted); }

/* Avatar color picker */
.avatar-color-picker { display: flex; gap: 8px; flex-wrap: wrap; padding: 4px 0; }
.color-swatch {
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  border: 3px solid transparent; transition: all .15s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: var(--text); transform: scale(1.1); }

/* =========================================================
   ACTIONS BAR
========================================================= */
.actions-bar { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 0; }
.formula-editor { max-width: 1200px; }

/* =========================================================
   EMPTY STATE
========================================================= */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state i { font-size: 38px; margin-bottom: 12px; display: block; }
.empty-state p { font-size: 13px; }

/* =========================================================
   LOADING
========================================================= */
.loading-spinner { display: inline-flex; align-items: center; gap: 8px; color: var(--primary); font-size: 13px; }
.spinner { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================
   UTILS
========================================================= */
.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.divider { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* =========================================================
   SCROLLBAR
========================================================= */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-xmuted); }

/* =========================================================
   OCR extracted
========================================================= */
.ocr-extracted-formula { padding: 14px 18px; }
.ocr-extracted-formula table { width: 100%; border-collapse: collapse; font-size: 12px; }
.ocr-extracted-formula th, .ocr-extracted-formula td { padding: 7px 10px; border: 1px solid var(--border); text-align: left; color: var(--text); }
.ocr-extracted-formula th { background: var(--bg-hover); font-weight: 700; color: var(--text-muted); }

/* =========================================================
   RESPONSIVE
========================================================= */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2,1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .props-grid { grid-template-columns: repeat(2,1fr); }
  .report-options { grid-template-columns: repeat(2,1fr); }
  .ocr-layout { grid-template-columns: 1fr; }
  .users-grid { grid-template-columns: repeat(auto-fill,minmax(260px,1fr)); }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .mobile-toggle { display: flex; }
  .topbar-menu-btn { display: block; }
  .main-content { margin-left: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .props-grid { grid-template-columns: repeat(2,1fr); }
  .compare-select-row { flex-direction: column; }
  .formulas-grid { grid-template-columns: 1fr; }
  .report-options { grid-template-columns: 1fr 1fr; }
  .users-grid { grid-template-columns: 1fr; }
  .ai-badge { display: none; }
  #topbar-username { display: none; }
  .login-card { padding: 28px 22px; margin: 16px; }
  .ai-gen-layout { grid-template-columns: 1fr; }
  .op-layout { grid-template-columns: 1fr; }
}

/* ===================================================
   MÓDULOS ADICIONAIS — IA Generator, OP, RM Avançado
=================================================== */

/* ── AI FORMULA GENERATOR ── */
.ai-gen-layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 16px;
  align-items: start;
}
.ai-gen-input-panel { position: sticky; top: 16px; }
.ai-gen-result-panel { min-height: 400px; }
.ai-gen-intro {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--primary-light);
  border: 1px solid rgba(20,65,150,0.2);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 12px;
  color: var(--text-sub);
}
.ai-gen-intro i { color: var(--primary); font-size: 18px; margin-top: 2px; flex-shrink: 0; }
.ai-gen-intro strong { color: var(--text); display: block; margin-bottom: 4px; }
.ai-gen-intro p { margin: 0; }
.ai-gen-mat-info {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ai-gen-mat-info i { color: var(--success); }
.ai-gen-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 40px;
  text-align: center;
  color: var(--text-muted);
}
.ai-gen-empty-icon {
  width: 80px; height: 80px;
  border-radius: 50%;
  background: var(--primary-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; color: var(--primary);
  margin-bottom: 20px;
}
.ai-gen-empty h3 { font-size: 18px; color: var(--text); margin-bottom: 8px; }
.ai-gen-empty p { font-size: 13px; max-width: 320px; line-height: 1.5; }
.ai-gen-loading {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding: 24px;
}
.ai-gen-loading-icon {
  width: 52px; height: 52px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: #fff; flex-shrink: 0;
  animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.8;transform:scale(0.97)} }
.ai-gen-loading-title { font-weight: 700; color: var(--text); margin-bottom: 4px; }
.ai-gen-loading-sub { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.ai-gen-progress { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; width: 260px; }
.ai-gen-progress-bar { height: 100%; background: linear-gradient(90deg, var(--primary), var(--secondary)); border-radius: 3px; transition: width 0.2s ease; }
.ai-gen-result-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}
.ai-gen-result-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.ai-gen-result-title h3 { font-size: 17px; margin: 4px 0; }
.ai-gen-result-actions { display: flex; gap: 8px; flex-shrink: 0; }
.ai-gen-rationale {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 20px;
  background: var(--warning-light);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-sub);
}
.ai-gen-rationale i { color: var(--warning); margin-top: 2px; flex-shrink: 0; }
.ai-gen-rationale p { margin: 4px 0 0; line-height: 1.5; }
.badge-success { background: var(--success-light) !important; color: var(--success) !important; }

/* ── PRODUCTION ORDERS ── */
.op-layout {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 16px;
  align-items: start;
}
.op-preview-card {
  border: 1px solid var(--primary);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 14px;
}
.op-preview-header {
  background: var(--primary);
  color: #fff;
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.op-preview-card table { font-size: 12px; }

/* ── RAW MATERIALS FULL MODAL ── */
.modal-xl { max-width: 820px !important; }

/* ── FORMULA CONSTANTS ── */
#formula-tech-constants-body { padding: 4px 0; }

/* ── NAVIGATION ACTIVE ── */
.nav-item[data-page="ai-generator"] { background: linear-gradient(90deg, rgba(201,164,0,0.15), transparent) !important; }
.nav-item[data-page="ai-generator"] i { color: #e8c400 !important; }
.nav-item[data-page="ai-generator"].active { background: linear-gradient(90deg, rgba(201,164,0,0.3), transparent) !important; }
.nav-item[data-page="production-orders"] i { color: #34d399 !important; }

/* ── FORMULA CARD ENHANCED ── */
.formula-card-actions { gap: 4px; }
.btn-info { background: var(--info); color: #fff; border: none; }
.btn-info:hover { background: #0e7490; color: #fff; }

/* ── NUMBER CELL ── */
.number-cell { text-align: right; font-variant-numeric: tabular-nums; }

/* ── OP BADGE COLORS ── */
.badge-orange { background: #fff7ed; color: #ea580c; }
.badge-red { background: #fef2f2; color: #dc2626; }
.badge-purple { background: #fffbea; color: #a58800; }

@media (max-width: 1100px) {
  .ai-gen-layout { grid-template-columns: 360px 1fr; }
  .op-layout { grid-template-columns: 360px 1fr; }
}
@media (max-width: 900px) {
  .ai-gen-layout { grid-template-columns: 1fr; }
  .op-layout { grid-template-columns: 1fr; }
  .ai-gen-input-panel { position: static; }
}

/* ===================================================
   WHATSAPP MODULE STYLES
=================================================== */

/* ── Layout ── */
.wa-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 16px;
  align-items: start;
}

@media (max-width: 1024px) { .wa-layout { grid-template-columns: 340px 1fr; } }
@media (max-width: 768px)  { .wa-layout { grid-template-columns: 1fr; } }

/* ── Contact Card ── */
.wa-contact-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  gap: 10px;
  transition: box-shadow .15s;
}
.wa-contact-card:hover { box-shadow: var(--shadow); }
.wa-contact-card.wa-inactive { opacity: .6; }

.wa-contact-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.wa-contact-avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: #fff;
}
.wa-contact-name { font-size: 13px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-contact-phone { font-size: 11px; color: var(--text-muted); }
.wa-contact-actions { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }

/* ── Schedule info ── */
.wa-schedule-info {
  display: flex; gap: 10px; align-items: flex-start;
  background: rgba(37,211,102,0.08);
  border: 1px solid rgba(37,211,102,0.3);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 12px; color: var(--text-sub);
}
.wa-schedule-info i { color: #25d366; font-size: 16px; flex-shrink: 0; margin-top: 2px; }
.wa-schedule-info strong { display: block; color: var(--text); margin-bottom: 3px; font-size: 13px; }

/* ── Status badge ── */
.wa-status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 20px; font-size: 12px; font-weight: 700;
}
.wa-status-active  { background: rgba(22,163,74,0.12); color: var(--success); }
.wa-status-inactive{ background: var(--bg-hover); color: var(--text-muted); }
.wa-status-active i  { color: var(--success); font-size: 8px; animation: blink 2s infinite; }
.wa-status-inactive i{ color: var(--text-muted); font-size: 8px; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ── Checkbox label ── */
.wa-checkbox-label {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: var(--text-sub); cursor: pointer;
  padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border);
  transition: background .1s;
}
.wa-checkbox-label:hover { background: var(--bg-hover); }
.wa-checkbox-label input[type="checkbox"] { width: 15px; height: 15px; accent-color: #25d366; cursor: pointer; }

/* ── Report Preview ── */
.wa-report-preview {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-height: 320px;
  max-height: 520px;
  overflow-y: auto;
}
.wa-preview-bubble {
  background: var(--bg-card);
  border-radius: 10px;
  overflow: hidden;
}
.wa-preview-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: linear-gradient(135deg, #25d366, #128c7e);
  color: #fff; font-size: 12px; font-weight: 700;
}
.wa-preview-body {
  padding: 14px 16px;
  font-size: 12px; line-height: 1.7; color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  white-space: pre-wrap; word-break: break-word;
}
.wa-preview-chars {
  text-align: right; font-size: 10px; color: var(--text-muted);
  padding: 4px 14px 8px;
}

/* ── WhatsApp green accent ── */
.btn-whatsapp {
  background: #25d366; color: #fff; border: none;
}
.btn-whatsapp:hover { background: #1ebe58; color: #fff; }

/* ── Nav item WhatsApp ── */
.nav-item[data-page="whatsapp"] i.fab { color: #25d366 !important; }

/* ── Hint text ── */
.hint-text {
  font-size: 11px; color: var(--text-muted);
  display: flex; align-items: center; gap: 5px; margin-top: 6px;
}
.hint-text i { flex-shrink: 0; }

/* ── KPI STATS GRID (6 cards) ── */
.stats-grid-6 {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card.stat-teal { background: linear-gradient(135deg, #0891b2, #0e7490); }
.stat-card.stat-red  { background: linear-gradient(135deg, #dc2626, #b91c1c); }

@media (max-width: 1280px) { .stats-grid-6 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px)  { .stats-grid-6 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px)  { .stats-grid-6 { grid-template-columns: 1fr 1fr; } }

/* ── METRIC BOX (production/quality KPIs inside cards) ── */
.metric-box {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  transition: box-shadow .15s;
}
.metric-box:hover { box-shadow: var(--shadow-md); }
.metric-icon {
  width: 42px; height: 42px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; flex-shrink: 0;
}
.metric-value { font-size: 20px; font-weight: 800; color: var(--text); line-height: 1.2; }
.metric-label { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }

.metric-blue  .metric-icon { background: var(--primary-light); color: var(--primary); }
.metric-green .metric-icon { background: var(--success-light); color: var(--success); }
.metric-orange .metric-icon { background: var(--warning-light); color: var(--warning); }
.metric-purple .metric-icon { background: rgba(201,164,0,0.1); color: var(--secondary); }
.metric-red   .metric-icon { background: var(--danger-light); color: var(--danger); }
.metric-teal  .metric-icon { background: var(--info-light); color: var(--info); }

/* ── DASHBOARD INSIGHTS ── */
#dashboard-insights { max-height: 400px; overflow-y: auto; }

/* ── LAB RESULTS SECTION (inside OP view modal) ── */
.lab-results-section {
  margin-top: 16px;
  border-top: 2px dashed rgba(22,163,74,0.25);
  padding-top: 16px;
}

/* ── BADGE VARIANTS ── */
.badge-green  { background: var(--success-light); color: var(--success); }
.badge-gray   { background: var(--bg-hover); color: var(--text-muted); }
.badge-teal   { background: var(--info-light); color: var(--info); }

/* ── AI BADGE SMALL ── */
.ai-badge-sm {
  display: inline-flex; align-items: center; gap: 4px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff; padding: 3px 10px; border-radius: 20px;
  font-size: 10px; font-weight: 700; letter-spacing: .4px;
  white-space: nowrap;
}
.ai-badge-sm.badge-success { background: linear-gradient(135deg, var(--success), #0d9488); }

/* ── COMPARE TABLE ── */
.compare-table tr:hover td { background: var(--bg-hover); }

/* ── LIGHT THEME TOGGLE IMPROVEMENTS ── */
[data-theme="light"] .stat-card.stat-blue    { background: linear-gradient(135deg,#144196,#0a2554); }
[data-theme="light"] .stat-card.stat-green   { background: linear-gradient(135deg,#16a34a,#15803d); }
[data-theme="light"] .stat-card.stat-orange  { background: linear-gradient(135deg,#d97706,#b45309); }
[data-theme="light"] .stat-card.stat-purple  { background: linear-gradient(135deg,#c9a400,#a58800); }
[data-theme="light"] .stat-card.stat-teal    { background: linear-gradient(135deg,#0891b2,#0e7490); }
[data-theme="light"] .stat-card.stat-red     { background: linear-gradient(135deg,#dc2626,#b91c1c); }

/* Theme toggle button active state */
.sidebar-icon-btn.theme-active,
.btn-icon.theme-active { color: var(--warning) !important; }

/* ── OP LAB RESULTS INLINE ── */
.op-lab-inline { background: var(--bg-hover); border-radius: 10px; padding: 14px; margin-top: 12px; }

/* ── TOPBAR REFRESH ── */
#last-refresh-time {
  font-size: 10px; color: var(--text-xmuted);
  display: flex; align-items: center; gap: 4px;
}

/* ── FORMULA ANALYSIS DONUT CHART ── */
#formula-analysis-modal .modal-box { max-width: 860px; }
#formula-analysis-content { padding: 0 8px 8px; max-height: 75vh; overflow-y: auto; }

/* ── INSIGHT CARDS ── */
.insight-card {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 14px;
  background: var(--bg-hover);
  border-left: 4px solid var(--primary);
  border-radius: 0 8px 8px 0;
  margin-bottom: 8px;
  transition: background .15s;
}
.insight-card:hover { background: var(--bg-card); box-shadow: var(--shadow); }
.insight-card.ins-warning { border-color: var(--warning); }
.insight-card.ins-danger  { border-color: var(--danger); }
.insight-card.ins-success { border-color: var(--success); }
.insight-card.ins-info    { border-color: var(--info); }
.insight-title { font-size: 13px; font-weight: 600; color: var(--text); }
.insight-desc  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── ENHANCED RESPONSIVE ── */
@media (max-width: 768px) {
  .stats-grid-6 { grid-template-columns: 1fr 1fr; }
  #dashboard-production-metrics .form-row,
  #dashboard-production-metrics > div > div > div[style*="grid-template-columns:repeat(4"] {
    grid-template-columns: 1fr 1fr !important;
  }
  #dashboard-quality-metrics .form-row {
    grid-template-columns: 1fr 1fr !important;
  }
  .metric-box { padding: 10px 12px; }
  .metric-value { font-size: 17px; }
  #formula-analysis-content { max-height: 85vh; }
}

@media (max-width: 480px) {
  .stats-grid-6 { grid-template-columns: 1fr 1fr; }
  .barcode-search-row { flex-direction: column; }
  .barcode-search-row .form-control-lg { width: 100%; }
  .topbar-left h1 { font-size: 15px; }
  .topbar-left .page-subtitle { display: none; }
}

/* ── TOGGLE SWITCH ── */
.toggle-switch-row { display: flex; align-items: center; gap: 12px; }
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-switch-slider {
  position: absolute; cursor: pointer; inset: 0;
  background-color: var(--gray-300, #d1d5db); border-radius: 24px;
  transition: background-color .2s ease;
}
.toggle-switch-slider::before {
  content: ""; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px;
  background-color: #fff; border-radius: 50%; transition: transform .2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.toggle-switch input:checked + .toggle-switch-slider { background-color: var(--primary); }
.toggle-switch input:checked + .toggle-switch-slider::before { transform: translateX(20px); }
.toggle-switch input:focus-visible + .toggle-switch-slider { outline: 2px solid var(--primary); outline-offset: 2px; }
.toggle-switch-label { margin: 0; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text); }

/* ── PRINT STYLES ── */
@media print {
  .sidebar, .topbar, .topbar-right, .actions-bar,
  .btn, .modal-footer, #toast-container, .mobile-toggle { display: none !important; }
  .main-content { margin: 0 !important; padding: 0 !important; }
  .page { display: block !important; padding: 0 !important; }
  body { background: #fff !important; color: #000 !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd !important; margin-bottom: 12px !important; }
}
