/* ============================================
   KONKAN.TECH — DESIGN SYSTEM
   Private platform, dark theme + glassmorphism
   ============================================ */

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a28;
  --bg-hover: #22223a;
  --bg-active: #2a2a48;
  --surface-glass: rgba(255, 255, 255, 0.04);
  --surface-glass-hover: rgba(255, 255, 255, 0.07);
  --surface-glass-border: rgba(255, 255, 255, 0.08);
  --text-primary: #e8e8f0;
  --text-secondary: #9898b0;
  --text-muted: #5e5e78;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.3);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px var(--accent-glow);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --sidebar-width: 280px;
}

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

html {
  height: 100%;
  height: -webkit-fill-available;
}

body {
  height: 100%;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

input, select, textarea, button { font-family: inherit; font-size: inherit; color: inherit; outline: none; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

.hidden { display: none !important; }
.screen { display: none; height: 100dvh; width: 100vw; }
.screen.active { display: flex; }
.accent { color: var(--accent); }

/* ============================================
   AUTH / LOGIN
   ============================================ */
.auth-container {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; position: relative; overflow: hidden;
  background: radial-gradient(ellipse at 30% 50%, rgba(99,102,241,0.08) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 50%, rgba(139,92,246,0.06) 0%, transparent 60%),
              var(--bg-primary);
}

.auth-glass {
  position: relative; z-index: 2; width: 100%; max-width: 380px; padding: 48px 40px;
  background: var(--surface-glass); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--surface-glass-border); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg); animation: fadeInUp 0.6s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

.auth-logo { text-align: center; margin-bottom: 36px; }

.logo-icon {
  width: 56px; height: 56px; margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700; color: #fff; box-shadow: var(--shadow-glow);
}

.auth-logo h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; }
.auth-subtitle { color: var(--text-secondary); font-size: 13px; margin-top: 4px; }
.auth-form { display: none; }
.auth-form.active { display: block; }

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 12px; font-weight: 500; color: var(--text-secondary);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px;
}
.form-group input {
  width: 100%; padding: 12px 16px; background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1); border-radius: var(--radius-md);
  color: var(--text-primary); transition: all 0.2s ease;
  font-size: 16px; /* prevent iOS zoom on focus */
  -webkit-appearance: none;
  appearance: none;
}
.form-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.form-group input::placeholder { color: var(--text-muted); }

.btn-primary {
  width: 100%; padding: 12px; background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border: none; border-radius: var(--radius-md); color: white; font-weight: 600;
  cursor: pointer; transition: all 0.3s ease; margin-top: 8px;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: var(--shadow-glow); }
.btn-primary:active { transform: translateY(0); }

.error-msg {
  margin-top: 16px; padding: 10px 14px; background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3); border-radius: var(--radius-sm);
  color: var(--danger); font-size: 13px; display: none;
}
.error-msg.show { display: block; animation: shake 0.4s ease; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.auth-bg-orbs { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.orb { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.4; animation: float 20s ease-in-out infinite; }
.orb-1 { width: 400px; height: 400px; background: var(--accent); top: -100px; left: -100px; animation-duration: 25s; }
.orb-2 { width: 300px; height: 300px; background: #8b5cf6; bottom: -80px; right: -80px; animation-duration: 20s; animation-delay: -5s; }
.orb-3 { width: 200px; height: 200px; background: #06b6d4; top: 50%; left: 60%; animation-duration: 15s; animation-delay: -10s; }
@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -30px) scale(1.05); }
  66% { transform: translate(-20px, 20px) scale(0.95); }
}

/* ============================================
   DASHBOARD
   ============================================ */
.dashboard {
  width: 100%; height: 100%; display: flex; flex-direction: column;
  background: radial-gradient(ellipse at 50% 0%, rgba(99,102,241,0.06) 0%, transparent 50%), var(--bg-primary);
}

.dash-nav {
  padding: 16px 32px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--surface-glass-border);
  background: rgba(18,18,26,0.8); backdrop-filter: blur(12px);
}

