/* Free tools (inc/tools.php): shared components for every tool page and the /tools/ hub.
   Scoped under .hmt (tool) and .hmt-* (page sections) so nothing leaks into the theme. */

.hmt-section { padding-block: clamp(1.5rem, 1rem + 2vw, 2.5rem) clamp(1.5rem, 1rem + 2vw, 3rem); background: var(--bg); }
.hmt-container { max-width: 1040px; }
.hmt-guide-section { background: var(--bg); }

/* ---- Tool shell ---- */
.hmt {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: clamp(1.1rem, 0.8rem + 1.6vw, 2rem);
  display: grid;
  gap: 1.25rem;
  color: var(--text);
}
.hmt > *, .hmt-grid > *, .hmt-split > *, .hmt-panel > *, .hmt-sticky > *, .hmt-split > div > * { min-width: 0; }
.hmt [hidden] { display: none !important; }
.hmt h2, .hmt h3 { margin: 0; color: var(--ink); font-family: var(--font-heading); letter-spacing: -0.01em; }
.hmt h2 { font-size: clamp(1.25rem, 1.05rem + 0.8vw, 1.6rem); }
.hmt h3 { font-size: 1.08rem; }
.hmt p { margin: 0; }
.hmt-lead { color: var(--muted); font-size: 0.95rem; }

/* Layout */
.hmt-grid { display: grid; gap: 0.9rem 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.hmt-split { display: grid; gap: 1.25rem; }
@media (min-width: 860px) { .hmt-split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; } }
.hmt-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 0.9rem; }
.hmt-panel { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg); padding: 1rem 1.1rem; display: grid; gap: 0.8rem; }

/* Fields */
.hmt-field { display: grid; gap: 0.35rem; }
.hmt-field > span, .hmt-label { font-weight: 600; color: var(--ink); font-size: 0.92rem; }
.hmt-field small, .hmt-hint { color: var(--muted); font-size: 0.82rem; }
.hmt input[type="text"], .hmt input[type="number"], .hmt input[type="url"], .hmt input[type="date"], .hmt input[type="email"],
.hmt select, .hmt textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}
.hmt textarea { min-height: 7rem; resize: vertical; line-height: 1.6; }
.hmt textarea.hmt-code, .hmt .hmt-code { font-family: var(--font-mono); font-size: 0.9rem; }
.hmt input:focus-visible, .hmt select:focus-visible, .hmt textarea:focus-visible,
.hmt button:focus-visible, .hmt a:focus-visible, .hmt label:focus-within { outline: 3px solid var(--focus); outline-offset: 1px; }
.hmt-check { display: flex; align-items: flex-start; gap: 0.55rem; cursor: pointer; font-size: 0.95rem; }
.hmt-check input { width: 1.15rem; height: 1.15rem; margin-top: 0.2rem; accent-color: var(--teal-ink); flex: none; }
.hmt-check small { display: block; color: var(--muted); font-size: 0.82rem; }

