/* ============================================================
   BASE.CSS — Shared Foundation for All Themes
   Branch Locator System v1.0
   
   This file provides: reset, CSS variables, layout, grid,
   status badges, animations, responsive, and RTL/LTR support.
   Theme files override visual appearance ONLY.
   ============================================================ */

/* --- CSS Variables (defaults — overridden dynamically by app.js) --- */
:root {
    --color-primary: #113626;
    --color-primary-rgb: 17, 54, 38;
    --color-secondary: #cfad64;
    --color-secondary-rgb: 207, 173, 100;
    --color-bg: #fcfcfc;
    --color-bg-rgb: 252, 252, 252;
    --color-text: #1a1a1a;
    --color-text-rgb: 26, 26, 26;
    --color-text-muted: #7a8a80;
    --font-family: 'Vazirmatn', system-ui, -apple-system, sans-serif;
    --border-radius: 24px;
    --border-radius-sm: 12px;
    --border-radius-pill: 100px;
    --transition: 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 12px 30px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 20px 45px rgba(0, 0, 0, 0.1);
    --max-width: 860px;
}

/* --- Reset --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-family);
    background-color: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.6;
}

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

img {
    max-width: 100%;
    height: auto;
    display: block;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    outline: none;
}

input {
    font-family: inherit;
    outline: none;
    border: none;
}

/* --- Video Background --- */
.video-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -2;
    overflow: hidden;
    display: none;
}

.video-background.active {
    display: block;
}

.video-background video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-background::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Theme overrides this overlay color */
    background: rgba(var(--color-bg-rgb), 0.85);
}

/* --- Theme Background Container --- */
.theme-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

/* --- Announcement Banner --- */
.announcement-banner {
    display: none;
    width: 100%;
    padding: 0.75rem 1.5rem;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 500;
    position: relative;
    z-index: 100;
    animation: slideDown 0.5s ease both;
}

.announcement-banner.active {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.announcement-banner.type-info {
    background: rgba(var(--color-primary-rgb), 0.1);
    color: var(--color-primary);
    border-bottom: 1px solid rgba(var(--color-primary-rgb), 0.15);
}

.announcement-banner.type-success {
    background: rgba(34, 197, 94, 0.1);
    color: #16a34a;
    border-bottom: 1px solid rgba(34, 197, 94, 0.15);
}

.announcement-banner.type-warning {
    background: rgba(245, 158, 11, 0.1);
    color: #d97706;
    border-bottom: 1px solid rgba(245, 158, 11, 0.15);
}

.announcement-text {
    flex: 1;
}

.announcement-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.3s ease;
    color: inherit;
    padding: 0 0.25rem;
    line-height: 1;
}

.announcement-close:hover {
    opacity: 1;
}

