/* © Mahdi Amouzegar — All rights reserved | مهدی آموزگار — همه حقوق محفوظ است */
/* responsive.css — Desktop Layout, Mobile Layout, Media Queries */

@layer layout, components;

/* ═══════════════════════════════════════════════════════════════════════════
   LAYER: layout — Desktop App Shell & Mobile App Shell
   ═══════════════════════════════════════════════════════════════════════════ */
@layer layout {
    /* ═══ Desktop: App Shell ═══ */
    @media (min-width: 901px) {
        html, body {
            height: 100%;
        }

        .container {
            width: 100%;
            max-width: none;
            height: 100vh;
        }

        .app-shell {
            display: flex;
            flex-direction: row;
            direction: inherit;
            height: 100vh;
            background: var(--bg-0);
        }

        .right-flow-container {
            flex: 1 1 auto;
            min-width: 0;
            min-height: 0;
            direction: inherit;
        }

        #panelMap {
            flex: 0 0 40%;
            min-width: 0;
            min-height: 0;
        }

        .right-flow {
            min-width: 0;
            height: 100vh;
            overflow-y: auto;
            overscroll-behavior: contain;
            padding: 28px 34px 0;
        }

        #panelMap {
            display: flex;
            flex-direction: column;
            min-width: 0;
            height: 100vh;
            padding: 28px 24px 18px;
            border-inline-start: 1px solid var(--border-dark);
            background: var(--bg-1);
        }

        #panelMap .map-wrap {
            flex: 1;
            min-height: 0;
        }

        #panelMap #map {
            height: 100%;
            min-height: 400px;
        }

        .right-flow .header {
            margin-bottom: 20px;
        }

        .right-flow .header-main {
            display: flex;
            align-items: baseline;
            gap: 10px;
            min-width: 0;
        }

        .right-flow .header h1,
        .right-flow .tagline-toggle {
            margin-top: 0;
            white-space: nowrap;
        }

        .right-flow .layout {
            display: block;
        }

        .right-flow .app-footer {
            margin-top: 24px;
        }

        body.map-hidden .container {
            max-width: none;
        }

        .app-shell.map-hidden > #panelMap,
        body.map-hidden #panelMap {
            display: none !important;
        }

        .app-shell.map-hidden > .right-flow-container,
        body.map-hidden .right-flow-container {
            flex: 1 1 100%;
            min-width: 0;
            width: 100%;
        }

        body.map-hidden .right-flow {
            max-width: 980px;
            width: 100%;
            margin-inline: auto;
        }

        .plan-body {
            width: 100%;
        }

        .child-item {
            width: 100%;
            box-sizing: border-box;
        }

        .child-text {
            flex: 1 1 auto;
            white-space: normal;
        }

        /* ═══ Bottom Action Bar — Desktop (sticky در ستون وظایف) ═══ */
        .bottom-actions {
            position: sticky;
            inset-block-end: 0;
            z-index: 40;
            margin-inline: -34px; /* برای پر کردن padding .right-flow */
            margin-block-start: 16px;
        }

        /* ═══ فاصله‌ی پایین برای اینکه نوار روی آخرین محتوا نیفتد ═══ */
        .right-flow .app-footer {
            margin-bottom: 16px;
        }
    }

    /* ═══ Mobile: App Shell ═══ */
    @media (max-width: 900px) {
        .app-shell {
            display: flex;
            flex-direction: column;
        }

        .right-flow-container {
            display: contents;
        }

        .right-flow {
            display: contents;
        }

        /* ═══ Padding بدنه در موبایل ═══ */
        /* padding افقی ۱۴px برای حاشیه‌ی گوشه‌ها */
        /* padding پایین برای نوار پایین */
        body {
            padding: 0 14px;
            padding-block-end: calc(var(--bottom-bar-height) + env(safe-area-inset-bottom, 0px));
        }

        .app-shell .header {
            order: 1;
        }

        .app-shell .mobile-tabs {
            order: 2;
        }

        .app-shell .layout {
            order: 3;
        }

        .app-shell #panelMap {
            order: 4;
            /* فاصله‌ی پایین برای اینکه نوار روی نقشه نیفتد */
            padding-block-end: 8px;
        }

        .app-shell .app-footer {
            order: 5;
        }

        /* ═══ Bottom Action Bar — Mobile (fixed پایین) ═══ */
        .app-shell .bottom-actions {
            order: 6;
            position: fixed;
            inset-inline: 0;
            inset-block-end: 0;
            z-index: 40;
            /* حاشیه‌ی افقی هم‌راستا با body padding */
            padding-inline: 0;
            padding-block-end: env(safe-area-inset-bottom, 0);
        }

        /* مودال‌ها همیشه بالا و fixed بمانند */
        .app-shell .picker-overlay,
        .app-shell .settings-overlay {
            order: 0;
            position: fixed;
        }

        body.map-hidden .mobile-tabs {
            display: flex;
        }

        body.map-hidden .mobile-tab[data-tab="map"] {
            display: none;
        }
    }

    /* ═══ Snackbar Mobile ═══ */
    @media (max-width: 900px) {
        .snackbar {
            /* بالای نوار پایین قرار می‌گیرد */
            bottom: calc(var(--bottom-bar-height) + 1rem + env(safe-area-inset-bottom, 0px));
            padding: 10px 14px;
            gap: 8px;
            font-size: 0.78rem;
            max-width: calc(100vw - 24px);
            flex-wrap: wrap;
            justify-content: center;
        }

        .snackbar button {
            padding: 5px 12px;
            font-size: 0.74rem;
        }
    }

    @media (max-width: 600px) {
        .snackbar {
            bottom: calc(var(--bottom-bar-height) + 0.8rem + env(safe-area-inset-bottom, 0px));
            max-width: calc(100vw - 24px);
            padding: 8px 14px;
            font-size: 0.78rem;
        }
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   LAYER: components — Responsive overrides for components
   ═══════════════════════════════════════════════════════════════════════════ */
@layer components {
    /* ═══ Desktop Header Layout ═══ */
    @media (min-width: 901px) {
        .header {
            display: grid;
            grid-template-columns: auto 1fr auto;
            gap: 8px 18px;
            align-items: center;
            text-align: start;
            margin-bottom: 20px;
        }

        .header .site-logo {
            width: 54px;
            height: 54px;
            margin: 0;
        }

        .header-side {
            display: flex;
            flex-direction: column;
            gap: 6px;
            align-items: flex-end;
            font-size: 0.75rem;
        }

        .header-side .today-line,
        .header-side .header-actions {
            margin-top: 0;
            margin-bottom: 0;
        }

        .layout {
            display: grid;
            grid-template-columns: minmax(0, 1fr) 400px;
            gap: 24px;
            align-items: start;
        }

        .right-flow .layout {
            display: block;
        }

        #panelTasks {
            min-width: 0;
        }

        .panel-map {
            position: fixed;
            top: 0;
            bottom: 0;
            inset-inline-start: max(20px, calc((100vw - 1180px) / 2));
            width: min(400px, calc(100vw - 40px));
            z-index: 30;
            display: flex;
            flex-direction: column;
            overflow: hidden;
            padding: 16px 0;
        }

        .map-wrap {
            flex: 1;
            min-height: 400px;
            display: flex;
            flex-direction: column;
        }

        #map {
            flex: 1;
            min-height: 400px;
        }

        .app-footer {
            grid-column: 1;
            grid-row: 3;
            display: flex;
            justify-content: center;
            align-items: baseline;
            gap: 4px 8px;
            flex-wrap: wrap;
            padding: 10px;
        }
    }

    /* ═══ Mobile Overrides ═══ */
    @media (max-width: 900px) {
        .settings-grid {
            grid-template-columns: 1fr;
        }

        .settings-card-wide {
            grid-column: auto;
        }

        .settings-overlay {
            align-items: center;
            padding: 12px;
        }

        .settings-panel {
            max-height: calc(100dvh - 24px);
        }

        .settings-panel-head {
            align-items: stretch;
        }

        /* ⚠️ در موبایل: header و mobile-tabs دیگه نیازی به margin-inline: -14px ندارند
           چون body خودش padding افقی دارد */
        .right-flow .header {
            position: sticky;
            top: 0;
            z-index: 10;
            padding: 12px 0;
            background: color-mix(in srgb, var(--bg-1) 92%, transparent);
            backdrop-filter: blur(14px);
            /* برای اینکه پس‌زمینه تا لبه برود، از box-shadow استفاده می‌کنیم */
            box-shadow:
                -14px 0 0 0 color-mix(in srgb, var(--bg-1) 92%, transparent),
                14px 0 0 0 color-mix(in srgb, var(--bg-1) 92%, transparent);
        }

        .mobile-tabs {
            position: sticky;
            top: 76px;
            z-index: 9;
            margin-bottom: 14px;
            padding: 4px;
            border: 1px solid var(--border-subtle);
            border-radius: 14px;
            background: var(--surface-soft);
        }

        .mobile-tab {
            min-height: 44px;
        }

        .mobile-tabs {
            display: flex;
        }

        .layout {
            grid-template-columns: 1fr;
        }

        .panel {
            display: none;
        }

        .panel.active {
            display: block;
        }

        .panel-map {
            position: static;
        }

        #map {
            height: 380px;
        }

        /* ═══ B4: header h1 — حذف 3D transform در موبایل ═══ */
        .header h1 {
            transform: none;
        }
    }

    /* ═══ Mobile Fixes ═══ */
    @media (max-width: 900px) {
        .input-section {
            flex-wrap: nowrap;
        }

        .input-section input {
            flex: 1;
            min-width: 0;
        }

        .task-item,
        .task-content,
        .child-text {
            min-width: 0;
        }

        .task-meta {
            flex-wrap: wrap;
        }

        .due-row {
            flex-wrap: wrap;
        }

        .due-chip,
        .loc-chip {
            max-width: 100%;
            overflow-wrap: anywhere;
        }

        /* ═══ Child Add Row در موبایل ═══ */
        .child-add {
            flex-wrap: wrap;
        }

        .child-add .child-input {
            flex: 1 1 100%;
        }

        .child-add .child-prio {
            flex: 1;
            padding: 10px;
        }

        .child-add .btn-child-add {
            flex: 2;
        }

        .sort-row,
        .stats {
            flex-wrap: wrap;
        }

        /* ═══ Child Item — تنظیمات موبایل ═══ */
        .child-item {
            padding: 10px 12px;
            gap: 6px;
        }

        .child-main-row {
            gap: 8px;
        }

        .child-text {
            font-size: 0.85rem;
        }

        .child-actions {
            gap: 4px;
        }

        .child-actions .operation-trigger {
            min-width: 44px;
            min-height: 34px;
            padding: 4px 8px;
        }

        .child-actions .operation-trigger span {
            display: none;
        }

        .child-meta-row {
            padding-inline-start: 30px;
            gap: 6px;
            font-size: 0.76rem;
        }

        .child-meta-item {
            font-size: 0.76rem;
        }

        .child-meta-badge {
            font-size: 0.82rem;
        }

        .child-meta-row .priority-badge {
            padding: 1px 6px;
            font-size: 0.68rem;
        }

        .child-due {
            white-space: normal;
        }

        .child-prio {
            min-width: 0;
        }
    }

    /* ═══ Small Mobile ═══ */
    @media (max-width: 480px) {
        html,
        body {
            max-width: 100%;
            overflow-x: hidden;
        }

        .task-item,
        .plan-head,
        .child-item {
            min-width: 0;
        }

        .task-actions,
        .child-actions {
            align-self: flex-start;
        }

        .operation-trigger {
            min-width: 42px;
            width: 42px;
            padding: 8px 4px;
        }

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

        .operation-list {
            position: absolute;
            inset-inline-end: 0;
            top: calc(100% + 8px);
            bottom: auto;
            min-width: min(190px, calc(100vw - 24px));
            max-width: calc(100vw - 24px);
            width: auto;
        }

        .operation-item {
            min-height: 46px;
            font-size: .84rem;
        }

        .settings-panel .settings-row,
        .settings-panel .settings-row > label,
        .settings-panel .settings-row > button {
            min-height: 44px;
        }

        .settings-panel select,
        .settings-panel input:not([type="checkbox"]),
        .settings-panel button,
        .detail-page button,
        .detail-page input,
        .detail-page select,
        .detail-page textarea {
            max-width: 100%;
        }

        .settings-panel :where(button, input, select):focus-visible,
        .detail-page :where(button, input, select, textarea):focus-visible,
        .operation-trigger:focus-visible,
        .operation-item:focus-visible {
            outline: 3px solid var(--accent-cyan);
            outline-offset: 2px;
        }

        .child-add .btn-child-add {
            padding: 10px 12px;
            font-size: 0.8rem;
        }

        .due-row .due-btn {
            flex: 1 1 100%;
        }

        .created-date {
            display: none;
        }

        .header h1 {
            font-size: 1.8rem;
        }

        .priority-select {
            padding: 12px 16px;
        }

        .btn-add {
            width: 100%;
        }

        .task-item {
            padding: 14px 16px;
            gap: 10px;
        }

        .stats {
            gap: 16px;
            flex-wrap: wrap;
        }

        .done-actions {
            flex-direction: column;
            align-items: stretch;
        }

        .done-actions .btn-clear {
            width: 100%;
        }

        /* ═══ Child Item — موبایل کوچک ═══ */
        .child-item {
            padding: 10px 12px;
        }

        .child-meta-row {
            padding-inline-start: 0;
            margin-inline-start: 30px;
            gap: 5px;
            font-size: 0.72rem;
        }

        .child-meta-item {
            font-size: 0.72rem;
        }

        .child-meta-row .priority-badge {
            font-size: 0.66rem;
            padding: 1px 6px;
        }

        .child-actions .operation-trigger {
            min-width: 38px;
            width: 38px;
            min-height: 32px;
            padding: 4px;
        }
    }

    /* ═══ Create Zone Responsive ═══ */
    @media (max-width: 900px) {
        #panelTasks {
            padding-bottom: 20px;
        }

        .task-zone-title {
            font-size: .98rem;
        }

        .create-zone {
            padding: 14px;
            border-radius: var(--radius-md);
        }

        .create-zone .kind3 {
            gap: 6px;
        }

        .create-zone .kind3-btn {
            min-height: 42px;
            padding-inline: 8px;
            font-size: .9rem;
        }

        .create-zone .due-row {
            display: grid;
            grid-template-columns: 1fr;
            gap: 8px;
        }

        .create-zone .due-row .due-btn {
            width: 100%;
        }

        .list-zone {
            margin-top: 22px;
        }

        .list-zone .search-row {
            width: 100%;
        }

        .list-zone .progress-wrap {
            margin-top: 15px;
        }

        .settings-zone {
            margin-top: 19px;
        }

        .insight-zone {
            margin-top: 22px;
            padding-top: 17px;
        }

        .map-head-actions .map-context-toggle {
            display: none !important;
        }
    }

    @media (max-width: 520px) {
        .create-zone {
            padding: 12px;
        }

        .create-zone .kind3 {
            grid-template-columns: repeat(3, minmax(0, 1fr));
            gap: 5px;
        }

        .create-zone .kind3-btn {
            min-height: 40px;
            padding: 7px 4px;
            font-size: .82rem;
        }

        .list-zone .sort-row {
            gap: 6px;
            overflow-x: auto;
            padding-bottom: 2px;
        }

        .list-zone .sort-row .sort-select {
            flex: 0 0 150px;
            min-width: 150px;
        }

        .list-zone .sort-row .btn-small {
            flex: 0 0 auto;
        }
    }
}