/* ----------------------------------------------------
 * Script: style.css
 * Version: 5.5 (Fixed sticky column colors for mobile themes)
 * ---------------------------------------------------- */

/* --- FONT DEFINITIONS --- */
@font-face {
    font-family: 'IRANSans';
    src: url('../fonts/IRANSansWeb(FaNum).woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IRANSans';
    src: url('../fonts/IRANSansWeb(FaNum)_Bold.woff2') format('woff2');
    font-weight: bold;
    font-style: normal;
    font-display: swap;
}

/* --- GLOBAL --- */
* { box-sizing: border-box; }

body {
    font-family: 'IRANSans', Arial, sans-serif;
    background-color: #f4f4f4;
    margin: 0; padding: 0;
    color: #333;
}

a { text-decoration: none; color: inherit; }

.container {
    max-width: 1140px;
    margin: 0 auto;
    padding: 0 16px;
}

main {
    max-width: 900px;
    margin: 32px auto 40px;
    padding: 0 20px;
}

/* ----------------------------------------------------
   REGION 1 — TOP BLACK BAR
---------------------------------------------------- */

.topbar {
    background-color: #000;
    color: #fff;
    font-size: 0.85rem;
}

.topbar__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
}

.topbar__right {
    order: 1;
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar__left {
    order: 2;
    display: flex;
    align-items: center;
    gap: 14px;
}

.topbar-social {
    display: flex;
    gap: 14px;
}

/* SOCIAL ICONS */
.social-link {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .25s ease;
}

.social-link i {
    font-size: 15px;
    color: #3d3d3d;
    transition: all .25s ease;
}

.social-link--whatsapp:hover { background-color: #25D366; }
.social-link--telegram:hover { background-color: #29A9E0; }
.social-link--instagram:hover {
    background: radial-gradient(circle at 30% 107%, #fdf497 0%, #fdf497 5%, #fd5949 45%, #d6249f 60%, #285AEB 90%);
}

.social-link:hover i { color: #ffffff; }

/* ----------------------------------------------------
   REGION 2 — WHITE HEADER BAR (LOGO + MENU)
---------------------------------------------------- */

.site-header {
    background-color: #ffffff;
    border-bottom: 1px solid #eee;
}

.site-header__inner {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 10px 0;
}

.site-logo {
    font-size: 1.35rem;
    font-weight: 700;
    color: #f5841a;
    white-space: nowrap;
}

.site-nav { margin-right: 20px; }

.site-nav ul {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0; margin: 0;
}

.site-nav a {
    font-size: 0.93rem;
    color: #f5841a;
    position: relative;
    padding-bottom: 2px;
}

.site-nav a::after {
    content: "";
    position: absolute;
    right: 0;
    bottom: -3px;
    width: 0;
    height: 2px;
    background-color: #f5841a;
    transition: width 0.2s ease;
}

.site-nav a:hover::after { width: 100%; }

@media (max-width: 900px) {
    .site-header__inner {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .site-nav { margin-right: 0; }
    .site-nav ul { gap: 10px; flex-wrap: wrap; }
}

/* ----------------------------------------------------
   CARDS & LAYOUT
---------------------------------------------------- */

.card {
    background-color: #fff;
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 30px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

/* --- TABS --- */
.tabs-container {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: center;
}

.tab-btn {
    flex: 1;
    max-width: 200px;
    height: 45px;
    background-color: #eee;
    color: #666;
    border: none;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
}

.tab-btn i {
    font-size: 1.1rem;
}

.tab-btn.active {
    color: #fff;
    background-color: #f5841a;
}

/* THEME: ROUND BALL (Blue + Orange) */
.theme-round .tab-btn[data-type="5401"].active {
    background-color: #2b6cb0; /* Blue-600 */
    border-bottom-color: #f5841a;
}
.theme-round .card:first-of-type {
    border-top: 4px solid #2b6cb0;
}
.theme-round #search-button {
    background-color: #2b6cb0;
}
.theme-round #search-button:hover {
    background-color: #2c5282;
}

/* THEME: NEEDLE ROLLER (Light Green + Orange) */
.theme-needle .tab-btn[data-type="5402"].active {
    background-color: #38a169; /* Green-500 */
    border-bottom-color: #f5841a;
}
.theme-needle .card:first-of-type {
    border-top: 4px solid #38a169;
}
.theme-needle #search-button {
    background-color: #38a169;
}
.theme-needle #search-button:hover {
    background-color: #2f855a;
}

/* --- SEARCH FORM STYLES --- */

.search-section {
    display: none;
}

.search-section.active {
    display: block;
}

/* Needle Input Grid */
.needle-search-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

@media (min-width: 600px) {
    .needle-search-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.input-with-unit {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 8px;
    border: 1px solid #eee;
}

.input-with-unit label {
    font-weight: bold;
}

.mini-unit-selector {
    display: flex;
    gap: 10px;
    font-size: 0.85rem;
}

.mini-unit-option {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

/* APP HEADER (Reversed Horizontal Layout) - New in v5.3 */
.app-header {
    display: flex;
    /* row-reverse puts the first item (logo) on the left in RTL */
    flex-direction: row-reverse;
    align-items: center;      /* Vertically center */
    justify-content: center;  /* Center the whole block */
    gap: 15px;
    margin-bottom: 25px;
}

.app-header__logo img {
    /* Set HEIGHT instead of width to match text block height */
    height: 55px; 
    width: auto; /* Maintain aspect ratio */
    display: block;
}

.app-header__text {
    text-align: left;
    direction: ltr;
}

.app-title {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 700;
    color: #f5841a;
    line-height: 1.1;
}

.app-subtitle {
    margin: 4px 0 0 0;
    font-size: 0.85rem;
    color: #777;
}

/* (a) Input Group Centering */
.input-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;
}

.input-group label {
    margin-bottom: 8px;
    font-weight: bold;
}

#diameter-input {
    width: 100%;
    max-width: 300px;
    text-align: center;
}

/* (b) Unit Selector Centering & Sizing */
.unit-selector {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 10px 20px;
    margin: 0 auto 20px auto;
    width: fit-content;
    display: flex;
    gap: 20px;
    justify-content: center;
}

.unit-selector legend {
    padding: 0 10px;
    color: #666;
    font-size: 0.9rem;
    margin: 0 auto;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

/* (c) User Guide Centering */
.user-guide {
    text-align: center;
    margin-bottom: 25px;
    color: #555;
    font-size: 0.95rem;
    line-height: 1.6;
}

.user-guide ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.user-guide li {
    margin-bottom: 5px;
}

/* (d) Buttons Centering */
.button-group {
    display: flex;
    justify-content: center;
    gap: 10px;
}

/* --- BUTTONS & INPUTS GLOBAL --- */

button, input, select {
    font-family: inherit;
    font-size: 1rem;
}

button {
    padding: 0 25px;
    height: 40px;
    border: none;
    border-radius: 5px;
    color: #fff;
    cursor: pointer;
    transition: 0.3s;
}

#search-button,
#first-page-button,
#prev-page-button,
#next-page-button,
#last-page-button {
    background-color: #f5841a;
}

#clear-button, #reset-filters-button {
    background-color: #6c757d;
}

button:hover:not(:disabled) { opacity: 0.85; }

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    filter: grayscale(0.7);
}

input[type="text"], select {
    height: 40px;
    border: 1px solid #ccc;
    padding: 0 10px;
    border-radius: 5px;
}

input[type="text"]:focus, select:focus {
    border-color: #f5841a;
    box-shadow: 0 0 5px rgba(245,132,26,0.5);
}

/* Hamburger Menu (Hidden by default, shown on mobile) */
.menu-toggle {
    display: none;
    background: none;
    color: #f5841a;
    font-size: 1.5rem;
    padding: 0;
    height: auto;
    border: none;
    cursor: pointer;
}

.nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

.nav-overlay.active {
    display: block;
}

/* View Toggle UI (Global) */
.header-with-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.header-with-toggle h2 {
    margin-bottom: 0 !important;
}

.view-toggle {
    display: flex;
    gap: 5px;
}

.view-toggle-btn {
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 4px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
    color: #666;
    padding: 0;
}

.view-toggle-btn.active {
    background: #f5841a;
    color: #fff !important;
    border-color: #f5841a;
}

.view-toggle-btn i {
    pointer-events: none;
}

/* Help Toggle (Hidden by default, shown on mobile) */
.help-toggle {
    display: none;
    background: #f5841a;
    color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    margin: 10px auto;
}

/* Card View Styles (Global so they work on Desktop too if toggled) */
.view-mode-card #results-table thead {
    display: none;
}

