/* ========================================
   Raisegrade Admin Dashboard Styles
   ======================================== */

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

:root {
  --bg: #f0f2f5;
  --text: #1a202c;
  --card-bg: #ffffff;
  --accent: #4299e1;
  --accent-dark: #2b6cb0;
  --accent-light: #ebf8ff;
  --muted: #718096;
  --header-bg: #1a202c;
  --shadow: rgba(0, 0, 0, 0.08);
  --border: #e2e8f0;
  --success: #48bb78;
  --warning: #ed8936;
  --danger: #f56565;
  --sidebar-bg: #1a202c;
  --sidebar-text: #e2e8f0;
  --sidebar-hover: #2d3748;
  --sidebar-active: #4299e1;
}

body.dark {
  --bg: #0d1117;
  --text: #e6edf3;
  --card-bg: #161b22;
  --accent: #58a6ff;
  --accent-dark: #1f6feb;
  --accent-light: rgba(88, 166, 255, 0.1);
  --muted: #8b949e;
  --header-bg: #010409;
  --shadow: rgba(0, 0, 0, 0.4);
  --border: #30363d;
  --success: #3fb950;
  --warning: #d29922;
  --danger: #f85149;
  --sidebar-bg: #010409;
  --sidebar-text: #c9d1d9;
  --sidebar-hover: #161b22;
  --sidebar-active: #58a6ff;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
}

/* ========== Login Screen ========== */

.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.login-overlay.hidden {
  display: none;
}

.login-card {
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: 0 8px 32px var(--shadow);
  padding: 3rem 2.5rem;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.login-card h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--accent);
}

