/* ===========================================================
   InvoChat AI — Design System
   =========================================================== */

:root {
  --color-primary: #2E5EFF;
  --color-primary-dark: #1E44D8;
  --color-primary-light: #E8EDFF;
  --color-success: #16A34A;
  --color-success-bg: #DCFCE7;
  --color-warning: #D97706;
  --color-warning-bg: #FEF3C7;
  --color-danger: #DC2626;
  --color-danger-bg: #FEE2E2;

  --bg: #F7F8FC;
  --surface: #FFFFFF;
  --surface-2: #F1F3F9;
  --border: #E4E7EF;
  --text: #14171F;
  --text-muted: #6B7280;
  --text-faint: #9CA3AF;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 999px;

  --shadow-sm: 0 1px 2px rgba(20, 23, 31, 0.05);
  --shadow-md: 0 4px 16px rgba(20, 23, 31, 0.08);
  --shadow-lg: 0 12px 32px rgba(20, 23, 31, 0.12);
  --shadow-glass: 0 8px 32px rgba(46, 94, 255, 0.10);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --nav-height: 68px;
  --sidebar-width: 240px;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg: #0B0D12;
  --surface: #14171F;
  --surface-2: #1B1F29;
  --border: #262B36;
  --text: #F3F4F6;
  --text-muted: #9CA3AF;
  --text-faint: #6B7280;
  --color-primary-light: #182144;
  --shadow-glass: 0 8px 32px rgba(0, 0, 0, 0.4);
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s var(--ease), color 0.25s var(--ease);
  min-height: 100vh;
}

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--radius-full); }

/* ===== Layout ===== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 40;
  transition: transform 0.3s var(--ease);
}

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px 24px;
}
.sidebar-brand img { width: 30px; height: 30px; }
.sidebar-brand span { font-weight: 700; font-size: 17px; letter-spacing: -0.02em; }

.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 14.5px;
  font-weight: 500;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.nav-link svg { width: 19px; height: 19px; flex-shrink: 0; opacity: 0.85; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--color-primary-light); color: var(--color-primary); font-weight: 600; }
.nav-link.active svg { opacity: 1; }

.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }

.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--nav-height);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}

.topbar-title { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; }
.topbar-sub { font-size: 13px; color: var(--text-muted); margin-top: 1px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }

.menu-toggle { display: none; background: none; border: none; padding: 6px; }
.menu-toggle svg { width: 22px; height: 22px; }

.content { padding: 28px; flex: 1; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: var(--radius-md);
  font-weight: 600; font-size: 14px;
  padding: 11px 20px;
  transition: transform 0.12s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease), opacity 0.15s var(--ease);
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--color-primary); color: #fff; box-shadow: 0 4px 14px rgba(46,94,255,0.28); }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.btn-danger:hover { opacity: 0.85; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn:disabled { opacity: 0.55; pointer-events: none; }
.btn-icon { padding: 9px; border-radius: var(--radius-full); background: var(--surface-2); }
.btn-icon:hover { background: var(--border); }

.fab {
  position: fixed; right: 22px; bottom: 22px;
  width: 56px; height: 56px; border-radius: var(--radius-full);
  background: var(--color-primary); color: #fff;
  display: none; align-items: center; justify-content: center;
  box-shadow: var(--shadow-lg); z-index: 50; border: none;
}
.fab svg { width: 24px; height: 24px; }

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.card-glass {
  background: linear-gradient(160deg, var(--surface) 0%, var(--surface) 100%);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-glass);
}

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.kpi-card { position: relative; overflow: hidden; }
.kpi-label { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin-top: 8px; }
.kpi-trend { font-size: 12.5px; margin-top: 6px; font-weight: 600; display: flex; align-items: center; gap: 4px; }
.kpi-trend.up { color: var(--color-success); }
.kpi-trend.down { color: var(--color-danger); }
.kpi-icon {
  position: absolute; top: 18px; right: 18px;
  width: 38px; height: 38px; border-radius: var(--radius-md);
  background: var(--color-primary-light); color: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
}
.kpi-icon svg { width: 18px; height: 18px; }

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.section-title { font-size: 15.5px; font-weight: 700; margin-bottom: 14px; letter-spacing: -0.01em; }

/* ===== Forms ===== */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.input, select.input, textarea.input {
  width: 100%; padding: 11px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-size: 14.5px;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(46,94,255,0.12); }
.input-error { border-color: var(--color-danger) !important; }
.field-error { color: var(--color-danger); font-size: 12.5px; margin-top: 5px; display: none; }
.input-icon-wrap { position: relative; }
.input-icon-wrap svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--text-faint); }
.input-icon-wrap .input { padding-left: 40px; }

