* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  line-height: 1.6;
  color: #333;
  background-color: #f5f5f5;
}

/* Breadcrumb */
.breadcrumb {
  margin-bottom: 1rem;
}

.breadcrumb ol {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: #666;
}

.breadcrumb li + li::before {
  content: '›';
  margin-right: 0.25rem;
  color: #aaa;
}

.breadcrumb a {
  color: #2166a5;
  text-decoration: none;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

.breadcrumb li:last-child {
  color: #333;
  font-weight: 500;
}

/* Header & Navigation */
header {
  background-color: #2c3e50;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.navbar {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  color: #fff;
  font-size: 1.5rem;
  font-weight: bold;
  text-decoration: none;
}

.nav-links {
  list-style: none;
  display: flex;
  gap: 2rem;
}

.nav-links a {
  color: #ecf0f1;
  text-decoration: none;
  transition: color 0.3s;
}

/* Dropdown Menu */
.dropdown {
  position: relative;
}

.dropdown > a {
  cursor: pointer;
}

.dropdown-menu {
  list-style: none;
  position: absolute;
  top: 100%;
  left: 0;
  background-color: #34495e;
  min-width: 200px;
  padding: 0.5rem 0;
  border-radius: 4px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: opacity 0.3s, visibility 0.3s, transform 0.3s;
  z-index: 1000;
}

.dropdown:hover .dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-menu li {
  margin: 0;
}

.dropdown-menu a {
  display: block;
  padding: 0.75rem 1.5rem;
  color: #ecf0f1;
  text-decoration: none;
  transition: background-color 0.3s;
}

.dropdown-menu a:hover {
  background-color: #2c3e50;
  color: #2166a5;
}

.dropdown-menu li:first-child a {
  border-radius: 4px 4px 0 0;
}

.dropdown-menu li:last-child a {
  border-radius: 0 0 4px 4px;
}

.nav-links a:hover {
  color: #2166a5;
}

/* Main Layout */
.container {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1rem;
  display: grid;
  grid-template-columns: 200px 1fr 200px;
  gap: 2rem;
}

.content {
  background: white;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  min-width: 0;
}

/* Ad Slots */
.ad-slot {
  background: #e8e8e8;
  border-radius: 8px;
  min-height: 600px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  font-size: 0.875rem;
}

/* Typography */
h1 {
  color: #2c3e50;
  margin-bottom: 1rem;
  font-size: 2rem;
}

h2 {
  color: #34495e;
  margin-top: 2rem;
  margin-bottom: 1rem;
  font-size: 1.5rem;
}

h3 {
  color: #34495e;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  font-size: 1.2rem;
}

p {
  margin-bottom: 1rem;
}

/* Converter List */
.converter-list {
  list-style: none;
  padding: 0;
}

.converter-list li {
  margin-bottom: 0.75rem;
}

.converter-list a {
  color: #2166a5;
  text-decoration: none;
  font-size: 1.1rem;
  transition: color 0.3s;
}


.converter-list a:hover {
  color: #15406a;
  text-decoration: underline;
}

/* Category table on home page */
.category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin: 1rem 0 1.5rem 0;
}

.category-card {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: #e0f5f5;
  border: 2px solid #7ecece;
  border-radius: 8px;
  padding: 0.85rem 0.75rem;
  text-decoration: none;
  color: #1a5f6e;
  font-size: 0.95rem;
  font-weight: 600;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.category-card:hover {
  border-color: #1a9aa0;
  background: #b2e8e8;
  color: #0e4a56;
}


.category-card.active {
  border-color: #2166a5;
  background: #2166a5;
  color: #fff;
}


.category-card.active:hover {
  background: #15406a;
  border-color: #15406a;
  color: #fff;
}

/* Quick Answer Box */
.quick-answer {
  background: #e8f4fd;
  border-left: 4px solid #2166a5;
  border-radius: 4px;
  padding: 1rem 1.5rem;
  margin: 1.5rem 0;
  font-size: 1.1rem;
}

.quick-answer p {
  margin: 0;
}

.quick-answer strong {
  color: #15406a;
  font-size: 1.25rem;
}

/* Converter Box */
.converter-box {
  background: #f8f9fa;
  border: 2px solid #e9ecef;
  border-radius: 8px;
  padding: 1.5rem 1rem;
  margin: 2rem 0;
}

.converter-box label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: #2c3e50;
}

.converter-box input {
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  margin-bottom: 1rem;
}

