/* ==========================================
   0. THEME VARIABLES
   ========================================== */
:root {
  --bg: #f3f4f6;
  --text: #111;
  --panel: #ffffff;
  --header: #1f3864;
  --nav: #2e5599;
  --border: #cfd5e1;
  --border-light: #e5e7eb;
  --highlight: #fff7c2;
  --highlight-sel: #ffd54f;
  --input-bg: #ffffff;
  --input-text: #0000ff;
  --kpi-bg: #d9e1f2;
  --table-even: #f9fafb;
}

body.theme-dark {
  --bg: #0f172a;
  --text: #f1f5f9;
  --panel: #1e293b;
  --header: #020617;
  --nav: #1e3a8a;
  --border: #334155;
  --border-light: #1e293b;
  --highlight: #334155;
  --highlight-sel: #475569;
  --input-bg: #0f172a;
  --input-text: #60a5fa;
  --kpi-bg: #334155;
  --table-even: #1e293b;
}

body.theme-floral {
  --bg: #fff5f8;
  --text: #4a1d24;
  --panel: #ffffff;
  --header: #d81b60;
  --nav: #ec407a;
  --border: #f8bbd0;
  --border-light: #fce4ec;
  --highlight: #f8bbd0;
  --highlight-sel: #f48fb1;
  --input-bg: #fff;
  --input-text: #ad1457;
  --kpi-bg: #fce4ec;
  --table-even: #fff0f5;
}

body.theme-desert {
  --bg: #2d1b1b;
  --text: #ffcc80;
  --panel: #3e2723;
  --header: #bf360c;
  --nav: #d84315;
  --border: #5d4037;
  --border-light: #4e342e;
  --highlight: #795548;
  --highlight-sel: #8d6e63;
  --input-bg: #2d1b1b;
  --input-text: #ff9800;
  --kpi-bg: #4e342e;
  --table-even: #3e2723;
}

/* ==========================================
   1. GLOBAL STYLES & LAYOUT
   ========================================== */
* { box-sizing: border-box; }
body {
  font-family: Arial, Helvetica, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

/* ==========================================
   2. AUTHENTICATION UI
   ========================================== */
.auth-card {
  background: var(--panel);
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 420px;
  border-top: 5px solid var(--header);
}
.auth-header h2 { margin: 0 0 5px 0; color: var(--header); font-size: 22px; }
.auth-header p { margin: 0 0 25px 0; color: #6b7280; font-size: 14px; }

.form-group { margin-bottom: 20px; }
.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text);
}
.form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
  background: var(--input-bg);
  color: var(--text);
}
.form-group input:focus {
  outline: none;
  border-color: var(--nav);
  box-shadow: 0 0 0 3px rgba(46, 85, 153, 0.15);
}

