/*
CBSE Result Analyser — Stylesheet
Developer: Mani Harsh Dubey
Purpose: Dark-themed responsive web UI
*/

/* Design Tokens */
:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #1c2330;
  --bg4: #212936;
  --border: #30363d;
  --border2: #3d4757;
  --accent: #2563eb;
  --accent2: #1d4ed8;
  --green: #16a34a;
  --green2: #22c55e;
  --red: #dc2626;
  --red2: #ef4444;
  --yellow: #ca8a04;
  --yellow2: #f59e0b;
  --purple: #7c3aed;
  --teal: #0d9488;
  --text: #e6edf3;
  --text2: #8b949e;
  --text3: #6e7681;
  --font: 'Space Grotesk', system-ui, sans-serif;
  --mono: 'JetBrains Mono', Consolas, monospace;
  --radius: 10px;
  --radius-sm: 6px;
  --nav-h: 54px;
}

/* Global Resets */
* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg2);
}

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

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border2) var(--bg2);
}

/* Focus States */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

button:focus-visible,
a:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Top Compliance Bar */
.topmenubar {
  height: 40px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.topmenubar::-webkit-scrollbar {
  display: none;
}

.topmenubar a {
  color: var(--text2);
  text-decoration: none;
  font-size: 0.875rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 28px;
  display: flex;
  align-items: center;
}

.topmenubar a:hover {
  color: var(--text);
  background: var(--bg3);
}

/* Navbar */
.navbar {
  position: sticky;
  top: 0;
  z-index: 200;
  height: var(--nav-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  max-width: 100vw;
  overflow: hidden;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
  min-height: 44px;
}

.nav-brand svg {
  width: 24px;
  height: 24px;
  fill: var(--accent);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: 2rem;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  flex: 1;
  min-width: 0;
}

.nav-links::-webkit-scrollbar {
  display: none;
}

.nav-lnk {
  color: var(--text2);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.nav-lnk:hover {
  color: var(--text);
  background: var(--bg3);
}

.nav-lnk.active {
  color: var(--accent);
  background: rgba(37, 99, 235, 0.1);
}

/* Hamburger Toggle */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  min-height: 44px;
  min-width: 40px;
  margin-left: auto;
}

.nav-toggle:hover {
  background: var(--bg3);
}

.nav-toggle svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* Dropdown Menus */
.nav-dd {
  position: relative;
}

.nav-dd-btn svg,
.nav-dd-btn path,
.nav-toggle svg,
.nav-toggle path {
  pointer-events: none;
}

.nav-dd-btn {
  background: none;
  border: none;
  color: var(--text2);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  min-height: 44px;
}

.nav-dd-btn:hover {
  color: var(--text);
  background: var(--bg3);
}

.nav-dd.open .nav-dd-btn {
  color: var(--accent);
  background: rgba(37, 99, 235, 0.1);
}

.nav-dd-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 400;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 160px;
  display: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.nav-dd:last-child .nav-dd-menu {
  left: auto;
  right: 0;
}

.nav-dd.open .nav-dd-menu {
  display: block;
}

.nav-dd-menu a {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  color: var(--text2);
  text-decoration: none;
  min-height: 36px;
}

.nav-dd-menu a:hover {
  color: var(--text);
  background: var(--bg4);
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 2rem 1rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Cards */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  min-width: 0;
  overflow: hidden;
}

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

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
}

/* Buttons */
.btn {
  min-height: 44px;
  padding: 0 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.btn-sm {
  min-height: 36px;
  padding: 0 0.75rem;
  font-size: 0.875rem;
}

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

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

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-outline:hover:not(:disabled) {
  background: var(--bg3);
  border-color: var(--text2);
}

.btn-danger {
  background: var(--red);
  color: white;
}

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

.btn-danger-outline {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
}

.btn-danger-outline:hover:not(:disabled) {
  background: var(--red);
  color: white;
}

.btn-success {
  background: var(--green);
  color: white;
}

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

.btn-excel {
  background: linear-gradient(135deg, #1a7431, #217346);
  color: #fff;
  border-color: #1a7431;
}

.btn-excel:hover {
  background: linear-gradient(135deg, #155724, #1a7431);
}

.btn-excel:hover:not(:disabled) {
  background: linear-gradient(135deg, #0e5e0e, #0a4a0a);
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--text);
}

.form-control {
  width: 100%;
  padding: 0.75rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  height: 44px;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
}

.form-select {
  width: 100%;
  padding: 0.75rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  height: 44px;
  cursor: pointer;
}

.form-select:focus {
  outline: none;
  border-color: var(--accent);
}

/* Control Rows */
.ctrl-row {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.ctrl-row .form-control,
.ctrl-row .form-select {
  flex: 1;
  min-width: 150px;
}

.ctrl-row .btn {
  flex-shrink: 0;
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  transition: all 0.2s ease;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.06);
}

.dropzone svg {
  width: 48px;
  height: 48px;
  fill: var(--text2);
  margin-bottom: 1rem;
}

.dropzone h3 {
  margin: 0 0 0.5rem 0;
  color: var(--text);
}

.dropzone p {
  margin: 0;
  color: var(--text2);
}

/* Tables */
.table-wrap,
.tbl-wrap {
  overflow-x: auto;
  max-width: 100%;
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.table-students table {
  min-width: 900px;
}

.table-subjects table {
  min-width: 900px;
}

.table-summary table {
  min-width: 500px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg2);
}

th {
  background: var(--bg3);
  color: var(--text);
  font-weight: 600;
  text-align: left;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}

td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  max-width: 200px;
  overflow-wrap: break-word;
  word-break: break-word;
}

td.mono {
  font-family: var(--mono);
  white-space: nowrap;
  overflow-wrap: normal;
}

tr:hover {
  background: var(--bg4);
}

/* Sticky First Column */
.sticky-col th:first-child,
.sticky-col td:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--bg3);
}

.sticky-col td:first-child {
  background: var(--bg2);
}

.sticky-col tr:hover td:first-child {
  background: var(--bg4);
}

/* Name Column */
.name-col {
  min-width: 140px;
  max-width: 200px;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Grade Badges */
.gr {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.gr-A1 { background: #065f46; color: #6ee7b7; }
.gr-A2 { background: #064e3b; color: #34d399; }
.gr-B1 { background: #134e4a; color: #5eead4; }
.gr-B2 { background: #115e59; color: #2dd4bf; }
.gr-C1 { background: #1e3a8a; color: #60a5fa; }
.gr-C2 { background: #1e40af; color: #3b82f6; }
.gr-D1 { background: #713f12; color: #fbbf24; }
.gr-D2 { background: #92400e; color: #f59e0b; }
.gr-E { background: #7f1d1d; color: #f87171; }
.gr-AB { background: #374151; color: #9ca3af; }

/* Result Status */
.res-PASS { color: var(--green2); font-weight: 600; }
.res-FAIL { color: var(--red2); font-weight: 600; }
.res-ABSENT { color: var(--text3); font-weight: 600; }
.res-COMPTT { color: var(--yellow2); font-weight: 600; }

/* Progress Bars */
.pbar {
  width: 100%;
  height: 8px;
  background: var(--bg3);
  border-radius: 4px;
  overflow: hidden;
}

.pfill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.pfill-success { background: var(--green); }
.pfill-danger { background: var(--red); }
.pfill-warning { background: var(--yellow); }
.pfill-info { background: var(--accent); }

/* Grade Distribution Chart */
.gdist {
  display: flex;
  align-items: flex-end;
  height: 60px;
  gap: 2px;
  margin: 0.5rem 0;
}

.gdist-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 20px;
}

.gdist-fill {
  width: 100%;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  min-height: 4px;
}

.gdist-label {
  font-size: 0.7rem;
  color: var(--text2);
  margin-top: 2px;
}

/* PI Ring */
.pi-ring {
  width: 80px;
  height: 80px;
  position: relative;
}

.pi-ring svg {
  transform: rotate(-90deg);
}

.pi-ring-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

/* View Tabs */
.view-tabs {
  display: flex;
  background: var(--bg3);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.5rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.view-tabs::-webkit-scrollbar {
  display: none;
}

.view-tab {
  padding: 1rem 1.5rem;
  background: transparent;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 36px;
  display: flex;
  align-items: center;
}

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

.view-tab.active {
  background: var(--bg2);
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}

/* Grid Layouts */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 1.5rem;
}

.format-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

.sum-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.sub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

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

.three-col {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}

/* Status Indicators */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.5rem;
}

.status-ready { background: var(--green); }
.status-pending { background: var(--yellow); }
.status-error { background: var(--red); }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  background: var(--bg3);
  color: var(--text2);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-success { background: var(--green); color: white; }
.badge-danger { background: var(--red); color: white; }
.badge-warning { background: var(--yellow); color: var(--bg); }

/* Loading Spinner */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

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

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

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
}

.page-btn {
  min-height: 36px;
  padding: 0.5rem 0.75rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.875rem;
}

.page-btn:hover:not(:disabled) {
  background: var(--bg4);
  border-color: var(--text2);
}

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

.page-btn.cur {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.page-info {
  color: var(--text2);
  font-size: 0.875rem;
}

/* Export Options */
.export-options {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.clear-btns {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Subject Tags */
.subject-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.subject-tag {
  background: var(--bg3);
  color: var(--text2);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
}

/* Stream Cards */
.stream-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.stream-stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.75rem;
}

/* Footer */
footer {
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text2);
  font-size: 0.875rem;
}

footer a {
  color: var(--text);
  text-decoration: none;
}

footer a:hover {
  color: var(--accent);
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

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

.modal-content {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}

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

.modal-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: var(--text);
  background: var(--bg3);
}

.modal-body {
  padding: 1.5rem;
}

/* Privacy Banner */
.privacy-banner {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.privacy-banner p {
  flex: 1;
  margin: 0;
  color: var(--text2);
  font-size: 0.875rem;
}

/* Responsive Breakpoints */
@media (max-width: 1024px) {
  .sum-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 900px) {
  .two-col,
  .dashboard-grid,
  .upload-grid,
  .format-grid {
    grid-template-columns: 1fr;
  }
  
  .three-col {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 768px) {
  .nav-toggle {
    display: inline-flex;
  }
  
  .nav-links {
    display: none;
    position: fixed;
    top: var(--nav-h);
    left: 0;
    right: 0;
    background: var(--bg2);
    flex-direction: column;
    align-items: stretch;
    overflow-y: auto;
    max-height: calc(100vh - var(--nav-h));
    z-index: 300;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    padding: 1rem;
  }
  
  .nav-links.open {
    display: flex;
  }
  
  .nav-dd {
    width: 100%;
  }
  
  .nav-dd-btn {
    width: 100%;
    justify-content: space-between;
  }
  
  .nav-dd-menu {
    position: static;
    box-shadow: none;
    border: none;
    background: var(--bg4);
    margin-top: 0.5rem;
  }
  
  .sum-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .three-col {
    grid-template-columns: 1fr;
  }
  
  .main-content {
    padding: 1rem 0.85rem;
  }
}

@media (max-width: 480px) {
  .sum-grid {
    grid-template-columns: 1fr 1fr;
  }
  
  .sub-grid {
    grid-template-columns: 1fr;
  }
  
  .clear-btns,
  .export-options {
    flex-direction: column;
  }
  
  .btn {
    width: 100%;
    justify-content: center;
  }
  
  .btn-sm {
    width: auto;
  }
  
  .ctrl-row {
    flex-direction: column;
    align-items: stretch;
  }
  
  .ctrl-row .form-control,
  .ctrl-row .form-select {
    min-width: auto;
  }
}
