/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-primary: #4a90d9;
  --color-primary-dark: #3570b0;
  --color-danger: #d9534f;
  --color-danger-bg: rgba(217, 83, 79, 0.1);
  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-text: #2c3e50;
  --color-text-light: #6c7a89;
  --color-border: #e1e8ed;
  --color-student-bubble: #e8f4fd;
  --color-anjana-bubble: #ffffff;
  --color-banner: #fff3cd;
  --color-banner-text: #856404;
  --color-input-bg: #ffffff;
  --color-error: #d9534f;
  --banner-height: 36px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
  --transition: 0.2s ease;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #1a1d23;
    --color-surface: #2a2d35;
    --color-text: #e4e6ea;
    --color-text-light: #9ca3af;
    --color-border: #3a3d45;
    --color-student-bubble: #2a3a4a;
    --color-anjana-bubble: #2a2d35;
    --color-banner: #3d3520;
    --color-banner-text: #ffc107;
    --color-input-bg: #2a2d35;
    --color-primary: #5a9fe6;
    --color-primary-dark: #4a90d9;
    --color-danger-bg: rgba(217, 83, 79, 0.15);
  }
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

/* === AI Disclosure Banner === */
.ai-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding: 8px 16px;
  background: var(--color-banner);
  color: var(--color-banner-text);
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  height: var(--banner-height);
}

/* === Screens === */
.screen {
  display: none;
  position: fixed;
  top: var(--banner-height);
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

.screen-content {
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px;
}

/* === Logo Area === */
.logo-area {
  text-align: center;
  margin-bottom: 32px;
}

.logo {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin-bottom: 12px;
}

.logo-area h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--color-text);
}

.subtitle {
  color: var(--color-text-light);
  font-size: 15px;
}

/* === Student List === */
.student-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.student-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 56px;
  transition: box-shadow var(--transition), transform var(--transition);
}

.student-card:hover,
.student-card:focus-visible {
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.student-card:active {
  transform: translateY(0);
}

.student-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 18px;
  flex-shrink: 0;
}

.student-card-name {
  font-size: 17px;
  font-weight: 500;
}

.student-list-empty {
  text-align: center;
  padding: 24px;
  color: var(--color-text-light);
  font-size: 15px;
}

/* === Forms === */
form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

label {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-light);
}

input[type="text"],
input[type="number"],
input[type="password"] {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: var(--font);
  background: var(--color-input-bg);
  color: var(--color-text);
  transition: border-color var(--transition);
  min-height: 48px;
}

input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.consent-box {
  margin-top: 8px;
  padding: 16px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
}

.checkbox-label {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.4;
  color: var(--color-text);
}

.checkbox-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-top: 2px;
  accent-color: var(--color-primary);
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.form-actions .btn {
  flex: 1;
}

.error-text {
  color: var(--color-error);
  font-size: 14px;
  min-height: 20px;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  min-height: 48px;
  transition: background var(--transition), opacity var(--transition);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-primary);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-bg);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-light);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--color-bg);
  color: var(--color-text);
}

.btn-danger {
  background: transparent;
  color: var(--color-danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--color-danger-bg);
}

.btn-icon {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 8px;
  color: white;
  min-width: 40px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* === Chat Screen (class-based for consistent specificity) === */
.screen-chat {
  display: none;
  flex-direction: column;
}

.screen-chat.active {
  display: flex;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--color-primary);
  color: white;
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  flex-direction: column;
}

.chat-header-name {
  font-weight: 600;
  font-size: 17px;
}

.chat-header-status {
  font-size: 12px;
  opacity: 0.85;
}

/* === Chat Messages === */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-student {
  align-self: flex-end;
  background: var(--color-student-bubble);
  border-bottom-right-radius: 4px;
}

.message-anjana {
  align-self: flex-start;
  background: var(--color-anjana-bubble);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 4px;
}

.message-system {
  align-self: center;
  background: transparent;
  color: var(--color-text-light);
  font-size: 13px;
  text-align: center;
  max-width: 100%;
}

/* Typing indicator */
.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 12px 16px;
  align-self: flex-start;
  background: var(--color-anjana-bubble);
  border: 1px solid var(--color-border);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-light);
  animation: typingBounce 1.2s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* === Chat Input === */
.chat-input-area {
  padding: 8px 12px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

.chat-input-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-direction: row;
}

#input-message {
  flex: 1;
  border: 1px solid var(--color-border);
  border-radius: 24px;
  padding: 12px 18px;
  font-size: 16px;
  font-family: var(--font);
  resize: none;
  max-height: 120px;
  min-height: 48px;
  line-height: 1.4;
  background: var(--color-input-bg);
  color: var(--color-text);
  overflow-y: auto;
}

#input-message:focus {
  outline: none;
  border-color: var(--color-primary);
}

.btn-send {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--color-primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition);
}

.btn-send:hover:not(:disabled) {
  background: var(--color-primary-dark);
}

.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* === Side Menu === */
.side-menu {
  display: none;
  position: fixed;
  top: var(--banner-height);
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
}

.side-menu.open {
  display: block;
}

.side-menu-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.side-menu-panel {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 280px;
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

.side-menu-header {
  padding: 20px;
  font-size: 18px;
  font-weight: 600;
  border-bottom: 1px solid var(--color-border);
}

.menu-item {
  width: 100%;
  text-align: left;
  padding: 16px 20px;
  border-radius: 0;
  font-size: 15px;
}

/* === Modal === */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal-box {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 360px;
  width: 90%;
  box-shadow: var(--shadow-lg);
}

.modal-box h3 {
  margin-bottom: 8px;
  font-size: 18px;
}

.modal-box p {
  color: var(--color-text-light);
  font-size: 14px;
  margin-bottom: 16px;
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* === Responsive === */
@media (min-width: 768px) {
  .screen-content {
    padding: 48px 24px;
  }

  .message {
    max-width: 70%;
  }
}

@media (max-height: 500px) {
  .logo-area {
    margin-bottom: 16px;
  }
  .logo {
    width: 48px;
    height: 48px;
  }
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
