/* ============================================================
   ExamChat – Custom stylesheet
   ============================================================ */

/* --- Variables -------------------------------------------- */
:root {
  --ec-primary:        #6366F1;
  --ec-primary-dark:   #4F46E5;
  --ec-primary-light:  #EEF2FF;
  --ec-sidebar-bg:     #18181B;
  --ec-sidebar-hover:  rgba(255,255,255,0.07);
  --ec-sidebar-active: #6366F1;
  --ec-sidebar-text:   rgba(255,255,255,0.65);
  --ec-sidebar-text-on:#fff;
  --ec-sidebar-w:      230px;
  --ec-bg:             #F4F6F9;
  --ec-surface:        #FFFFFF;
  --ec-border:         #E4E7EC;
  --ec-text:           #101828;
  --ec-muted:          #667085;
  --ec-success:        #12B76A;
  --ec-danger:         #F04438;
  --ec-warning:        #F79009;
  --ec-radius:         10px;
  --ec-shadow:         0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.05);
  --ec-shadow-md:      0 4px 12px rgba(16,24,40,.10), 0 2px 6px rgba(16,24,40,.06);
}

/* --- Base ------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { font-size: 14px; }
@media (min-width: 768px) { html { font-size: 15px; } }

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--ec-text);
  background: var(--ec-bg);
  margin: 0;
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #D0D5DD; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #98A2B3; }

.btn:focus, .form-control:focus, .form-select:focus, .form-check-input:focus {
  box-shadow: 0 0 0 3px rgba(99,102,241,.18);
  outline: none;
}

/* --- App layout (authenticated) --------------------------- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar ---------------------------------------------- */
.sidebar {
  width: var(--ec-sidebar-w);
  background: var(--ec-sidebar-bg);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 200;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 18px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  text-decoration: none;
}

.sidebar-brand-icon {
  width: 34px; height: 34px;
  background: var(--ec-primary);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 800; color: #fff;
  flex-shrink: 0;
  letter-spacing: -1px;
}

.sidebar-brand-name {
  font-size: 15px; font-weight: 700; color: #fff; letter-spacing: -.02em;
}

.sidebar-section { padding: 18px 16px 5px; }

.sidebar-section-label {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em;
  color: rgba(255,255,255,.28);
}

.sidebar-body { padding: 4px 10px; }

.sidebar-nav-link {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px;
  border-radius: 7px;
  color: var(--ec-sidebar-text);
  text-decoration: none;
  font-size: 13.5px; font-weight: 500;
  margin-bottom: 1px;
  transition: background .12s, color .12s;
}
.sidebar-nav-link:hover {
  background: var(--ec-sidebar-hover);
  color: #fff;
}
.sidebar-nav-link.active {
  background: var(--ec-sidebar-active);
  color: #fff;
}
.sidebar-nav-link .ni {
  font-size: 15px; width: 18px; text-align: center; flex-shrink: 0;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px 10px;
  border-top: 1px solid rgba(255,255,255,.07);
}

