﻿/**
 * UI مشترک صفحات ابزار (shell) — جدا از grid ابزارها در core.css
 */
body.ic-tool-page {
  background: #fff;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

body.ic-tool-page::-webkit-scrollbar {
  display: none;
}

main.ic-tool {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  direction: rtl;
  background: #fff;
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: default;
  color: var(--ic-text, #2d3a4a);
  font-family: inherit;
  --ic-tool-pad-x: 32px;
  --ic-tool-content-max: 380px;
  --ic-tool-desc-max: 350px;
  --ic-tool-footer-pad-x: 30px;
  --ic-tool-edge: max(var(--ic-tool-pad-x), calc(50% - var(--ic-tool-content-max) / 2));
}

/* ── Header (مثل ic-ght-head قطعه‌شناسی) ── */
main.ic-tool .ic-tool-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  box-sizing: border-box;
  padding: 24px;
  background: #fff;
  flex-shrink: 0;
  direction: ltr;
}

main.ic-tool > .ic-tool-head {
  position: sticky;
  top: 0;
  z-index: 50;
}

main.ic-tool .ic-tool-head > .ic-tool-title {
  margin: 0;
  padding: 0 48px;
  font-size: 13px;
  font-weight: 700;
  color: #2d3a4a;
  text-align: center;
  line-height: 1.4;
  direction: rtl;
}

main.ic-tool .ic-tool-head .ic-tool-info-btn {
  position: absolute;
  left: 26px;
  right: auto;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
}

main.ic-tool .ic-tool-head .ic-tool-back {
  position: absolute;
  right: 26px;
  left: auto;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
}

main.ic-tool .ic-tool-head .ic-tool-back,
main.ic-tool .ic-tool-head .ic-tool-info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  text-decoration: none;
  color: inherit;
}

main.ic-tool .ic-tool-head .ic-tool-back .ic-icon {
  background: #4e91e6;
}

main.ic-tool .ic-tool-head .ic-tool-info-btn .ic-icon {
  background: #6a81a9;
}

/* ── Sticky top (header + tabs) ── */
main.ic-tool > .ic-tool-sticky-top {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #fff;
  flex-shrink: 0;
  width: 100%;
}

main.ic-tool > .ic-tool-sticky-top > .ic-tool-head {
  position: relative;
  top: auto;
  z-index: auto;
  padding-bottom: 16px;
}

main.ic-tool > .ic-tool-sticky-top > .ic-tool-tabs-wrap {
  padding: 10px var(--ic-tool-pad-x) 3px;
  box-sizing: border-box;
}

main.ic-tool > .ic-tool-sticky-top > .ic-tool-tabs-wrap .ic-tool-tabs {
  margin: 0 auto;
}

/* با تب: فاصله بیشتر بین متن راهنما و اولین ورودی */
main.ic-tool > .ic-tool-sticky-top + .ic-tool-body .ic-tool-desc {
  margin-bottom: 43px;
}

/* ── Body ── */
main.ic-tool > .ic-tool-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
  padding: 28px var(--ic-tool-pad-x) 120px;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

main.ic-tool > .ic-tool-body::-webkit-scrollbar {
  display: none;
}

/* بدون تب: فاصله کمتر بین عنوان هدر و متن راهنما */
main.ic-tool > .ic-tool-head + .ic-tool-body {
  padding-top: 16px;
}

main.ic-tool .ic-tool-desc {
  width: 100%;
  max-width: min(var(--ic-tool-desc-max), calc(100% - 40px));
  padding-inline: 8px;
  font-size: 11.5px;
  color: #8090a8;
  text-align: center;
  line-height: 2;
  margin: 0 auto 36px;
  box-sizing: border-box;
}

main.ic-tool .ic-tool-fields,
main.ic-tool > .ic-tool-body > .ic-tool-field-row,
main.ic-tool > .ic-tool-body > .ic-tool-input-wrap,
main.ic-tool > .ic-tool-body > .ic-tool-result {
  width: 100%;
  max-width: var(--ic-tool-content-max);
  margin-left: auto;
  margin-right: auto;
}

main.ic-tool .ic-tool-fields {
  margin-right: auto;
  margin-left: auto;
}