/* --- App Loading State --- */
.app-loading {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    gap: 1.5rem;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    background: var(--color-bg);
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.app-loading.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(var(--color-primary-rgb), 0.15);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-text {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    font-weight: 400;
}

/* --- Main Layout --- */
.app-container {
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 3rem 1.5rem 5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* --- Header & Branding --- */
.site-header {
    text-align: center;
    margin-bottom: 2.5rem;
    animation: fadeSlideDown 0.8s var(--transition) both;
}

.brand-logo {
    width: 100px;
    height: 100px;
    margin: 0 auto 1.25rem;
    border-radius: 28px;
    object-fit: cover;
    /* Visual overrides in themes */
}

.brand-name {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 0.4rem;
    color: var(--color-primary);
}

.brand-tagline {
    font-size: 0.95rem;
    color: var(--color-text-muted);
    font-weight: 400;
    margin-bottom: 1rem;
}

.brand-tagline:empty {
    display: none;
    margin: 0;
}

/* --- Social Links --- */
.social-links {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

.social-links:empty {
    display: none;
}

.social-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    transition: all var(--transition);
    background: rgba(var(--color-primary-rgb), 0.06);
}

.social-link:hover {
    background: rgba(var(--color-primary-rgb), 0.12);
    transform: translateY(-2px);
}

.social-link svg {
    width: 18px;
    height: 18px;
    fill: var(--color-primary);
    transition: fill 0.3s ease;
}

/* --- Find Nearest Button --- */
.action-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
    animation: fadeSlideUp 0.8s var(--transition) 0.15s both;
}

.action-wrapper.hidden {
    display: none;
}

.btn-nearest {
    background: var(--color-primary);
    color: var(--color-secondary);
    padding: 1rem 2.25rem;
    border-radius: var(--border-radius-pill);
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    transition: all var(--transition);
}

.btn-nearest::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(rgba(255,255,255,0.1), transparent);
    border-radius: inherit;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.btn-nearest:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.btn-nearest:hover::after {
    opacity: 1;
}

.btn-nearest:active {
    transform: translateY(1px);
}

.btn-nearest svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.btn-nearest:hover svg {
    transform: scale(1.1);
}

.btn-nearest.loading-state {
    opacity: 0.8;
    pointer-events: none;
}

/* --- Search --- */
.search-wrapper {
    width: 100%;
    max-width: 500px;
    margin: 0 auto 2rem;
    position: relative;
    display: none;
    animation: fadeSlideUp 0.6s var(--transition) 0.2s both;
}

.search-wrapper.active {
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    width: 20px;
    height: 20px;
    fill: var(--color-text-muted);
    pointer-events: none;
    transition: fill 0.3s ease;
}

[dir="rtl"] .search-icon {
    right: 1rem;
}

[dir="ltr"] .search-icon {
    left: 1rem;
}

.search-input {
    width: 100%;
    padding: 0.85rem 1rem;
    font-size: 0.95rem;
    color: var(--color-text);
    background: rgba(var(--color-primary-rgb), 0.04);
    border: 1px solid rgba(var(--color-primary-rgb), 0.1);
    border-radius: var(--border-radius-sm);
    transition: all var(--transition);
}

[dir="rtl"] .search-input {
    padding-right: 2.75rem;
}

[dir="ltr"] .search-input {
    padding-left: 2.75rem;
}

.search-input::placeholder {
    color: var(--color-text-muted);
}

.search-input:focus {
    border-color: rgba(var(--color-primary-rgb), 0.3);
    background: rgba(var(--color-primary-rgb), 0.02);
}

/* --- Branch Grid --- */
.branches-grid {
    display: grid;
    gap: 1.25rem;
    width: 100%;
}

.branches-grid.columns-2 {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.branches-grid.columns-1 {
    grid-template-columns: 1fr;
    max-width: 560px;
    margin: 0 auto;
}

/* --- Branch Card (Base Structure) --- */
.branch-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.35rem 1.5rem;
    border-radius: var(--border-radius);
    text-decoration: none;
    position: relative;
    overflow: hidden;
    transition: all var(--transition);
    animation: fadeSlideUp 0.6s var(--transition) both;
    /* Visual appearance set by themes */
}

.branch-card[data-status="active"] {
    cursor: pointer;
}

.branch-card[data-status="coming_soon"],
.branch-card[data-status="temporarily_closed"],
.branch-card[data-status="permanently_closed"] {
    cursor: default;
}

/* --- Branch Card Content --- */
.branch-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-width: 0; /* Prevent text overflow */
}

.branch-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 2px;
    flex-wrap: wrap;
}

.branch-name {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--color-primary);
    margin: 0;
    line-height: 1.4;
}

.branch-address {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    font-weight: 400;
    margin: 0;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.branch-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 4px;
    flex-wrap: wrap;
}

.branch-hours,
.branch-phone {
    font-size: 0.82rem;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.branch-hours svg,
.branch-phone svg {
    width: 13px;
    height: 13px;
    fill: var(--color-text-muted);
    flex-shrink: 0;
}

.branch-phone a {
    color: inherit;
    text-decoration: none;
    transition: color 0.3s ease;
}

.branch-phone a:hover {
    color: var(--color-primary);
}

/* Open/Closed Indicator */
.open-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--border-radius-pill);
}

.open-indicator.is-open {
    color: #16a34a;
    background: rgba(34, 197, 94, 0.1);
}

.open-indicator.is-closed {
    color: #dc2626;
    background: rgba(220, 38, 38, 0.1);
}

.open-indicator::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.open-indicator.is-open::before {
    background: #22c55e;
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

.open-indicator.is-closed::before {
    background: #ef4444;
}

/* --- Branch Arrow Icon --- */
.branch-icon {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
    background: rgba(var(--color-primary-rgb), 0.04);
}

.branch-icon svg {
    width: 18px;
    height: 18px;
    fill: var(--color-primary);
    transition: all var(--transition);
}

/* RTL: Arrow points left */
[dir="rtl"] .branch-icon svg {
    transform: rotate(180deg);
}

/* LTR: Arrow points right (default) */
[dir="ltr"] .branch-icon svg {
    transform: rotate(0deg);
}

/* --- Status Badges --- */
.branch-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: var(--border-radius-pill);
    margin-bottom: 0;
    line-height: 1.4;
    flex-shrink: 0;
}