.sidebar-user {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px;
  border-radius: 8px;
  margin-bottom: 4px;
  background: rgba(255,255,255,.05);
}
.sidebar-avatar {
  width: 30px; height: 30px;
  background: var(--ec-primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
  flex-shrink: 0; text-transform: uppercase;
}
.sidebar-user-name  { font-size: 12.5px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role  { font-size: 11px; color: rgba(255,255,255,.4); }

/* --- Main wrapper ----------------------------------------- */
.main-wrapper {
  flex: 1;
  margin-left: var(--ec-sidebar-w);
  min-width: 0;
}

.page-content { padding: 28px 32px; }

/* --- Page toolbar ----------------------------------------- */
.page-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px;
}
.page-toolbar .page-title {
  font-size: 20px; font-weight: 700; color: var(--ec-text); margin: 0;
}

/* --- Alerts ----------------------------------------------- */
.alert {
  border-radius: 8px;
  font-size: 13.5px;
  padding: 10px 14px;
  border: none;
  margin-bottom: 20px;
}
.alert-success { background: #ECFDF5; color: #065F46; }
.alert-danger   { background: #FEF2F2; color: #991B1B; }
.alert-info     { background: #EFF6FF; color: #1E40AF; }

/* --- Stat cards ------------------------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin-bottom: 28px; }

.stat-card {
  background: var(--ec-surface);
  border-radius: var(--ec-radius);
  border: 1px solid var(--ec-border);
  box-shadow: var(--ec-shadow);
  padding: 18px 20px;
}
.stat-card-icon  { font-size: 20px; margin-bottom: 10px; display: block; }
.stat-card-value { font-size: 28px; font-weight: 700; line-height: 1; color: var(--ec-text); }
.stat-card-label { font-size: 11.5px; font-weight: 500; color: var(--ec-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: .04em; }

/* --- Tables ----------------------------------------------- */
.ec-table-wrap {
  background: var(--ec-surface);
  border-radius: var(--ec-radius);
  border: 1px solid var(--ec-border);
  box-shadow: var(--ec-shadow);
  overflow: hidden;
}
.ec-table-wrap .table { margin: 0; }
.ec-table-wrap .table thead th {
  background: #F9FAFB;
  border-bottom: 1px solid var(--ec-border);
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--ec-muted);
  padding: 11px 16px; white-space: nowrap;
}
.ec-table-wrap .table tbody td {
  padding: 13px 16px;
  border-color: var(--ec-border);
  vertical-align: middle;
  font-size: 13.5px;
}
.ec-table-wrap .table tbody tr:hover td { background: #FAFAFA; }
.ec-table-wrap .table tbody tr:last-child td { border-bottom: none; }

/* --- Form card -------------------------------------------- */
.form-card {
  background: var(--ec-surface);
  border-radius: var(--ec-radius);
  border: 1px solid var(--ec-border);
  box-shadow: var(--ec-shadow);
  padding: 28px 28px 24px;
}

.form-label { font-size: 13px; font-weight: 600; color: var(--ec-text); margin-bottom: 6px; }

.form-control, .form-select {
  border-radius: 8px;
  border-color: var(--ec-border);
  font-size: 13.5px;
  padding: 8px 12px;
  color: var(--ec-text);
  background: var(--ec-surface);
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus {
  border-color: var(--ec-primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.14);
}

.form-text { font-size: 12px; color: var(--ec-muted); }

/* --- Buttons ---------------------------------------------- */
.btn { border-radius: 8px; font-size: 13.5px; font-weight: 500; padding: 7px 14px; transition: all .15s; }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }

.btn-primary { background: var(--ec-primary); border-color: var(--ec-primary); }
.btn-primary:hover { background: var(--ec-primary-dark); border-color: var(--ec-primary-dark); }

.btn-outline-secondary { color: var(--ec-text); border-color: var(--ec-border); }
.btn-outline-secondary:hover { background: #F9FAFB; color: var(--ec-text); border-color: #C4CAD4; }

.btn-outline-danger { color: var(--ec-danger); border-color: #FECACA; }
.btn-outline-danger:hover { background: #FEF2F2; border-color: var(--ec-danger); color: var(--ec-danger); }

/* --- Badges ----------------------------------------------- */
.badge { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 5px; }

/* --- Info card (hierarchy) -------------------------------- */
.info-card {
  background: var(--ec-surface);
  border-radius: var(--ec-radius);
  border: 1px solid var(--ec-border);
  box-shadow: var(--ec-shadow);
  padding: 20px 24px;
}
.info-card h6 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ec-muted); margin-bottom: 14px; }
.hierarchy-tree ul { list-style: none; padding-left: 18px; margin: 2px 0; }
.hierarchy-tree > ul { padding-left: 0; }
.hierarchy-tree li { padding: 3px 0; font-size: 13px; color: var(--ec-text); line-height: 1.5; }
.hierarchy-tree li::before { content: '›'; margin-right: 6px; color: var(--ec-muted); }
.hierarchy-tree > ul > li::before { content: none; }

/* --- Quick action buttons --------------------------------- */
.quick-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 28px; }

/* --- Login page ------------------------------------------- */
.login-bg {
  min-height: 100vh;
  background: linear-gradient(145deg, #1E1B4B 0%, #312E81 55%, #4F46E5 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-box {
  background: var(--ec-surface);
  border-radius: 16px;
  padding: 36px;
  width: 100%; max-width: 420px;
  box-shadow: 0 24px 60px rgba(0,0,0,.25);
}
.login-icon {
  width: 48px; height: 48px;
  background: var(--ec-primary);
  border-radius: 13px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 900; color: #fff;
  margin: 0 auto 20px;
  letter-spacing: -2px;
}
.login-box h1 { font-size: 22px; font-weight: 700; text-align: center; color: var(--ec-text); margin-bottom: 4px; }
.login-box .subtitle { font-size: 13px; color: var(--ec-muted); text-align: center; margin-bottom: 24px; }

/* --- Hero page -------------------------------------------- */
.hero-bg {
  min-height: 100vh;
  background: linear-gradient(145deg, #1E1B4B 0%, #312E81 55%, #4F46E5 100%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px 24px;
  text-align: center;
}
.hero-icon {
  width: 64px; height: 64px;
  background: rgba(255,255,255,.15);
  border: 2px solid rgba(255,255,255,.25);
  border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 900; color: #fff;
  margin: 0 auto 24px;
  letter-spacing: -2px;
}
.hero-bg h1 { font-size: 42px; font-weight: 800; color: #fff; margin-bottom: 12px; letter-spacing: -.03em; }
.hero-bg .lead { font-size: 16px; color: rgba(255,255,255,.75); margin-bottom: 32px; max-width: 480px; }
.hero-bg .btn-hero {
  background: #fff; color: var(--ec-primary);
  border: none; padding: 12px 28px;
  font-size: 15px; font-weight: 600; border-radius: 10px;
  text-decoration: none;
  transition: all .2s;
}
.hero-bg .btn-hero:hover { background: #EEF2FF; transform: translateY(-1px); }
.hero-bg .hero-note { font-size: 12.5px; color: rgba(255,255,255,.45); margin-top: 28px; }

/* --- Instructor threads (card layout) --------------------- */
.thread-grid { display: flex; flex-direction: column; gap: 10px; }

.thread-card {
  background: var(--ec-surface);
  border-radius: var(--ec-radius);
  border: 1px solid var(--ec-border);
  box-shadow: var(--ec-shadow);
  padding: 16px 20px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  text-decoration: none;
  color: var(--ec-text);
  transition: box-shadow .15s, border-color .15s;
}
.thread-card:hover { box-shadow: var(--ec-shadow-md); border-color: #C7D2FE; color: var(--ec-text); text-decoration: none; }
.thread-card.unclaimed { border-left: 3px solid var(--ec-warning); }

.thread-module-badge {
  background: var(--ec-primary-light);
  color: var(--ec-primary-dark);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  min-width: 80px;
  text-align: center;
}
.thread-info-main { font-size: 13.5px; font-weight: 600; color: var(--ec-text); margin-bottom: 2px; }
.thread-info-sub  { font-size: 12px; color: var(--ec-muted); }
.thread-preview   { font-size: 12.5px; color: var(--ec-muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 400px; }
.thread-meta      { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.thread-count-badge {
  background: var(--ec-primary);
  color: #fff; border-radius: 10px;
  font-size: 11px; font-weight: 600;
  padding: 1px 8px; white-space: nowrap;
}

/* --- Chat UI ---------------------------------------------- */
.chat-card {
  display: flex; flex-direction: column;
  height: calc(100vh - 120px);
  min-height: 480px;
  background: var(--ec-surface);
  border-radius: var(--ec-radius);
  border: 1px solid var(--ec-border);
  box-shadow: var(--ec-shadow-md);
  overflow: hidden;
}
.chat-card .card-header {
  background: var(--ec-surface);
  border-bottom: 1px solid var(--ec-border);
  padding: 14px 20px;
}
.chat-messages {
  flex: 1 1 auto; overflow-y: auto;
  padding: 20px;
  background: var(--ec-bg);
}
.chat-bubble {
  max-width: 72%;
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: 14px;
  box-shadow: var(--ec-shadow);
  word-wrap: break-word;
}
.chat-mine {
  margin-left: auto;
  background: var(--ec-primary);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.chat-mine .chat-meta   { color: rgba(255,255,255,.65); }
.chat-mine .chat-sender { color: rgba(255,255,255,.9); }
.chat-theirs {
  margin-right: auto;
  background: var(--ec-surface);
  border: 1px solid var(--ec-border);
  border-bottom-left-radius: 3px;
}
.chat-broadcast {
  margin: 12px auto;
  background: #fff8e1;
  border: 1px solid #f0c000;
  border-left: 4px solid #f0c000;
  max-width: 85%;
  border-radius: 6px;
}
.chat-broadcast-tag {
  font-size: 11px;
  font-weight: 700;
  color: #8a6d00;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
.chat-broadcast-time {
  font-size: 11px;
  color: #8a6d00;
  text-align: right;
  margin-top: 4px;
}
.chat-meta {
  display: flex; justify-content: space-between; gap: 1rem;
  font-size: 11px; color: var(--ec-muted); margin-bottom: 4px;
}
.chat-sender  { font-weight: 600; }
.chat-content { white-space: pre-wrap; font-size: 13.5px; line-height: 1.5; }

.chat-card .card-footer {
  background: var(--ec-surface);
  border-top: 1px solid var(--ec-border);
  padding: 12px 16px;
}
#connectionStatus { font-size: 11px; color: var(--ec-muted); margin-top: 6px; }
