/* ============================================================
   Headstart Education Group - Admin Portal
   Dark Theme
   ============================================================ */

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

:root {
  --app-bg: #101827;
  --sidebar-bg: #151e2f;
  --surface: #1d283c;
  --surface-hover: #1a2539;
  --border: #2c394f;
  --text: #ffffff;
  --text-secondary: #8896ab;
  --text-muted: #5a6a80;
  --accent: #2869ff;
  --accent-hover: #6291fd;
  --accent-light: rgba(40, 105, 255, 0.15);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #2ba972;
  --success-light: rgba(43, 169, 114, 0.2);
  --warning: #ca8a04;
  --warning-light: rgba(202, 138, 4, 0.2);
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: rgba(0, 0, 0, 0.3) 0px 2px 8px 0px;
  --shadow-md: rgba(16, 24, 39, 0.8) 0px 6px 12px -2px, rgba(0, 0, 0, 0.3) 0px 3px 7px -3px;
  --font: 'Poppins', sans-serif;
  --font-mono: 'Consolas', 'Monaco', 'Courier New', monospace;
}

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

body, html {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background-color: var(--app-bg);
  color: var(--text);
  line-height: 1.6;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================================
   App layout
   ============================================================ */

.app-container {
  display: flex;
  height: 100vh;
  width: 100%;
}

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

.sidebar {
  flex: 0 0 220px;
  background-color: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 20px 20px 16px;
}

.sidebar-header h1 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.sidebar-header .sidebar-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 400;
}

.sidebar-nav {
  list-style: none;
  padding: 0;
  margin: 8px 0;
  flex: 1;
}

.sidebar-nav li {
  position: relative;
  margin-bottom: 2px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 400;
  line-height: 24px;
  transition: background-color 0.15s, color 0.15s;
}

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

.sidebar-nav li:hover {
  background-color: var(--surface-hover);
}

.sidebar-nav li:hover a {
  color: var(--text);
}

.sidebar-nav li.active {
  background-color: var(--surface);
}

.sidebar-nav li.active::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  width: 3px;
  background-color: var(--accent);
}

.sidebar-nav li.active a {
  color: var(--text);
  font-weight: 500;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.sidebar-user-role {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-light);
  color: var(--accent-hover);
}

.sidebar-logout {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 12px;
  transition: color 0.15s;
}

.sidebar-logout:hover {
  color: var(--danger);
}

/* ============================================================
   Main content area
   ============================================================ */

.app-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--app-bg);
}

.app-content-header {
  padding: 24px 32px 0;
  flex-shrink: 0;
}

.app-content-header h2 {
  font-size: 22px;
  font-weight: 500;
  color: var(--text);
  margin: 0;
}

#app {
  flex: 1;
  overflow-y: auto;
  padding: 20px 32px 32px;
}

/* ============================================================
   Page: Loading
   ============================================================ */

.page-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  color: var(--text-secondary);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

.spinner-sm {
  width: 20px;
  height: 20px;
  border-width: 2px;
  margin-bottom: 0;
}

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

/* ============================================================
   Page: Message (no-access, error)
   ============================================================ */

.page-message {
  text-align: center;
  padding: 80px 20px;
}

.page-message h2 {
  margin-bottom: 12px;
  color: var(--text);
  font-size: 20px;
  font-weight: 500;
}

.page-message p {
  color: var(--text-secondary);
  margin-bottom: 24px;
  max-width: 440px;
  margin-left: auto;
  margin-right: auto;
  font-size: 14px;
  line-height: 1.7;
}

.page-error h2 {
  color: var(--danger);
}

/* ============================================================
   Page: Dashboard
   ============================================================ */

.page-dashboard h2 {
  font-size: 20px;
  font-weight: 500;
  margin-bottom: 8px;
}

.dashboard-orgs {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 32px;
}

.dashboard-welcome {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 32px;
  max-width: 560px;
}

.dashboard-welcome p {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.7;
  margin-bottom: 12px;
}

.dashboard-welcome p:last-child {
  margin-bottom: 0;
}

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

.dashboard-welcome a:hover {
  text-decoration: underline;
}

/* ============================================================
   Toolbar (filters)
   ============================================================ */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 20px;
  align-items: flex-end;
}

.toolbar-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toolbar-group-grow {
  flex: 1;
  min-width: 200px;
}

.toolbar-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ============================================================
   Form elements
   ============================================================ */

.input-text,
.input-select {
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238896ab' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 36px;
}

.input-text::placeholder {
  color: var(--text-muted);
}

.input-text:focus,
.input-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.input-text:disabled,
.input-select:disabled {
  background: var(--app-bg);
  color: var(--text-muted);
  border-color: var(--border);
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
  line-height: 1.4;
}

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

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

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--text-muted);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-sm {
  font-size: 13px;
  padding: 6px 12px;
}

/* ============================================================
   Data table
   ============================================================ */

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

.data-table th {
  background: var(--surface);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  text-align: left;
  padding: 10px 16px;
}

