:root {
  --primary: #1EB6DE;
  --primary-dark: #1892B2;
  --light-bg: #F8FCFF;
  --border: #E1E5F1;
  --text: #1E293B;
  --text-light: #475569;
  --card-bg: #FFFFFF;
  --toast-bg: #2C3E50;
  --danger: #E53E3E;
  --success: #2C7A4D;
  --warning: #ED8936;
  --info: #4299E1;
}

[data-theme="dark"] {
  --primary: #1EB6DE;
  --primary-dark: #1892B2;
  --light-bg: #292B32;
  --border: #4A4A5A;
  --text: #F1F5F9;
  --text-light: #CBD5E1;
  --card-bg: #1E1F28;
  --toast-bg: #111827;
  --danger: #F56565;
  --success: #48BB78;
  --warning: #F6AD55;
  --info: #63B3ED;
}

.container-custom {
  width: 100%;
  max-width: none;
  margin: 0 auto;
  background: var(--card-bg);
  box-shadow: 0 20px 35px -12px rgba(0, 0, 0, 0.1);
  transition: background 0.2s;
  overflow: hidden;
  padding: 0;
}

.tool-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
}

.tool-title {
  margin: 0;
  color: var(--primary);
  font-size: 1.4rem;
}

.tool-subtitle {
  margin: 4px 0 0 0;
  color: var(--text-light);
  font-size: 0.9rem;
}

/* ===== TABS BAR ===== */
.tabs-bar {
  display: flex;
  align-items: stretch;
  background: var(--light-bg);
  border-bottom: 1px solid var(--border);
  padding: 0;
  position: relative;
}

.tabs-wrapper {
  display: flex;
  flex-wrap: nowrap;
  flex: 1;
  overflow: hidden;
  min-width: 0;
}

.cat-tab {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  display: inline-flex;
  align-items: center;
  background: transparent;
  color: var(--text-light);
  border: 1px solid transparent;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  margin: 0;
  white-space: nowrap;
  border-radius: 0;
  box-shadow: none;
  outline: none;
  text-shadow: none;
  min-height: auto;
  gap: 0;
  transform: none;
  filter: none;
  flex-shrink: 0;
}

.cat-tab:hover {
  color: var(--primary-dark);
  background: rgba(30, 182, 222, 0.05);
  border: 1px solid transparent;
  border-bottom: 2px solid var(--primary);
  box-shadow: none;
  transform: none;
  filter: none;
}

.cat-tab.active {
  color: var(--primary-dark);
  font-weight: 600;
  background: var(--card-bg);
  border-bottom: 2px solid var(--primary);
  box-shadow: none;
  transform: none;
  filter: none;
}
[data-theme="dark"] .cat-tab.active,
[data-theme="dark"] .cat-tab:hover {
    color: var(--primary) !important;
}

/* ===== TABS DROPDOWN ===== */
.tabs-dropdown {
  position: relative;
  flex-shrink: 0;
  display: none;
}

.tabs-dropdown.open .tabs-dropdown-menu {
  display: block;
}

.tabs-more-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  background: transparent;
  color: var(--text-light);
  border: 1px solid transparent;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  border-radius: 0;
  white-space: nowrap;
  box-shadow: none;
  transform: none;
  filter: none;
  text-shadow: none;
  font-family: inherit;
  min-height: auto;
  height: 100%;
  transition: color 0.15s, background 0.15s;
  outline: none;
}

.tabs-more-btn:hover {
  color: var(--primary-dark);
  background: rgba(30, 182, 222, 0.05);
  border: 1px solid transparent;
  border-bottom: 2px solid var(--primary);
  box-shadow: none;
  transform: none;
  filter: none;
  text-shadow: none;
}

.tabs-more-btn.active {
  color: var(--primary-dark);
  font-weight: 600;
  background: var(--card-bg);
  border-bottom: 2px solid var(--primary);
  box-shadow: none;
  transform: none;
  filter: none;
}

[data-theme="dark"] .tabs-more-btn,
[data-theme="dark"] .tabs-more-btn:hover,
[data-theme="dark"] .tabs-more-btn.active {
    color: var(--primary) !important;
}

.tabs-more-btn i {
  font-size: 10px;
  transition: transform 0.2s;
}

.tabs-dropdown.open .tabs-more-btn i {
  transform: rotate(180deg);
}

