/* ════════════════════════════════════════════════════════════
   Innovalue Lead Collection — Stylesheet
   ════════════════════════════════════════════════════════════ */

/* ─── Design Tokens ─────────────────────────────────────── */
:root {
  /* Brand */
  --primary: #1e3a5f;
  --primary-dark: #142a45;
  --primary-light: #2c5282;
  --accent: #e67e22;
  --accent-dark: #c66913;

  /* Status colors */
  --success: #27ae60;
  --success-tint: #e8f8ed;
  --warning: #f39c12;
  --warning-tint: #fef5e7;
  --danger: #e74c3c;
  --danger-tint: #fdeeec;
  --info: #3498db;
  --info-tint: #ebf5fb;
  --auto: #8e44ad;
  --auto-tint: #f4ebfa;

  /* Tier colors */
  --tier-hot: #e74c3c;
  --tier-warm: #f39c12;
  --tier-cold: #3498db;

  /* Admin colors */
  --admin-baifern: #e74c3c;
  --admin-ling: #2980b9;
  --admin-gatai: #27ae60;
  --admin-jay: #8e44ad;
  --admin-pim: #d35400;

  /* Neutrals */
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e1e7ee;
  --border-strong: #c5d0dc;
  --text: #1e3a5f;
  --text-muted: #5a6a82;
  --text-subtle: #8a98ab;
  --text-light: #ffffff;

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(30,58,95,0.06);
  --shadow-md: 0 2px 8px rgba(30,58,95,0.08);
  --shadow-lg: 0 8px 24px rgba(30,58,95,0.12);
  --shadow-xl: 0 16px 48px rgba(30,58,95,0.18);

  /* Spacing */
  --gap-xs: 4px;
  --gap-sm: 8px;
  --gap-md: 12px;
  --gap-lg: 16px;
  --gap-xl: 24px;
  --gap-2xl: 32px;

  /* Typography */
  --font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --fs-xs: 11px;
  --fs-sm: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 18px;
  --fs-2xl: 22px;
  --fs-3xl: 28px;

  /* Layout */
  --header-h: 56px;
  --footer-h: 32px;
  --max-w: 1280px;
}

/* ─── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  font-size: var(--fs-md);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Header ────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--primary);
  color: var(--text-light);
  height: var(--header-h);
  box-shadow: var(--shadow-md);
}
.header-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  height: 100%;
  padding: 0 var(--gap-lg);
  display: flex;
  align-items: center;
  gap: var(--gap-lg);
}
.header-brand {
  display: flex;
  align-items: center;
  gap: var(--gap-md);
  cursor: pointer;
  user-select: none;
}
.brand-logo {
  width: 36px;
  height: 36px;
  background: var(--accent);
  color: var(--text-light);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.5px;
}
.brand-text { line-height: 1.15; }
.brand-title { font-weight: 700; font-size: var(--fs-lg); }
.brand-subtitle { font-size: var(--fs-xs); opacity: 0.7; }

.header-nav {
  display: flex;
  gap: 2px;
  flex: 1;
  margin-left: var(--gap-xl);
  overflow-x: auto;
  scrollbar-width: thin;
}
.nav-item {
  background: transparent;
  border: 0;
  color: rgba(255,255,255,0.75);
  padding: 8px 14px;
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: white; }
.nav-item.active { background: rgba(255,255,255,0.15); color: white; font-weight: 600; }

.header-actions { display: flex; align-items: center; gap: var(--gap-sm); margin-left: auto; }

.bell-btn {
  position: relative;
  width: 38px;
  height: 38px;
  border: 0;
  background: rgba(255,255,255,0.08);
  color: white;
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.bell-btn:hover { background: rgba(255,255,255,0.15); }
.bell-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: var(--r-full);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--primary);
}

.user-area { display: flex; align-items: center; gap: var(--gap-sm); }

/* Login button — visible to public */
.btn-login {
  background: var(--accent);
  color: white;
  border: 0;
  padding: 8px 16px;
  border-radius: var(--r-md);
  font-weight: 600;
  font-size: var(--fs-md);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s ease;
}
.btn-login:hover { background: var(--accent-dark); }

/* Logged-in user pill */
.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 4px;
  background: rgba(255,255,255,0.1);
  border-radius: var(--r-full);
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
}
.user-name { font-size: var(--fs-sm); font-weight: 600; color: white; }
.user-role {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: rgba(255,255,255,0.15);
  padding: 1px 6px;
  border-radius: var(--r-full);
  color: white;
}
.btn-logout {
  background: transparent;
  border: 0;
  color: rgba(255,255,255,0.6);
  padding: 4px 8px;
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
}
.btn-logout:hover { color: white; background: rgba(255,255,255,0.1); }

/* ─── Main ──────────────────────────────────────────────── */
.app-main {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: var(--gap-xl);
  min-height: calc(100vh - var(--header-h) - var(--footer-h));
}

