/* ============================================================
   SemiParts — Mobile-First Stylesheet (multi-image support)
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
    --primary: #0a3d62;
    --accent: #1e90ff;
    --bg: #f5f7fa;
    --card: #ffffff;
    --text: #2c3e50;
    --muted: #7f8c8d;
    --border: #e1e8ed;
    --success: #27ae60;
    --radius: 10px;
    --tap-target: 44px;
}

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.6;
    font-size: 16px;
    overflow-x: hidden;
}

img { max-width: 100%; height: auto; display: block; }
a { -webkit-touch-callout: none; }

.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* ============================================================
   HEADER + MOBILE NAV
   ============================================================ */
.header {
    background: var(--primary);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    min-height: 60px;
    position: relative;
    gap: 12px;
}
.logo a { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; }
.logo-mark {
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 8px;
    font-size: 20px;
    flex-shrink: 0;
}
.logo-text { font-size: 19px; font-weight: 700; white-space: nowrap; }
.logo-dot { color: var(--accent); }

.mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.12);
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    width: var(--tap-target);
    height: var(--tap-target);
    border-radius: 8px;
    flex-shrink: 0;
    transition: background .2s;
}
.mobile-menu-toggle:active { background: rgba(255,255,255,0.25); }

.nav { display: flex; gap: 22px; align-items: center; }
.nav a {
    color: #fff;
    text-decoration: none;
    font-weight: 500;
    padding: 10px 4px;
    display: inline-block;
}
.nav a:hover { color: var(--accent); }
.btn-admin {
    background: var(--accent);
    padding: 10px 16px;
    border-radius: 6px;
}
.btn-admin:hover { background: #0b7bd0; color: #fff !important; }

/* ============================================================
   HERO
   ============================================================ */
.hero {
    background: linear-gradient(135deg, var(--primary), #1e5799);
    color: #fff;
    padding: 44px 16px;
    text-align: center;
}
.hero h1 {
    font-size: clamp(24px, 5.5vw, 38px);
    margin-bottom: 10px;
    line-height: 1.25;
}
.hero p {
    font-size: clamp(15px, 3.8vw, 18px);
    margin-bottom: 22px;
    opacity: 0.95;
    padding: 0 8px;
}
.search-bar {
    display: flex;
    max-width: 600px;
    margin: 0 auto;
    gap: 8px;
}
.search-bar input {
    flex: 1;
    padding: 14px 16px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    outline: none;
    min-height: var(--tap-target);
}
.search-bar button {
    padding: 14px 24px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    min-height: var(--tap-target);
    flex-shrink: 0;
}
.search-bar button:active { background: #0b7bd0; }

/* ============================================================
   FILTERS
   ============================================================ */
.filters {
    display: flex;
    gap: 12px;
    padding: 20px 16px 4px;
    flex-wrap: wrap;
    align-items: center;
}
.filters label {
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    flex: 1 1 auto;
    min-width: 140px;
}
.filters select {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    font-size: 16px;
    min-height: var(--tap-target);
    width: 100%;
}

/* ============================================================
   CATALOG GRID
   ============================================================ */
.catalog { padding: 24px 16px 48px; }

.parts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 18px;
}

.part-card {
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
    cursor: pointer;
    transition: transform .2s, box-shadow .2s;
    display: flex;
    flex-direction: column;
    -webkit-user-select: none;
    user-select: none;
}
.part-card:hover,
.part-card:active {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.12);
}

.part-img-wrap {
    position: relative;
    background: #eef2f6;
}
.part-img {
    width: 100%;
    height: 190px;
    object-fit: cover;
    background: #eef2f6;
}
.photo-count {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0,0,0,0.65);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 12px;
}