.tabs-dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  min-width: 200px;
  max-height: 350px;
  overflow-y: auto;
  z-index: 100;
  display: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.tabs-dropdown-menu::-webkit-scrollbar {
  width: 6px;
}

.tabs-dropdown-menu::-webkit-scrollbar-track {
  background: var(--light-bg);
}

.tabs-dropdown-menu::-webkit-scrollbar-thumb {
  background: var(--border);
}

.tabs-dropdown-menu::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

.tabs-more-btn span {
  display: inline-block;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text);
  background: var(--card-bg);
  border: 1px solid transparent;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  box-shadow: none;
  border-radius: 0;
  transform: none;
  filter: none;
  text-shadow: none;
  min-height: auto;
  font-weight: 500;
  outline: none;
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item:hover {
  background: var(--primary);
  color: #ffffff;
  box-shadow: none;
  transform: none;
  filter: none;
  text-shadow: none;
  border: 1px solid transparent;
}

.dropdown-item.active {
  background: var(--primary);
  color: #ffffff;
  font-weight: 600;
  box-shadow: none;
  transform: none;
  filter: none;
}

/* ===== CONVERTER MAIN ===== */
.converter-main {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0;
  padding: 24px 20px 16px 20px;
  align-items: start;
  background: var(--card-bg);
}

.conversion-col {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

/* ===== UPDATED: From / To label with right-aligned unit ===== */
.col-label {
  font-size: 18px;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 24px;
}

.col-title {
  flex-shrink: 0;
}

.col-unit {
  display: inline-flex;
  align-items: center;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  color: var(--primary);
  background: var(--light-bg);
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-transform: none;
  letter-spacing: normal;
  box-sizing: border-box;
  flex-shrink: 1;
  min-width: 0;
  visibility: hidden;
}

.col-unit.is-visible {
  visibility: visible;
}

.input-wrapper {
  position: relative;
  width: 100%;
}

/* ===== UPDATED: Badge box sizing and hidden state ===== */
.unit-badge {
  position: absolute;
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  font-weight: 600;
  color: var(--primary-dark);
  background: var(--light-bg);
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 0;
  pointer-events: none;
  white-space: nowrap;
  max-width: 230px;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1;
  z-index: 2;
  box-sizing: border-box;
}
[data-theme="dark"] .unit-badge  {
    color: var(--primary) !important;
}
.unit-badge.is-hidden {
  display: none !important;
}

.value-input {
  width: 100% !important;
  max-width: 100% !important;
  background: var(--card-bg) !important;
  color: var(--text) !important;
  border: 2px solid var(--border) !important;
  border-radius: 0 !important;
  padding: 15px 20px 15px 20px !important;
  font-family: inherit !important;
  font-size: 38px !important;
  font-weight: 600 !important;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-sizing: border-box !important;
  margin: 0 !important;
  min-width: 60px !important;
  outline: 0 !important;
  line-height: 1.2 !important;
}

.value-input:focus {
  outline: none !important;
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px rgba(30, 182, 222, 0.12) !important;
}

.value-input::placeholder {
  color: var(--text-light) !important;
  opacity: 0.4 !important;
}

.result-input {
  background: var(--light-bg) !important;
  color: var(--primary-dark) !important;
  cursor: text !important;
}
[data-theme="dark"] .result-input  {
    color: var(--primary) !important;
}
/* ===== UNIT LIST ===== */
.unit-list-wrap {
  border: 1px solid var(--border);
  border-radius: 0;
  overflow: hidden;
  background: var(--card-bg);
  display: block;
}

.unit-list {
  width: 100%;
  height: 360px;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--card-bg);
  box-sizing: border-box;
}

.unit-list::-webkit-scrollbar {
  width: 16px;
}

.unit-list::-webkit-scrollbar-track {
  background: var(--light-bg);
  border-radius: 0;
  border-left: 1px solid var(--border);
}

.unit-list::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 0;
  border: 3px solid var(--light-bg);
  background-clip: padding-box;
}

.unit-list::-webkit-scrollbar-thumb:hover {
  background: var(--primary-dark);
  background-clip: padding-box;
}

.unit-list::-webkit-scrollbar-button:single-button {
  display: block;
  height: 16px;
  background-color: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 0;
  background-size: 10px 6px;
  background-repeat: no-repeat;
  background-position: center;
}