/* Loading screen */
.loading-screen {
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--gap-lg);
  color: var(--text-muted);
}
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: var(--r-full);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Card ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-pad { padding: var(--gap-xl); }
.card-tight { padding: var(--gap-md); }
.card-header {
  padding: var(--gap-md) var(--gap-xl);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-md);
}
.card-title { font-size: var(--fs-lg); font-weight: 600; }
.card-subtitle { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 2px; }

/* ─── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  font-weight: 600;
  background: var(--surface);
  color: var(--text);
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: white; border-color: var(--accent); }
.btn-accent:hover { background: var(--accent-dark); }
.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-warning { background: var(--warning); color: white; border-color: var(--warning); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-lg { padding: 12px 24px; font-size: var(--fs-lg); }
.btn-sm { padding: 4px 10px; font-size: var(--fs-sm); }
.btn-icon { padding: 6px; aspect-ratio: 1; }

.icon-btn {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  padding: 6px;
  border-radius: var(--r-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ─── Form ──────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-full { grid-column: 1 / -1; }
.field label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
}
.req { color: var(--danger); }
.field input, .field select, .field textarea, .field-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: white;
  font-size: var(--fs-md);
  color: var(--text);
  transition: border-color 0.15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 0;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30,58,95,0.1);
}
.field input.is-valid { border-color: var(--success); }
.field input.is-invalid { border-color: var(--danger); }
.field-help { font-size: var(--fs-xs); color: var(--text-muted); }
.field-error { font-size: var(--fs-xs); color: var(--danger); font-weight: 600; }
.field textarea { min-height: 70px; resize: vertical; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap-md);
}
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
}

/* ─── Modal ─────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30,58,95,0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gap-lg);
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 920px; }
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-header {
  padding: var(--gap-lg) var(--gap-xl);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: var(--fs-xl); font-weight: 700; }
.modal-body { padding: var(--gap-xl); }
.modal-footer {
  padding: var(--gap-md) var(--gap-xl);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: var(--gap-md);
}

/* ─── Toast ─────────────────────────────────────────────── */
.toast-root {
  position: fixed;
  bottom: var(--gap-xl);
  right: var(--gap-xl);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
  max-width: 380px;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border-left: 4px solid var(--primary);
  padding: var(--gap-md) var(--gap-lg);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: flex-start;
  gap: var(--gap-md);
  pointer-events: auto;
  animation: slideInRight 0.2s ease;
}
@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } }
.toast-success { border-left-color: var(--success); }
.toast-warning { border-left-color: var(--warning); }
.toast-danger { border-left-color: var(--danger); }
.toast-icon { font-size: 18px; }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: 600; font-size: var(--fs-md); }
.toast-msg { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 2px; }
.toast-close { color: var(--text-subtle); }

/* ─── Activity Feed ─────────────────────────────────────── */
.activity-feed {
  position: fixed;
  top: 60px;
  right: 70px;
  width: 360px;
  max-height: 70vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xl);
  z-index: 60;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.activity-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--gap-md) var(--gap-lg);
  border-bottom: 1px solid var(--border);
}
.activity-list { overflow-y: auto; flex: 1; }
.activity-item {
  padding: var(--gap-md) var(--gap-lg);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s ease;
}
.activity-item:hover { background: var(--surface-2); }
.activity-empty {
  padding: var(--gap-2xl);
  text-align: center;
  color: var(--text-subtle);
  font-size: var(--fs-sm);
}

/* ─── Footer ────────────────────────────────────────────── */
.app-footer {
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-sm);
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.footer-sep { opacity: 0.5; }
#footer-status { color: var(--success); }
#footer-status.is-offline { color: var(--danger); }

/* ─── Utility ───────────────────────────────────────────── */
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.fw-700 { font-weight: 700; }
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }
.text-lg { font-size: var(--fs-lg); }
.tabular { font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--gap-md); }
.gap-4 { gap: 4px; }
.gap-6 { gap: 6px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-20 { gap: 20px; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-12 { margin-bottom: 12px; }
.hidden { display: none !important; }

/* ─── Empty State ───────────────────────────────────────── */
.empty {
  text-align: center;
  padding: var(--gap-2xl);
  color: var(--text-muted);
}
.empty-icon { font-size: 36px; margin-bottom: var(--gap-sm); opacity: 0.5; }
.empty-title { font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-msg { font-size: var(--fs-sm); }

/* ─── Print ─────────────────────────────────────────────── */
@media print {
  .no-print { display: none !important; }
  body { background: white; }
  .app-main { padding: 0; max-width: none; }
  .card { border: 1px solid #ddd; box-shadow: none; break-inside: avoid; }
  @page { size: A4; margin: 12mm; }
}

/* ─── Responsive ────────────────────────────────────────── */
@media (max-width: 760px) {
  .header-nav { display: none; }
  .brand-subtitle { display: none; }
  .app-main { padding: var(--gap-md); }
}