.converter-box button {
  background-color: #2166a5;
  color: white;
  border: none;
  padding: 0.75rem 2rem;
  font-size: 1rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.converter-box button:hover {
  background-color: #15406a;
}

.converter-box select {
  font-weight: bold;
}

/* Converter Grid Layout */
.converter-grid {
  position: relative;
  margin: 0 0 1.5rem 0;
  padding-right: 3.5rem;
}

.converter-row {
  display: grid;
  grid-template-columns: 55px 1fr 1fr;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}

.converter-row label {
  margin-bottom: 0;
  text-align: right;
  font-weight: bold;
  color: #2c3e50;
}

.converter-row input {
  margin-bottom: 0;
}

.converter-row select {
  margin-top: 0;
  margin-bottom: 0;
  max-height: 340px;
  overflow-y: auto;
  display: none; /* hidden until custom-select.js replaces with styled dropdown */
}

/* keep listbox selects (select[size]) visible - they are not replaced */
.converter-row select[size] {
  display: block;
}

/* Listbox select (main converter pages) */
.converter-row select[size] {
  height: auto;
  max-height: 340px;
  padding: 0;
  border: 1px solid #ced4da;
  border-radius: 4px;
  font-size: 0.9rem;
  background-color: #fff;
  width: 100%;
  cursor: pointer;
  overflow-y: auto;
}

.converter-row select[size] option {
  padding: 0.4rem 0.75rem;
}

.converter-row select[size] option:checked {
  background-color: #2166a5;
  color: white;
}

/* Unit badge (generated pair pages) */
.unit-badge {
  display: inline-flex;
  align-items: center;
  background: #e8f4fd;
  border: 1.5px solid #2166a5;
  border-radius: 4px;
  padding: 0.6rem 1rem;
  font-weight: 700;
  color: #2c3e50;
  font-size: 1rem;
  width: 100%;
  box-sizing: border-box;
}

.swap-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  background: #2166a5;
  color: white;
  border-radius: 50%;
  text-decoration: none;
  transition: background-color 0.2s, transform 0.3s;
  user-select: none;
}

.swap-btn svg {
  display: block;
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: white;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Side-by-side layout (main full converter pages) */
.converter-grid-side {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  max-width: 700px;
  margin: 0 auto 1.5rem auto;
}

.converter-col {
  display: flex;
  flex-direction: column;
}

.converter-col label {
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 0.5rem;
}

.converter-col input {
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  margin-bottom: 0.5rem;
  box-sizing: border-box;
  width: 100%;
}

.converter-col select[size] {
  flex: 1;
  height: auto;
  max-height: 340px;
  padding: 0;
  border: 1px solid #ced4da;
  border-radius: 4px;
  font-size: 0.9rem;
  background-color: #fff;
  width: 100%;
  cursor: pointer;
  overflow-y: auto;
}

.converter-col select[size] option {
  padding: 0.4rem 0.75rem;
}

.converter-col select[size] option:checked {
  background-color: #2166a5;
  color: white;
}

.swap-btn:hover {
  background-color: #15406a;
  transform: rotate(180deg);
}

/* Swap button positioned in converter-grid right padding */
.swap-btn-main {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  cursor: pointer;
}

/* Higher specificity needed to override .converter-box button { padding; border-radius; transition } */
.converter-box .swap-btn-main {
  padding: 0;
  border-radius: 50%;
  width: 2.4rem;
  height: 2.4rem;
  transition: background-color 0.2s, transform 0.3s;
}

.swap-btn-main:hover {
  transform: translateY(-50%) rotate(180deg);
}

.swap-btn-main:disabled {
  background: #a8c9e8;
  cursor: not-allowed;
  transform: translateY(-50%);
}

.swap-btn-main:disabled:hover {
  transform: translateY(-50%);
}

.result {
  margin-top: 1rem;
  padding: 1rem;
  background: #e8f4f8;
  border-left: 4px solid #2166a5;
  border-radius: 4px;
  font-weight: 600;
  color: #2c3e50;
  min-height: 3rem;
  text-align: center;
  font-size: 1.25rem;
  box-sizing: border-box;
  min-width: 100%;
}

.result.number-resizable {
  overflow-x: auto;
  resize: horizontal;
  cursor: col-resize;
  word-break: normal;
}

.result.fx-resizable {
  overflow-x: auto;
  resize: horizontal;
  cursor: col-resize;
  word-break: normal;
}

/* Formula Display */
.formula {
  background: #f8f9fa;
  border-left: 4px solid #2166a5;
  padding: 1rem;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  overflow: auto;
  white-space: pre;
  max-height: 450px;
}
.formula.formula-rx { resize: horizontal; cursor: col-resize; }
.formula.formula-ry { resize: vertical;   cursor: row-resize; max-height: none; }
.formula.formula-rx.formula-ry { resize: both; cursor: nwse-resize; }

/* Quick reference conversion table */
.ref-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.95rem;
}

.ref-table thead th {
  background: #2166a5;
  color: white;
  padding: 0.55rem 1rem;
  text-align: left;
  font-weight: 600;
}

.ref-table td {
  padding: 0.45rem 1rem;
  border-bottom: 1px solid #e8e8e8;
}

.ref-table tbody tr:nth-child(even) td {
  background: #f8f9fa;
}