.unit-list::-webkit-scrollbar-button:single-button:vertical:decrement {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M5 0L0 6h10z' fill='%231EB6DE'/%3E%3C/svg%3E");
}

.unit-list::-webkit-scrollbar-button:single-button:vertical:decrement:hover {
  background-color: var(--light-bg);
}

.unit-list::-webkit-scrollbar-button:single-button:vertical:increment {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M5 6L0 0h10z' fill='%231EB6DE'/%3E%3C/svg%3E");
}

.unit-list::-webkit-scrollbar-button:single-button:vertical:increment:hover {
  background-color: var(--light-bg);
}

.unit-list::-webkit-scrollbar-button:double-button {
  display: none;
}

.unit-item {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--card-bg);
  transition: background 0.15s, color 0.15s;
  user-select: none;
  line-height: 1.5;
}

.unit-item:last-child {
  border-bottom: none;
}

.unit-item:hover {
  background: var(--primary-dark);
  color: #ffffff;
}

.unit-item.selected {
  background: var(--primary-dark) !important;
  color: #ffffff !important;
  font-weight: 600;
}
[data-theme="dark"] .unit-item.selected  {
    background: var(--primary) !important;
}

/* ===== UNIT SELECT ===== */
.unit-select-wrap {
  display: none;
  border: 1px solid var(--border);
  border-radius: 0;
  overflow: hidden;
  background: var(--card-bg);
}

.unit-select {
  width: 100% !important;
  max-width: 100% !important;
  padding: 14px 40px 14px 16px !important;
  font-family: inherit !important;
  font-size: 15px !important;
  font-weight: 500 !important;
  color: var(--text) !important;
  background-color: var(--card-bg) !important;
  border: none !important;
  border-radius: 0 !important;
  outline: none !important;
  margin: 0 !important;
  box-sizing: border-box !important;
  cursor: pointer !important;
  appearance: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M6 8L0 0h12z' fill='%231EB6DE'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 16px center !important;
  background-size: 12px 8px !important;
  min-height: 50px !important;
  transition: box-shadow 0.2s ease !important;
  text-shadow: none !important;
  box-shadow: none !important;
  transform: none !important;
  filter: none !important;
}

.unit-select:focus {
  outline: none !important;
  box-shadow: 0 0 0 3px rgba(30, 182, 222, 0.12) !important;
  border-color: var(--primary) !important;
}

.unit-select option {
  padding: 10px 14px !important;
  background: var(--card-bg) !important;
  color: var(--text) !important;
  font-size: 15px !important;
  border-bottom: 1px solid var(--border) !important;
  border-radius: 0 !important;
}

.unit-select option:checked {
  background: var(--primary) !important;
  color: #ffffff !important;
  font-weight: 600 !important;
}

/* ===== SWAP BUTTON ===== */
.swap-col {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  margin-top: 60px;
}

.swap-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, box-shadow 0.2s;
  font-size: 16px;
  box-shadow: 0 4px 12px rgba(30, 182, 222, 0.25);
  min-height: auto;
  padding: 0;
  gap: 0;
  transform: none;
  filter: none;
  text-shadow: none;
}

.swap-btn:hover {
  color: #ffffff;
  background: var(--primary-dark);
  box-shadow: 0 6px 16px rgba(30, 182, 222, 0.35);
  border-color: transparent;
  transform: none;
  filter: none;
  text-shadow: none;
}

.swap-btn:active {
  background: var(--primary-dark);
  transform: none;
}

/* ===== FORMULA ROW ===== */
.formula-row {
  display: flex;
  gap: 12px;
  padding: 0 20px 20px 20px;
  align-items: stretch;
}

.formula-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 22px;
  background: var(--light-bg);
  border: 1px solid var(--border);
  border-radius: 0;
  font-size: 18px;
  color: var(--text);
  line-height: 1.5;
}

.formula-box i {
  color: var(--primary);
  font-size: 20px;
}

.copy-btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary);
  color: #ffffff;
  border: 1px solid transparent;
  padding: 0 22px;
  white-space: nowrap;
  text-shadow: none;
  min-width: 140px;
  justify-content: center;
  box-shadow: none;
  outline: none;
  min-height: auto;
  transform: none;
  filter: none;
}

.copy-btn:hover {
  color: #ffffff;
  background: var(--primary-dark);
  border-color: transparent;
  box-shadow: none;
  transform: none;
  filter: none;
  text-shadow: none;
}

