/* ============================================
   ChatX v8 — Go Digit Branded Dashboard
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;700&display=swap');

:root {
  --primary: #F15F28;
  --primary-hover: #d9501f;
  --secondary: #F36F39;
  --tertiary: #F49E1F;
  --accent: #3F2C76;
  --accent-light: #5a4399;
  --bg: #f5f6fa;
  --bg-card: #ffffff;
  --bg-dark: #1a1a2e;
  --text: #2d2d3a;
  --text-light: #6b7280;
  --text-white: #ffffff;
  --border: #e5e7eb;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --status-idle: #6b7280;
  --status-working: #F15F28;
  --status-done: #10B981;
  --status-needs-input: #F49E1F;
  --status-error: #EF4444;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Kanit', sans-serif;
  font-weight: 400;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ---- Utility ---- */
.container { max-width: 1280px; margin: 0 auto; padding: 0 24px; }
.hidden { display: none !important; }
.text-center { text-align: center; }

/* ---- Login Page ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent) 0%, #1a1a2e 60%, #0f0f23 100%);
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: '';
  position: absolute;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(241,95,40,0.15) 0%, transparent 70%);
  top: -200px;
  right: -100px;
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 1;
}

.login-card .logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-card .logo h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

.login-card .logo h1 span { color: var(--primary); }

.login-card .logo p {
  font-size: 14px;
  color: var(--text-light);
  font-weight: 300;
  margin-top: 4px;
}

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

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

.form-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  transition: border-color 0.2s;
  outline: none;
  background: #fafafa;
}

.form-group input:focus {
  border-color: var(--primary);
  background: #fff;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 400;
  border: none;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: var(--text-white);
  width: 100%;
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--accent);
  color: var(--text-white);
}

.btn-secondary:hover { background: var(--accent-light); }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

.btn-outline:hover {
  background: var(--primary);
  color: var(--text-white);
}

.btn-sm { padding: 8px 16px; font-size: 13px; }

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ---- Top Nav ---- */
.topnav {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.topnav .brand {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}

.topnav .brand span { color: var(--primary); }

.topnav-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topnav-right .user-info {
  font-size: 14px;
  color: var(--text-light);
}

.topnav-right .user-info strong {
  color: var(--text);
  font-weight: 400;
}

/* ---- Sidebar Nav (mobile) ---- */
.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-links a {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-light);
  transition: all 0.2s;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--primary);
  background: rgba(241,95,40,0.08);
}

/* ---- Dashboard Layout ---- */
.dashboard-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 24px;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.main-content { min-width: 0; }

/* ---- Employee Header ---- */
.employee-header {
  background: linear-gradient(135deg, var(--accent) 0%, #2a1d5e 100%);
  border-radius: var(--radius);
  padding: 24px 28px;
  color: var(--text-white);
  margin-bottom: 24px;
}

.employee-header h2 {
  font-size: 22px;
  font-weight: 700;
}

.employee-header .meta {
  font-size: 14px;
  font-weight: 300;
  opacity: 0.85;
  margin-top: 4px;
}

/* ---- Section Title ---- */
.section-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title .badge {
  background: var(--primary);
  color: white;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 400;
}

/* ---- Agent Cards Grid ---- */
.agents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.agent-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  transition: all 0.25s;
  position: relative;
  overflow: hidden;
}

.agent-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.agent-card .agent-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin-bottom: 12px;
  background: rgba(241,95,40,0.1);
}

.agent-card .agent-name {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 2px;
}

.agent-card .agent-role {
  font-size: 12px;
  color: var(--text-light);
  font-weight: 300;
  margin-bottom: 12px;
}

/* Status Badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 400;
  padding: 4px 10px;
  border-radius: 20px;
}

.status-badge.idle {
  background: rgba(107,114,128,0.1);
  color: var(--status-idle);
}

.status-badge.working {
  background: rgba(241,95,40,0.1);
  color: var(--status-working);
  animation: pulse-badge 2s ease-in-out infinite;
}

.status-badge.done {
  background: rgba(16,185,129,0.1);
  color: var(--status-done);
}

.status-badge.needs_input {
  background: rgba(244,158,31,0.1);
  color: var(--status-needs-input);
}

.status-badge.error {
  background: rgba(239,68,68,0.1);
  color: var(--status-error);
}

@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.status-badge.working .status-dot {
  animation: pulse-dot 1.5s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.4); }
}

/* Progress Bar */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-top: 12px;
  overflow: hidden;
}

.progress-bar .fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  border-radius: 3px;
  transition: width 0.5s ease;
}

