/* سامانه رهگیری ماهکس — #0B1F4B | #E31E24 */
:root {
    --brand-navy: #0B1F4B;
    --brand-navy-light: #162447;
    --brand-navy-mid: #1a2d5a;
    --brand-red: #E31E24;
    --brand-red-dark: #c4191f;
    --bg-page: #f4f6f9;
    --bg-white: #ffffff;
    --text: #1a2340;
    --text-muted: #5c6478;
    --border: #d5dbe6;
    --error: #E31E24;
    --error-bg: #fdf0ef;
    --success: #059669;
    --success-bg: #ecfdf5;
    --radius: 8px;
    --max-w: 980px;
}

*, *::before, *::after { box-sizing: border-box; }

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    font-family: 'Vazirmatn', Tahoma, Arial, sans-serif;
    background: var(--bg-page);
    color: var(--text);
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
    overflow-x: hidden;
}

/* ── Header ── */
.site-header {
    background: var(--brand-navy);
    color: #fff;
    box-shadow: 0 2px 12px rgba(11, 31, 75, 0.25);
}

.header-inner {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.site-logo {
    height: 36px;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
}

.brand-word {
    font-size: 1.25rem;
    font-weight: 800;
    color: #fff;
    letter-spacing: 0.5px;
    line-height: 1;
}

.header-text h1 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
}

/* ── Hero ── */
.hero-wrap {
    position: relative;
    flex: 1;
}

.hero-band {
    height: 280px;
    background:
        linear-gradient(135deg, rgba(11, 31, 75, 0.55) 0%, rgba(22, 36, 71, 0.35) 100%),
        url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 400"><defs><linearGradient id="g" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="%230a1628"/><stop offset="0.5" stop-color="%2316284a"/><stop offset="1" stop-color="%230d4a6e"/></linearGradient></defs><rect fill="url(%23g)" width="1200" height="400"/><path d="M0 320 Q300 280 600 300 T1200 280 L1200 400 L0 400Z" fill="%23081a35" opacity="0.6"/><circle cx="200" cy="120" r="80" fill="%2322d3ee" opacity="0.08"/><circle cx="900" cy="80" r="120" fill="%23E31E24" opacity="0.06"/><path d="M100 250 L400 230 L700 260 L1100 220" stroke="%2322d3ee" stroke-width="2" fill="none" opacity="0.25"/></svg>') center/cover no-repeat;
    position: relative;
    overflow: hidden;
}

.hero-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, transparent 40%, rgba(244, 246, 249, 0.3) 100%);
}

/* ── Main ── */
.site-main {
    max-width: var(--max-w);
    width: 100%;
    margin: -72px auto 0;
    padding: 0 24px 48px;
    position: relative;
    z-index: 2;
    overflow-x: hidden;
}

/* ── کارت جستجو ── */
.search-section {
    background: var(--bg-white);
    border-radius: var(--radius);
    padding: 24px 28px 20px;
    margin-bottom: 28px;
    box-shadow: 0 12px 40px rgba(11, 31, 75, 0.15);
}

.search-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.search-row {
    display: flex;
    gap: 12px;
    align-items: stretch;
}

.input-wrap {
    flex: 1;
    min-width: 0;
    position: relative;
}

.tracking-input {
    width: 100%;
    padding: 13px 44px 13px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 1rem;
    color: var(--text);
    background: var(--bg-white);
    direction: ltr;
    text-align: left;
    letter-spacing: 0.5px;
    transition: border-color 0.15s;
}

.tracking-input:focus {
    border-color: var(--brand-navy);
    outline: 2px solid rgba(11, 31, 75, 0.1);
    outline-offset: 0;
}

.tracking-input.is-valid {
    border-color: var(--success);
    background: var(--success-bg);
}

.tracking-input.is-invalid {
    border-color: var(--error);
    background: var(--error-bg);
}

.btn-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--brand-navy);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    z-index: 2;
    padding: 0;
    box-shadow: 0 1px 4px rgba(11, 31, 75, 0.12);
}

.btn-clear[hidden] {
    display: none !important;
}

.btn-clear:hover {
    background: var(--brand-navy);
    color: #fff;
    border-color: var(--brand-navy);
}

.field-error,
.search-error {
    font-size: 0.8rem;
    color: var(--error);
    margin-top: 10px;
    text-align: center;
    display: none;
}

.field-error.show,
.search-error.show { display: block; }

.btn-submit {
    flex-shrink: 0;
    padding: 14px 24px;
    background: var(--brand-red);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
    transition: background 0.15s;
    min-width: 140px;
}

.btn-submit:hover:not(:disabled) { background: var(--brand-red-dark); }

.btn-submit:disabled {
    background: #9aa5b4;
    cursor: not-allowed;
}

.btn-submit .spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* ── Alerts ── */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-top: 12px;
}

.alert-error {
    background: var(--error-bg);
    border: 1px solid #f5c6c3;
    color: var(--error);
}

.alert svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ── Results ── */
#result-container {
    margin-top: 0;
    max-width: 100%;
    overflow: hidden;
}

.result-panel {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(11, 31, 75, 0.08);
    max-width: 100%;
}

.result-topbar {
    background: var(--brand-navy);
    color: #fff;
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    flex-wrap: wrap;
}

.result-topbar h3 {
    margin: 0 0 4px;
    font-size: 1rem;
    font-weight: 700;
}

.result-topbar .meta {
    font-size: 0.8rem;
    opacity: 0.8;
}