.login-card .subtitle {
  color: var(--muted);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

.login-card input {
  width: 100%;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.login-card input:focus {
  border-color: var(--accent);
}

.login-card button {
  width: 100%;
  padding: 0.85rem;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 0.5rem;
}

.login-card button:hover {
  background: var(--accent-dark);
}

.login-divider {
  display: flex;
  align-items: center;
  margin: 1.25rem 0;
  gap: 0.75rem;
}

.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.login-divider span {
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.google-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.google-btn:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  box-shadow: 0 2px 8px var(--shadow);
}

.google-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.google-icon {
  flex-shrink: 0;
}

.login-error {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 0.75rem;
  min-height: 1.4rem;
}

/* ========== Sidebar ========== */

.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s;
}

.sidebar-brand {
  padding: 1.5rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
}

.sidebar-brand span {
  font-size: 0.8rem;
  color: var(--muted);
  display: block;
  margin-top: 0.25rem;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar-nav a.active {
  background: var(--sidebar-hover);
  color: var(--sidebar-active);
  border-left-color: var(--sidebar-active);
}

.sidebar-nav a svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-footer .admin-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-footer .admin-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
}

.sidebar-footer .admin-name {
  font-size: 0.9rem;
  color: #fff;
  font-weight: 500;
}

.sidebar-footer .admin-email {
  font-size: 0.75rem;
  color: var(--muted);
}

.sidebar-footer .logout-btn {
  margin-top: 0.75rem;
  width: 100%;
  padding: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: transparent;
  color: var(--sidebar-text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}

.sidebar-footer .logout-btn:hover {
  background: rgba(245, 101, 101, 0.15);
  color: var(--danger);
  border-color: var(--danger);
}

/* ========== Main Content ========== */

.main-content {
  margin-left: 260px;
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.topbar .theme-toggle {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}

.topbar .theme-toggle:hover {
  background: var(--bg);
}

.content-area {
  flex: 1;
  padding: 2rem;
}

/* ========== Pages (Views) ========== */

.page {
  display: none;
}

.page.active {
  display: block;
}

/* ========== Stats Grid ========== */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 1.5rem;
  box-shadow: 0 2px 12px var(--shadow);
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: transform 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.stat-icon.blue { background: rgba(66, 153, 225, 0.12); color: var(--accent); }
.stat-icon.green { background: rgba(72, 187, 120, 0.12); color: var(--success); }
.stat-icon.orange { background: rgba(237, 137, 54, 0.12); color: var(--warning); }
.stat-icon.red { background: rgba(245, 101, 101, 0.12); color: var(--danger); }

.stat-info h3 {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-info p {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

/* ========== Charts Section ========== */

.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.chart-card {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 1.5rem;
  box-shadow: 0 2px 12px var(--shadow);
}

.chart-card h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.chart-bar-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chart-bar-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chart-bar-label {
  width: 140px;
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: capitalize;
  flex-shrink: 0;
}

.chart-bar-track {
  flex: 1;
  height: 28px;
  background: var(--bg);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.chart-bar-fill {
  height: 100%;
  border-radius: 6px;
  background: var(--accent);
  transition: width 0.6s ease;
  min-width: 2px;
}

.chart-bar-value {
  font-size: 0.85rem;
  font-weight: 600;
  width: 45px;
  text-align: right;
  flex-shrink: 0;
}

/* Activity timeline */
.activity-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 350px;
  overflow-y: auto;
}

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 10px;
}

.activity-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 5px;
  flex-shrink: 0;
}

.activity-text {
  font-size: 0.88rem;
  line-height: 1.4;
}

.activity-text strong {
  font-weight: 600;
}

.activity-time {
  font-size: 0.75rem;
  color: var(--muted);
  display: block;
  margin-top: 0.25rem;
}

/* ========== Students Table ========== */

.table-card {
  background: var(--card-bg);
  border-radius: 14px;
  box-shadow: 0 2px 12px var(--shadow);
  overflow: hidden;
}

.table-header {
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.table-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.search-input {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  width: 260px;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--accent);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 0.85rem 1.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.data-table th {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg);
}

.data-table tr:hover td {
  background: var(--accent-light);
}

.data-table .clickable {
  cursor: pointer;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-blue { background: rgba(66, 153, 225, 0.15); color: var(--accent); }
.badge-green { background: rgba(72, 187, 120, 0.15); color: var(--success); }
.badge-orange { background: rgba(237, 137, 54, 0.15); color: var(--warning); }

.view-btn {
  padding: 0.4rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.view-btn:hover {
  background: var(--accent);
  color: #fff;
}

/* ========== Conversation Viewer ========== */

.conversation-panel {
  display: none;
}

.conversation-panel.active {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
  width: fit-content;
}

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

.conversation-meta {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 2px 12px var(--shadow);
}

.conversation-meta h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.conversation-meta p {
  font-size: 0.88rem;
  color: var(--muted);
}

.messages-container {
  background: var(--card-bg);
  border-radius: 14px;
  box-shadow: 0 2px 12px var(--shadow);
  max-height: 600px;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.message-bubble {
  max-width: 75%;
  padding: 0.85rem 1.15rem;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.message-bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

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

.message-bubble.system {
  align-self: center;
  background: rgba(237, 137, 54, 0.1);
  color: var(--warning);
  font-style: italic;
  max-width: 90%;
  text-align: center;
}

.message-time {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.65);
  margin-top: 0.35rem;
  text-align: right;
}

.message-bubble.bot .message-time,
.message-bubble.system .message-time {
  color: var(--muted);
}

/* ========== Student Detail ========== */

.student-detail-header {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 1.5rem;
  box-shadow: 0 2px 12px var(--shadow);
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.student-avatar-lg {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 1.35rem;
  flex-shrink: 0;
}

.student-detail-info h2 {
  font-size: 1.35rem;
  font-weight: 700;
}

.student-detail-info p {
  font-size: 0.9rem;
  color: var(--muted);
}

/* Subject tabs */

.subject-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.subject-tab {
  padding: 0.5rem 1.15rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  text-transform: capitalize;
  transition: all 0.15s;
}

.subject-tab:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.subject-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ========== Loading & Empty States ========== */

.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.loading-spinner::before {
  content: '';
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 0.75rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state p {
  font-size: 1rem;
}

/* ========== Responsive ========== */

.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 200;
  padding: 0.6rem;
  border: none;
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  box-shadow: 0 2px 8px var(--shadow);
  cursor: pointer;
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .mobile-menu-btn {
    display: block;
  }

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

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

  .search-input {
    width: 160px;
  }

  .message-bubble {
    max-width: 90%;
  }
}

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

  .content-area {
    padding: 1rem;
  }
}

/* ========== 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(--muted);
}

/* ========== Conversations List in Student Detail ========== */

.conversations-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.conversation-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.conversation-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 12px var(--shadow);
}

.conversation-card-info h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.conversation-card-info p {
  font-size: 0.82rem;
  color: var(--muted);
}

.conversation-card-arrow {
  color: var(--muted);
  font-size: 1.2rem;
}

/* ========== Refresh Button ========== */

.refresh-btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.refresh-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.refresh-btn.spinning svg {
  animation: spin 0.6s linear infinite;
}

/* ========== Settings Page ========== */

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

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

.settings-card {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 1.75rem;
  box-shadow: 0 2px 12px var(--shadow);
}

.settings-card h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.settings-desc {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.settings-input {
  padding: 0.7rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.settings-input:focus {
  border-color: var(--accent);
}

.settings-btn {
  padding: 0.7rem 1.25rem;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  width: fit-content;
}

.settings-btn:hover {
  background: var(--accent-dark);
}

.settings-status {
  font-size: 0.88rem;
  min-height: 1.3rem;
  font-weight: 500;
}