.logo-small { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.logo-icon-sm {
  width: 32px; height: 32px; background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: #fff;
}

.dash-nav-right { display: flex; align-items: center; gap: 16px; }
.dash-user-name { color: var(--text-secondary); font-size: 13px; }

.icon-btn {
  width: 32px; height: 32px; background: none; border: none; color: var(--text-secondary);
  cursor: pointer; border-radius: var(--radius-sm); display: flex; align-items: center;
  justify-content: center; transition: all 0.2s; font-size: 16px;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.dash-content {
  flex: 1; padding: 48px 32px; max-width: 900px; margin: 0 auto; width: 100%;
}

.dash-title { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; margin-bottom: 4px; }
.dash-subtitle { color: var(--text-secondary); font-size: 14px; margin-bottom: 36px; }

.module-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px;
}

.module-card {
  padding: 28px 24px; background: var(--surface-glass); border: 1px solid var(--surface-glass-border);
  border-radius: var(--radius-lg); cursor: pointer; transition: all 0.3s ease; position: relative;
  overflow: hidden;
}
.module-card:hover:not(.disabled) {
  background: var(--surface-glass-hover); border-color: var(--accent);
  transform: translateY(-4px); box-shadow: var(--shadow-glow);
}
.module-card.disabled { opacity: 0.5; cursor: default; }

.module-icon { font-size: 36px; margin-bottom: 16px; }
.module-card h3 { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.module-card p { font-size: 12px; color: var(--text-secondary); line-height: 1.5; }

.module-badge {
  position: absolute; top: 16px; right: 16px; font-size: 10px; font-weight: 600;
  padding: 3px 10px; border-radius: 12px; text-transform: uppercase; letter-spacing: 0.5px;
}
.module-badge.live { background: rgba(16,185,129,0.15); color: var(--success); border: 1px solid rgba(16,185,129,0.3); }
.module-badge.soon { background: rgba(245,158,11,0.1); color: var(--warning); border: 1px solid rgba(245,158,11,0.2); }

/* ============================================
   CHAT LAYOUT
   ============================================ */
.chat-layout { display: flex; height: 100dvh; width: 100vw; }

.sidebar {
  width: var(--sidebar-width); min-width: var(--sidebar-width); background: var(--bg-secondary);
  border-right: 1px solid var(--surface-glass-border); display: flex; flex-direction: column;
  transition: transform 0.3s ease; overflow: hidden;
}
.sidebar-header {
  padding: 16px 20px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--surface-glass-border);
}

.sidebar-section { padding: 16px 12px 8px; overflow-y: auto; }
.sidebar-section:first-of-type { flex: 1; }
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 10px; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 1px; color: var(--text-muted);
}

.room-list { list-style: none; }
.room-item {
  padding: 8px 12px; border-radius: var(--radius-sm); cursor: pointer;
  display: flex; align-items: center; gap: 8px; color: var(--text-secondary);
  transition: all 0.15s; font-size: 13px; margin-bottom: 2px;
}
.room-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.room-item.active { background: var(--bg-active); color: var(--text-primary); font-weight: 500; }
.room-item::before { content: '#'; color: var(--text-muted); font-weight: 700; font-size: 15px; }

.member-list { list-style: none; }
.member-item {
  padding: 6px 12px; display: flex; align-items: center; gap: 10px;
  border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 2px;
}
.agent-item {
  cursor: pointer; transition: background 0.15s;
}
.agent-item:hover { background: var(--bg-hover); }
.agent-item.active { background: var(--bg-active); }
.agent-avatar { box-shadow: 0 0 8px rgba(139,92,246,0.4); }
.member-avatar {
  width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 11px; font-weight: 600; color: white;
  flex-shrink: 0; position: relative;
}
.member-avatar .status-dot {
  position: absolute; bottom: -1px; right: -1px; width: 10px; height: 10px;
  border-radius: 50%; border: 2px solid var(--bg-secondary);
}
.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--text-muted); }
.member-info { overflow: hidden; }
.member-name { color: var(--text-primary); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-role { font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }

.sidebar-footer {
  padding: 12px 16px; border-top: 1px solid var(--surface-glass-border);
  display: flex; align-items: center; justify-content: space-between;
}
.user-badge { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 500; }

/* ============================================
   CHAT MAIN
   ============================================ */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg-primary); }