.tracking-code {
    background: #fff;
    border: 1px solid rgba(255,255,255,0.2);
    padding: 5px 12px;
    border-radius: 8px;
    font-size: 0.82rem;
    direction: ltr;
    letter-spacing: 0.5px;
    color: var(--brand-red);
    font-weight: 700;
    word-break: break-all;
    max-width: 100%;
}

.btn-close-result {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--brand-red);
    border: none;
    color: #fff;
    padding: 7px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 700;
    font-family: inherit;
    flex-shrink: 0;
    transition: background 0.15s;
}

.btn-close-result:hover { background: var(--brand-red-dark); }

.btn-close-result svg { width: 14px; height: 14px; flex-shrink: 0; }

.result-topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    max-width: 100%;
    min-width: 0;
}

.status-strip {
    background: #f0f3f8;
    padding: 16px 24px;
    border-bottom: 3px solid var(--brand-red);
}

.status-strip .label {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.status-strip .value {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--brand-navy);
    line-height: 1.55;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.status-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.chip {
    font-size: 0.75rem;
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
    padding: 4px 10px;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.chip svg { width: 11px; height: 11px; opacity: 0.85; flex-shrink: 0; }

.result-body {
    padding: 24px;
    overflow: hidden;
    max-width: 100%;
}

.section-heading {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--brand-navy);
    margin: 0 0 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--brand-red);
    display: inline-block;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
    margin-bottom: 28px;
    max-width: 100%;
}

.info-cell {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    background: var(--bg-page);
    min-width: 0;
    overflow: hidden;
}

.info-cell .k {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.info-cell .v {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text);
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* ── Timeline ── */
.timeline {
    padding: 0;
    max-width: 100%;
    overflow: hidden;
}

.tl-date {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--brand-navy);
    background: #e8edf5;
    padding: 5px 12px;
    border-radius: 8px;
    display: inline-block;
    margin: 20px 0 12px;
}

.tl-date:first-child { margin-top: 0; }

.tl-item {
    display: flex;
    gap: 14px;
    padding-bottom: 18px;
    position: relative;
    max-width: 100%;
    min-width: 0;
}

.tl-item::before {
    content: '';
    position: absolute;
    right: 13px;
    top: 28px;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.tl-item:last-child::before { display: none; }

.tl-num {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--bg-white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 800;
    color: var(--text-muted);
    flex-shrink: 0;
    z-index: 1;
}

.tl-item.is-latest .tl-num {
    background: var(--brand-navy);
    border-color: var(--brand-navy);
    color: #fff;
}

.tl-body {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    background: var(--bg-white);
    overflow: hidden;
}

.tl-item.is-latest .tl-body {
    border-color: var(--brand-navy);
    border-inline-start: 3px solid var(--brand-red);
}

.tl-status {
    font-size: 0.88rem;
    font-weight: 600;
    margin-bottom: 8px;
    line-height: 1.55;
}

.tl-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-page);
    border: 1px solid var(--border);
    padding: 3px 8px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.tag svg { width: 11px; height: 11px; flex-shrink: 0; }

.loading-box {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-size: 0.9rem;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 20px rgba(11, 31, 75, 0.08);
}

.loading-box .spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--brand-navy);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 0 auto 12px;
}

/* ── Print FAB ── */
.btn-print-fab {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 900;
    display: none;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--brand-navy);
    color: #fff;
    border: 2px solid var(--brand-red);
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,0.18);
}

.btn-print-fab.visible { display: inline-flex; }

.btn-print-fab svg { width: 16px; height: 16px; }

@media print {
    @page {
        size: A4 portrait;
        margin: 12mm 14mm;
    }

    html, body {
        background: #fff !important;
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow: visible !important;
    }

    .site-header,
    .hero-band,
    .search-section,
    .btn-print-fab {
        display: none !important;
    }

    .hero-wrap {
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .site-main,
    #result-container,
    #printArea,
    .result-panel {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        box-sizing: border-box !important;
        float: none !important;
    }

    .result-topbar,
    .status-strip,
    .result-body {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 12px 10px !important;
        overflow: visible !important;
        box-sizing: border-box !important;
    }

    .result-topbar {
        flex-wrap: wrap !important;
    }

    .result-topbar-actions {
        width: 100% !important;
        margin-top: 8px !important;
    }

    .tracking-code {
        max-width: 100% !important;
        word-break: break-all !important;
        white-space: normal !important;
    }

    .info-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 8px !important;
        width: 100% !important;
    }

    .info-cell,
    .tl-body,
    .tl-item,
    .timeline,
    .status-chips,
    .tl-tags {
        max-width: 100% !important;
        overflow: visible !important;
        box-sizing: border-box !important;
    }

    .info-cell,
    .tl-body {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .tl-item.is-latest .tl-body {
        border-inline-start: none !important;
        padding-inline-start: 14px !important;
    }

    .tl-item::before { display: none !important; }

    .tl-num { display: none !important; }

    .tl-item { gap: 0 !important; padding-bottom: 12px !important; }

    .result-topbar,
    .status-strip {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .btn-close-result { display: none !important; }
}

@media (max-width: 768px) {
    .hero-band { height: 200px; }
    .site-main { margin-top: -56px; padding: 0 14px 80px; }
    .search-section { padding: 18px 16px; }
    .search-row { flex-direction: column; }
    .btn-submit { width: 100%; }
    .result-topbar, .status-strip, .result-body { padding-left: 16px; padding-right: 16px; }
    .header-inner { padding: 12px 16px; }
    .btn-print-fab { left: 16px; bottom: 16px; }
}