/* Footer */
footer {
  background-color: #2c3e50;
  color: #ecf0f1;
  padding: 2rem;
  margin-top: 4rem;
  text-align: center;
}

.footer-links {
  list-style: none;
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-top: 1rem;
}

.footer-links a {
  color: #ecf0f1;
  text-decoration: none;
  transition: color 0.3s;
}

.footer-links a:hover {
  color: #2166a5;
}

/* Direct Converters Accordion */
.direct-converters {
  margin-top: 2rem;
}

.dc-group {
  border-bottom: 1px solid #e9ecef;
}

.dc-btn {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0.75rem 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: #2c3e50;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: color 0.2s, background-color 0.2s;
  border-radius: 4px;
}

.dc-btn:hover {
  color: #2166a5;
  background-color: #f0f8ff;
}

.dc-btn.open {
  color: #2166a5;
}

.dc-arrow {
  font-size: 0.75rem;
  transition: transform 0.25s;
  display: inline-block;
  flex-shrink: 0;
}

.dc-btn.open .dc-arrow {
  transform: rotate(180deg);
}

.dc-links {
  list-style: none;
  padding: 0.5rem 0.5rem 1rem;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.25rem 1rem;
}

.dc-links[hidden] {
  display: none;
}

/* ── Custom Select Dropdown ── */
.cs-wrapper {
  position: relative;
  width: 100%;
  min-width: 0;
  display: block;
}

.cs-trigger {
  width: 100%;
  padding: 0.45rem 0.6rem 0.45rem 0.75rem;
  font-size: 1rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: white;
  cursor: pointer;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #333;
  box-sizing: border-box;
  font-family: inherit;
}

/* Override converter-box button padding which is too wide for our trigger */
.converter-box .cs-trigger {
  padding: 0.45rem 0.6rem 0.45rem 0.75rem;
}

.cs-trigger:hover {
  border-color: #2166a5;
}

.cs-trigger.cs-open {
  border-color: #2166a5;
  outline: none;
}

.cs-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cs-arrow {
  font-size: 0.65rem;
  margin-left: 0.5rem;
  flex-shrink: 0;
  transition: transform 0.2s;
}

.cs-trigger.cs-open .cs-arrow {
  transform: rotate(180deg);
}

.cs-dropdown {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  max-height: 340px; /* ~10 items */
  overflow-y: auto;
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
  z-index: 1000;
}

.cs-option {
  padding: 0.42rem 0.75rem;
  cursor: pointer;
  font-size: 0.95rem;
  color: #333;
  line-height: 1.4;
}

.cs-option:hover {
  background: #e8f4fd;
  color: #2c3e50;
}

.cs-option.cs-si {
  color: #c0392b;
  font-weight: 600;
}

.cs-option.cs-selected {
  background: #2166a5;
  color: white;
}

.cs-option.cs-selected:hover {
  background: #15406a;
}

.cs-group-header {
  padding: 0.3rem 0.75rem 0.15rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #23272b;
  background: #c2c3c5;
  border-top: 1px solid #a0a1a3;
  border-bottom: 1px solid #a0a1a3;
  cursor: default;
  user-select: none;
}

.cs-group-header:first-child {
  border-top: none;
}

.si-iec-info {
  background: #eaf4fb;
  border-left: 4px solid #2166a5;
  border-radius: 0 6px 6px 0;
  padding: 0.7rem 1rem;
  margin: 0.6rem 0 0.8rem;
  font-size: 0.93rem;
  color: #2c3e50;
  line-height: 1.5;
}

.dc-links li {
  margin: 0;
}

.dc-links a {
  color: #2166a5;
  text-decoration: none;
  font-size: 0.9rem;
  display: block;
  padding: 0.2rem 0;
  transition: color 0.2s;
}

.dc-links a:hover {
  color: #15406a;
  text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 768px) {
  .container {
    grid-template-columns: 1fr;
  }
  
  .ad-slot {
    min-height: 250px;
  }
  
  .nav-links {
    gap: 1rem;
    flex-wrap: wrap;
  }
  
  .navbar {
    flex-direction: column;
    gap: 1rem;
  }

  .converter-row {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .converter-row label {
    text-align: left;
  }
}

/* Dropdown styling */
.converter-box select {
  width: 100%;
  padding: 0.72rem;
  font-size: 1rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  margin-top: 0.5rem; 
  margin-bottom: 0.5rem;
  background-color: white;
  cursor: pointer;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.converter-box select:focus {
  outline: none;
  border-color: #2166a5;
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.converter-box select:hover {
  border-color: #95a5a6;
}

/* Read-only input styling */
#toValue {
  background-color: #f8f9fa;
  cursor: not-allowed;
  color: #2c3e50;
  font-weight: 600;
}

.formula strong {
  font-weight: bold;
  font-family: inherit;
  font-size: inherit;
}