.auth-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 25px; }
button {
  padding: 12px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary { background: var(--header); color: #fff; }
.btn-primary:hover { background: #142542; }
.btn-secondary { background: var(--border-light); color: var(--text); }
.btn-secondary:hover { background: var(--border); }

.error-msg {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
  padding: 10px;
  border-radius: 4px;
  font-size: 13px;
  margin-bottom: 20px;
}
.auth-footer { text-align: center; margin-top: 20px; color: #9ca3af; }

/* ==========================================
   3. WORKSPACE UI (HIDDEN UNTIL LOGIN)
   ========================================== */
#app-container { width: 100%; align-self: flex-start; display: none; }

header {
  background: var(--header);
  color: #fff;
  padding: 14px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
header h1 { margin: 0; font-size: 18px; font-weight: 700; }
header .meta { font-size: 12px; opacity: .85; }

nav {
  background: var(--nav);
  padding: 0 14px;
  display: flex;
  flex-wrap: wrap;
  overflow-x: auto;
}
nav button {
  background: none;
  border: 0;
  color: #dbe2f1;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
nav button:hover { color: #fff; background: rgba(255, 255, 255, .06); }
nav button.active { color: #fff; border-color: #ffd54f; background: rgba(255, 255, 255, .08); }

main { padding: 18px; max-width: 1400px; margin: 0 auto; }
.panel {
  background: var(--panel);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
}
.panel h2 { margin: 0 0 12px; font-size: 16px; color: var(--header); border-bottom: 2px solid var(--border-light); padding-bottom: 8px; }
.panel h3 { margin: 18px 0 8px; font-size: 14px; color: var(--header); }

.row { display: flex; flex-wrap: wrap; gap: 12px; }
.col { flex: 1 1 220px; }

label { display: block; font-size: 12px; color: var(--text); opacity: 0.8; margin-bottom: 4px; }
input[type=number], input[type=text], input[type=date], select, textarea {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
}
input.input { color: var(--input-text); font-weight: 600; }
textarea { min-height: 80px; font-family: 'Consolas', monospace; font-size: 12px; }

.btn {
  background: var(--nav);
  color: #fff;
  border: 0;
  border-radius: 4px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  width: auto;
}
.btn:hover { background: #264a85; }
.btn.alt { background: #0d8a44; }
.btn.alt:hover { background: #0a6e36; }
.btn.warn { background: #c53030; }
.btn.warn:hover { background: #991b1b; }

table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { background: var(--nav); color: #fff; padding: 6px 8px; text-align: left; position: sticky; top: 0; }
td { padding: 5px 8px; border-bottom: 1px solid var(--border-light); }
tr:nth-child(even) td { background: var(--table-even); }
tr:hover td { background: var(--highlight) !important; cursor: pointer; }
.selected-row td { background: var(--highlight-sel) !important; font-weight: 600; }
td.num, th.num { text-align: right; }
td input { border: 0; background: transparent; padding: 2px 4px; text-align: right; font-size: 12px; color: var(--input-text); font-weight: 600; width: 100%; }
td input:focus { background: var(--highlight); outline: 1px solid var(--header); }
td.locked { background: var(--table-even); color: var(--text); opacity: 0.6; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.kpi { background: var(--kpi-bg); border-radius: 6px; padding: 12px; text-align: center; }
.kpi .l { font-size: 11px; color: var(--text); opacity: 0.7; text-transform: uppercase; letter-spacing: .5px; }
.kpi .v { font-size: 20px; font-weight: 700; color: var(--header); margin-top: 6px; }
.kpi.good { background: #e2efda; } .kpi.good .v { color: #0a6e36; }
.kpi.bad { background: #fce4d6; } .kpi.bad .v { color: #a02828; }
.kpi.warn { background: #fff3cd; } .kpi.warn .v { color: #7a5b00; }
.pos { color: #0a6e36; font-weight: 600; } .neg { color: #a02828; font-weight: 600; }

.chart-box { position: relative; height: 300px; margin-top: 10px; }
.scroll { max-height: 520px; overflow: auto; border: 1px solid var(--border-light); border-radius: 4px; }
.small { font-size: 11px; color: #666; }
.tag { display: inline-block; background: var(--kpi-bg); color: var(--header); font-size: 11px; padding: 2px 6px; border-radius: 3px; margin-right: 4px; }
.badge-warn { background: #fff3cd; color: #7a5b00; font-size: 11px; padding: 2px 6px; border-radius: 3px; }
.badge-bad { background: #fce4d6; color: #a02828; font-size: 11px; padding: 2px 6px; border-radius: 3px; }
.badge-good { background: #e2efda; color: #0a6e36; font-size: 11px; padding: 2px 6px; border-radius: 3px; }
.yellow { background: var(--highlight); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.help { background: var(--highlight); border-left: 4px solid var(--highlight-sel); padding: 10px 12px; border-radius: 4px; font-size: 12px; color: var(--text); margin-bottom: 12px; }
details { background: var(--table-even); border: 1px solid var(--border-light); border-radius: 4px; padding: 8px; margin-bottom: 8px; }
summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--header); }
.footer { padding: 14px; text-align: center; color: #666; font-size: 11px; }

/* ==========================================
   5. PRIVACY MODE (BLUR)
   ========================================== */
body.privacy-active .num, 
body.privacy-active .v, 
body.privacy-active input[type=number],
body.privacy-active .kpi .v {
  filter: blur(6px);
  user-select: none;
  pointer-events: none;
  transition: filter 0.3s ease;
}
body.privacy-active .num:hover, 
body.privacy-active .v:hover {
  filter: blur(0px);
}

.btn-logout { background: #b91c1c; color: white; padding: 8px 14px; font-size: 12px; width: auto; }
.btn-logout:hover { background: #991b1b; }

/* ==========================================
   4. FLOATING AI WIDGET
   ========================================== */
.ai-widget {
  position: fixed;
  bottom: 25px;
  right: 25px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.ai-bubble {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--header);
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 0.2s;
}
.ai-bubble:hover { transform: scale(1.1); background: var(--nav); }
.ai-bubble.disabled {
  background: #9ca3af !important;
  cursor: not-allowed;
  opacity: 0.6;
  filter: grayscale(1);
  transform: none !important;
}

.ai-chat-window {
  width: 350px;
  height: 480px;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  margin-bottom: 15px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border-light);
}
.ai-chat-header {
  background: var(--header);
  color: white;
  padding: 12px 15px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}
.ai-chat-body {
  flex: 1;
  padding: 15px;
  overflow-y: auto;
  background: var(--table-even);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ai-msg {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.4;
  max-width: 85%;
}
.ai-msg.bot {
  background: var(--border-light);
  color: var(--text);
  align-self: flex-start;
}
.ai-msg.user {
  background: var(--header);
  color: white;
  align-self: flex-end;
}
.ai-chat-footer {
  padding: 15px;
  border-top: 1px solid var(--border-light);
  background: var(--panel);
}
