@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=Inter:wght@300;400;500;600;700&display=swap');

/* ─── Reset & Base ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0d1117;
  --bg-2:        #161b22;
  --bg-3:        #1c2330;
  --border:      rgba(255,255,255,0.08);
  --border-2:    rgba(255,255,255,0.14);
  --primary:     #00e5a0;
  --primary-dim: rgba(0,229,160,0.12);
  --primary-glow:rgba(0,229,160,0.25);
  --accent:      #58a6ff;
  --warn:        #f0883e;
  --error:       #f85149;
  --success:     #3fb950;
  --text-1:      #e6edf3;
  --text-2:      #8b949e;
  --text-3:      #484f58;
  --mono:        'JetBrains Mono', monospace;
  --sans:        'Inter', sans-serif;
  --radius:      10px;
  --radius-sm:   6px;
  --sidebar-w:   64px;
  --header-h:    52px;
  --transition:  all 0.2s cubic-bezier(0.4,0,0.2,1);
}

html { font-size: 14px; }

body {
  background: var(--bg);
  color: var(--text-1);
  font-family: var(--sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ─── Header ────────────────────────────────────────── */
.header {
  height: var(--header-h);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.logo-icon {
  width: 30px; height: 30px;
  background: var(--primary);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  box-shadow: 0 0 16px var(--primary-glow);
  flex-shrink: 0;
}

.logo-text {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.5px;
}

.logo-text span { color: var(--primary); }

.header-tagline {
  font-size: 12px;
  color: var(--text-2);
  border-left: 1px solid var(--border-2);
  padding-left: 12px;
  margin-left: 4px;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-badge {
  font-size: 11px;
  font-family: var(--mono);
  background: var(--primary-dim);
  color: var(--primary);
  border: 1px solid rgba(0,229,160,0.3);
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
}

/* ─── Layout ─────────────────────────────────────────── */
.app-layout {
  display: flex;
  margin-top: var(--header-h);
  min-height: calc(100vh - var(--header-h));
}

/* ─── Sidebar ────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 4px;
  position: fixed;
  top: var(--header-h);
  left: 0;
  bottom: 0;
  z-index: 50;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar::-webkit-scrollbar {
  width: 4px;
}
.sidebar::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: 2px;
}
.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

.nav-item {
  width: 48px; height: 48px;
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
  background: transparent;
  position: relative;
}

.nav-item:hover {
  background: var(--bg-3);
  border-color: var(--border);
}

.nav-item.active {
  background: var(--primary-dim);
  border-color: rgba(0,229,160,0.35);
  box-shadow: 0 0 12px rgba(0,229,160,0.1);
}

.nav-item .nav-icon { font-size: 18px; line-height: 1; }
.nav-item .nav-label {
  font-size: 8px;
  font-family: var(--mono);
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.nav-item.active .nav-label { color: var(--primary); }

.nav-divider {
  width: 32px;
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* Tooltip (Disabled due to overflow clipping, replaced by native title tooltips) */
.nav-item::after {
  display: none;
}

/* ─── Main Content ───────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 32px;
  max-width: 1100px;
}

/* ─── Tool Panel ─────────────────────────────────────── */
.tool-panel { display: none; }
.tool-panel.active { display: block; }

.tool-header {
  margin-bottom: 28px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.tool-icon-lg {
  width: 48px; height: 48px;
  background: var(--primary-dim);
  border: 1px solid rgba(0,229,160,0.3);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.tool-title { font-size: 22px; font-weight: 700; color: var(--text-1); margin-bottom: 4px; }
.tool-desc  { font-size: 13px; color: var(--text-2); line-height: 1.6; }

/* ─── Calculator Grid ────────────────────────────────── */
.calc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 768px) {
  .calc-grid { grid-template-columns: 1fr; }
  .main-content { padding: 20px 16px; }
}

/* ─── Card ───────────────────────────────────────────── */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  transition: var(--transition);
}

.card:hover { border-color: var(--border-2); }

.card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title::before {
  content: '';
  display: inline-block;
  width: 3px; height: 14px;
  background: var(--primary);
  border-radius: 2px;
}

/* ─── Form Controls ──────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }

.form-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-label .unit {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-3);
  background: var(--bg-3);
  padding: 2px 8px;
  border-radius: 4px;
}

.form-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-1);
  font-family: var(--mono);
  font-size: 14px;
  transition: var(--transition);
  outline: none;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}

.form-input::placeholder { color: var(--text-3); }

select.form-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%238b949e'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px;
  padding-right: 36px;
  cursor: pointer;
}

select.form-input option { background: var(--bg-2); }

/* ─── Result Items ───────────────────────────────────── */
.result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.result-item:last-child { border-bottom: none; padding-bottom: 0; }

.result-label { font-size: 12px; color: var(--text-2); font-weight: 500; }

.result-value {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  text-align: right;
}

.result-value.secondary { color: var(--accent); font-size: 14px; }
.result-value.warn      { color: var(--warn); }
.result-value.error     { color: var(--error); }
.result-value.success   { color: var(--success); }

.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
}
.result-badge.pass { background: rgba(63,185,80,0.15); color: var(--success); border: 1px solid rgba(63,185,80,0.3); }
.result-badge.fail { background: rgba(248,81,73,0.15); color: var(--error);   border: 1px solid rgba(248,81,73,0.3); }
.result-badge.warn { background: rgba(240,136,62,0.15); color: var(--warn);  border: 1px solid rgba(240,136,62,0.3); }

/* ─── Bit Field Visualizer ───────────────────────────── */
.bit-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin-bottom: 16px;
}