.data-table th:first-child {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.data-table th:last-child {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.data-table td {
  padding: 10px 16px;
  color: var(--text);
  border: none;
}

.data-table tbody tr {
  border-radius: var(--radius-sm);
  transition: background-color 0.15s, box-shadow 0.15s;
}

.data-table tbody tr:hover {
  background: var(--surface);
  box-shadow: var(--shadow);
}

.data-table-selectable tbody tr {
  cursor: pointer;
}

/* ============================================================
   Badges
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
}

.badge-staff {
  background: var(--accent-light);
  color: var(--accent-hover);
}

.badge-student {
  background: rgba(124, 58, 237, 0.2);
  color: #a78bfa;
}

.badge-unknown {
  background: rgba(90, 106, 128, 0.2);
  color: var(--text-secondary);
}

.badge-enabled {
  color: var(--success);
  background: var(--success-light);
}

.badge-enabled::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  margin-right: 6px;
}

.badge-disabled {
  color: #59719d;
  background: rgba(89, 113, 157, 0.2);
}

.badge-disabled::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #59719d;
  margin-right: 6px;
}

/* ============================================================
   Form sections
   ============================================================ */

.form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
  margin-bottom: 20px;
}

.form-section h3 {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 20px;
  color: var(--text);
}

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

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

.form-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.5;
}

.form-row {
  display: flex;
  gap: 16px;
}

.form-group-half {
  flex: 1;
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* ============================================================
   Radio group
   ============================================================ */

.radio-group {
  display: flex;
  gap: 24px;
  margin-top: 4px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
}

.radio-label input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* ============================================================
   Checkbox group (multi-select)
   ============================================================ */

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

.checkbox-group .checkbox-label {
  font-size: 14px;
}

/* ============================================================
   Selected user card
   ============================================================ */

.selected-user-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--app-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 20px;
}

.selected-user-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.selected-user-info strong {
  color: var(--text);
  font-size: 14px;
}

.selected-user-info span {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ============================================================
   Result card
   ============================================================ */

.result-card {
  background: var(--success-light);
  border: 1px solid rgba(43, 169, 114, 0.3);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
}

.result-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 14px;
}

.result-row[hidden] {
  display: none;
}

.result-label {
  font-weight: 500;
  min-width: 120px;
  color: var(--text-secondary);
}

.result-row-highlight {
  background: var(--warning-light);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin: 8px 0;
}

.result-row-highlight code {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.05em;
}

.result-actions {
  display: flex;
  gap: 12px;
}

/* ============================================================
   Alerts
   ============================================================ */

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
}

.alert-error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* ============================================================
   Inline loading & empty state
   ============================================================ */

.inline-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 0;
  color: var(--text-secondary);
  font-size: 14px;
}

.inline-loading[hidden] {
  display: none;
}

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ============================================================
   Copy feedback
   ============================================================ */

.copy-success {
  color: var(--success);
  font-size: 13px;
  font-weight: 500;
  animation: fade-in-out 2s ease-in-out;
}

@keyframes fade-in-out {
  0% { opacity: 0; }
  15% { opacity: 1; }
  85% { opacity: 1; }
  100% { opacity: 0; }
}

/* ============================================================
   Preview value (email preview)
   ============================================================ */

.preview-value {
  font-family: var(--font-mono);
  font-size: 15px;
  padding: 6px 0;
  color: var(--accent-hover);
  font-weight: 600;
}

.preview-status {
  font-size: 13px;
}

.preview-status.available {
  color: var(--success);
}

.preview-status.taken {
  color: var(--warning);
}

.preview-status.checking {
  color: var(--text-muted);
}

/* ============================================================
   Review card
   ============================================================ */

.review-card {
  background: var(--app-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
}

/* ============================================================
   Actions list (create/edit result)
   ============================================================ */

#create-result-actions-list,
#edit-result-actions-list {
  margin-bottom: 20px;
}

#create-result-actions-list h4,
#edit-result-actions-list h4 {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

#create-result-actions,
#edit-result-actions {
  list-style: none;
  font-size: 14px;
}

#create-result-actions li,
#edit-result-actions li {
  padding: 3px 0;
  color: var(--text-secondary);
}

#create-result-actions li::before,
#edit-result-actions li::before {
  content: "\2713  ";
  color: var(--success);
}

#create-result-actions li.action-warning::before,
#edit-result-actions li.action-warning::before {
  content: "\26A0  ";
  color: var(--warning);
}

/* ============================================================
   Email autocomplete
   ============================================================ */

.email-autocomplete-wrapper {
  position: relative;
}

.email-autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 50;
  max-height: 200px;
  overflow-y: auto;
}

.email-autocomplete-dropdown[hidden] {
  display: none;
}

.email-autocomplete-item {
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  gap: 8px;
  align-items: baseline;
  color: var(--text);
}

.email-autocomplete-item:hover {
  background: var(--surface-hover);
}

.email-autocomplete-item span {
  color: var(--text-secondary);
  font-size: 13px;
}

/* ============================================================
   Page header (per-page)
   ============================================================ */

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

.page-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 500;
}

/* ============================================================
   Scrollbar styling (dark theme)
   ============================================================ */

#app::-webkit-scrollbar {
  width: 6px;
}

#app::-webkit-scrollbar-track {
  background: transparent;
}

#app::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

#app::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

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

@media (max-width: 1024px) {
  .sidebar {
    display: none;
  }

  .app-content-header {
    padding: 20px 20px 0;
  }

  #app {
    padding: 16px 20px 24px;
  }
}

@media (max-width: 640px) {
  .toolbar {
    flex-direction: column;
  }

  .toolbar-group {
    width: 100%;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .data-table {
    font-size: 13px;
  }

  .data-table th,
  .data-table td {
    padding: 8px 10px;
  }

  .result-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .selected-user-card {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }
}