.branch-status-badge .status-icon {
    font-size: 0.75rem;
}

/* Coming Soon */
.branch-card.status-coming-soon {
    opacity: 0.7;
}

.branch-card.status-coming-soon .branch-status-badge {
    background: rgba(59, 130, 246, 0.1);
    color: #2563eb;
}

.branch-card.status-coming-soon .branch-icon {
    opacity: 0.4;
}

/* Temporarily Closed */
.branch-card.status-temporarily-closed {
    opacity: 0.65;
}

.branch-card.status-temporarily-closed .branch-status-badge {
    background: rgba(245, 158, 11, 0.1);
    color: #d97706;
}

.branch-card.status-temporarily-closed .branch-icon {
    opacity: 0.4;
}

/* Permanently Closed */
.branch-card.status-permanently-closed {
    opacity: 0.45;
    filter: grayscale(0.5);
}

.branch-card.status-permanently-closed .branch-name {
    text-decoration: line-through;
    text-decoration-color: rgba(var(--color-text-rgb), 0.3);
}

.branch-card.status-permanently-closed .branch-status-badge {
    background: rgba(220, 38, 38, 0.1);
    color: #dc2626;
}

.branch-card.status-permanently-closed .branch-icon {
    display: none;
}

/* --- Nearest Highlight --- */
.branch-card.nearest-highlight {
    animation: pulseGlow 2s ease-in-out 3;
    z-index: 10;
}

.nearest-badge {
    position: absolute;
    top: -1px;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 3px 12px;
    border-radius: 0 0 var(--border-radius-sm) var(--border-radius-sm);
    background: var(--color-secondary);
    color: var(--color-primary);
    z-index: 5;
    animation: fadeSlideDown 0.5s ease both;
}

[dir="rtl"] .nearest-badge {
    right: 1.5rem;
}

[dir="ltr"] .nearest-badge {
    left: 1.5rem;
}

/* --- Toast Notification --- */
.toast-notification {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 0.85rem 1.75rem;
    border-radius: var(--border-radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--color-primary);
    color: var(--color-secondary);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    text-align: center;
    max-width: 90vw;
    white-space: nowrap;
}

.toast-notification.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* --- Footer --- */
.site-footer {
    text-align: center;
    padding: 2rem 1.5rem;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-top: auto;
    animation: fadeIn 1s ease 1s both;
}

.site-footer a {
    transition: color 0.3s ease;
}

.site-footer a:hover {
    color: var(--color-primary);
}

.footer-brand {
    color: var(--color-primary);
    font-weight: 700;
}

/* --- Animations --- */
@keyframes fadeSlideDown {
    from { opacity: 0; transform: translateY(-25px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(25px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-100%); }
    to { opacity: 1; transform: translateY(0); }
}

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

@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(var(--color-secondary-rgb), 0); }
    50% { box-shadow: 0 0 20px 5px rgba(var(--color-secondary-rgb), 0.25); }
}

/* --- No Results --- */
.no-results {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted);
    font-size: 0.95rem;
    grid-column: 1 / -1;
    animation: fadeIn 0.5s ease both;
}

.no-results svg {
    width: 48px;
    height: 48px;
    fill: rgba(var(--color-text-rgb), 0.15);
    margin-bottom: 1rem;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .app-container {
        padding: 2rem 1.25rem 4rem;
    }
    
    .site-header {
        margin-bottom: 2rem;
    }
    
    .brand-logo {
        width: 80px;
        height: 80px;
    }
    
    .brand-name {
        font-size: 1.5rem;
    }
    
    .btn-nearest {
        padding: 0.9rem 1.75rem;
        font-size: 0.92rem;
    }
    
    .branches-grid.columns-2 {
        grid-template-columns: 1fr;
    }
    
    .branch-card {
        padding: 1.15rem 1.25rem;
    }
    
    .branch-address {
        font-size: 0.78rem;
    }
}

@media (max-width: 400px) {
    .app-container {
        padding: 1.5rem 1rem 3rem;
    }
    
    .branch-name {
        font-size: 1rem;
    }
    
    .social-link {
        width: 34px;
        height: 34px;
    }
    
    .branch-icon {
        width: 36px;
        height: 36px;
    }
}

/* --- Print --- */
@media print {
    .video-background,
    .theme-background,
    .btn-nearest,
    .search-wrapper,
    .announcement-banner,
    .toast-notification,
    .app-loading {
        display: none !important;
    }
    
    .branch-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* --- Accessibility --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* --- Utilities --- */
.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
