:root {
  --bg-primary: #121212;
  --bg-surface: #1e1e1e;
  --bg-surface-elevated: #282828;
  --bg-hover: #333333;
  --border-color: #383838;
  --text-primary: #ffffff;
  --text-secondary: #b3b3b3;
  --text-muted: #777777;
  
  --primary: #90caf9;
  --primary-variant: #1976d2;
  --secondary: #03dac6;
  
  --palette-answered: #2e7d32;
  --palette-not-answered: #c62828;
  --palette-not-visited: #757575;
  --palette-review: #7b1fa2;
  --palette-ans-review: #1565c0;
  
  --header-bg: #1f1f1f;
  --header-border: #333333;
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f1f5f9;
  --bg-hover: #e2e8f0;
  --border-color: #cbd5e1;
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  
  --primary: #1d4ed8;
  --primary-variant: #1e40af;
  --secondary: #0f766e;
  
  --header-bg: #1e3a8a;
  --header-border: #1e40af;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header & Navbar */
.app-header {
  height: 56px;
  background-color: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 100;
}

[data-theme="light"] .app-header {
  color: #ffffff;
}
[data-theme="light"] .app-header .brand-title {
  color: #ffffff;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  height: 32px;
  border-radius: 4px;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Material Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 16px;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  border: none;
  outline: none;
  transition: all 0.15s ease-in-out;
}

.btn-primary {
  background-color: var(--primary-variant);
  color: #ffffff;
}
.btn-primary:hover {
  filter: brightness(1.15);
}

.btn-secondary {
  background-color: var(--bg-surface-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover {
  background-color: var(--bg-hover);
}

.btn-danger {
  background-color: #dc2626;
  color: #ffffff;
}
.btn-danger:hover {
  background-color: #b91c1c;
}

.btn-success {
  background-color: #16a34a;
  color: #ffffff;
}
.btn-success:hover {
  background-color: #15803d;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.75rem;
}

/* Tab Navigation */
.view-tabs {
  display: flex;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0 20px;
}

.tab-btn {
  padding: 12px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-btn:hover {
  color: var(--text-primary);
}

/* Main Container */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.view-section {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}

.view-section.active {
  display: flex;
}

/* Excel Spreadsheet Table View */
.table-toolbar {
  padding: 12px 20px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.search-input-group {
  display: flex;
  align-items: center;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 4px 10px;
  width: 320px;
}

.search-input-group input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.85rem;
  width: 100%;
  margin-left: 6px;
}

.filter-pills {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.grid-table-container {
  flex: 1;
  overflow: auto;
  background-color: var(--bg-primary);
  position: relative;
}

.spreadsheet-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  text-align: left;
}

.spreadsheet-table th,
.spreadsheet-table td {
  padding: 8px 12px;
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.spreadsheet-table thead th {
  background-color: var(--bg-surface-elevated);
  color: var(--text-primary);
  position: sticky;
  top: 0;
  z-index: 10;
  font-weight: 700;
  letter-spacing: 0.3px;
  user-select: none;
}

/* Sticky Action Column so Start button is always visible on zoom */
.sticky-action-col {
  position: sticky;
  right: 0;
  background-color: var(--bg-surface);
  z-index: 5;
  box-shadow: -2px 0 5px rgba(0, 0, 0, 0.12);
  min-width: 120px;
  text-align: center;
}

.spreadsheet-table thead th.sticky-action-col {
  z-index: 15;
  background-color: var(--bg-surface-elevated);
}

.th-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.th-header-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.sort-icon {
  font-size: 0.75rem;
  opacity: 0.6;
}

.th-filter-input,
.th-filter-select {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 0.75rem;
  outline: none;
  width: 100%;
}

.spreadsheet-table tbody tr {
  background-color: var(--bg-surface);
  transition: background-color 0.1s ease;
}

.spreadsheet-table tbody tr:hover {
  background-color: var(--bg-hover);
}

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-attempted {
  background-color: rgba(22, 163, 74, 0.2);
  color: #16a34a;
  border: 1px solid #16a34a;
}

[data-theme="dark"] .badge-attempted {
  background-color: rgba(46, 125, 50, 0.25);
  color: #81c784;
  border: 1px solid #2e7d32;
}

.badge-unattempted {
  background-color: rgba(100, 116, 139, 0.15);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

/* Metric Cards */
.metrics-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  padding: 20px;
}

.metric-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-title {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.metric-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary);
}

.metric-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Activity Heatmap Grid across days */
.activity-section {
  padding: 0 20px 20px 20px;
}

.activity-grid {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding: 12px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
}

.activity-day-cell {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface-elevated);
  cursor: pointer;
}

.activity-day-cell.active-1 { background-color: rgba(34, 197, 94, 0.3); border-color: #22c55e; }
.activity-day-cell.active-2 { background-color: rgba(34, 197, 94, 0.6); color: #fff; border-color: #22c55e; }
.activity-day-cell.active-3 { background-color: #16a34a; color: #fff; border-color: #15803d; }

/* Authentic TCS iON Exam Engine Layout */
.exam-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.exam-top-bar {
  height: 50px;
  background-color: var(--header-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  color: #ffffff;
}

.exam-test-title {
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
}

.exam-top-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.exam-workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Left Panel: Question area (75%) */
.exam-left-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-right: 2px solid var(--border-color);
  overflow: hidden;
  background-color: var(--bg-surface);
}

.section-bar {
  display: flex;
  align-items: center;
  background-color: var(--bg-surface-elevated);
  border-bottom: 1px solid var(--border-color);
  padding: 0 12px;
  gap: 4px;
  overflow-x: auto;
}

.section-btn {
  padding: 8px 16px;
  background: none;
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 3px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}

.section-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background-color: var(--bg-surface);
}

.question-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 24px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.9rem;
  background-color: var(--bg-surface);
}

.question-marking-info {
  display: flex;
  gap: 16px;
}

.marking-tag {
  font-weight: 600;
}

.tag-green { color: #16a34a; }
.tag-red { color: #dc2626; }

/* Question scroll body: natural left alignment with official examination typography */
.question-scroll-body {
  flex: 1;
  overflow-y: auto;
  padding: 22px 30px;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 1.05rem;
  line-height: 1.75;
  width: 100%;
  color: var(--text-primary);
}

.question-text {
  margin-bottom: 24px;
  color: var(--text-primary);
  word-wrap: break-word;
  font-family: inherit;
}

/* GATE Standard Code Block: Pure neutral lighter gray background without any bluish tint */
.question-text pre,
.question-text code,
.review-item pre,
.review-item code {
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.95rem;
}

.question-text pre,
.review-item pre {
  background-color: #2b2b2b;
  color: #f0f0f0;
  border: 1px solid #404040;
  border-radius: 4px;
  padding: 12px 16px;
  margin: 12px 0;
  overflow-x: auto;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: normal;
}

[data-theme="light"] .question-text pre,
[data-theme="light"] .review-item pre {
  background-color: #e5e5e5;
  color: #1a1a1a;
  border: 1px solid #cccccc;
}

/* Inline code tags */
.question-text :not(pre) > code,
.review-item :not(pre) > code {
  background-color: #333333;
  color: #f0f0f0;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.92em;
  border: 1px solid #484848;
}

[data-theme="light"] .question-text :not(pre) > code,
[data-theme="light"] .review-item :not(pre) > code {
  background-color: #e0e0e0;
  color: #1a1a1a;
  border: 1px solid #cccccc;
}

/* Question Options Formatting: Indent choices/options in question text */
.question-text ol,
.question-text ul {
  margin-left: 36px;
  padding-left: 10px;
  margin-top: 10px;
  margin-bottom: 14px;
}

.question-text ol li,
.question-text ul li {
  margin-bottom: 8px;
  line-height: 1.6;
}

/* In question options with images, give indentation */
.question-text li img {
  margin-left: 4px;
}

/* Options Container: Normal alignment without artificial indentation */
.options-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 30px;
  padding-left: 0;
  max-width: 420px;
}

.option-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface-elevated);
  cursor: pointer;
  transition: all 0.15s ease;
}

.option-row:hover {
  background-color: var(--bg-hover);
  border-color: var(--primary);
}

.option-row.selected {
  border-color: var(--primary);
  background-color: rgba(29, 78, 216, 0.1);
}

[data-theme="dark"] .option-row.selected {
  background-color: rgba(144, 202, 249, 0.12);
}

.option-input {
  margin-top: 3px;
  cursor: pointer;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.option-text {
  flex: 1;
  color: var(--text-primary);
  font-size: 0.95rem;
}

/* User Notes Area in Exam & Review */
.notes-panel {
  margin-top: 24px;
  border-top: 1px dashed var(--border-color);
  padding-top: 14px;
}

.notes-input {
  width: 100%;
  padding: 10px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface-elevated);
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
  resize: vertical;
  min-height: 60px;
}

/* Virtual Numeric Keypad for NAT */
.nat-container {
  margin-top: 16px;
  max-width: 360px;
}

.nat-display {
  width: 100%;
  padding: 10px;
  font-size: 1.2rem;
  font-weight: 600;
  font-family: monospace;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-primary);
  margin-bottom: 12px;
  outline: none;
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.keypad-btn {
  padding: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface-elevated);
  color: var(--text-primary);
  cursor: pointer;
}

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

/* TCS iON Bottom Hotbar */
.exam-hotbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background-color: var(--bg-surface-elevated);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  gap: 8px;
}

.hotbar-left,
.hotbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Right Panel: Candidate Profile & Palette (25%) */
.exam-right-panel {
  width: 320px;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-surface);
  overflow: hidden;
  flex-shrink: 0;
}