.agent-card .task-text {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-card .card-actions {
  margin-top: 14px;
}

/* ---- Kanban ---- */
.kanban {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.kanban-col {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  min-height: 200px;
}

.kanban-col-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.kanban-col-title .count {
  background: var(--bg);
  color: var(--text-light);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
}

.kanban-col.todo .kanban-col-title { border-color: var(--status-idle); }
.kanban-col.working .kanban-col-title { border-color: var(--status-working); }
.kanban-col.done .kanban-col-title { border-color: var(--status-done); }

.kanban-item {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 8px;
  font-size: 13px;
  border-left: 3px solid transparent;
  transition: all 0.2s;
}

.kanban-item:hover { box-shadow: var(--shadow); }

.kanban-col.todo .kanban-item { border-left-color: var(--status-idle); }
.kanban-col.working .kanban-item { border-left-color: var(--status-working); }
.kanban-col.done .kanban-item { border-left-color: var(--status-done); }

.kanban-item .item-title { font-weight: 400; margin-bottom: 4px; }
.kanban-item .item-agent {
  font-size: 11px;
  color: var(--text-light);
  font-weight: 300;
}

/* ---- Chat Panel ---- */
.chat-panel {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 108px);
  position: sticky;
  top: 84px;
}

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header .avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 18px;
  font-weight: 700;
}

.chat-header .chat-title {
  font-size: 16px;
  font-weight: 700;
}

.chat-header .chat-subtitle {
  font-size: 12px;
  color: var(--text-light);
  font-weight: 300;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.message.user {
  background: var(--primary);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  background: var(--bg);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.message .delegation-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(241,95,40,0.12);
  color: var(--primary);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  margin-bottom: 6px;
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  align-self: flex-start;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-light);
  border-radius: 50%;
  animation: typing 1.4s 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% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

.chat-input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.chat-input-area input {
  flex: 1;
  padding: 10px 16px;
  border: 1.5px solid var(--border);
  border-radius: 24px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.chat-input-area input:focus { border-color: var(--primary); }

.chat-input-area .send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.chat-input-area .send-btn:hover { background: var(--primary-hover); }

/* ---- Agent Detail Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 90%;
  max-width: 560px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 { font-size: 18px; font-weight: 700; }

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg);
  border-radius: 50%;
  font-size: 18px;
  color: var(--text-light);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.modal-close:hover { background: var(--border); color: var(--text); }

.modal-body { padding: 24px; }

.modal-body .detail-section { margin-bottom: 20px; }
.modal-body .detail-section h4 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-light);
  margin-bottom: 8px;
}

.task-history-item {
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.task-history-item .task-date {
  font-size: 11px;
  color: var(--text-light);
}

/* ---- Settings Page ---- */
.settings-layout {
  max-width: 720px;
  margin: 24px auto;
  padding: 0 24px;
}

.settings-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  margin-bottom: 20px;
}

.settings-card h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-group select {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  outline: none;
  background: #fafafa;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

.form-group select:focus { border-color: var(--primary); background-color: #fff; }

.test-result {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-top: 8px;
}

.test-result.success { background: rgba(16,185,129,0.1); color: var(--status-done); }
.test-result.error { background: rgba(239,68,68,0.1); color: var(--status-error); }

/* ---- Admin Page ---- */
.admin-layout {
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 24px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--text-light);
  font-weight: 300;
  margin-bottom: 4px;
}

.stat-card .stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
}

.stat-card .stat-value.orange { color: var(--primary); }

/* Token Usage Chart (CSS-only) */
.chart-container {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  margin-bottom: 24px;
}

.chart-container h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 20px;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  height: 200px;
  padding: 0 8px;
}

.bar-chart .bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.bar-chart .bar {
  width: 100%;
  max-width: 48px;
  background: linear-gradient(180deg, var(--primary), var(--secondary));
  border-radius: 6px 6px 0 0;
  transition: height 0.6s ease;
  position: relative;
  min-height: 4px;
}

.bar-chart .bar:hover { opacity: 0.85; }

.bar-chart .bar .bar-value {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.bar-chart .bar-label {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 8px;
  text-align: center;
}

/* User Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-light);
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
}

.data-table td {
  padding: 12px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.data-table tr:hover td { background: rgba(241,95,40,0.03); }

.role-badge {
  font-size: 11px;
  padding: 2px 10px;
  border-radius: 12px;
  font-weight: 400;
}

.role-badge.admin {
  background: rgba(63,44,118,0.1);
  color: var(--accent);
}

.role-badge.employee {
  background: rgba(241,95,40,0.1);
  color: var(--primary);
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
  .dashboard-layout {
    grid-template-columns: 1fr;
  }

  .chat-panel {
    position: static;
    height: 500px;
  }

  .kanban {
    grid-template-columns: 1fr;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .nav-links { display: none; }
  .nav-links.open { display: flex; flex-direction: column; position: absolute; top: 60px; left: 0; right: 0; background: var(--bg-card); padding: 16px; border-bottom: 1px solid var(--border); box-shadow: var(--shadow); }

  .menu-toggle { display: block !important; }
}

@media (max-width: 560px) {
  .agents-grid {
    grid-template-columns: 1fr;
  }

  .admin-grid {
    grid-template-columns: 1fr;
  }

  .login-card {
    margin: 16px;
    padding: 32px 24px;
  }

  .employee-header {
    padding: 18px 20px;
  }

  .employee-header h2 {
    font-size: 18px;
  }

  .topnav {
    padding: 0 16px;
  }

  .dashboard-layout {
    padding: 16px;
  }
}

/* ---- Menu Toggle (hidden on desktop) ---- */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text);
  padding: 4px;
}