.part-info {
    padding: 14px 16px 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.part-no {
    font-size: 12px;
    color: var(--muted);
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.part-name {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.35;
}
.part-desc {
    font-size: 14px;
    color: var(--muted);
    margin: 6px 0 10px;
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.part-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.part-price {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-new         { background: #d4f5e2; color: #18794e; }
.badge-refurbished { background: #dbeafe; color: #1e40af; }
.badge-used        { background: #fef3c7; color: #92400e; }

.stock { font-size: 13px; color: var(--muted); }
.stock.low { color: #d97706; font-weight: 600; }
.stock.out { color: #dc2626; font-weight: 600; }

.no-results {
    text-align: center;
    padding: 60px 20px;
    color: var(--muted);
    font-size: 17px;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    z-index: 200;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px;
}
.modal.active { display: block; }

.modal-content {
    background: #fff;
    max-width: 900px;
    margin: 0 auto;
    border-radius: var(--radius);
    position: relative;
    animation: slideUp .3s ease;
    overflow: hidden;
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: none; }
}

.close {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    color: #fff;
    background: rgba(0,0,0,0.5);
    width: var(--tap-target);
    height: var(--tap-target);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border: none;
}
.close:active { background: rgba(0,0,0,0.8); }

.modal-body { padding: 0; }

.gallery-main {
    position: relative;
    background: #eef2f6;
}
.modal-header-img {
    width: 100%;
    max-height: 320px;
    object-fit: contain;
    background: #eef2f6;
    display: block;
}
.gallery-counter {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 12px;
}

.gallery-thumbs {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
}
.gallery-thumb {
    flex: 0 0 auto;
    width: 64px;
    height: 64px;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    overflow: hidden;
    transition: border-color .15s, transform .15s;
}
.gallery-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.gallery-thumb.active { border-color: var(--accent); }
.gallery-thumb:active { transform: scale(0.95); }

.modal-details { padding: 22px 20px 26px; }
.modal-details h2 {
    font-size: clamp(20px, 5vw, 26px);
    margin-bottom: 4px;
    line-height: 1.3;
    padding-right: 8px;
}
.modal-partno {
    color: var(--muted);
    font-weight: 600;
    margin-bottom: 18px;
    font-size: 14px;
    word-break: break-word;
}

.spec-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin: 16px 0;
}
.spec-item {
    background: #f8fafc;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
}
.spec-label {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.5px;
    font-weight: 700;
}
.spec-value {
    font-size: 15px;
    font-weight: 600;
    margin-top: 2px;
    word-break: break-word;
}

.terms-box {
    background: #fff8e6;
    border-left: 4px solid #f0b429;
    padding: 14px 16px;
    border-radius: 6px;
    margin-top: 18px;
    font-size: 14px;
}
.terms-box h4 { margin-bottom: 8px; color: #92400e; font-size: 15px; }
.terms-box ul { padding-left: 18px; color: #555; }
.terms-box li { margin-bottom: 4px; }

.action-row {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.btn {
    padding: 12px 18px;
    border-radius: 8px;
    border: none;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--tap-target);
    flex: 1 1 auto;
    text-align: center;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: #062a45; }
.btn-accent  { background: var(--accent); color: #fff; }
.btn-accent:active { background: #0b7bd0; }
.btn-outline { background: #fff; color: var(--primary); border: 2px solid var(--primary); }
.btn-outline:active { background: var(--primary); color: #fff; }

/* ============================================================
   SECTIONS
   ============================================================ */
.about, .contact {
    padding: 48px 16px;
    text-align: center;
    background: #fff;
}
.about h2, .contact h2 {
    font-size: clamp(22px, 5vw, 30px);
    margin-bottom: 14px;
    color: var(--primary);
}
.about p, .contact p {
    max-width: 700px;
    margin: 0 auto;
    color: var(--muted);
    font-size: 16px;
}

/* ============================================================
   FOOTER
   ============================================================ */
.footer {
    background: var(--primary);
    color: #fff;
    text-align: center;
    padding: 22px 16px;
    font-size: 14px;
}
.footer a { color: var(--accent); text-decoration: none; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--primary);
        flex-direction: column;
        padding: 12px 16px 16px;
        gap: 4px;
        box-shadow: 0 8px 16px rgba(0,0,0,0.2);
        border-top: 1px solid rgba(255,255,255,0.1);
    }
    .nav.open { display: flex; }
    .nav a {
        padding: 14px 12px;
        border-radius: 8px;
        font-size: 16px;
        width: 100%;
    }
    .nav a:active { background: rgba(255,255,255,0.12); }
    .btn-admin { text-align: center; margin-top: 6px; }

    .parts-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .part-img   { height: 140px; }
    .part-info  { padding: 12px; }
    .part-name  { font-size: 15px; }
    .part-desc  { font-size: 13px; }
    .part-price { font-size: 16px; }
    .badge      { font-size: 11px; padding: 2px 8px; }
    .photo-count { font-size: 11px; padding: 2px 7px; bottom: 6px; right: 6px; }

    .search-bar { flex-direction: column; }
    .search-bar input,
    .search-bar button { width: 100%; border-radius: 8px; }

    .modal { padding: 0; }
    .modal-content {
        border-radius: 0;
        min-height: 100vh;
        animation: none;
    }
    .modal-header-img { max-height: 240px; }
    .gallery-thumb { width: 56px; height: 56px; }
    .spec-grid { grid-template-columns: 1fr; }
    .action-row { flex-direction: column; }
    .action-row .btn { width: 100%; flex: 1 1 100%; }
}

@media (max-width: 400px) {
    .parts-grid { grid-template-columns: 1fr; }
    .part-img   { height: 180px; }
    .logo-text  { font-size: 17px; }
}

@media (min-width: 992px) {
    .parts-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 24px; }
    .part-img   { height: 200px; }
    .modal { padding: 40px 20px; }
    .modal-content { border-radius: var(--radius); min-height: auto; }
    .action-row .btn { flex: 0 0 auto; }
}

@media (max-width: 768px) and (orientation: landscape) and (max-height: 500px) {
    .hero { padding: 24px 16px; }
    .modal-header-img { max-height: 160px; }
}

body.modal-open { overflow: hidden; position: fixed; width: 100%; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}