.candidate-card {
  padding: 12px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 12px;
}

.candidate-avatar {
  width: 48px;
  height: 48px;
  border-radius: 4px;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.candidate-info {
  display: flex;
  flex-direction: column;
}

.candidate-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.timer-box {
  padding: 8px 12px;
  background-color: var(--bg-surface-elevated);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}

.time-left {
  font-size: 1.25rem;
  font-family: monospace;
  color: #ea580c;
}

/* Legend */
.palette-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 10px 12px;
  font-size: 0.72rem;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-surface);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-badge {
  width: 22px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
}

/* Authentic TCS iON shapes */
.badge-answered {
  background-color: var(--palette-answered);
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

.badge-not-answered {
  background-color: var(--palette-not-answered);
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
}

.badge-not-visited {
  background-color: var(--palette-not-visited);
  border-radius: 3px;
}

.badge-review {
  background-color: var(--palette-review);
  border-radius: 50%;
}

.badge-ans-review {
  background-color: var(--palette-ans-review);
  border-radius: 50%;
  position: relative;
}

.badge-ans-review::after {
  content: "";
  position: absolute;
  bottom: 0px;
  right: 0px;
  width: 7px;
  height: 7px;
  background-color: #16a34a;
  border-radius: 50%;
}

/* Question Palette Grid */
.palette-container {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.palette-btn {
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  outline: none;
  transition: transform 0.1s ease;
  color: #ffffff;
}

.palette-btn:hover {
  transform: scale(1.05);
}

.palette-btn.current {
  outline: 2px solid #ffffff;
  outline-offset: 1px;
}

.palette-submit-bar {
  padding: 12px;
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-surface-elevated);
}

/* Modals */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  width: 90%;
  max-width: 650px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 1.1rem;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Summary / Result View */
.result-container {
  max-width: 950px;
  margin: 0 auto;
  padding: 24px;
  width: 100%;
  overflow-y: auto;
  height: 100%;
}

.result-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 24px;
}