/* ===== Badges ===== */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: var(--radius-full); font-size: 12px; font-weight: 700; }
.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-muted { background: var(--surface-2); color: var(--text-muted); }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { text-align: left; padding: 10px 14px; color: var(--text-muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--border); }
.data-table td { padding: 14px; border-bottom: 1px solid var(--border); }
.data-table tr { transition: background 0.12s var(--ease); }
.data-table tbody tr:hover { background: var(--surface-2); cursor: pointer; }

/* ===== Empty state ===== */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state svg { width: 56px; height: 56px; margin: 0 auto 16px; opacity: 0.35; }
.empty-state h3 { font-size: 16px; color: var(--text); margin-bottom: 6px; }
.empty-state p { font-size: 13.5px; }

/* ===== Skeleton ===== */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ===== Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(10,12,18,0.5); backdrop-filter: blur(3px); display: none; align-items: center; justify-content: center; z-index: 100; padding: 16px; opacity: 0; transition: opacity 0.2s var(--ease); }
.modal-overlay.open { display: flex; opacity: 1; }
.modal { background: var(--surface); border-radius: var(--radius-lg); padding: 26px; width: 100%; max-width: 480px; max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-lg); transform: translateY(12px) scale(0.98); transition: transform 0.2s var(--ease); }
.modal-overlay.open .modal { transform: translateY(0) scale(1); }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-header h3 { font-size: 17px; font-weight: 700; }

/* ===== Toast ===== */
.toast-stack { position: fixed; top: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-md); border-radius: var(--radius-md); padding: 13px 18px; font-size: 13.5px; font-weight: 600; min-width: 240px; display: flex; align-items: center; gap: 10px; animation: toast-in 0.25s var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
.toast.success { border-left: 3px solid var(--color-success); }
.toast.error { border-left: 3px solid var(--color-danger); }
.toast.info { border-left: 3px solid var(--color-primary); }

/* ===== Auth pages ===== */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(circle at 20% 20%, var(--color-primary-light), var(--bg) 55%); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 36px 32px; }
.auth-logo { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 22px; }
.auth-logo span { font-weight: 800; font-size: 19px; }
.auth-title { text-align: center; font-size: 21px; font-weight: 800; letter-spacing: -0.02em; }
.auth-sub { text-align: center; color: var(--text-muted); font-size: 13.5px; margin: 6px 0 26px; }
.auth-footer { text-align: center; font-size: 13.5px; color: var(--text-muted); margin-top: 18px; }
.spinner { width: 17px; height: 17px; border: 2.5px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; }
.spinner-dark { border: 2.5px solid var(--border); border-top-color: var(--color-primary); }
@keyframes spin { to { transform: rotate(360deg); } }
.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600; margin-bottom: 16px; display: none; }
.alert-error { background: var(--color-danger-bg); color: var(--color-danger); }
.alert-success { background: var(--color-success-bg); color: var(--color-success); }

/* ===== Landing ===== */
.landing-nav { display: flex; align-items: center; justify-content: space-between; padding: 18px 6%; position: sticky; top: 0; background: rgba(247,248,252,0.85); backdrop-filter: blur(10px); z-index: 50; border-bottom: 1px solid var(--border); }
[data-theme="dark"] .landing-nav { background: rgba(11,13,18,0.85); }
.landing-nav .brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 18px; }
.landing-nav .brand img { width: 28px; height: 28px; }
.hero { padding: 90px 6% 70px; text-align: center; max-width: 780px; margin: 0 auto; }
.hero h1 { font-size: clamp(32px, 5vw, 54px); font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; }
.hero .accent { color: var(--color-primary); }
.hero p { color: var(--text-muted); font-size: 17px; margin: 20px auto 30px; max-width: 560px; }
.hero-actions { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.hero-mock { max-width: 920px; margin: 50px auto 0; border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-lg); border: 1px solid var(--border); }
.features { max-width: 1100px; margin: 90px auto; padding: 0 6%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; }
.feature-card { padding: 26px; border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--border); }
.feature-card .f-icon { width: 42px; height: 42px; border-radius: var(--radius-md); background: var(--color-primary-light); color: var(--color-primary); display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.feature-card h3 { font-size: 16px; margin-bottom: 6px; }
.feature-card p { font-size: 13.5px; color: var(--text-muted); line-height: 1.5; }
.landing-footer { text-align: center; padding: 40px 6%; color: var(--text-muted); font-size: 13px; border-top: 1px solid var(--border); }

/* ===== Print ===== */
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .print-doc { box-shadow: none !important; border: none !important; margin: 0 !important; }
}

/* ===== Utility ===== */
.flex { display: flex; } .flex-col { flex-direction: column; }
.items-center { align-items: center; } .justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
.font-bold { font-weight: 700; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--color-primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.divider { height: 1px; background: var(--border); margin: 18px 0; }

/* ===== Responsive ===== */
@media (max-width: 980px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .features { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 18px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .topbar { padding: 0 16px; }
  .fab { display: flex; }
  .hero { padding: 60px 6% 40px; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .auth-card { padding: 28px 22px; }
}
