:root {
  --green: #4A9D3F;
  --green-dark: #3A7D32;
  --green-light: #6BBF59;
  --green-bg: #E8F5E3;
  --red: #D40000;
  --red-light: #FEE2E2;
  --blue: #2563EB;
  --blue-bg: #DBEAFE;
  --amber: #D97706;
  --amber-bg: #FEF3C7;
  --dark: #111827;
  --gray: #4B5563;
  --gray-light: #9CA3AF;
  --border: #E5E7EB;
  --bg: #F9FAFB;
  --card: #FFFFFF;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
  --font: 'DM Sans', system-ui, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font); color: var(--dark); background: var(--bg); }

/* ── Forms ── */
.field {
  width: 100%; padding: 14px 16px; border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 15px; font-family: var(--font); margin-bottom: 12px; outline: none;
  transition: border-color 0.2s; background: var(--card);
}
.field:focus { border-color: var(--green); }
select.field { cursor: pointer; }

/* ── Buttons ── */
.btn-primary {
  padding: 12px 24px; border: none; border-radius: 10px;
  background: var(--green); color: white; font-size: 14px; font-weight: 700;
  font-family: var(--font); cursor: pointer; transition: background 0.2s; white-space: nowrap;
}
.btn-primary:hover { background: var(--green-dark); }
.btn-primary:disabled { background: var(--gray-light); cursor: not-allowed; }
.btn-full { width: 100%; }
.btn-ghost {
  padding: 8px 16px; border: 1.5px solid var(--border); border-radius: 8px;
  background: transparent; font-size: 13px; font-weight: 500; color: var(--gray);
  cursor: pointer; font-family: var(--font); transition: all 0.2s;
}
.btn-ghost:hover { border-color: var(--red); color: var(--red); }
.btn-sm { padding: 6px 14px; font-size: 12px; border-radius: 8px; }

/* ── Error / Success ── */
.error-msg { color: var(--red); font-size: 13px; margin-top: 12px; display: none; }
.success-msg { color: var(--green-dark); font-size: 13px; margin-top: 8px; display: none; }

/* ── Login ── */
.login-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: linear-gradient(135deg, #1B4332 0%, #2D6A4F 50%, #40916C 100%);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  background: var(--card); border-radius: 20px; padding: 48px 40px;
  width: min(420px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,0.3); text-align: center;
}
.login-logo { width: 80px; height: 80px; border-radius: 16px; margin-bottom: 20px; }
.login-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.login-card p { font-size: 14px; color: var(--gray-light); margin-bottom: 28px; }

/* ── App Shell ── */
.app { display: none; height: 100vh; flex-direction: column; }
.app.active { display: flex; }

/* ── Header ── */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; background: var(--card);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.header-brand { display: flex; align-items: center; gap: 12px; }
.header-logo { width: 38px; height: 38px; border-radius: 10px; }
.header-title { font-size: 18px; font-weight: 700; color: var(--green-dark); }
.header-subtitle { font-size: 12px; color: var(--gray-light); }
.header-user { display: flex; align-items: center; gap: 12px; }
.header-name { font-size: 13px; font-weight: 500; color: var(--gray); }
.header-role {
  font-size: 11px; font-weight: 700; color: var(--green-dark);
  background: var(--green-bg); padding: 3px 10px; border-radius: 20px;
}

/* ── Navigation ── */
.nav {
  display: flex; gap: 4px; padding: 8px 24px; background: var(--card);
  border-bottom: 1px solid var(--border); flex-shrink: 0; overflow-x: auto;
}
.nav-btn {
  padding: 10px 20px; border: none; border-radius: 8px;
  background: transparent; font-size: 13px; font-weight: 500;
  color: var(--gray); cursor: pointer; font-family: var(--font);
  transition: all 0.2s; white-space: nowrap;
}
.nav-btn:hover { background: var(--green-bg); color: var(--green-dark); }
.nav-btn.active { background: var(--green); color: white; }

