/* ==========================================================
   enhancements.css - responsive, a11y and landing-page layer
   Loaded after layout.css + components.css so it can override.
   ========================================================== */

/* ---------- Tokens ---------- */
:root {
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --header-h: 64px;
    --tap: 44px; /* minimum comfortable touch target */
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
}

/* ---------- Base ---------- */
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { overflow-x: hidden; }
img, svg, video, canvas, iframe { max-width: 100%; height: auto; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* the header is sticky: keep anchored targets clear of it */
main[id], [id="main"] { scroll-margin-top: calc(var(--header-h) + 0.5rem); }

/* Respect users who ask for less motion */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ---------- Skip link / no-JS ---------- */
.skip-link {
    position: absolute; left: -9999px; top: 0; z-index: 10000;
    background: var(--accent); color: #fff; padding: 0.75rem 1rem;
    border-radius: 0 0 var(--radius) 0; font-weight: 600; text-decoration: none;
}
.skip-link:focus { left: 0; }

.noscript-banner {
    background: #fef3c7; color: #78350f; border-bottom: 1px solid #fcd34d;
    padding: var(--space-3) var(--space-4); text-align: center; font-size: 0.95rem;
}
.noscript-banner a { color: #92400e; font-weight: 600; }

/* ---------- Header ---------- */
header { padding: var(--space-3) clamp(var(--space-4), 4vw, 2.5rem); }
.header-container {
    gap: var(--space-3); flex-wrap: wrap;
    max-width: 1280px; margin: 0 auto;
    align-items: center; justify-content: space-between;
}
header h1 {
    font-size: clamp(1.05rem, 2.2vw, 1.45rem); margin: 0;
    display: flex; align-items: center; gap: 0.5rem; white-space: nowrap;
}
.brand-link { color: inherit; text-decoration: none; display: inline-flex; align-items: center; flex: 0 1 auto; min-width: 0; }
/* Landing pages use a <span> in the header so the page's own <h1> can carry
   the topic instead of repeating the brand name on every page. */
.brand-name {
    display: inline-flex; align-items: center; gap: 0.5rem;
    font-size: clamp(1.05rem, 2.2vw, 1.45rem); font-weight: 700;
}

/* One flat row: the old rules let the language select keep its margin-right
   and stretch, which wrapped the actions into a vertical column. */
.header-actions { flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--space-2); }
.header-actions .lang-selector {
    width: auto; max-width: 170px; margin: 0; min-height: var(--tap);
    flex: 0 1 auto; font-size: 0.875rem;
}
.header-actions .btn, .header-actions .icon-btn, .header-actions .btn-outline-tmsofts {
    width: auto; min-height: var(--tap); flex: 0 0 auto; white-space: nowrap;
}
.icon-btn { min-width: var(--tap); min-height: var(--tap); display: inline-flex; align-items: center; justify-content: center; }
/* header links are not .btn on the landing pages */
header a.btn-outline-tmsofts, header .brand-link { min-height: var(--tap); }

/* Close button on the sticky ad: a 28px target is unusable on a phone */
.close-ad-btn {
    min-width: 40px; min-height: 40px; font-size: 1rem;
    display: inline-flex; align-items: center; justify-content: center;
}

@media (max-width: 900px) {
    .header-actions .btn-outline-tmsofts span:not(.visually-hidden) { display: none; }
    .header-actions .btn-outline-tmsofts { padding: 0 0.7rem; }
}

/* ---------- Layout ---------- */
.container {
    padding-left: max(var(--space-4), env(safe-area-inset-left));
    padding-right: max(var(--space-4), env(safe-area-inset-right));
    max-width: 1280px;
}
.grid { align-items: start; }

@media (min-width: 1024px) {
    .grid { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 1.75rem; }
    /* Results follow the reader on tall screens */
    .print-report-card { position: sticky; top: calc(var(--header-h) + 1rem); }
}

/* ---------- Forms ---------- */
.form-control {
    min-height: var(--tap);
    font-size: 1rem; /* >=16px stops iOS Safari zoom-on-focus */
    width: 100%;
}
input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.form-group label { font-size: 0.875rem; }
.dimension-grid { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.dimension-grid.col-2 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.dimension-grid.col-3 { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }

/* Both classes are needed: .btn sets width:100% in components.css, so
   .action-buttons .btn must also reset the width or the buttons stack. */
.action-buttons { gap: var(--space-3); display: flex; flex-wrap: wrap; }
.action-buttons .btn { flex: 1 1 160px; width: auto; }

/* components.css turns .action-buttons into a column under 768px via a media
   query; equal-specificity rules declared EARLIER lose to it. Must come after. */
@media (max-width: 768px) {
    .action-buttons { flex-direction: row; flex-wrap: nowrap; gap: var(--space-2); }
    .action-buttons .btn { flex: 1 1 0; min-width: 0; width: auto; padding-left: 0.5rem; padding-right: 0.5rem; }
}

/* ---------- Buttons ---------- */
.btn { min-height: var(--tap); width: auto; padding: 0.7rem 1.1rem; }
.btn-group .btn { flex: 1 1 160px; width: auto; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }

/* ---------- Results ---------- */
.unit-results { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.smart-result-value { font-size: clamp(1.05rem, 3.4vw, 1.4rem); word-break: break-word; }
.highlight-box .total-cost { font-size: clamp(1.3rem, 5vw, 2rem); word-break: break-word; line-height: 1.3; }
.breakdown-row { gap: var(--space-3); }
.result-note { font-size: 0.8rem; color: var(--text-muted); margin-top: var(--space-3); text-align: center; }

/* Unit labels are set dynamically per region (Cent, Guntha, Ropani...) and get
   long; uppercase + letter-spacing made them collide with the value. */
.result-box label {
    text-transform: none; letter-spacing: 0; font-size: 0.8rem;
    line-height: 1.35; display: block; overflow-wrap: anywhere;
}

/* ---------- Plot list ---------- */
.plot-item { gap: var(--space-3); align-items: flex-start; flex-wrap: wrap; }
.plot-item > span { flex: 1 1 60%; min-width: 0; overflow-wrap: anywhere; }
.plot-label { font-weight: 600; }
.btn-remove { min-width: var(--tap); min-height: var(--tap); display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }

/* ---------- Toast ---------- */
.toast {
    left: 50%; right: auto; bottom: calc(1rem + env(safe-area-inset-bottom));
    width: max-content; max-width: min(560px, calc(100vw - 2rem));
    min-width: 0; flex-wrap: wrap;
}
.toast.show { visibility: visible; }
@media (max-width: 480px) {
    .toast { left: 1rem; right: 1rem; transform: none; width: auto; }
}

/* ---------- Tables (conversion pages) ---------- */
.table-scroll {
    width: 100%; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border-color); border-radius: var(--radius);
}
.conversion-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; min-width: 520px; }
.conversion-table th, .conversion-table td { padding: 0.65rem 0.85rem; text-align: left; border-bottom: 1px solid var(--border-color); }
.conversion-table thead th { background: var(--bg-color); font-weight: 700; color: var(--primary); white-space: nowrap; }
.conversion-table tbody th { font-weight: 600; color: var(--text-dark); }
.conversion-table tbody tr:last-child th, .conversion-table tbody tr:last-child td { border-bottom: 0; }
.conversion-table tbody tr:hover { background: var(--smart-box-bg); }

/* ---------- SEO content blocks ---------- */
.card, .grid > *, .container > * { min-width: 0; }
.seo-block { padding: clamp(1rem, 3vw, 1.75rem); }
.seo-lead { color: var(--text-muted); font-size: 0.95rem; line-height: 1.75; }
.seo-links { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); margin-top: var(--space-4); }
.seo-links a { color: var(--accent); font-weight: 600; text-decoration: none; padding: 0.35rem 0; }
.seo-links a:hover { text-decoration: underline; }