.view-mode-card #results-table, 
.view-mode-card #results-table tbody, 
.view-mode-card #results-table tr, 
.view-mode-card #results-table td {
    display: block;
    width: 100%;
}

.view-mode-card #results-table tr {
    margin-bottom: 15px;
    border: 1px solid #eee;
    border-radius: 8px;
    background: #fff;
    padding: 15px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.view-mode-card #results-table tr:nth-child(even) {
    background: #f9f9f9;
}
.theme-round .view-mode-card #results-table tr:nth-child(even) { background-color: #ebf8ff; }
.theme-needle .view-mode-card #results-table tr:nth-child(even) { background-color: #f0fff4; }

.view-mode-card #results-table td {
    text-align: right;
    padding: 10px 5px;
    border: none;
    position: relative;
    padding-right: 40%;
    font-size: 0.95rem;
}

.view-mode-card #results-table td::before {
    content: attr(data-label);
    position: absolute;
    right: 0;
    width: 35%;
    padding-right: 10px;
    font-weight: bold;
    color: #777;
}

.view-mode-card #results-table td:last-child {
    padding-right: 5px;
    text-align: center;
    border-top: 1px solid #eee;
    margin-top: 10px;
    padding-top: 15px;
}

.view-mode-card #results-table td:last-child::before {
    content: none;
}

