/* ============================================
   DESIGN SYSTEM & CSS VARIABLES - LIGHT THEME
   ============================================ */
:root {
    /* Colors - Light Premium Theme (Brand: Red/Black/Blue) */
    --bg-primary: #f5f7fb;
    --bg-secondary: #eef1f8;
    --bg-card: #ffffff;
    --bg-card-hover: #f8f9fd;
    --bg-glass: rgba(255, 255, 255, 0.9);

    --accent-primary: #1a3a7a;
    --accent-secondary: #2556b0;
    --accent-glow: rgba(26, 58, 122, 0.15);
    --accent-gradient: linear-gradient(135deg, #1a3a7a 0%, #2556b0 50%, #3366cc 100%);
    --accent-gradient-reverse: linear-gradient(135deg, #3366cc 0%, #2556b0 50%, #1a3a7a 100%);
    --brand-red: #c41e2a;
    --brand-dark: #1c1c1c;

    --text-primary: #1a1a2e;
    --text-secondary: #555770;
    --text-muted: #8890a4;
    --text-accent: #1a3a7a;

    --border-color: rgba(26, 58, 122, 0.12);
    --border-glow: rgba(26, 58, 122, 0.25);

    --success: #0d9f6e;
    --warning: #d97706;
    --danger: #dc2626;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 20px rgba(26, 58, 122, 0.1);

    /* Spacing */
    --header-height: 80px;
    --container-max: 1400px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   RESET & BASE
   ============================================ */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Tajawal', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.7;
    overflow-x: hidden;
    min-height: 100vh;
    position: relative;
}

/* Ambient background gradient */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    right: -30%;
    width: 80vw;
    height: 80vw;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(26, 58, 122, 0.04) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

body::after {
    content: '';
    position: fixed;
    bottom: -30%;
    left: -20%;
    width: 60vw;
    height: 60vw;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(196, 30, 42, 0.03) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

.container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 20px;
    position: relative;
    z-index: 1;
}

/* ============================================
   LOADING OVERLAY
   ============================================ */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

.loader-container {
    text-align: center;
}

.loader-ring {
    display: inline-block;
    position: relative;
    width: 64px;
    height: 64px;
}

.loader-ring div {
    box-sizing: border-box;
    display: block;
    position: absolute;
    width: 52px;
    height: 52px;
    margin: 6px;
    border: 3px solid transparent;
    border-radius: 50%;
    animation: loader-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
    border-top-color: var(--accent-primary);
}

.loader-ring div:nth-child(1) {
    animation-delay: -0.45s;
}

.loader-ring div:nth-child(2) {
    animation-delay: -0.3s;
    border-top-color: var(--brand-red);
}

.loader-ring div:nth-child(3) {
    animation-delay: -0.15s;
}

@keyframes loader-ring {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.loader-text {
    color: var(--text-secondary);
    font-size: 16px;
    margin-top: 20px;
    font-weight: 500;
    animation: pulse-text 1.5s ease-in-out infinite;
}

@keyframes pulse-text {

    0%,
    100% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }
}

/* ============================================
   HEADER
   ============================================ */
.header {
    background: linear-gradient(180deg, #ffffff 0%, var(--bg-primary) 100%);
    border-bottom: 1px solid var(--border-color);
    padding: 20px 0;
    position: relative;
    overflow: hidden;
}

.header-bg-pattern {
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle at 20% 50%, rgba(26, 58, 122, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 50%, rgba(196, 30, 42, 0.02) 0%, transparent 50%);
    pointer-events: none;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-icon {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    background: transparent;
    box-shadow: none;
}

.logo-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.logo-icon svg {
    width: 30px;
    height: 30px;
}

.site-title {
    font-size: 22px;
    font-weight: 800;
    color: var(--accent-primary);
    line-height: 1.3;
}

.site-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 400;
}

.header-stats {
    display: flex;
    gap: 10px;
}

.stat-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 50px;
    padding: 8px 16px;
    font-size: 14px;
    box-shadow: var(--shadow-sm);
}

.stat-icon {
    font-size: 16px;
}

.stat-value {
    font-weight: 700;
    color: var(--accent-primary);
}

.stat-label {
    color: var(--text-secondary);
}

/* ============================================
   SEARCH
   ============================================ */
.search-section {
    padding: 20px 0 0;
    position: sticky;
    top: 0;
    z-index: 100;
    background: linear-gradient(180deg, var(--bg-primary) 60%, transparent 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.search-wrapper {
    position: relative;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    right: 18px;
    width: 22px;
    height: 22px;
    color: var(--text-muted);
    transition: color var(--transition-normal);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 16px 50px 16px 50px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 16px;
    font-family: 'Tajawal', sans-serif;
    transition: all var(--transition-normal);
    outline: none;
    box-shadow: var(--shadow-sm);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input:focus {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow), 0 0 0 4px rgba(26, 58, 122, 0.08);
    background: #fff;
}

.search-input:focus~.search-icon,
.search-input:focus+.search-icon {
    color: var(--accent-primary);
}

.clear-search-btn {
    position: absolute;
    left: 14px;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.clear-search-btn svg {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
}

.clear-search-btn:hover {
    background: rgba(220, 38, 38, 0.1);
}

.clear-search-btn:hover svg {
    color: var(--danger);
}

.search-results-count {
    padding: 8px 0;
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
}

.search-results-count .highlight {
    color: var(--accent-primary);
    font-weight: 700;
}

/* ============================================
   TABS
   ============================================ */
.tabs-nav {
    padding: 16px 0 0;
    position: sticky;
    top: 72px;
    z-index: 99;
    background: linear-gradient(180deg, var(--bg-primary) 80%, transparent 100%);
}

.tabs-scroll-container {
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 12px;
}

.tabs-scroll-container::-webkit-scrollbar {
    display: none;
}

.tabs-list {
    display: flex;
    gap: 8px;
    min-width: max-content;
}

.tab-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: 2px solid var(--border-color);
    border-radius: 50px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: 'Tajawal', sans-serif;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-normal);
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.tab-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--accent-gradient);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.tab-btn:hover {
    border-color: var(--accent-primary);
    color: var(--text-primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.tab-btn.active {
    border-color: var(--accent-primary);
    color: white;
    box-shadow: 0 4px 15px rgba(26, 58, 122, 0.25);
}

.tab-btn.active::before {
    opacity: 1;
}

.tab-btn>* {
    position: relative;
    z-index: 1;
}

.tab-icon {
    font-size: 16px;
}

.tab-count {
    background: rgba(255, 255, 255, 0.25);
    padding: 2px 8px;
    border-radius: 50px;
    font-size: 12px;
    font-weight: 700;
    min-width: 28px;
    text-align: center;
}

.tab-btn:not(.active) .tab-count {
    background: rgba(26, 58, 122, 0.1);
    color: var(--accent-primary);
}

/* ============================================
   MAIN CONTENT & TABLE
   ============================================ */
.main-content {
    padding: 16px 0 40px;
    min-height: 50vh;
}

.tab-panel {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-panel.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.table-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table thead {
    position: sticky;
    top: 0;
    z-index: 5;
}

.data-table th {
    background: linear-gradient(135deg, #1a3a7a 0%, #2556b0 100%);
    color: #ffffff;
    font-weight: 700;
    padding: 14px 16px;
    text-align: right;
    white-space: nowrap;
    font-size: 13px;
    letter-spacing: 0.3px;
    border-bottom: 3px solid var(--brand-red);
}

.th-index {
    width: 50px;
    text-align: center !important;
}

.th-code {
    width: 130px;
}

.th-unit {
    width: 80px;
    text-align: center !important;
}

.th-price {
    width: 100px;
    text-align: center !important;
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    vertical-align: middle;
    transition: background var(--transition-fast);
}

.data-table tbody tr {
    transition: all var(--transition-fast);
}

.data-table tbody tr:hover {
    background: rgba(26, 58, 122, 0.04);
}

.data-table tbody tr:hover td {
    border-bottom-color: rgba(26, 58, 122, 0.1);
}

/* Row animations */
.data-table tbody tr {
    animation: rowSlideIn 0.3s ease forwards;
    opacity: 0;
}

@keyframes rowSlideIn {
    from {
        opacity: 0;
        transform: translateX(-8px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.td-index {
    text-align: center;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 12px;
}

.td-code {
    font-family: 'Courier New', monospace;
    color: var(--accent-primary);
    font-weight: 600;
    font-size: 13px;
    direction: ltr;
    text-align: right;
}

.td-name {
    font-weight: 500;
    color: var(--text-primary);
    min-width: 200px;
    line-height: 1.5;
}

.td-unit {
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
}

.td-price {
    text-align: center;
    font-weight: 700;
    white-space: nowrap;
}

.price-value {
    color: var(--success);
    font-size: 15px;
}

.price-na {
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
}

.price-custom {
    color: var(--warning);
    font-size: 12px;
}

/* Search highlight */
.search-highlight {
    background: rgba(217, 119, 6, 0.15);
    color: var(--warning);
    padding: 1px 3px;
    border-radius: 3px;
    font-weight: 700;
}

/* Zebra striping subtle */
.data-table tbody tr:nth-child(even) {
    background: rgba(26, 58, 122, 0.02);
}

.data-table tbody tr:nth-child(even):hover {
    background: rgba(26, 58, 122, 0.05);
}

/* ============================================
   NO RESULTS
   ============================================ */
.no-results {
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
}

.no-results-icon {
    width: 80px;
    height: 80px;
    color: var(--text-muted);
    margin-bottom: 16px;
    opacity: 0.5;
}

.no-results p {
    font-size: 16px;
    font-weight: 500;
}

/* ============================================
   BACK TO TOP
   ============================================ */
.back-to-top {
    position: fixed;
    bottom: 30px;
    left: 30px;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: var(--accent-gradient);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(26, 58, 122, 0.3);
    transition: all var(--transition-normal);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    z-index: 200;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(26, 58, 122, 0.4);
}

.back-to-top svg {
    width: 22px;
    height: 22px;
}

/* ============================================
   REFRESH BUTTON
   ============================================ */
.refresh-btn {
    position: fixed;
    bottom: 90px;
    left: 30px;
    width: 48px;
    height: 48px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--accent-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-normal);
    z-index: 200;
}

.refresh-btn:hover {
    border-color: var(--accent-primary);
    color: white;
    transform: rotate(180deg);
    background: var(--accent-primary);
}

.refresh-btn svg {
    width: 20px;
    height: 20px;
}

.refresh-btn.spinning svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   FOOTER
   ============================================ */
.footer {
    background: #ffffff;
    border-top: 1px solid var(--border-color);
    padding: 24px 0;
    text-align: center;
}

.footer-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.footer-text {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.footer-update {
    font-size: 12px;
    color: var(--text-muted);
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .header {
        padding: 14px 0;
    }

    .site-title {
        font-size: 18px;
    }

    .site-subtitle {
        font-size: 12px;
    }

    .logo-icon {
        width: 48px;
        height: 48px;
    }

    .header-stats {
        width: 100%;
        justify-content: center;
    }

    .search-section {
        top: 0;
    }

    .search-input {
        padding: 14px 44px 14px 44px;
        font-size: 15px;
        border-radius: var(--radius-md);
    }

    .tabs-nav {
        top: 62px;
    }

    .tab-btn {
        padding: 8px 14px;
        font-size: 13px;
    }

    /* Mobile: Convert table to card layout */
    .data-table thead {
        display: none;
    }

    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
    }

    .data-table tbody tr {
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-md);
        padding: 14px;
        margin-bottom: 10px;
        position: relative;
        box-shadow: var(--shadow-sm);
    }

    .data-table tbody tr:hover {
        border-color: var(--accent-primary);
        box-shadow: var(--shadow-md);
    }

    .data-table td {
        padding: 4px 0;
        border-bottom: none !important;
    }

    .data-table td::before {
        display: none;
    }

    .td-index {
        position: absolute;
        top: 10px;
        left: 14px;
        background: rgba(26, 58, 122, 0.08);
        width: 28px;
        height: 28px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 11px;
        color: var(--accent-primary);
    }

    .td-code {
        font-size: 12px;
        color: var(--accent-primary);
        margin-bottom: 4px;
    }

    .td-name {
        font-size: 14px;
        font-weight: 600;
        min-width: auto;
        margin-bottom: 8px;
        padding-left: 36px;
    }

    .mobile-bottom-row {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 4px;
        padding-top: 8px;
        border-top: 1px solid rgba(0, 0, 0, 0.05) !important;
    }

    .td-unit {
        text-align: right;
    }

    .td-price {
        text-align: left;
    }

    .price-value {
        font-size: 16px;
    }

    .footer-content {
        flex-direction: column;
        text-align: center;
    }

    .container {
        padding: 0 14px;
    }

    .table-card {
        background: transparent;
        border: none;
        box-shadow: none;
    }
}

@media (max-width: 380px) {
    .site-title {
        font-size: 16px;
    }

    .stat-chip {
        padding: 6px 12px;
        font-size: 12px;
    }

    .tab-btn {
        padding: 6px 10px;
        font-size: 12px;
        gap: 4px;
    }
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(26, 58, 122, 0.2);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(26, 58, 122, 0.35);
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {

    .search-section,
    .tabs-nav,
    .back-to-top,
    .refresh-btn,
    .loading-overlay,
    .header-stats {
        display: none !important;
    }

    body {
        background: white;
        color: black;
    }

    .header {
        background: none;
        border: none;
    }

    .site-title {
        color: black;
    }

    .data-table th {
        background: #f0f0f0 !important;
        color: black;
    }

    .data-table td {
        color: black;
    }

    .table-card {
        border: 1px solid #ccc;
    }

    .tab-panel {
        display: block !important;
    }
}