.chat-header {
  padding: 14px 24px; border-bottom: 1px solid var(--surface-glass-border);
  display: flex; align-items: center; gap: 16px;
  background: rgba(18,18,26,0.8); backdrop-filter: blur(12px);
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-info h2 { font-size: 16px; font-weight: 600; }
.room-description { font-size: 12px; color: var(--text-muted); }

.messages-container { flex: 1; overflow-y: auto; padding: 16px 24px; }
.messages { display: flex; flex-direction: column; gap: 4px; }
.welcome-msg { text-align: center; padding: 60px 20px; color: var(--text-secondary); }
.welcome-icon { font-size: 48px; margin-bottom: 16px; }
.welcome-msg h3 { font-size: 20px; font-weight: 600; color: var(--text-primary); margin-bottom: 8px; }

.message {
  display: flex; gap: 12px; padding: 8px 12px;
  border-radius: var(--radius-md); transition: background 0.15s; animation: msgIn 0.3s ease;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.message:hover { background: var(--surface-glass); }

.msg-avatar {
  width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 13px; font-weight: 600; color: white; flex-shrink: 0;
}
.msg-body { flex: 1; min-width: 0; }
.msg-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }
.msg-author { font-weight: 600; font-size: 14px; }
.msg-role-badge {
  font-size: 9px; font-weight: 600; padding: 1px 6px; border-radius: 3px;
  text-transform: uppercase; letter-spacing: 0.3px; opacity: 0.8;
}
.msg-time { font-size: 11px; color: var(--text-muted); }
.msg-content { font-size: 14px; line-height: 1.5; color: var(--text-primary); word-wrap: break-word; }

.typing-indicator { padding: 4px 24px 8px; font-size: 12px; color: var(--text-muted); font-style: italic; min-height: 28px; }

.message-input-area {
  padding: 12px 24px 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--surface-glass-border);
}
.input-wrapper {
  display: flex; align-items: flex-end; gap: 8px; background: var(--bg-tertiary);
  border: 1px solid var(--surface-glass-border); border-radius: var(--radius-lg);
  padding: 8px 12px; transition: border-color 0.2s;
}
.input-wrapper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
#message-input {
  flex: 1; background: none; border: none; resize: none; color: var(--text-primary);
  padding: 4px 8px; max-height: 120px; line-height: 1.5;
  font-size: 16px; /* prevent iOS zoom */
  -webkit-appearance: none;
  appearance: none;
}
#message-input::placeholder { color: var(--text-muted); }

/* Voice button */
.voice-btn {
  width: 36px; height: 36px; background: none; border: 1px solid var(--surface-glass-border);
  border-radius: 50%; color: var(--text-secondary); cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: all 0.2s;
}
.voice-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.voice-btn.recording {
  background: rgba(239,68,68,0.15); border-color: var(--danger); color: var(--danger);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50% { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}

/* Voice recording indicator */
.voice-indicator {
  display: flex; align-items: center; gap: 8px; padding: 6px 4px;
  font-size: 12px; color: var(--danger);
}
.voice-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--danger);
  animation: pulse-dot 1s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; } 50% { opacity: 0.3; }
}

.send-btn {
  width: 36px; height: 36px; background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border: none; border-radius: 50%; color: white; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: all 0.2s;
}
.send-btn:hover { transform: scale(1.05); box-shadow: var(--shadow-glow); }

/* Auth link button */
.btn-link {
  width: 100%; padding: 8px; background: none; border: none; color: var(--text-secondary);
  cursor: pointer; font-size: 12px; margin-top: 4px; transition: color 0.2s;
  text-decoration: underline; text-underline-offset: 2px;
}
.btn-link:hover { color: var(--text-primary); }

/* Agent thinking dots */
.thinking-dots { display: flex; gap: 4px; align-items: center; padding: 4px 0; }
.thinking-dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted);
  animation: blink 1.2s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1); }
}

/* Agent / error message variants */
.message-error .msg-content { color: var(--danger); }

.mobile-only { display: none; }

@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100dvh; z-index: 100;
    transform: translateX(-100%);
    padding-top: env(safe-area-inset-top);
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .mobile-only { display: flex; }
  .messages-container {
    padding: 12px 16px;
    -webkit-overflow-scrolling: touch;
  }
  .message-input-area {
    padding: 8px 16px max(16px, env(safe-area-inset-bottom));
  }
  .module-grid { grid-template-columns: 1fr; }
  .dash-content { padding: 24px 16px; }
  .auth-glass { padding: 36px 24px; margin: 16px; }
  .chat-header { padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); }
}

/* iOS Safari: prevent rubber-band on body but allow scroll inside containers */
@supports (-webkit-touch-callout: none) {
  .messages-container { -webkit-overflow-scrolling: touch; }
  .sidebar-section { -webkit-overflow-scrolling: touch; }
}