/* ── Field row (calculator) ── */
.ic-tool-field-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin-bottom: 14px;
  width: 100%;
  direction: ltr;
}

.ic-tool-field-row:has(> .ic-tool-select-btn:only-child) {
  direction: rtl;
}

.ic-tool-field-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.ic-tool-field {
  width: 100%;
  height: 65px;
  padding: 0 14px;
  border: none;
  border-radius: 14px;
  background: #f4f4f4;
  font-size: 14px;
  font-family: inherit;
  color: #2d3a4a;
  outline: none;
  box-sizing: border-box;
  direction: ltr;
  text-align: center;
  -webkit-appearance: none;
  appearance: none;
}

.ic-tool-field::placeholder {
  color: transparent;
}

.ic-tool-field:focus {
  background: #f4f4f4;
  outline: none;
  box-shadow: none;
}

.ic-tool-field[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.ic-tool-field[type="number"]::-webkit-inner-spin-button,
.ic-tool-field[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.ic-tool-field.is-calculated {
  color: #10b981;
  font-weight: 700;
  background: #f4f4f4;
}

.ic-tool-field.is-converted {
  color: #4e91e6;
  font-weight: 400;
  background: #f4f4f4;
}

.ic-tool-field.is-muted {
  background: #e5e7eb;
  opacity: 0.6;
}

.ic-tool-field.is-unavailable {
  color: #b7b7b7;
  font-weight: 400;
}

.ic-tool-field:read-only {
  opacity: 0.95;
}

.ic-tool-field-ph {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #a3a3a3;
  text-align: center;
  pointer-events: none;
  padding: 0 14px;
  box-sizing: border-box;
}

.ic-tool-field:not(:placeholder-shown) + .ic-tool-field-ph {
  display: none;
}

select.ic-tool-field,
.ic-tool-field.ic-tool-select {
  color: #a6a6a6;
  cursor: pointer;
}

select.ic-tool-field:valid,
.ic-tool-field.ic-tool-select.is-selected {
  color: #2d3a4a;
}

.ic-tool-unit-btn,
.ic-tool-select-btn {
  flex-shrink: 0;
  width: 42%;
  max-width: 160px;
  min-height: 65px;
  padding: 8px 12px;
  border: 0.7px solid #dbdbdb;
  border-radius: 14px;
  background: #fff;
  color: #a6a6a6;
  font-family: inherit;
  font-size: 10px;
  line-height: 1.5;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.ic-tool-field-row > .ic-tool-select-btn:only-child {
  width: 100%;
  max-width: none;
  color: #a6a6a6;
  min-height: 65px;
}

.ic-tool-unit-btn.is-selected,
.ic-tool-select-btn.is-selected,
.ic-tool-select-btn.is-selected .ic-tool-select-label {
  border-color: #4e91e6;
  color: #4e91e6;
  font-weight: 400;
}

.ic-tool-unit-btn.is-calculated,
.ic-tool-select-btn.is-calculated {
  color: #10b981;
  border-color: #10b981;
  font-weight: 700;
}

/* ── Tabs ── */
.ic-tool-tabs {
  display: flex;
  flex-direction: row;
  direction: rtl;
  gap: 6px;
  margin: 0 auto;
  padding: 6px;
  width: 100%;
  max-width: 300px;
  border-radius: 18px;
  background: #f1f3f6;
  box-sizing: border-box;
}

.ic-tool-tab {
  flex: 1;
  padding: 12px 8px;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: #7e8a9a;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}

.ic-tool-tab.is-active,
.ic-tool-tab--active {
  background: #fff;
  color: #2d3a4a;
  font-weight: 700;
}

/* ── Result ── */
.ic-tool-result {
  margin-top: 20px;
  padding: 16px 18px;
  border-radius: 14px;
  background: #f0fdf4;
  border: 1.5px solid #b8e6cc;
  text-align: center;
  direction: rtl;
}

.ic-tool-result[hidden] {
  display: none !important;
}

.ic-tool-result-line {
  margin: 0 0 8px;
  font-size: 13px;
  line-height: 1.8;
  color: #2d3a4a;
}

.ic-tool-result-line:last-child {
  margin-bottom: 0;
}

.ic-tool-result-line strong {
  color: #10b981;
  font-family: "IRANYekanFa", "IRANYekan", sans-serif;
}

/* ── Result grid (مثل WireConverter / PCBTraceCalculator اپ) ── */
.ic-tool-results-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin: 25px 0 48px;
}

.ic-tool-results-grid[hidden] {
  display: none !important;
}

.ic-tool-result-row {
  display: flex;
  flex-direction: row;
  gap: 10px;
  align-items: stretch;
}

.ic-tool-result-item {
  flex: 1;
  min-width: 0;
  padding: 14px;
  border-radius: 14px;
  background: #f8f8f8;
  border: 0.7px solid #dbdbdb;
  text-align: center;
}

.ic-tool-result-item--empty {
  visibility: hidden;
  pointer-events: none;
}

.ic-tool-result-value {
  font-size: 16px;
  font-weight: 700;
  font-family: "IRANYekanFa", "IRANYekan", sans-serif;
  color: #2d3a4a;
  line-height: 1.35;
  word-break: break-word;
}

.ic-tool-result-label {
  margin: 8px 0 0;
  font-size: 9px;
  color: #8090a8;
  line-height: 1.4;
}

.ic-tool-field-row.ic-pcb-split {
  direction: ltr;
}

.ic-tool-field-row.ic-pcb-split .ic-tool-select-btn {
  flex: 1;
  width: auto;
  max-width: none;
  min-height: 65px;
}

.ic-tool-field-row.ic-pcb-split .ic-tool-field-wrap {
  flex: 1;
}

/* فاصلهٔ نتایج تا دکمهٔ ثابت پایین — همهٔ ابزارها */
main.ic-tool .ic-tool-results-grid:not([hidden]),
main.ic-tool .ic-tool-rpl-results:not([hidden]),
main.ic-tool .ic-tool-rpl-empty:not([hidden]),
main.ic-tool .ic-wc-results:not([hidden]),
main.ic-tool .ic-pc-results-grid:not([hidden]),
main.ic-tool .ic-rp-results:not([hidden]),
main.ic-tool .ic-joule-results:not([hidden]),
main.ic-tool .ic-eff-results:not([hidden]),
main.ic-tool .ic-fuse-results:not([hidden]),
main.ic-tool .ic-zc-results:not([hidden]),
main.ic-tool .ic-ad-results:not([hidden]),
main.ic-tool .ic-res-results:not([hidden]),
main.ic-tool .ic-hs-results:not([hidden]),
main.ic-tool .ic-vdiv-results:not([hidden]),
main.ic-tool .ic-fil-results:not([hidden]),
main.ic-tool .ic-vd-results:not([hidden]),
main.ic-tool .ic-tr-results:not([hidden]),
main.ic-tool .ic-sp-results:not([hidden]),
main.ic-tool .ic-sd-results:not([hidden]),
main.ic-tool .ic-pu-results:not([hidden]),
main.ic-tool .ic-ne555-results:not([hidden]),
main.ic-tool .ic-cc-results:not([hidden]),
main.ic-tool .ic-lcd-code-results:not([hidden]),
main.ic-tool .ic-tool-result:not([hidden]) {
  margin-bottom: 48px;
}

.ic-tool-error {
  width: 100%;
  max-width: 300px;
  margin: 8px auto 0;
  font-size: 12px;
  color: #e64747;
  text-align: center;
}

.ic-tool-error[hidden] {
  display: none !important;
}

/* ── Search-style input (replacement-like) ── */
.ic-tool-input-wrap {
  position: relative;
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
  box-sizing: border-box;
}

.ic-tool-input {
  width: 100%;
  height: 65px;
  background: #f4f4f4;
  border: none;
  border-radius: 14px;
  text-align: center;
  font-size: 13px;
  color: #2d3a4a;
  outline: none;
  font-family: inherit;
  direction: ltr;
  box-sizing: border-box;
  padding: 0 44px;
  transition: background 0.2s;
}

.ic-tool-input::placeholder {
  font-size: 10px;
  color: #a3a3a3;
  font-family: inherit;
}

.ic-tool-input:focus {
  background: #f4f4f4;
  outline: none;
  box-shadow: none;
}

.ic-tool-input-clear {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: #9aa6b2;
  padding: 4px;
  line-height: 1;
}

/* ── Footer button ── */
main.ic-tool > .ic-tool-footer {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  padding: 12px var(--ic-tool-footer-pad-x) calc(20px + env(safe-area-inset-bottom, 0px));
  background: #fff;
  border-top: 1px solid #eef1f7;
  z-index: 50;
}

.ic-tool-btn {
  display: grid;
  place-items: center;
  width: 100%;
  height: 56px;
  border-radius: 14px;
  border: none;
  background: #4e91e6;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

.ic-tool-btn:disabled {
  background: #bfccd4;
  cursor: not-allowed;
}

.ic-tool-btn.is-clear {
  background: #fb5d5d;
}

.ic-tool-btn.is-clear:hover {
  background: #e04444;
}

.ic-led-visual {
  position: relative;
  width: min(80%, 280px);
  height: 140px;
  margin: 0 auto 15px;
}

.ic-led-top {
  position: absolute;
  top: -28px;
  left: -8px;
  z-index: 1;
  width: calc(100% + 8px);
  height: 30px;
  object-fit: contain;
}

.ic-led-circuit {
  display: block;
  width: 100%;
  height: 120px;
  object-fit: contain;
}

/* ── Unit / select picker (وسط صفحه — مثل PopupToolsList اپ) ── */
.ic-tool-picker {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
}

.ic-tool-picker[hidden] {
  display: none !important;
}

.ic-tool-picker-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  background: rgba(0, 0, 0, 0.5);
  cursor: pointer;
}

.ic-tool-picker-card {
  position: relative;
  z-index: 1;
  width: min(95%, 340px);
  max-height: min(90vh, 520px);
  padding: 10px;
  border-radius: 15px;
  background: #fff;
  overflow-y: auto;
  direction: rtl;
  box-sizing: border-box;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.ic-tool-picker-card::-webkit-scrollbar {
  display: none;
}

.ic-tool-picker-option {
  display: block;
  width: 100%;
  margin: 0;
  padding: 12px 15px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #2d3a4a;
  font-family: inherit;
  font-size: 12px;
  text-align: center;
  cursor: pointer;
}

.ic-tool-picker-option.is-selected {
  background: transparent;
  color: #4e91e6;
  font-weight: 400;
}

@keyframes ic-tool-picker-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes ic-tool-picker-scale-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.ic-tool-picker-backdrop.ic-tool-picker-animate {
  animation: ic-tool-picker-fade-in 0.15s ease both;
}

.ic-tool-picker-card.ic-tool-picker-animate {
  animation: ic-tool-picker-scale-in 0.22s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@media (min-width: 801px) {
  main.ic-tool {
    --ic-tool-pad-x: 48px;
    --ic-tool-content-max: 340px;
    --ic-tool-desc-max: 280px;
    --ic-tool-footer-pad-x: 32px;
    /* داخل قاب 430px — نه بر اساس عرض کل مانیتور */
    --ic-tool-edge: var(--ic-tool-pad-x);
  }

  main.ic-tool .ic-tool-desc {
    max-width: var(--ic-tool-desc-max);
    padding-inline: 0;
  }

  main.ic-tool .ic-tool-fields,
  main.ic-tool .ic-tool-field-row,
  main.ic-tool .ic-tool-input-wrap,
  .ic-tool-input-wrap,
  .ic-tool-tabs,
  .ic-tool-error {
    max-width: var(--ic-tool-content-max);
  }

  main.ic-tool > .ic-tool-footer {
    left: calc(50% - var(--ic-phone-width, 430px) / 2);
    right: auto;
    width: var(--ic-phone-width, 430px);
    max-width: 100%;
  }
}

@media (max-width: 800px), (min-width: 801px) {
  body.ic-tool-page .ic-header,
  body.ic-tool-page .ic-footer {
    display: none;
  }

  main.ic-tool {
    min-height: calc(100dvh - env(safe-area-inset-bottom, 0px));
  }
}
