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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #f8fafc;
  color: #1e293b;
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  zoom: 1.1;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 2rem;
}

.header-logo {
  margin-bottom: 0.5rem;
}

.mikrotik-logo {
  height: 5rem;
  width: auto;
  fill: #0f172a;
}

header h1 {
  font-size: 2.75rem;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.02em;
  margin-bottom: 0.75rem;
}

.subtitle {
  color: #64748b;
  font-size: 0.95rem;
  max-width: 580px;
  margin: 0 auto;
  line-height: 1.6;
}

/* Input Section */
.input-section {
  margin-bottom: 2rem;
}

.input-wrapper {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

#productCode {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 1.1rem;
  font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
  border: 2px solid #cbd5e1;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s;
  background: #fff;
}

#productCode:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

#productCode::placeholder {
  color: #94a3b8;
}

#decodeBtn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: #2563eb;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

#decodeBtn:hover {
  background: #1d4ed8;
}

#decodeBtn:active {
  background: #1e40af;
}

/* Example buttons */
.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  align-items: center;
}

.examples-label {
  font-size: 0.8rem;
  color: #94a3b8;
  margin-right: 0.25rem;
}

.example-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
  color: #475569;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.example-btn:hover {
  background: #e2e8f0;
  color: #1e293b;
}

/* Result Section */
.result-section {
  animation: fadeIn 0.2s ease-out;
}

.result-section.hidden,
.error-section.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Decoded Code Display */
.decoded-code {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 1.5rem 1.5rem;
  padding-top: 3rem;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px 10px 0 0;
  font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
  font-size: 2.25rem;
  font-weight: 700;
  overflow: visible;
}

.code-segment {
  position: relative;
  padding: 0 0.35rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.code-segment:hover,
.code-segment.highlight {
}

.code-segment .segment-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.4rem 0.4rem;
  font-size: 0.65rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 500;
  color: #fff;
  background: #1e293b;
  border-radius: 5px;
  white-space: nowrap;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: translateX(-50%) rotate(180deg);
  z-index: 10;
  pointer-events: none;
}

.code-segment .segment-tooltip::after {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-bottom-color: #1e293b;
}

.code-segment:hover .segment-tooltip,
.code-segment.highlight .segment-tooltip {
  display: block;
}

.code-group {
  display: inline-flex;
  align-items: center;
  border: 2px solid #cbd5e1;
  border-radius: 6px;
  padding: 0.25rem;
  gap: 0.2rem;
  transition: all 0.15s;
}

.code-group.highlight {
  box-shadow: 0 2px 10px rgba(0,0,0,0.12);
}

.code-group .code-segment {
  border-bottom: none;
  border-radius: 3px;
}

.code-separator {
  color: #94a3b8;
  padding: 0 0.05rem;
  font-weight: 400;
}

/* Breakdown Panel */
.breakdown {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-top: none;
  border-radius: 0 0 10px 10px;
  overflow: hidden;
}

.breakdown-item {
  display: flex;
  gap: 1rem;
  padding: 0.875rem 1.25rem;
  border-top: 1px solid #f1f5f9;
  transition: background 0.15s;
}

.breakdown-item:hover,
.breakdown-item.highlight {
  background: #f0f4ff;
}

.breakdown-item.flash {
  animation: breakdown-flash 0.7s ease-out;
}

