/* ============================================================
   UPOS AI Platform — Design System
   Material 3 x Fluent 2 inspired, dark-first
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Tokens ─────────────────────────────────────────────── */
:root {
  /* Surface */
  --bg-base:    #080c14;
  --bg-surface: #0f1521;
  --bg-card:    #141c2e;
  --bg-card2:   #1a2440;
  --bg-hover:   #1f2b46;
  --bg-active:  #243258;

  /* Brand */
  --brand-500: #6366f1;
  --brand-400: #818cf8;
  --brand-300: #a5b4fc;
  --brand-600: #4f46e5;
  --brand-glow: rgba(99,102,241,.35);

  /* Accent palette */
  --teal:   #06b6d4;
  --violet: #8b5cf6;
  --green:  #10b981;
  --amber:  #f59e0b;
  --rose:   #f43f5e;
  --pink:   #ec4899;
  --orange: #f97316;

  /* Text */
  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #475569;
  --text-disabled:  #2d3748;

  /* Border */
  --border:      rgba(148,163,184,.12);
  --border-md:   rgba(148,163,184,.20);
  --border-brand:rgba(99,102,241,.4);

  /* Feedback */
  --success: #10b981;
  --warning: #f59e0b;
  --error:   #f43f5e;
  --info:    #06b6d4;

  /* Elevation */
  --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,.5);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.6);
  --shadow-brand: 0 4px 24px var(--brand-glow);

  /* Motion */
  --ease-out: cubic-bezier(0.0,0.0,0.2,1);
  --ease-in:  cubic-bezier(0.4,0.0,1,1);
  --ease:     cubic-bezier(0.4,0.0,0.2,1);
  --dur-fast: 120ms;
  --dur-base: 200ms;
  --dur-slow: 350ms;

  /* Radius */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 24px;
  --r-full: 9999px;

  /* Layout */
  --sidebar-w: 260px;
  --topbar-h: 60px;
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  min-height: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-400); text-decoration: none; transition: color var(--dur-fast); }
a:hover { color: var(--brand-300); }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: var(--r-full); }
::-webkit-scrollbar-thumb:hover { background: var(--brand-500); }

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

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform var(--dur-slow) var(--ease-out);
}
.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--brand-500), var(--violet));
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; color: #fff;
  box-shadow: var(--shadow-brand);
}
.sidebar-logo-text { font-weight: 700; font-size: 17px; letter-spacing: -.3px; }
.sidebar-logo-text span { color: var(--brand-400); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 0; }
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 16px 20px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  border-radius: 0;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  border-left: 3px solid transparent;
  position: relative;
}
.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.nav-item.active {
  background: linear-gradient(90deg, rgba(99,102,241,.15), transparent);
  color: var(--brand-400);
  border-left-color: var(--brand-500);
}
.nav-item svg { flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  background: var(--brand-500);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--r-full);
}
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--dur-fast);
}
.user-pill:hover { background: var(--bg-hover); }
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-500), var(--violet));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #fff;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-plan { font-size: 11px; color: var(--text-muted); }

/* Main content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-size: 16px; font-weight: 600; flex: 1; }
.page-content { flex: 1; padding: 28px 28px; }

/* ── Card ────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 15px; font-weight: 600; }
.card-glass {
  background: rgba(20,28,46,.7);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

/* ── Stat Cards ──────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 16px; }
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: border-color var(--dur-base), transform var(--dur-base);
}
.stat-card:hover { border-color: var(--border-md); transform: translateY(-1px); }
.stat-icon {
  width: 42px; height: 42px;
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-num { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.stat-trend { font-size: 11px; margin-top: 4px; }
.stat-trend.up { color: var(--green); }
.stat-trend.down { color: var(--rose); }

/* ── Generator Cards ─────────────────────────────────────── */
.gen-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px,1fr)); gap: 16px; }
.gen-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  cursor: pointer;
  transition: all var(--dur-base) var(--ease);
  position: relative;
  overflow: hidden;
}
.gen-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--card-color, var(--brand-500));
  transform: scaleX(0);
  transition: transform var(--dur-base) var(--ease);
  transform-origin: left;
}
.gen-card:hover {
  border-color: var(--border-md);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.gen-card:hover::before { transform: scaleX(1); }
.gen-card-icon {
  width: 48px; height: 48px;
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
  font-size: 22px;
}
.gen-card-name { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.gen-card-desc { font-size: 12.5px; color: var(--text-secondary); line-height: 1.5; }
.gen-card-meta {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Form Elements ───────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-control {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 13.5px;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
  outline: none;
}
.form-control:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(99,102,241,.2);
}
.form-control::placeholder { color: var(--text-muted); }
textarea.form-control { resize: vertical; min-height: 100px; line-height: 1.6; }
select.form-control { cursor: pointer; }
.form-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--r-md);
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--brand-500);
  color: #fff;
  border-color: var(--brand-500);
}
.btn-primary:hover:not(:disabled) {
  background: var(--brand-600);
  box-shadow: var(--shadow-brand);
}
.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-md);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-active); }
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-icon { padding: 8px; width: 36px; height: 36px; border-radius: var(--r-md); }

/* Loading spinner on btn */
.btn-loading { pointer-events: none; }
.btn-loading::after {
  content: '';
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
  margin-left: 6px;
}

