/* ============================================================
   DELYAR GLOBAL STYLES
   Warm, calm, Persian-first design baseline
   ============================================================ */

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

/* Base */
html {
    font-size: 100%;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font-body);
    font-size: var(--text-base);
    font-weight: var(--weight-regular);
    line-height: var(--leading-normal);
    color: var(--color-text-primary);
    background-color: var(--color-bg-canvas);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-body);
    font-weight: var(--weight-semibold);
    line-height: var(--leading-snug);
    color: var(--color-text-primary);
    margin: 0 0 var(--space-4);
}

h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }

p {
    margin: 0 0 var(--space-4);
    line-height: var(--leading-relaxed);
}

a {
    color: var(--color-text-link);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Focus ring — warm rose, visible for accessibility */
:focus-visible {
    outline: 2px solid var(--color-border-focus);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Inputs */
input, textarea, select {
    font-family: var(--font-body);
    font-size: 16px; /* Prevents iOS auto-zoom */
    color: var(--color-text-primary);
    background-color: var(--color-bg-sunken);
    border: 1.5px solid var(--color-border-default);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    min-height: 52px;
    width: 100%;
    transition: border-color var(--duration-fast) var(--ease-standard),
                box-shadow    var(--duration-fast) var(--ease-standard);
}

input:focus, textarea:focus, select:focus {
    border-color: var(--color-border-focus);
    outline: none;
    box-shadow: 0 0 0 3px var(--color-rose-100);
}

input::placeholder, textarea::placeholder {
    color: var(--color-text-placeholder);
}

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

/* Page enter animation */
@keyframes page-enter {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.page-enter {
    animation: page-enter var(--duration-normal) var(--ease-enter) both;
}

/* Blazor reconnection modal */
.components-reconnect-modal {
    background: var(--color-bg-surface) !important;
    border: 1px solid var(--color-neutral-200) !important;
    border-radius: var(--radius-xl) !important;
    box-shadow: var(--shadow-xl) !important;
    color: var(--color-text-secondary) !important;
    font-family: var(--font-persian) !important;
    font-size: var(--text-sm) !important;
}

/* Blazor error boundary */
.blazor-error-boundary {
    background: var(--color-amber-100);
    border: 1px solid var(--color-amber-200);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    color: var(--color-amber-700);
    font-family: var(--font-body);
    font-size: var(--text-sm);
}

.blazor-error-boundary::after {
    content: "مشکلی پیش آمد. لطفاً صفحه را بارگذاری مجدد کنید.";
}

/* Utility: visually hidden but accessible */
.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;
}

/* ══════════════════════════════════════════════════════════
   APP SHELL LAYOUT
   Shared by MainLayout and OpsLayout.
   Controls the sidebar + content two-column structure.
   ══════════════════════════════════════════════════════════ */

.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    background-color: var(--color-bg-canvas);
}

.app-body {
    display: flex;
    flex-direction: row;           /* Explicit: sidebar left, content right */
    padding-top: var(--nav-height-top);
    min-height: 100dvh;
}

/* Mobile: sidebar hidden */
.app-sidebar {
    display: none;
}

.app-content {
    flex: 1;
    min-width: 0;
    padding-bottom: calc(var(--nav-height-bottom) + env(safe-area-inset-bottom, 0px));
}

/* Tablet+ (≥768px): sidebar appears at fixed width */
@media (min-width: 768px) {
    .app-sidebar {
        display: flex;
        flex-direction: column;
        width: var(--sidebar-width);
        flex-shrink: 0;
        position: sticky;
        top: var(--nav-height-top);
        height: calc(100dvh - var(--nav-height-top));
        overflow-y: auto;
        background-color: var(--color-bg-sidebar);
        border-inline-end: 1px solid var(--color-border-sidebar);
    }

    .app-content {
        padding-bottom: var(--space-12);
    }
}

/* Admin shell: always reserve bottom space (no bottom nav);
   horizontal inset only on desktop — the page itself provides mobile padding. */
.admin-shell .app-content {
    padding-bottom: var(--space-12);
}

@media (min-width: 768px) {
    .admin-shell .app-content {
        padding: var(--space-6) var(--space-6) var(--space-12);
    }
}

/* Ops shell: amber-tinted sidebar distinguishes operations context */
.ops-shell .app-sidebar {
    background-color: #FAF0E4;
    border-inline-end-color: var(--color-amber-200);
}

/* ── Responsive card grid ──────────────────────────────── */
.card-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-4);
}