.page-title { font-size: clamp(1.3rem, 4vw, 1.9rem); color: var(--primary); margin-bottom: var(--space-2); line-height: 1.25; }
.page-subtitle { color: var(--text-muted); font-size: 0.98rem; line-height: 1.7; margin-bottom: var(--space-5); }
.breadcrumbs { font-size: 0.85rem; color: var(--text-muted); margin-bottom: var(--space-3); }
.breadcrumbs a { color: var(--accent); text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }

.unit-hint {
    font-size: 0.85rem; color: var(--text-muted); background: var(--bg-color);
    border: 1px dashed var(--border-color); border-radius: 6px;
    padding: 0.5rem 0.75rem; margin: 0 0 var(--space-3);
    overflow-wrap: anywhere;
}
.unit-hint strong { color: var(--primary); }

.formula-steps { padding-left: 1.25rem; color: var(--text-dark); line-height: 1.85; font-size: 0.95rem; }
.formula-steps li { margin-bottom: 0.25rem; }
code {
    background: var(--bg-color); border: 1px solid var(--border-color);
    border-radius: 4px; padding: 0.05rem 0.35rem; font-size: 0.9em;
}

/* ---------- Privacy note (analytics disclosure) ---------- */
.privacy-note {
    font-size: 0.8rem; color: var(--text-muted); text-align: center;
    margin: 0 auto 1rem; max-width: 60ch; line-height: 1.6;
}
.privacy-note a { color: var(--accent); }