.bit-cell {
  aspect-ratio: 1;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid var(--border);
  background: var(--bg);
}

.bit-cell .bit-index { font-size: 7px; color: var(--text-3); }
.bit-cell .bit-val   { font-size: 13px; font-weight: 700; }

.bit-cell.bit-1 {
  background: var(--primary-dim);
  border-color: rgba(0,229,160,0.4);
  box-shadow: 0 0 8px rgba(0,229,160,0.15);
}
.bit-cell.bit-1 .bit-val { color: var(--primary); }
.bit-cell.bit-0 .bit-val { color: var(--text-3); }

.bit-cell:hover {
  border-color: var(--primary);
  transform: scale(1.08);
}

.bit-row-label {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-3);
  font-family: var(--mono);
  margin-bottom: 4px;
  padding: 0 2px;
}

/* Byte separator */
.bit-grid-section { margin-bottom: 12px; }
.byte-label {
  font-size: 10px;
  color: var(--text-3);
  font-family: var(--mono);
  text-align: center;
  margin-bottom: 4px;
}

/* ─── CRC Table ──────────────────────────────────────── */
.crc-results {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.crc-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.crc-row:last-child { border-bottom: none; }

.crc-name  { font-size: 12px; color: var(--text-2); font-weight: 600; }
.crc-poly  { font-size: 11px; color: var(--text-3); font-family: var(--mono); }
.crc-value { font-family: var(--mono); font-size: 15px; font-weight: 700; color: var(--primary); }

.btn-copy-crc {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-2);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--sans);
}
.btn-copy-crc:hover { border-color: var(--primary); color: var(--primary); }

/* ─── Home / Welcome Panel ───────────────────────────── */
.welcome-panel {
  max-width: 640px;
  margin: 40px auto;
  text-align: center;
}

.welcome-icon {
  font-size: 64px;
  margin-bottom: 24px;
  display: block;
  filter: drop-shadow(0 0 24px rgba(0,229,160,0.3));
}

.welcome-title {
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--text-1), var(--primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.welcome-desc {
  font-size: 15px;
  color: var(--text-2);
  line-height: 1.7;
  margin-bottom: 40px;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  text-align: left;
}

@media (max-width: 520px) { .tool-grid { grid-template-columns: 1fr; } }

.tool-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 12px;
}

.tool-card:hover {
  border-color: var(--primary);
  background: var(--bg-3);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.tool-card-icon {
  width: 40px; height: 40px;
  background: var(--primary-dim);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.tool-card-name { font-size: 13px; font-weight: 600; color: var(--text-1); }
.tool-card-desc { font-size: 11px; color: var(--text-2); margin-top: 2px; }

/* ─── Info Box ───────────────────────────────────────── */
.info-box {
  background: rgba(88,166,255,0.08);
  border: 1px solid rgba(88,166,255,0.2);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 12px;
  color: var(--accent);
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 16px;
  line-height: 1.6;
}

/* ─── Scrollbar ──────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-2); }
/* Carbon Ads */
.carbon-wrapper {
  padding: 8px 6px;
  margin-top: auto;
  border-top: 1px solid var(--border);
}
#carbonads {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
  background: var(--surface);
  border-radius: 6px;
  padding: 8px;
}
#carbonads a { color: var(--text-secondary); text-decoration: none; }
#carbonads a:hover { color: var(--text-primary); }
.carbon-img img { width: 100%; border-radius: 4px; display: block; }
.carbon-poweredby { font-size: 10px; opacity: 0.5; text-align: right; }

/* ─── Struct Alignment Visualizer ────────────────────── */
.struct-visual-grid-container {
  border: 1px solid var(--border);
  background: var(--bg-2);
  border-radius: var(--radius-sm);
  padding: 10px;
}
.grid-row-label {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  color: var(--text-2);
  padding-right: 6px;
  font-weight: 600;
}
.grid-byte-cell {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-weight: 500;
  transition: var(--transition);
  cursor: help;
  user-select: none;
  font-size: 10px;
}
.grid-byte-cell.data-cell {
  background: var(--primary-dim);
  border: 1px solid var(--primary);
  color: var(--primary);
}
.grid-byte-cell.data-cell:hover {
  box-shadow: 0 0 10px var(--primary-glow);
}
.grid-byte-cell.padding-cell {
  background: rgba(224, 108, 117, 0.15);
  border: 1px solid #e06c75;
  color: #e06c75;
}
.grid-byte-cell.padding-cell:hover {
  box-shadow: 0 0 10px rgba(224, 108, 117, 0.4);
}
.grid-byte-cell.empty-cell {
  background: transparent;
  border: 1px dashed var(--text-3);
  opacity: 0.3;
}
.row-padding {
  background: rgba(224, 108, 117, 0.05);
  color: #e06c75;
}
.row-padding td {
  border-top: 1px dashed rgba(224, 108, 117, 0.2);
  border-bottom: 1px dashed rgba(224, 108, 117, 0.2);
}