/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0f1117;
  --surface:     #1a1d27;
  --surface-alt: #22263a;
  --border:      #2e3250;
  --accent:      #4f7cf7;
  --accent-dim:  #2a3f8f;
  --text:        #dde1f5;
  --text-muted:  #7880a4;
  --ok:          #4ade80;
  --warn:        #f59e0b;
  --error:       #f87171;
  --radius:      8px;
  --font-mono:   "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== Layout ===== */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ===== Header ===== */
header { margin-bottom: 2rem; }

h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* ===== Controls ===== */
.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: flex-end;
  margin-bottom: 1.5rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

select {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  font-size: 0.95rem;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237880a4' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  cursor: pointer;
}

select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ===== SYSCLK number input ===== */
input[type="number"] {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
  width: 120px;
  font-family: var(--font-mono);
}

input[type="number"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="number"]::-webkit-inner-spin-button { opacity: 0.4; }

/* ===== File drop zone ===== */
.file-drop-zone {
  position: relative;
  background: var(--surface-alt);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  cursor: pointer;
  transition: border-color 0.2s;
  min-width: 280px;
}

.file-drop-zone.dragging { border-color: var(--accent); }

#file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.drop-hint {
  color: var(--text-muted);
  font-size: 0.9rem;
  pointer-events: none;
}

.browse-link {
  color: var(--accent);
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
  pointer-events: all;
}

/* ===== Sample link ===== */
.sample-link {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-decoration: none;
  margin-top: 0.3rem;
  display: inline-block;
}

.sample-link:hover { color: var(--accent); text-decoration: underline; }

/* ===== Parse button ===== */
button#parse-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.55rem 1.4rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  align-self: flex-end;
}

button#parse-btn:hover:not(:disabled) { background: #3b66e0; }
button#parse-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ===== Error banner ===== */
.error-banner {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid var(--error);
  color: var(--error);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

/* ===== Results ===== */
.results-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

h2 { font-size: 1.1rem; font-weight: 600; color: var(--text); }

.filename-tag {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.5rem;
  font-family: var(--font-mono);
}

.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead th {
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.65rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-alt); }

td {
  padding: 0.6rem 1rem;
  vertical-align: top;
}

/* Column: Field name */
td:nth-child(1) {
  font-family: var(--font-mono);
  font-size: 0.83rem;
  color: var(--accent);
  white-space: nowrap;
}

/* Column: Bits */
td:nth-child(3) {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Column: Raw value */
td:nth-child(4) {
  font-family: var(--font-mono);
  font-size: 0.83rem;
  white-space: nowrap;
}

/* Column: Meaning */
td:nth-child(5) { }

/* Meaning states */
.meaning-ok    { color: var(--ok); }
.meaning-unknown {
  color: var(--warn);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.meaning-unknown .badge {
  font-size: 0.7rem;
  font-weight: 700;
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  color: var(--warn);
  white-space: nowrap;
}

/* ===== Derived Frequencies ===== */
#frequencies { margin-top: 2rem; }

.freq-groups {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.freq-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.freq-card h3 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.freq-table { width: 100%; border-collapse: collapse; }

.freq-table tr + tr td { padding-top: 0.45rem; }

.freq-label {
  font-size: 0.85rem;
  color: var(--text);
  white-space: nowrap;
  padding-right: 0.75rem;
}

.freq-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  padding-right: 0.75rem;
}

.freq-value {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--ok);
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

.freq-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* ===== Frequency limit indicators ===== */
.freq-out { color: var(--error) !important; }

.freq-limit-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 3px;
  padding: 0.05rem 0.3rem;
  margin-left: 0.4rem;
  vertical-align: middle;
  line-height: 1.4;
}

.freq-over-badge {
  background: rgba(248, 113, 113, 0.15);
  border: 1px solid rgba(248, 113, 113, 0.5);
  color: var(--error);
}

.freq-under-badge {
  background: rgba(248, 113, 113, 0.15);
  border: 1px solid rgba(248, 113, 113, 0.5);
  color: var(--error);
}

/* ===== CRC badge ===== */
.crc-badge {
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 4px;
  padding: 0.15rem 0.55rem;
  font-family: var(--font-mono);
  cursor: default;
}
.crc-none  { background: var(--surface-alt); color: var(--text-muted); border: 1px solid var(--border); }
.crc-ok    { background: rgba(74, 222, 128, 0.12); color: var(--ok);    border: 1px solid rgba(74, 222, 128, 0.4); }
.crc-fail  { background: rgba(248, 113, 113, 0.12); color: var(--error); border: 1px solid rgba(248, 113, 113, 0.4); }

/* ===== Observed Issues ===== */
#issues { margin-top: 2rem; }

.issues-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.issue-item {
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
  border-left: 3px solid transparent;
}

.issue-error {
  background: rgba(248, 113, 113, 0.08);
  border-left-color: var(--error);
  color: var(--error);
}

.issue-warn {
  background: rgba(245, 158, 11, 0.08);
  border-left-color: var(--warn);
  color: var(--warn);
}

.issues-none {
  color: var(--ok);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* ===== SerDes hover tooltip ===== */
.serdes-row { cursor: default; }
.serdes-row:hover td:nth-child(1) { text-decoration: underline dotted var(--accent); }

.serdes-tooltip {
  position: absolute;
  z-index: 9999;
  background: var(--surface);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  max-width: 740px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  pointer-events: none;
}

.sd-title {
  font-size: 0.78rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent);
  margin-bottom: 0.6rem;
}

.sd-group-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-top: 0.65rem;
  margin-bottom: 0.25rem;
}

.sd-lane-table {
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  width: 100%;
}

.sd-lane-table th {
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: 0.2rem 0.35rem;
  text-align: center;
  border: 1px solid var(--border);
  min-width: 56px;
}

.sd-lane-table td {
  padding: 0.25rem 0.35rem;
  text-align: center;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.sd-used   { color: var(--ok); }
.sd-unused { color: var(--text-muted); }

/* ===== Footer ===== */
.app-footer {
  margin-top: 3rem;
  padding: 1rem 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

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

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

.footer-sep {
  margin: 0 0.5rem;
}

/* ===== Utility ===== */
.hidden { display: none !important; }