/* Buttons */
.hmt-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  min-height: 42px; padding: 0 1rem; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  font: 600 0.9rem/1 var(--font-body); cursor: pointer; transition: border-color .2s, background-color .2s;
}
.hmt-btn:hover { border-color: var(--teal-ink); background: var(--teal-tint, #e6f4f5); }
.hmt-btn:active { transform: translateY(1px); }
.hmt-btn--primary { background: var(--teal-ink); border-color: var(--teal-ink); color: #fff; }
.hmt-btn--primary:hover { background: var(--teal-ink-hover, #00636a); color: #fff; }
.hmt-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.hmt-link { border: 0; background: none; padding: 0; color: var(--teal-ink); font: 600 0.9rem/1.3 var(--font-body); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* Tabs */
.hmt-tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; border-bottom: 1px solid var(--border); }
.hmt-tabs button { border: 0; background: none; padding: 0.65rem 0.95rem; margin-bottom: -1px; border-bottom: 2px solid transparent; color: var(--muted); font: 600 0.95rem/1.2 var(--font-body); cursor: pointer; }
.hmt-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--teal-ink); }

/* Output */
.hmt-out { position: relative; }
.hmt-sticky { display: grid; gap: 0.75rem; align-content: start; }
@media (min-width: 860px) { .hmt-sticky { position: sticky; top: calc(var(--header-h) + 1rem); } }
.hmt-out pre {
  margin: 0; padding: 1rem; max-height: 32rem; overflow: auto;
  border-radius: var(--radius-md); background: #0d1b2e; color: #e3ecf6;
  font: 0.86rem/1.6 var(--font-mono); white-space: pre-wrap; word-break: break-word;
}
.hmt-out-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.hmt-result { border-radius: var(--radius-md); padding: 1rem 1.1rem; background: var(--bg); border: 1px solid var(--border); display: grid; gap: 0.6rem; }
.hmt-big { font: 700 clamp(1.6rem, 1.2rem + 1.6vw, 2.4rem)/1.1 var(--font-heading); color: var(--ink); font-variant-numeric: tabular-nums; }

/* Stat tiles */
.hmt-stats { display: grid; gap: 0.6rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr)); }
.hmt-stat { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 0.75rem 0.9rem; background: var(--surface); }
.hmt-stat b { display: block; font: 700 1.5rem/1.15 var(--font-heading); color: var(--ink); font-variant-numeric: tabular-nums; }
.hmt-stat span { color: var(--muted); font-size: 0.82rem; }

/* Tables */
.hmt-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.hmt table { width: 100%; border-collapse: collapse; font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.hmt th, .hmt td { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.hmt th { color: var(--muted); font-weight: 600; font-size: 0.82rem; }

/* Alerts */
.hmt-alert { border-radius: var(--radius-sm); padding: 0.7rem 0.9rem; font-size: 0.92rem; border: 1px solid var(--border); background: var(--bg); }
.hmt-alert.is-ok { background: #e7f6ee; border-color: #9ad5b6; color: #145c3a; }
.hmt-alert.is-warn { background: #fdf3dc; border-color: #ecc979; color: #6b4a00; }
.hmt-alert.is-bad { background: #fcebeb; border-color: #eba4a4; color: #8f1d1d; }
.hmt-alert ul { margin: 0.35rem 0 0; padding-left: 1.2rem; }

/* Drop zone (image tools) */
.hmt-drop {
  display: grid; justify-items: center; gap: 0.4rem; text-align: center; cursor: pointer;
  padding: clamp(1.5rem, 1rem + 2.5vw, 2.5rem) 1rem; border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md); background: var(--bg); transition: border-color .2s, background-color .2s;
}
.hmt-drop:hover, .hmt-drop.is-over { border-color: var(--teal-ink); background: var(--teal-tint, #e6f4f5); }
.hmt-drop input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.hmt-drop b { color: var(--ink); }
.hmt-drop span { color: var(--muted); font-size: 0.88rem; }
.hmt canvas { max-width: 100%; height: auto; display: block; }
.hmt-stage { position: relative; display: grid; place-items: center; background: repeating-conic-gradient(#eef2f6 0 25%, #fff 0 50%) 0 0 / 16px 16px; border-radius: var(--radius-md); overflow: hidden; touch-action: none; }

/* Photo tools */
.hmt-pc-start { display: grid; gap: 0.6rem; }
.hmt-pc-camera { justify-self: center; cursor: pointer; }
.hmt-pc-camera:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
@media (hover: hover) and (pointer: fine) { .hmt-pc-camera { display: none; } }
.hmt-chks { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; font-size: 0.9rem; }
.hmt-chk { position: relative; padding-left: 1.6rem; }
.hmt-chk::before { position: absolute; left: 0; top: 0.05rem; width: 1.15rem; height: 1.15rem; border-radius: 50%; display: grid; place-items: center; font: 700 0.72rem/1 var(--font-body); color: #fff; }
.hmt-chk.is-ok::before { content: "\2713"; background: #13734a; }
.hmt-chk.is-warn::before { content: "!"; background: #b7791f; }
.hmt-chk.is-bad::before { content: "\00D7"; background: #b42318; }

/* Privacy note */
.hmt-privacy { margin: 0; display: flex; gap: 0.5rem; align-items: flex-start; color: var(--muted); font-size: 0.85rem; }
.hmt-privacy svg { color: #13734a; flex: none; margin-top: 2px; }

/* RTL text (Urdu) */
.hmt [dir="rtl"], .hmt .hmt-rtl { font-family: "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", "Noto Naskh Arabic", "Segoe UI", Tahoma, sans-serif; }

/* ---- Cards: related tools and the hub ---- */
.hmt-related { background: var(--surface); }
.hmt-cards { list-style: none; margin: 1.25rem 0 0; padding: 0; display: grid; gap: 0.9rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); }
.hmt-card a {
  display: grid; gap: 0.35rem; height: 100%; padding: 1.1rem; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text); text-decoration: none; transition: border-color .2s, transform .2s;
}
.hmt-card a:hover { border-color: var(--teal-ink); transform: translateY(-2px); }
.hmt-card-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--teal-tint, #e6f4f5); color: var(--teal-ink); }
.hmt-card-name { font-weight: 700; color: var(--ink); }
.hmt-card-note { color: var(--muted); font-size: 0.9rem; }
.hmt-all { margin: 1.25rem 0 0; }
.hmt-all a { color: var(--teal-ink); font-weight: 600; }
.hmt-hub { padding-block: clamp(2rem, 1.5rem + 2vw, 3.5rem); }
.hmt-hub-group + .hmt-hub-group { margin-top: clamp(2rem, 1.5rem + 2vw, 3rem); }
.hmt-hub-title { margin: 0; font-size: clamp(1.25rem, 1.1rem + 0.6vw, 1.5rem); color: var(--ink); }

/* Invoice generator */
.hmt details.hmt-panel > summary { cursor: pointer; }
.hmt details.hmt-panel[open] > summary { margin-bottom: 0.2rem; }
.hmt-inv-item { display: grid; gap: 0.5rem 0.75rem; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; align-items: end; padding-bottom: 0.75rem; border-bottom: 1px dashed var(--border); }
.hmt-inv-item .hmt-inv-desc { grid-column: 1 / -1; }
.hmt-inv-item [data-k="remove"] { min-height: 44px; }
.hmt-invoice {
  background: #fff; color: #1E293B; border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: clamp(1rem, 0.6rem + 2vw, 2rem); font-size: 0.85rem; line-height: 1.5; display: grid; gap: 1.1rem;
  overflow-wrap: anywhere;
}
.hmt-invoice h4 { margin: 0; font: 700 1.5rem/1.1 var(--font-heading); color: var(--navy); letter-spacing: 0.02em; }
.hmt-invoice .inv-top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem; }
.hmt-invoice .inv-logo { max-width: 140px; max-height: 70px; object-fit: contain; display: block; margin-bottom: 0.4rem; }
.hmt-invoice .inv-meta { display: grid; gap: 0.15rem; justify-items: end; text-align: end; }
.hmt-invoice .inv-k { color: #64748B; font-size: 0.75rem; }
.hmt-invoice .inv-ur { font-family: "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", "Noto Naskh Arabic", Tahoma, sans-serif; }
.hmt-invoice table { font-size: 0.82rem; min-width: 460px; }
.hmt-invoice td, .hmt-invoice th { overflow-wrap: normal; }
.hmt-invoice td:nth-child(2) { min-width: 9rem; }
@media print { .hmt-invoice table { min-width: 0; } }
.hmt-invoice th { background: #F1F5F9; color: #334155; }
.hmt-invoice td.n, .hmt-invoice th.n { text-align: end; white-space: nowrap; }
.hmt-invoice .inv-totals { display: grid; gap: 0.25rem; justify-self: end; min-width: min(100%, 260px); }
.hmt-invoice .inv-totals div { display: flex; justify-content: space-between; gap: 1.5rem; font-variant-numeric: tabular-nums; }
.hmt-invoice .inv-grand { border-top: 2px solid var(--navy); padding-top: 0.35rem; font-weight: 700; font-size: 1rem; color: var(--navy); }
.hmt-invoice .inv-words { background: #F8FAFC; border-radius: var(--radius-sm); padding: 0.5rem 0.75rem; }
.hmt-invoice[dir="rtl"] .inv-meta { justify-items: start; text-align: start; }
.hmt-invoice[dir="rtl"] th, .hmt-invoice[dir="rtl"] td { text-align: right; }
.hmt-invoice[dir="rtl"] td.n, .hmt-invoice[dir="rtl"] th.n { text-align: left; }
.hmt-invoice[dir="rtl"] .inv-totals { justify-self: start; }
@media print {
  body.hmt-printing .hmt-invoice { font-size: 11pt; padding: 0; }
  @page { margin: 14mm; }
}

/* Solar calculator: monthly bars */
.hmt-sol-chart { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; align-items: end; height: 150px; padding-top: 1.2rem; }
.hmt-sol-chart .bar { position: relative; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.hmt-sol-chart .bar i { display: block; background: var(--teal-ink); border-radius: 4px 4px 0 0; min-height: 2px; }
.hmt-sol-chart .bar.is-low i { background: var(--gold); }
.hmt-sol-chart .bar b { font: 600 0.62rem/1 var(--font-body); color: var(--muted); text-align: center; margin-bottom: 3px; font-variant-numeric: tabular-nums; }
.hmt-sol-chart .bar span { font-size: 0.68rem; color: var(--muted); text-align: center; margin-top: 4px; }
@media (max-width: 420px) { .hmt-sol-chart .bar b { display: none; } }

/* Baggage calculator */
.hmt-bg-bag { display: grid; gap: 0.5rem 0.75rem; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) auto; align-items: end; }
.hmt-bg-bag [data-k="remove"] { min-height: 44px; }

/* Print (invoice): only the printable area */
@media print {
  body.hmt-printing * { visibility: hidden !important; }
  body.hmt-printing .hmt-print, body.hmt-printing .hmt-print * { visibility: visible !important; }
  body.hmt-printing .hmt-print { position: absolute; inset: 0 auto auto 0; width: 100%; box-shadow: none !important; border: 0 !important; }
}

@media (prefers-reduced-motion: reduce) {
  .hmt *, .hmt-card a { transition: none !important; }
}

/* Wide tables in tool guides scroll inside themselves on phones */
.hmt-guide-section .prose table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