/* Table Sticky Column Styles for Table View */
.view-mode-table .results-table-container {
    overflow-x: auto;
}

/* ----------------------------------------------------
   RESULTS SECTION
---------------------------------------------------- */

#results-section h2 {
    text-align: center;
    margin-top: 0;
    color: #333;
}

/* Filters */
#filter-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px;
    background-color: #f9f9f9;
    border-radius: 6px;
    justify-content: center;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Message Area */
#message-area {
    margin: 15px 0;
    padding: 10px;
    border-radius: 5px;
    text-align: center;
    font-weight: bold;
}

.error-message {
    background-color: #ffebee;
    color: #c62828;
    border: 1px solid #ef9a9a;
}

.suggestion-link {
    color: #f5841a;
    text-decoration: underline;
    cursor: pointer;
    font-weight: bold;
    margin: 0 4px;
    transition: color 0.2s;
}

.suggestion-link:hover {
    color: #d46f14;
}

/* Table */
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

thead { background-color: #efbc8c; }

td, th {
    padding: 10px;
    text-align: center;
    border-bottom: 1px solid #ddd;
}

tbody tr:nth-child(even) { background-color: #f9f9f9; }
.theme-round tbody tr:nth-child(even) { background-color: #ebf8ff; } /* Light blue for Round */
.theme-needle tbody tr:nth-child(even) { background-color: #f0fff4; } /* Light green for Needle */
tbody tr:hover { background-color: #f1f1f1; }
.theme-round tbody tr:hover { background-color: #bee3f8; }
.theme-needle tbody tr:hover { background-color: #c6f6d5; }

/* Pagination */
#pagination-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
    margin-top: 25px;
}

.rows-per-page-selector {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 5px;
}

/* ----------------------------------------------------
   MOBILE RESPONSIVENESS
---------------------------------------------------- */

@media (max-width: 768px) {
    main { padding: 0 12px; margin-top: 20px; }

    /* Topbar adjustments */
    .topbar { font-size: 0.75rem; }
    .topbar__inner { flex-direction: column; gap: 4px; padding: 10px 0; }
    .topbar__right { flex-direction: column; gap: 4px; align-items: center; }
    .topbar__left { margin-top: 5px; }

    /* Hamburger Menu */
    .menu-toggle {
        display: block;
        order: -1; /* Right side in RTL */
    }

    .site-header__inner {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 15px 16px;
    }

    .site-nav {
        position: fixed;
        right: -280px;
        top: 0;
        width: 280px;
        height: 100%;
        background: #fff;
        z-index: 1000;
        transition: right 1.2s cubic-bezier(0.4, 0, 0.2, 1);
        padding: 60px 20px 20px;
        box-shadow: -5px 0 15px rgba(0,0,0,0.1);
        margin-right: 0;
    }

    .site-nav.active {
        right: 0;
    }

    .site-nav ul {
        flex-direction: column;
        align-items: flex-start;
        gap: 20px;
    }

    .site-nav a {
        font-size: 1.1rem;
        display: block;
        width: 100%;
        padding: 8px 0;
        border-bottom: 1px solid #f0f0f0;
    }

    .view-mode-table #results-table {
        display: table;
        min-width: 600px; /* Force scroll */
    }

    .view-mode-table #results-table th:nth-child(1),
    .view-mode-table #results-table td:nth-child(1) {
        position: sticky;
        right: 0;
        z-index: 10;
        background: #fdfdfd;
        box-shadow: -2px 0 5px rgba(0,0,0,0.05);
    }

    .view-mode-table #results-table th:nth-child(2),
    .view-mode-table #results-table td:nth-child(2) {
        position: sticky;
        right: 50px; /* Width of first column */
        z-index: 10;
        background: #fdfdfd;
        box-shadow: -2px 0 5px rgba(0,0,0,0.05);
    }

    /* Theme colors for sticky columns on mobile */
    .theme-round .view-mode-table #results-table tr:nth-child(even) td:nth-child(1),
    .theme-round .view-mode-table #results-table tr:nth-child(even) td:nth-child(2) {
        background-color: #ebf8ff;
    }
    .theme-needle .view-mode-table #results-table tr:nth-child(even) td:nth-child(1),
    .theme-needle .view-mode-table #results-table tr:nth-child(even) td:nth-child(2) {
        background-color: #f0fff4;
    }
    .theme-round .view-mode-table #results-table tr:hover td:nth-child(1),
    .theme-round .view-mode-table #results-table tr:hover td:nth-child(2) {
        background-color: #bee3f8;
    }
    .theme-needle .view-mode-table #results-table tr:hover td:nth-child(1),
    .theme-needle .view-mode-table #results-table tr:hover td:nth-child(2) {
        background-color: #c6f6d5;
    }

    /* Card View overrides for Mobile (now manual toggle) */
    .view-mode-card #results-table td {
        padding-right: 45%;
    }

    .view-mode-card #results-table td::before {
        width: 40%;
    }

    /* Guides/Help Logic on Mobile */
    .user-guide ul {
        display: none;
    }

    .user-guide ul.active {
        display: block;
        margin-top: 10px;
        padding: 15px;
        background: #fdfdfd;
        border: 1px dashed #f5841a;
        border-radius: 8px;
    }

    .help-toggle {
        display: flex;
    }

    /* App Header adjustments */
    .app-header {
        flex-direction: column;
        text-align: center;
        direction: rtl; 
    }
    .app-header__text {
        text-align: center;
        direction: ltr;
    }
    .app-header__logo img {
        height: auto;
        max-width: 80px;
        margin-bottom: 10px;
    }

    .app-title { font-size: 1.5rem; }

    /* Filters Stack */
    #filter-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .filter-group {
        flex-direction: column;
        align-items: stretch;
    }

    #pagination-controls { flex-wrap: wrap; gap: 8px; }
    
    .rows-per-page-selector {
        margin-left: 0;
        justify-content: center;
        width: 100%;
        margin-top: 10px;
    }
}