/* ── Tabs ─────────────────────────────────────────────────── */
.tabs { display: flex; border-bottom: 1px solid var(--border); gap: 4px; margin-bottom: 20px; }
.tab-btn {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all var(--dur-fast);
}
.tab-btn:hover { color: var(--text-secondary); }
.tab-btn.active { color: var(--brand-400); border-bottom-color: var(--brand-500); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Badge ───────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px;
  border-radius: var(--r-full);
  font-size: 11px; font-weight: 600;
  white-space: nowrap;
}
.badge-brand { background: rgba(99,102,241,.2); color: var(--brand-400); }
.badge-success { background: rgba(16,185,129,.15); color: var(--green); }
.badge-warning { background: rgba(245,158,11,.15); color: var(--amber); }
.badge-error   { background: rgba(244,63,94,.15);  color: var(--rose); }
.badge-muted   { background: var(--bg-hover); color: var(--text-muted); }

/* ── Toast / Alert ───────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: var(--bg-card2);
  border: 1px solid var(--border-md);
  border-radius: var(--r-md);
  padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  animation: slideInRight var(--dur-slow) var(--ease-out) forwards;
  min-width: 280px; max-width: 380px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--rose); }
.toast.info    { border-left: 3px solid var(--brand-500); }

/* ── Output Display ──────────────────────────────────────── */
.output-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.7;
  padding: 20px;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 200px;
  position: relative;
  color: var(--text-primary);
}
.output-actions {
  display: flex; gap: 8px;
  margin-top: 12px;
}

/* ── Progress bar ────────────────────────────────────────── */
.progress-bar {
  height: 4px;
  background: var(--bg-hover);
  border-radius: var(--r-full);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand-500), var(--violet));
  border-radius: var(--r-full);
  transition: width .6s var(--ease);
}

/* ── Table ───────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--bg-hover); }

/* ── Skeleton ────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-hover) 25%, var(--bg-active) 50%, var(--bg-hover) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--r-sm);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Modal ───────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur-base);
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-md);
  border-radius: var(--r-xl);
  width: 100%; max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px) scale(.97);
  transition: transform var(--dur-slow) var(--ease-out);
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end;
}

/* ── Prompt history row ──────────────────────────────────── */
.history-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: padding-left var(--dur-fast);
}
.history-item:last-child { border-bottom: none; }
.history-item:hover { padding-left: 4px; }
.history-cat-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.history-title { font-size: 13.5px; font-weight: 500; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-meta { font-size: 11.5px; color: var(--text-muted); display: flex; gap: 8px; flex-shrink: 0; }

/* ── Auth pages ──────────────────────────────────────────── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg-base);
  position: relative;
  overflow: hidden;
}
.auth-wrap::before {
  content: '';
  position: absolute;
  top: -200px; left: 50%;
  transform: translateX(-50%);
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(99,102,241,.2) 0%, transparent 70%);
  pointer-events: none;
}
.auth-card {
  width: 100%; max-width: 440px;
  background: var(--bg-card);
  border: 1px solid var(--border-md);
  border-radius: var(--r-xl);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
}
.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}
.auth-logo-icon {
  width: 52px; height: 52px;
  border-radius: var(--r-lg);
  background: linear-gradient(135deg, var(--brand-500), var(--violet));
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800; color: #fff;
  margin: 0 auto 12px;
  box-shadow: var(--shadow-brand);
}
.auth-logo h1 { font-size: 22px; font-weight: 700; }
.auth-logo p { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.divider {
  display: flex; align-items: center; gap: 12px;
  margin: 20px 0;
  color: var(--text-muted);
  font-size: 12px;
}
.divider::before, .divider::after {
  content: ''; flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Streaming cursor ────────────────────────────────────── */
.stream-cursor::after {
  content: '▋';
  animation: blink .8s step-end infinite;
  color: var(--brand-400);
}
@keyframes blink { 50% { opacity: 0; } }

/* ── Animations ──────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity:0; transform:translateY(16px); } to { opacity:1; transform:translateY(0); } }
@keyframes slideInRight { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:translateX(0); } }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.5; } }

.fade-in  { animation: fadeIn var(--dur-slow) var(--ease-out) both; }
.slide-up { animation: slideUp var(--dur-slow) var(--ease-out) both; }

/* ── Utility ─────────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.font-semibold { font-weight: 600; }
.w-full { width: 100%; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; }
.truncate { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

/* ── Pricing ─────────────────────────────────────────────── */
.pricing-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 28px;
  transition: all var(--dur-base);
}
.pricing-card.featured {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 1px var(--brand-500), var(--shadow-brand);
}
.pricing-price { font-size: 32px; font-weight: 800; line-height: 1; }
.pricing-period { font-size: 13px; color: var(--text-muted); }
.pricing-features { list-style: none; margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.pricing-features li { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.pricing-features li::before { content:'✓'; color:var(--green); font-weight:700; flex-shrink:0; }
.pricing-features li.na { color: var(--text-muted); }
.pricing-features li.na::before { content:'—'; color:var(--text-muted); }

/* ── Responsive ──────────────────────────────────────────── */
.menu-toggle {
  display: none;
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer; padding: 6px;
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main-content { margin-left: 0; }
  .menu-toggle { display: flex; align-items: center; }
  .page-content { padding: 16px; }
  .gen-grid { grid-template-columns: 1fr 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 500px) {
  .gen-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr; }
  .auth-card { padding: 24px 18px; }
}

/* Sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 99;
}
.sidebar-overlay.open { display: block; }
