/* 2Agent PWA — Design System aligned with 2market.cl */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --sidebar: #111827;
  --border: #334155;
  --primary: #3b82f6;
  --gold: #d4a017;
  --gold-dark: #b8860b;
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --purple: #8b5cf6;
  --orange: #f97316;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-full: 9999px;
}

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  height: 100dvh;
  overflow: hidden;
}

/* ===================== LOGIN PAGE ===================== */
.login-page {
  display: flex;
  height: 100dvh;
}

.login-brand {
  flex: 1;
  background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 80px;
  position: relative;
  overflow: hidden;
}

.login-brand::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 50%, rgba(59,130,246,0.08) 0%, transparent 60%);
}

.login-brand .logo {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 48px;
  position: relative;
}

.login-brand .logo-mark {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  background: linear-gradient(135deg, #1e3a5f, #0f172a);
  border: 2px solid var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-brand .logo-text h1 {
  font-size: 36px;
  font-weight: 700;
  color: #fff;
}

.login-brand .logo-text span {
  font-size: 14px;
  color: var(--text-secondary);
}

.login-features {
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: relative;
}

.login-feature {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.login-feature .feat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.login-feature h3 { font-size: 16px; font-weight: 600; color: #fff; }
.login-feature p { font-size: 13px; color: var(--text-secondary); margin-top: 4px; line-height: 1.4; }

.login-form-section {
  width: 520px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 80px 60px;
  background: var(--bg);
}

.login-form-section h2 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
}

.login-form-section .subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 32px;
}

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
}

.form-group input:focus { border-color: var(--primary); }
.form-group input::placeholder { color: var(--text-muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity .2s, transform .1s;
  width: 100%;
}

.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { opacity: 0.9; }

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-outline:hover { border-color: var(--text-secondary); }

.login-footer {
  margin-top: 32px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

.login-footer a { color: var(--text-secondary); text-decoration: none; }

/* ===================== MAIN LAYOUT ===================== */
.app {
  display: flex;
  height: 100dvh;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  padding: 32px 24px;
  gap: 32px;
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo .logo-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1e3a5f, #0f172a);
  border: 1.5px solid var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-logo .logo-text h2 {
  font-size: 18px;
  font-weight: 700;
}

.sidebar-logo .logo-text span {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: -16px 0;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-nav-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
}

.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item i { width: 20px; text-align: center; }

.sidebar-spacer { flex: 1; }

.sidebar-status {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.user-info span { font-size: 13px; font-weight: 500; display: block; }
.user-info small { font-size: 11px; color: var(--text-muted); }

/* Main Content */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.agent-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.agent-info h3 { font-size: 15px; font-weight: 600; }

.agent-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--success);
}

.agent-status .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

/* KPI Dashboard Strip */
.kpi-strip {
  display: flex;
  gap: 12px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  overflow-x: auto;
}

.kpi-item {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.kpi-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-icon.green { background: rgba(16,185,129,0.12); color: var(--success); }
.kpi-icon.yellow { background: rgba(245,158,11,0.12); color: var(--warning); }
.kpi-icon.red { background: rgba(239,68,68,0.12); color: var(--error); }
.kpi-icon.blue { background: rgba(59,130,246,0.12); color: var(--primary); }
.kpi-icon.purple { background: rgba(139,92,246,0.12); color: var(--purple); }
.kpi-icon.orange { background: rgba(249,115,22,0.12); color: var(--orange); }

.kpi-label { font-size: 10px; color: var(--text-muted); }
.kpi-value { font-size: 13px; font-weight: 700; }

/* Messages Area */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.msg { display: flex; gap: 10px; max-width: 80%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.agent { align-self: flex-start; }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.msg-content { display: flex; flex-direction: column; gap: 8px; }

.msg-bubble {
  padding: 10px 16px;
  font-size: 14px;
  line-height: 1.5;
}

.msg.agent .msg-bubble {
  background: var(--surface);
  border-radius: 16px 16px 16px 2px;
  color: var(--text-primary);
}

.msg.user .msg-bubble {
  background: var(--primary);
  border-radius: 16px 16px 2px 16px;
  color: #fff;
}

.msg-time {
  font-size: 10px;
  color: var(--text-muted);
  padding: 0 4px;
}

.msg.user .msg-time { text-align: right; color: rgba(255,255,255,0.6); }

/* Data Cards */
.data-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.data-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 600;
}

.data-card-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 14px;
  font-size: 12px;
  border-top: 1px solid var(--border);
}

.data-card-row .label { color: var(--text-secondary); }
.data-card-row .value { font-weight: 700; }

/* Stock Table */
.stock-table { width: 100%; border-collapse: collapse; }

.stock-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 10px 14px;
  background: var(--border);
}

.stock-table th:nth-child(3),
.stock-table th:nth-child(4),
.stock-table td:nth-child(3),
.stock-table td:nth-child(4) { text-align: right; }

.stock-table td {
  font-size: 11px;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  color: var(--text-primary);
}

.text-red { color: var(--error) !important; font-weight: 700; }
.text-yellow { color: var(--warning) !important; font-weight: 700; }
.text-green { color: var(--success) !important; font-weight: 700; }

/* Input Bar */
.input-area {
  padding: 12px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.quick-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all .15s;
}

.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip i { font-size: 14px; color: var(--primary); }

.input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.input-field {
  flex: 1;
  padding: 10px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
}

.input-field:focus { border-color: var(--primary); }
.input-field::placeholder { color: var(--text-muted); }

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .2s;
  flex-shrink: 0;
}

.send-btn:hover { opacity: 0.9; }
.send-btn:disabled { opacity: 0.4; cursor: default; }

/* Loading dots */
.typing-indicator span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  margin: 0 2px;
  animation: typing 1.2s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* ===================== MOBILE ===================== */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .login-brand { display: none; }
  .login-form-section { width: 100%; padding: 40px 24px; }

  .kpi-strip { padding: 8px 12px; gap: 6px; }
  .kpi-item {
    flex-direction: column;
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    gap: 2px;
    flex: 1;
    min-width: 0;
  }
  .kpi-item .kpi-icon { display: none; }
  .kpi-value { font-size: 14px; }
  .kpi-label { font-size: 8px; }

  .messages { padding: 16px; }
  .msg { max-width: 90%; }
  .input-area { padding: 8px 12px; }
  .quick-actions { overflow-x: auto; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
