@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
  --bg: #090d16;
  --bg-gradient: radial-gradient(circle at 50% 0%, #151d30 0%, #090d16 75%);
  --surface: rgba(18, 26, 43, 0.85);
  --surface-card: #151f33;
  --surface-hover: #1e2c47;
  --surface-active: #283a5e;
  --border: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(99, 102, 241, 0.5);
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --primary: #6366f1;
  --primary-glow: rgba(99, 102, 241, 0.25);
  --primary-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --ok: #10b981;
  
  --g0: #ef4444;
  --g0-glow: rgba(239, 68, 68, 0.35);
  --g1: #f97316;
  --g1-glow: rgba(249, 115, 22, 0.35);
  --g2: #eab308;
  --g2-glow: rgba(234, 179, 8, 0.35);
  --g3: #10b981;
  --g3-glow: rgba(16, 185, 129, 0.35);
  --g4: #06b6d4;
  --g4-glow: rgba(6, 182, 212, 0.35);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.5), 0 0 1px 1px rgba(255, 255, 255, 0.05);
}

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

body {
  min-height: 100vh;
  background: var(--bg);
  background-image: var(--bg-gradient);
  color: var(--text);
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Header */
header {
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
}

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

.brand-icon {
  font-size: 22px;
  filter: drop-shadow(0 2px 8px var(--primary-glow));
}

h1 {
  font-family: 'Outfit', sans-serif;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 20px;
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.spacer {
  flex: 1;
}

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

#saveTick {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ok);
  background: rgba(16, 185, 129, 0.12);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid rgba(16, 185, 129, 0.25);
  opacity: 0;
  transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s ease;
  transform: translateY(2px);
  pointer-events: none;
}

#saveTick.visible {
  opacity: 1;
  transform: translateY(0);
}

.progress-info {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
}

.progress-info strong {
  color: var(--text);
}

/* Buttons & Inputs */
button {
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text);
  padding: 8px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s ease;
}

button:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary-grad);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.05);
}

select, input[type=text], input[type=number] {
  font-family: inherit;
  font-size: 13.5px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text);
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select:focus, input[type=text]:focus, input[type=number]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* Progress Track */
#barTrack {
  height: 5px;
  background: rgba(255, 255, 255, 0.04);
  width: 100%;
}

#barFill {
  height: 100%;
  width: 0%;
  background: var(--primary-grad);
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 8px var(--primary-glow);
}

/* Main */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* Dropzone Empty State */
#dropzone {
  width: 100%;
  max-width: 680px;
  margin: 60px auto;
  border: 2px dashed rgba(99, 102, 241, 0.35);
  border-radius: var(--radius-lg);
  padding: 50px 32px;
  text-align: center;
  background: rgba(19, 27, 43, 0.5);
  backdrop-filter: blur(12px);
  cursor: pointer;
  transition: all 0.2s ease;
}

#dropzone:hover, #dropzone.dragover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.08);
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
}

.drop-icon {
  font-size: 54px;
  margin-bottom: 16px;
  display: block;
}

.drop-title {
  font-family: 'Outfit', sans-serif;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

.drop-desc {
  font-size: 14.5px;
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 480px;
  margin: 0 auto 24px auto;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-top: 24px;
  text-align: left;
}

.feature-pill {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-muted);
}

.feature-pill strong {
  display: block;
  color: var(--text);
  margin-bottom: 3px;
}

/* Toolbar */
.toolbar {
  width: 100%;
  max-width: 960px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

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

.stat-pills {
  display: flex;
  gap: 6px;
}

.stat-pill {
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* Stage */
#stage {
  width: 100%;
  max-width: 960px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#viewerWrap {
  width: 100%;
  height: 58vh;
  min-height: 380px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #06090f;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

#viewer {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: transform 0.2s ease;
  user-select: none;
}

#filename {
  margin-top: 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

/* Grade Buttons */
#grades {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.gbtn {
  width: 60px;
  height: 60px;
  border-radius: 14px;
  font-family: 'Outfit', sans-serif;
  font-size: 22px;
  font-weight: 700;
  border: 2px solid var(--border);
  background: var(--surface-card);
  color: var(--text);
  cursor: pointer;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.gbtn:hover {
  transform: translateY(-3px);
  border-color: rgba(255, 255, 255, 0.25);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.gbtn .key-hint {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-dim);
  position: absolute;
  bottom: 4px;
}

.gbtn.sel {
  color: #fff;
  transform: scale(1.06);
}

.gbtn[data-g="0"].sel { background: var(--g0); border-color: var(--g0); box-shadow: 0 0 24px var(--g0-glow); }
.gbtn[data-g="1"].sel { background: var(--g1); border-color: var(--g1); box-shadow: 0 0 24px var(--g1-glow); }
.gbtn[data-g="2"].sel { background: var(--g2); border-color: var(--g2); box-shadow: 0 0 24px var(--g2-glow); }
.gbtn[data-g="3"].sel { background: var(--g3); border-color: var(--g3); box-shadow: 0 0 24px var(--g3-glow); }
.gbtn[data-g="4"].sel { background: var(--g4); border-color: var(--g4); box-shadow: 0 0 24px var(--g4-glow); }

/* Navigation */
#nav {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  align-items: center;
}

#nav input {
  width: 75px;
  text-align: center;
}

#hint {
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--text-dim);
  text-align: center;
  display: flex;
  align-items: center;
  gap: 10px;
}

.kbd {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  color: var(--text-muted);
}

#folderInput {
  display: none;
}

/* Modal Backdrop */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(4, 7, 13, 0.75);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: #111827;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 820px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.75);
  overflow: hidden;
  animation: modalEnter 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalEnter {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

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

/* Telemetry Cards */
.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 20px 24px 10px 24px;
}

.telemetry-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
}

.telemetry-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.telemetry-value {
  font-family: 'Outfit', sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

/* Breakdown Box */
.breakdown-box {
  padding: 10px 24px;
}

.breakdown-bars {
  display: flex;
  height: 24px;
  border-radius: 6px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.05);
}

.bar-segment {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  transition: width 0.3s ease;
}

/* DB Table */
.db-table-wrap {
  flex: 1;
  overflow-y: auto;
  max-height: 260px;
  margin: 0 24px 16px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.2);
}

.db-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 12.5px;
}

.db-table th {
  background: #1f2937;
  color: var(--text-muted);
  font-weight: 600;
  padding: 9px 12px;
  position: sticky;
  top: 0;
  border-bottom: 1px solid var(--border);
}

.db-table td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.db-table tr:hover td {
  background: rgba(255, 255, 255, 0.03);
}

.badge-grade {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0, 0, 0, 0.2);
}