@keyframes breakdown-flash {
  0%   { background: #bfdbfe; }
  60%  { background: #bfdbfe; }
  100% { background: transparent; }
}

.breakdown-item:first-child {
  border-top: 1px solid #e2e8f0;
}

.breakdown-color {
  flex-shrink: 0;
  width: auto;
  min-width: 2.5rem;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 0.125rem;
}

.breakdown-color-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
  font-size: 0.85rem;
  font-weight: 700;
  min-width: 1.75rem;
  text-align: center;
  white-space: nowrap;
}

.breakdown-icon {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  padding-top: 0.15rem;
  color: #94a3b8;
}

.breakdown-icon svg {
  width: 1.5rem;
  height: 1.5rem;
}

.breakdown-item:hover .breakdown-icon,
.breakdown-item.highlight .breakdown-icon {
  color: #64748b;
}

.breakdown-content {
  flex: 1;
  min-width: 0;
}

.breakdown-label {
  font-weight: 600;
  font-size: 0.9rem;
  color: #0f172a;
  margin-bottom: 0.125rem;
}

.breakdown-description {
  font-size: 0.85rem;
  color: #475569;
  line-height: 1.5;
}

.breakdown-item.unknown {
  background: #fffbeb;
}

.breakdown-item.unknown .breakdown-color-chip {
  background: #fef3c7 !important;
  color: #92400e !important;
  border: 1px dashed #f59e0b !important;
}

.breakdown-label .unknown-badge {
  display: inline-block;
  margin-left: 0.375rem;
  padding: 0.05rem 0.35rem;
  font-size: 0.65rem;
  font-weight: 600;
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 3px;
  vertical-align: middle;
}

/* Breakdown Group */
.breakdown-group {
  border-left: 3px solid #cbd5e1;
  margin: 0.25rem 0;
  overflow: hidden;
}

.breakdown-group-header {
  padding: 0.375rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  border-bottom: 1px solid #f1f5f9;
}

.breakdown-group .breakdown-item {
  padding-left: 1.5rem;
  border-top: 1px solid #f1f5f9;
}

.breakdown-group .breakdown-item:first-of-type {
  border-top: none;
}

/* Block Diagram */
.block-diagram {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
  margin-top: 1rem;
}

.block-diagram.hidden {
  display: none;
}

.block-diagram-header {
  padding: 0.625rem 1.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.block-diagram-content {
  padding: 1rem;
  text-align: center;
}

.block-diagram-content a {
  display: inline-block;
  cursor: zoom-in;
}

.block-diagram-content img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  transition: opacity 0.15s;
}

.block-diagram-content a:hover img {
  opacity: 0.85;
}

/* Error */
.error-section {
  padding: 1rem 1.25rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #991b1b;
  font-size: 0.9rem;
}

/* Footer */
footer {
  margin-top: 3rem;
  text-align: center;
}

footer p {
  font-size: 0.8rem;
  color: #94a3b8;
}

.disclaimer {
  color: #94a3b8;
  line-height: 1.6;
}

.disclaimer a {
  color: #94a3b8;
  text-decoration: underline;
}

.disclaimer a:hover {
  color: #64748b;
}

/* Glossary Term (inline in descriptions) */
.glossary-term {
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: #94a3b8;
  text-underline-offset: 2px;
  cursor: help;
  transition: text-decoration-color 0.15s, color 0.15s;
}

.glossary-term:hover {
  text-decoration-color: #3b82f6;
  color: #1d4ed8;
}

/* Glossary Tooltip (floating popup) */
.glossary-tooltip {
  display: none;
  position: absolute;
  z-index: 1000;
  max-width: 340px;
  padding: 0.75rem 1rem;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  font-size: 0.82rem;
  line-height: 1.5;
  pointer-events: auto;
  --arrow-left: 50%;
}

/* Arrow pointing down (default: tooltip above the term) */
.glossary-tooltip::after {
  content: "";
  position: absolute;
  bottom: -8px;
  left: var(--arrow-left);
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: #0f172a;
  border-bottom: none;
}

/* Arrow pointing up (fallback: tooltip below the term) */
.glossary-tooltip.glossary-tooltip-below::after {
  bottom: auto;
  top: -8px;
  border: 8px solid transparent;
  border-bottom-color: #0f172a;
  border-top: none;
}

.glossary-tooltip-term {
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
  margin-bottom: 0.3rem;
  font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
}

.glossary-tooltip-def {
  color: #cbd5e1;
  margin-bottom: 0.5rem;
}

.glossary-tooltip-link {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: #60a5fa;
  text-decoration: none;
  transition: color 0.15s;
}

.glossary-tooltip-link svg {
  vertical-align: -1px;
  margin-left: 2px;
}

.glossary-tooltip-link:hover {
  color: #93bbfc;
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 600px) {
  .container {
    padding: 1.25rem 1rem;
  }

  header h1 {
    font-size: 1.35rem;
  }

  .input-wrapper {
    flex-direction: column;
  }

  #decodeBtn {
    width: 100%;
  }

  .decoded-code {
    font-size: 1.5rem;
    padding: 1rem;
    padding-top: 2.5rem;
  }

  .breakdown-item {
    flex-direction: column;
    gap: 0.375rem;
    padding: 0.75rem 1rem;
  }

  .breakdown-icon {
    display: none;
  }

  .breakdown-color {
    width: auto;
    justify-content: flex-start;
  }
}
