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

:root {
  /* Color Palette - Premium HSL Dark Mode */
  --bg-dark: hsl(222, 47%, 7%);
  --bg-card: hsla(222, 40%, 12%, 0.7);
  --bg-card-hover: hsla(222, 40%, 16%, 0.8);
  --bg-sidebar: hsla(222, 47%, 9%, 0.95);
  --border-color: hsla(217, 33%, 25%, 0.4);
  --border-highlight: hsla(217, 91%, 60%, 0.3);

  --primary: hsl(217, 91%, 60%);
  --primary-hover: hsl(217, 91%, 50%);
  --primary-glow: hsla(217, 91%, 60%, 0.25);

  --accent-cyan: hsl(186, 100%, 50%);
  --accent-purple: hsl(270, 95%, 65%);
  --accent-green: hsl(142, 71%, 45%);
  --accent-amber: hsl(38, 92%, 50%);
  --accent-red: hsl(0, 84%, 60%);

  --text-main: hsl(210, 40%, 98%);
  --text-muted: hsl(215, 20%, 65%);
  --text-dim: hsl(215, 16%, 45%);

  --glass-bg: rgba(15, 23, 42, 0.75);
  --glass-border: rgba(255, 255, 255, 0.08);

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5), 0 0 20px var(--primary-glow);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  background-image: 
    radial-gradient(circle at 15% 15%, hsla(217, 91%, 60%, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 85% 85%, hsla(270, 95%, 65%, 0.06) 0%, transparent 40%);
}

h1, h2, h3, h4, .brand-font {
  font-family: 'Outfit', sans-serif;
}

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

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  z-index: 10;
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 2.5rem;
}

.brand-logo {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--accent-purple));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.3rem;
  color: #fff;
  box-shadow: 0 0 16px var(--primary-glow);
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(90deg, #fff, var(--text-muted));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  list-style: none;
  flex-grow: 1;
}

.nav-item button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
}

.nav-item button:hover {
  background: hsla(217, 91%, 60%, 0.1);
  color: var(--text-main);
  border-color: var(--border-highlight);
}

.nav-item button.active {
  background: linear-gradient(90deg, hsla(217, 91%, 60%, 0.2), transparent);
  color: #fff;
  border-left: 3px solid var(--primary);
  font-weight: 600;
}

.user-profile {
  margin-top: auto;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-cyan), var(--primary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: #000;
}

.user-details .name {
  font-size: 0.88rem;
  font-weight: 600;
}

.user-details .role {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: var(--transition);
}

.btn-logout:hover {
  color: var(--accent-red);
  background: hsla(0, 84%, 60%, 0.1);
}

/* Main Content Area */
.main-content {
  flex-grow: 1;
  padding: 2.5rem;
  overflow-y: auto;
  max-width: 1400px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.page-title {
  font-size: 1.8rem;
  font-weight: 700;
}

.page-desc {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: var(--transition);
  border: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), hsl(217, 91%, 50%));
  color: #fff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--primary-glow);
}

.btn-secondary {
  background: hsla(217, 33%, 25%, 0.4);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: hsla(217, 33%, 35%, 0.6);
  border-color: var(--text-muted);
}

/* Stats Cards Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  backdrop-filter: blur(10px);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-highlight);
  box-shadow: var(--shadow-lg);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--accent-cyan));
}

.stat-title {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  margin: 8px 0 4px 0;
  font-family: 'Outfit', sans-serif;
}

.stat-meta {
  font-size: 0.8rem;
  color: var(--accent-green);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Data Tables */
.table-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-bottom: 2rem;
}

.custom-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.custom-table th {
  background: hsla(222, 47%, 9%, 0.8);
  padding: 14px 20px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
}

.custom-table td {
  padding: 16px 20px;
  border-bottom: 1px solid hsla(217, 33%, 25%, 0.2);
  font-size: 0.9rem;
}

.custom-table tr:hover td {
  background: var(--bg-card-hover);
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-active {
  background: hsla(142, 71%, 45%, 0.15);
  color: var(--accent-green);
  border: 1px solid hsla(142, 71%, 45%, 0.3);
}

.badge-suspended {
  background: hsla(0, 84%, 60%, 0.15);
  color: var(--accent-red);
  border: 1px solid hsla(0, 84%, 60%, 0.3);
}

.badge-shared {
  background: hsla(217, 91%, 60%, 0.15);
  color: var(--primary);
  border: 1px solid hsla(217, 91%, 60%, 0.3);
}

.badge-personal {
  background: hsla(270, 95%, 65%, 0.15);
  color: var(--accent-purple);
  border: 1px solid hsla(270, 95%, 65%, 0.3);
}

/* Workers Grid for Client View */
.workers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.worker-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition: var(--transition);
}

.worker-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-highlight);
  box-shadow: var(--shadow-lg);
}

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

.worker-avatar {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--accent-cyan));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: #fff;
}

.worker-title-area {
  flex-grow: 1;
}

.worker-name {
  font-size: 1.1rem;
  font-weight: 700;
}

.worker-prompt {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

/* Chat Layout */
.chat-container {
  display: flex;
  height: calc(100vh - 120px);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.chat-sidebar {
  width: 280px;
  border-right: 1px solid var(--border-color);
  background: hsla(222, 47%, 8%, 0.6);
  display: flex;
  flex-direction: column;
}

.chat-sidebar-header {
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border-color);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.worker-selector-list {
  overflow-y: auto;
  flex-grow: 1;
}

.worker-selector-item {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  border-bottom: 1px solid hsla(217, 33%, 25%, 0.15);
  transition: var(--transition);
}

.worker-selector-item:hover {
  background: var(--bg-card-hover);
}

.worker-selector-item.selected {
  background: hsla(217, 91%, 60%, 0.15);
  border-left: 3px solid var(--primary);
}

.chat-main {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: hsla(222, 47%, 9%, 0.7);
}

.chat-active-worker {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-messages {
  flex-grow: 1;
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.message-row {
  display: flex;
  gap: 12px;
  max-width: 80%;
}

.message-row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-row.bot {
  align-self: flex-start;
}

.message-bubble {
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 0.93rem;
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
}

.message-row.user .message-bubble {
  background: linear-gradient(135deg, var(--primary), hsl(217, 91%, 50%));
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message-row.bot .message-bubble {
  background: hsla(217, 33%, 20%, 0.7);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-bottom-left-radius: 4px;
}

.token-pill {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-input-area {
  padding: 1.2rem 1.5rem;
  border-top: 1px solid var(--border-color);
  background: hsla(222, 47%, 8%, 0.8);
  display: flex;
  gap: 12px;
}

.chat-input {
  flex-grow: 1;
  background: hsla(222, 40%, 15%, 0.8);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: #fff;
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
}

.chat-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 12px var(--primary-glow);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform 0.3s ease;
}

.modal-backdrop.active .modal-card {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.form-group {
  margin-bottom: 1.2rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.form-control {
  width: 100%;
  background: hsla(222, 40%, 15%, 0.8);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: #fff;
  font-size: 0.9rem;
  outline: none;
  transition: var(--transition);
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
}

/* Auth Screens */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(16px);
}

/* Typing Indicator Animation */
.typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--primary);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1.0); }
}

@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }
  .chat-container {
    flex-direction: column;
  }
  .chat-sidebar {
    width: 100%;
    height: 140px;
  }
}