/* ---------- Tap targets (WCAG 2.5.8: >=24px, aim 44px) ---------- */
.radio-label, .checkbox-label { min-height: var(--tap); }
.lang-selector, .header-actions select { min-height: var(--tap); }
/* the native 18px radio/checkbox control was the smallest hit area on the page */
.radio-label input[type="radio"], .checkbox-label input[type="checkbox"] {
    width: 24px; height: 24px; flex: 0 0 auto;
}
.footer-links { gap: 0.4rem 1.25rem; }
.footer-links a, .seo-links a, .privacy-note a {
    display: inline-flex; align-items: center; min-height: 32px; padding: 0.15rem 0;
}

/* ---------- Ads: never reserve space for an empty placeholder ---------- */
.ad-container[hidden] { display: none !important; }

/* ---------- RTL (Urdu) ---------- */
/* Mirrors the layout for Urdu without a second stylesheet. Directional
   utilities (margin-left, text-align) are flipped here, not per rule. */
[dir="rtl"] body { text-align: right; }
[dir="rtl"] .fa-solid, [dir="rtl"] .fa-regular, [dir="rtl"] .fa-brands { transform: scaleX(1); }
[dir="rtl"] .result-box { border-left: 0; border-right: 3px solid var(--accent); }
[dir="rtl"] .network-info, [dir="rtl"] .seo-block, [dir="rtl"] .faq-content { text-align: right; }
[dir="rtl"] .formula-steps { padding-left: 0; padding-right: 1.25rem; }
[dir="rtl"] input[type="number"], [dir="rtl"] .result-box .value { direction: ltr; text-align: right; }

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
    :root { --header-h: 112px; }
    header { position: sticky; top: 0; }
    .header-container { flex-direction: column; align-items: center; gap: 0.5rem; }
    .header-actions { justify-content: center; width: 100%; }
    .header-actions .lang-selector { max-width: 150px; }

    .container { margin: 1rem auto; }
    .card { padding: 1.1rem; border-radius: 12px; }
    /* Single column: "Bihar (Standard)" and "Punjab / Haryana" were clipped
       in a half-width select on a 390px screen. */
    .dimension-grid.col-2, .dimension-grid.col-3 { grid-template-columns: 1fr; }
    .unit-results { grid-template-columns: 1fr 1fr; }
    .btn-group { flex-direction: column; }
    .btn-group .btn { width: 100%; }
    /* Side-by-side actions on mobile: full-width stacked buttons pushed the
       results panel a whole screen down. */
    .action-buttons { flex-wrap: nowrap; }
    .action-buttons .btn { flex: 1 1 0; min-width: 0; }

    /* Segmented control instead of three loose radio rows */
    .custom-radio-group { gap: 0.35rem; padding: 0.35rem; }
    .radio-label {
        flex: 1 1 100%; padding: 0.55rem 0.7rem; border-radius: 8px;
        background: var(--card-bg); border: 1px solid transparent;
        transition: background 0.15s, border-color 0.15s;
    }
    .radio-label:has(input:checked) {
        background: var(--smart-box-bg); border-color: var(--accent);
        color: var(--smart-text); font-weight: 600;
    }

    .formula-steps { padding-left: 1rem; }
}

@media (max-width: 380px) {
    .unit-results { grid-template-columns: 1fr; }
    header h1 { font-size: 1rem; white-space: normal; text-align: center; }
}

/* ---------- Landscape phones: give back vertical space ---------- */
@media (max-height: 480px) and (orientation: landscape) {
    header { position: static; }
    .print-report-card { position: static; }
}

/* ---------- Print ---------- */
@media print {
    /* Nothing that only exists on screen should survive the print sheet,
       including anything the print script hid by styling it inline. */
    .no-print, .skip-link, .noscript-banner, .seo-block, .unit-hint, .result-note,
    .breadcrumbs, .seo-links, .ad-container { display: none !important; }
    body { padding: 0 !important; }
    .conversion-table { min-width: 0; }
    .table-scroll { overflow: visible; border: none; }
}