.result-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin: 20px 0;
}

.result-metric-item {
  background-color: var(--bg-surface-elevated);
  border-radius: 6px;
  padding: 14px;
  text-align: center;
  border: 1px solid var(--border-color);
}

.result-metric-num {
  font-size: 1.8rem;
  font-weight: 700;
  margin-top: 4px;
}

.review-item {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 20px 24px;
  margin-bottom: 20px;
}

.review-item .question-text ol,
.review-item .question-text ul {
  margin-left: 36px;
  padding-left: 10px;
  margin-top: 10px;
  margin-bottom: 14px;
}

.review-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 10px;
  margin-bottom: 14px;
}

.review-badge {
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 700;
}

.review-correct {
  background-color: rgba(22, 163, 74, 0.2);
  color: #16a34a;
  border: 1px solid #16a34a;
}

.review-incorrect {
  background-color: rgba(220, 38, 38, 0.2);
  color: #dc2626;
  border: 1px solid #dc2626;
}

.review-unattempted {
  background-color: rgba(100, 116, 139, 0.2);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.answer-comparison {
  margin-top: 16px;
  padding: 14px 18px;
  background-color: var(--bg-surface-elevated);
  border-radius: 6px;
  font-size: 0.92rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--border-color);
}

/* Online Sync / Compact String Box */
.sync-box {
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 14px;
  margin-top: 12px;
}

.sync-textarea {
  width: 100%;
  height: 80px;
  font-family: monospace;
  font-size: 0.78rem;
  padding: 8px;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  margin-top: 8px;
  outline: none;
  resize: vertical;
}