/* ── Main ── */
.main { flex: 1; overflow-y: auto; padding: 24px; }

/* ── Cards & Stats ── */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow);
}
.stat-card { border-left: 4px solid var(--green); }
.stat-card.warn { border-left-color: var(--amber); }
.stat-card.danger { border-left-color: var(--red); }
.stat-card.info { border-left-color: var(--blue); }
.stat-number { font-size: 32px; font-weight: 700; }
.stat-label { font-size: 13px; color: var(--gray-light); margin-top: 4px; }

/* ── Tables ── */
.tbl {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.tbl th {
  padding: 12px 16px; text-align: left; font-size: 12px;
  font-weight: 700; color: var(--gray-light); text-transform: uppercase;
  letter-spacing: 0.5px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.tbl td { padding: 12px 16px; font-size: 14px; color: var(--gray); border-bottom: 1px solid var(--border); }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: rgba(74,157,63,0.04); }

/* ── Badges ── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-draft { background: var(--amber-bg); color: #92400E; }
.badge-review { background: var(--blue-bg); color: #1E40AF; }
.badge-approved { background: var(--green-bg); color: var(--green-dark); }

/* ── Chat ── */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 140px); }
.chat-header { display: flex; align-items: center; gap: 12px; padding-bottom: 16px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.agent-select {
  padding: 10px 14px; border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 14px; font-weight: 600; font-family: var(--font); background: var(--card);
  cursor: pointer; color: var(--dark);
}
.agent-select:focus { border-color: var(--green); outline: none; }
.chat-upload-btn {
  padding: 10px 16px; border: 1.5px dashed var(--border); border-radius: 10px;
  background: transparent; font-size: 13px; font-weight: 500; color: var(--gray);
  cursor: pointer; font-family: var(--font); transition: all 0.2s;
}
.chat-upload-btn:hover { border-color: var(--green); color: var(--green-dark); background: var(--green-bg); }
.chat-messages {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 4px 0;
}
.chat-msg {
  max-width: 80%; padding: 14px 18px; border-radius: 16px; font-size: 14px; line-height: 1.6;
}
.chat-msg.bot { align-self: flex-start; background: var(--green-bg); color: var(--dark); border-bottom-left-radius: 4px; }
.chat-msg.user { align-self: flex-end; background: var(--green); color: white; border-bottom-right-radius: 4px; }
.chat-msg.system { align-self: center; background: var(--amber-bg); color: #92400E; font-size: 12px; border-radius: 8px; }
.chat-msg p { margin-bottom: 8px; } .chat-msg p:last-child { margin-bottom: 0; }
.chat-input-row { display: flex; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.chat-input {
  flex: 1; padding: 12px 16px; border: 1.5px solid var(--border);
  border-radius: 10px; font-size: 14px; font-family: var(--font);
  outline: none; resize: none; min-height: 44px; max-height: 120px;
}
.chat-input:focus { border-color: var(--green); }

/* ── Section ── */
.section-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.section-desc { font-size: 14px; color: var(--gray-light); margin-bottom: 20px; }
.section-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

/* ── Loading ── */
.loading::after {
  content: ''; display: inline-block; width: 14px; height: 14px;
  border: 2px solid var(--green-bg); border-top-color: var(--green);
  border-radius: 50%; animation: spin 0.8s linear infinite;
  vertical-align: middle; margin-left: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Upload status ── */
.upload-status {
  background: var(--card); border-radius: var(--radius); padding: 14px 18px;
  box-shadow: var(--shadow); margin-bottom: 16px; border-left: 4px solid var(--green);
  font-size: 13px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .header { padding: 10px 16px; }
  .nav { padding: 6px 16px; }
  .main { padding: 16px; }
  .grid { grid-template-columns: 1fr 1fr; }
  .chat-msg { max-width: 92%; }
  .header-user .header-name { display: none; }
}
@media (max-width: 480px) {
  .grid { grid-template-columns: 1fr; }
}