.copy-btn:active {
  transform: none;
}

/* ===== COMMON CONVERSIONS ===== */
.common-section {
  padding: 20px;
  background: var(--light-bg);
  border-top: 1px solid var(--border);
}

.common-header {
  margin-bottom: 14px;
}

.common-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.common-title i {
  color: var(--primary);
}

.common-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
}

.common-item {
  padding: 12px 14px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 0;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  line-height: 1.5;
}

.common-item:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(30, 182, 222, 0.1);
}

.common-item:hover .arrow {
  color: var(--primary);
}

.common-item .arrow {
  color: var(--text-light);
  font-size: 11px;
  flex-shrink: 0;
}

/* ===== TOAST ===== */
#toastContainer {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  max-width: calc(100% - 48px);
}

.toast {
  background: var(--toast-bg);
  color: white;
  padding: 12px 20px;
  border-radius: 5px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  margin-top: 8px;
  animation: slideUp 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
  max-width: 350px;
  border-left: 4px solid var(--primary);
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--info); }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
  to { opacity: 0; transform: translateY(10px); }
}

/* ===== UNIT VALUE DISPLAY ===== */
.unit-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.unit-name {
  flex: 1;
  min-width: 0;
}

.unit-value {
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}
[data-theme="dark"] .unit-value  {
    color: var(--primary) !important;
}
.unit-item:hover .unit-value {
  color: #ffffff;
}

.unit-item.selected .unit-value {
  color: #ffffff;
  font-weight: 600;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1400px) {
  .unit-badge {
    display: none !important;
  }

  .value-input {
    padding: 15px 17px !important;
  }
}

@media (max-width: 768px) {
  .tool-header {
    padding: 14px 16px;
  }

  .tool-title {
    font-size: 1.2rem;
  }

  .tabs-wrapper {
    display: none !important;
  }

  .tabs-dropdown {
    display: block !important;
    flex: 1 !important;
    width: 100% !important;
  }

  .tabs-more-btn {
    width: 100% !important;
    justify-content: center !important;
    padding: 12px 16px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    border-bottom: 2px solid var(--primary) !important;
    color: var(--primary) !important;
    background: var(--card-bg) !important;
  }

  .tabs-more-btn i {
    font-size: 11px !important;
    margin-left: 4px !important;
  }
  
  .tabs-more-btn span {
    max-width: none;
  }
  
  .tabs-dropdown-menu {
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-height: 60vh !important;
    box-shadow: 0 8px 20px rgba(0,0,0,0.15) !important;
  }

  .dropdown-item {
    padding: 14px 20px !important;
    font-size: 15px !important;
  }

  .converter-main {
    grid-template-columns: 1fr;
    gap: 20px;
    padding: 20px 16px;
  }

  .swap-col {
    padding: 0;
    margin-top: 0;
    justify-content: center;
  }

  .value-input {
    font-size: 32px !important;
    padding: 13px 15px 13px 15px !important;
  }

  .unit-badge {
    font-size: 16px;
    padding: 6px 12px;
    right: 16px;
    max-width: 200px;
  }

  .col-unit {
    max-width: 150px;
    font-size: 12px;
    padding: 5px 8px;
  }

  .unit-list-wrap {
    display: none !important;
  }

  .unit-select-wrap {
    display: block !important;
  }

  .formula-row {
    flex-direction: column;
    padding: 0 16px 16px 16px;
  }

  .formula-box {
    font-size: 16px;
    padding: 14px 18px;
  }

  .copy-btn {
    width: 100%;
    padding: 14px 20px;
  }

  .common-section {
    padding: 16px;
  }

  .common-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .tool-title {
    font-size: 1.1rem;
  }

  .tool-subtitle {
    font-size: 0.85rem;
  }

  .value-input {
    font-size: 28px !important;
    padding: 13px 14px 13px 14px !important;
  }

  .unit-badge {
    font-size: 14px;
    padding: 5px 10px;
    max-width: 100px;
  }

  .col-label {
    font-size: 16px;
  }

  .col-unit {
    max-width: 110px;
    font-size: 11px;
    padding: 4px 7px;
  }

  .formula-box {
    padding: 12px 14px;
    font-size: 15px;
  }

  #toastContainer {
    right: 12px;
    left: 12px;
    max-width: calc(100% - 24px);
  }

  .toast {
    max-width: 100%;
  }
}