@media (min-width: 640px) {
    .card-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1024px) {
    .card-grid { grid-template-columns: repeat(3, 1fr); gap: var(--space-6); }
}

/* ── Two-column layout ─────────────────────────────────── */
.layout-split {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-6);
}

@media (min-width: 900px) {
    .layout-split { grid-template-columns: 1fr 1fr; }
}

/* ── Section headings ──────────────────────────────────── */
.section-heading {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    color: var(--color-text-primary);
    margin: 0 0 var(--space-4);
    line-height: var(--leading-snug);
}

.section-subheading {
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--color-text-tertiary);
    margin: 0 0 var(--space-3);
    letter-spacing: 0.03em;
}

/* ══════════════════════════════════════════════════════════
   MOBILE HAMBURGER DRAWER
   Three-bar button in the top bar opens the sidebar as a
   slide-in drawer panel on mobile (< 768 px). Hidden on
   desktop where the sidebar is always visible.
   ══════════════════════════════════════════════════════════ */

/* ── Three-bar button ────────────────────────────────────── */
.hamburger-btn {
    display: none;              /* desktop: sidebar is always visible */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: 40px;
    height: 40px;
    padding: 0;
    margin-inline-start: var(--space-1);
    background: none;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-md);
    flex-shrink: 0;
    transition: background-color var(--duration-fast) var(--ease-standard);
}

.hamburger-btn:hover {
    background-color: var(--color-neutral-100);
}

.hamburger-btn__bar {
    display: block;
    width: 20px;
    height: 2px;
    background-color: var(--color-text-secondary);
    border-radius: 2px;
    transition:
        transform var(--duration-fast) var(--ease-standard),
        opacity   var(--duration-fast) var(--ease-standard);
}

/* Bars animate into an X when the drawer is open */
.mobile-drawer-open .hamburger-btn__bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
.mobile-drawer-open .hamburger-btn__bar:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}
.mobile-drawer-open .hamburger-btn__bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* ── Backdrop ────────────────────────────────────────────── */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.45);
    z-index: 149;
    animation: drawer-backdrop-in var(--duration-normal) var(--ease-enter) both;
}

@media (min-width: 768px) {
    /* Backdrop is only meaningful on mobile; hide it if screen resizes */
    .drawer-backdrop {
        display: none;
    }
}

@keyframes drawer-backdrop-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ── Mobile-only drawer activation ──────────────────────── */
@media (max-width: 767px) {
    /* Reveal the hamburger button */
    .hamburger-btn {
        display: flex;
    }

    /* Sidebar becomes a fixed overlay panel when drawer is open.
       High-specificity selectors (3 classes) beat scoped Blazor CSS (2 classes)
       so !important is not needed, even for companion-sidebar isolation. */
    .app-shell.mobile-drawer-open .app-sidebar,
    .admin-shell.mobile-drawer-open .app-sidebar,
    .companion-shell.mobile-drawer-open .companion-sidebar {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: var(--nav-height-top);
        inset-inline-start: 0;          /* RTL: right edge; LTR: left edge */
        width: min(var(--sidebar-width), 85vw);
        height: calc(100dvh - var(--nav-height-top));
        z-index: 150;
        overflow-y: auto;
        background-color: var(--color-bg-sidebar);
        border-inline-end: 1px solid var(--color-border-sidebar);
        box-shadow: var(--shadow-xl);
        animation: drawer-panel-in var(--duration-normal) var(--ease-enter) both;
    }

    /* Ops shell keeps its amber tint inside the drawer */
    .ops-shell.mobile-drawer-open .app-sidebar {
        background-color: #FAF0E4;
        border-inline-end-color: var(--color-amber-200);
    }
}

@keyframes drawer-panel-in {
    from { opacity: 0; transform: translateX(12px); }
    to   { opacity: 1; transform: translateX(0); }
}
