﻿/* =====================================================================
   App.css — Cordova bootstrap layer (offline shell)
   --------------------------------------------------------------------
   File này nằm trong APK/IPA, load NGAY khi app mở. App.css online
   từ {Domain}/data/template/{TemplateID}/{Folder}/App.css sẽ override
   các token trong :root khi step 4 hoàn tất.
   ===================================================================== */

/* ---- Theme tokens (light default) ---- */
:root {
    --safe-top:    env(safe-area-inset-top, 0);
    --safe-bottom: env(safe-area-inset-bottom, 0);
    --safe-left:   env(safe-area-inset-left, 0);
    --safe-right:  env(safe-area-inset-right, 0);

    --az-bg-overlay:         rgba(255, 255, 255, 0.96);
    --az-bg-surface:         #ffffff;
    --az-bg-surface-alt:     #f0f4f5;
    --az-bg-surface-hover:   #d8e2e5;
    --az-text-main:          #101c2c;
    --az-text-muted:         #6b7280;
    --az-text-subtle:        #a8b5b8;
    --az-border-color:       #d5dcde;
    --az-color-primary:      #4f46e5;
    --az-color-primary-soft: #eef2ff;
    --az-success-500:        #22c55e;
    --az-danger-500:         #ef4444;
    --az-warning-500:        #f59e0b;

    --font-size:             14px;
}

/* ---- Dark mode auto theo system preference ---- */
@media (prefers-color-scheme: dark) {
    :root {
        --az-bg-overlay:         rgba(17, 24, 39, 0.96);
        --az-bg-surface:         #1f2937;
        --az-bg-surface-alt:     #111827;
        --az-bg-surface-hover:   #374151;
        --az-text-main:          #f9fafb;
        --az-text-muted:         #9ca3af;
        --az-text-subtle:        #6b7280;
        --az-border-color:       #374151;
        --az-color-primary-soft: #312e81;
    }
}

/* ---- Utility ---- */
.az-hide { display: none !important; }

/* ---- Body baseline ---- */
html, body {
    margin: 0;
    padding: 0;
    background: var(--az-bg-surface-alt);
    color: var(--az-text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: var(--font-size);
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior: contain;
}

/* =====================================================================
   AZ.Bootstrap — Progress overlay (cold-start, P1A)
   ===================================================================== */
.az-app-boot-overlay {
    position: fixed;
    inset: 0;
    z-index: 100000000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
    background: var(--az-bg-overlay);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    transition: opacity 300ms ease;
    opacity: 1;
}
.az-app-boot-overlay.az-app-boot-fade-out {
    opacity: 0;
    pointer-events: none;
}

.az-app-boot-card {
    width: min(360px, 88vw);
    padding: 32px 24px 28px;
    background: var(--az-bg-surface);
    border: 1px solid var(--az-border-color);
    border-radius: 18px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
    text-align: center;
    color: var(--az-text-main);
}

.az-app-boot-logo {
    max-width: 96px;
    max-height: 96px;
    margin: 0 auto 12px;
    display: block;
}

.az-app-boot-version {
    font-size: 12px;
    color: var(--az-text-muted);
    margin-bottom: 24px;
    letter-spacing: 0.3px;
}

.az-app-boot-progress {
    width: 100%;
    height: 6px;
    margin: 0 0 20px;
    background: var(--az-bg-surface-alt);
    border-radius: 999px;
    overflow: hidden;
}
.az-app-boot-progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--az-color-primary), var(--az-success-500));
    border-radius: 999px;
    transition: width 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

.az-app-boot-step {
    font-size: 11px;
    font-weight: 600;
    color: var(--az-text-subtle);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.az-app-boot-message {
    font-size: 16px;
    font-weight: 600;
    color: var(--az-text-main);
    margin-bottom: 4px;
    line-height: 1.4;
    min-height: 22px;
}
.az-app-boot-detail {
    font-size: 12px;
    color: var(--az-text-muted);
    word-break: break-all;
    min-height: 16px;
    line-height: 1.4;
}

/* ---- Error UI ---- */
.az-app-boot-error {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--az-border-color);
}
.az-app-boot-error-icon {
    font-size: 28px;
    line-height: 1;
    color: var(--az-danger-500);
    margin-bottom: 10px;
}
.az-app-boot-error-msg {
    font-size: 14px;
    font-weight: 600;
    color: var(--az-danger-500);
    margin-bottom: 6px;
}
.az-app-boot-error-detail {
    font-size: 12px;
    color: var(--az-text-muted);
    margin-bottom: 16px;
    word-break: break-all;
    max-height: 80px;
    overflow: auto;
    text-align: left;
    padding: 0 4px;
}
.az-app-boot-error-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}
.az-app-boot-error-actions button {
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 150ms ease, transform 100ms ease;
    border: 1px solid var(--az-border-color);
    background: var(--az-bg-surface);
    color: var(--az-text-main);
    min-width: 88px;
    -webkit-appearance: none;
    appearance: none;
}
.az-app-boot-error-actions button:active { transform: scale(0.97); }
.az-app-boot-error-actions .az-app-boot-retry {
    background: var(--az-color-primary);
    color: #fff;
    border-color: var(--az-color-primary);
}

/* =====================================================================
   Legacy classes (giữ tương thích các thư viện gọi class cũ)
   ===================================================================== */
.AZAppInit {
    width: 100vw; height: 100vh;
    margin: 0; padding: 0;
    background: var(--az-bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000000;
    position: absolute;
    top: 0; left: 0;
}
.AZAppInit div {
    color: var(--az-text-muted);
    text-align: center;
}
.AZAppInit img {
    max-width: 50%;
    max-height: 20%;
    margin: 0 auto 20px;
    display: block;
}

.AZLoading {
    margin: 20px auto;
    text-align: center;
    color: var(--az-text-muted);
}
.AZLoading > img {
    max-width: 50%;
    max-height: 50px;
    margin: 20px auto;
    display: block;
}

/* =====================================================================
   AZHistory — Edge-swipe back/forward indicator
   ===================================================================== */
.AZHistory {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 80px;
    background: rgba(0, 0, 0, 0.18);
    color: #fff;
    z-index: 99999999;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    overflow: hidden;
    transition: width 80ms linear;
    pointer-events: none;
}
.AZHistory.Back    { left: 0;  border-radius: 0 12px 12px 0; }
.AZHistory.Forward { right: 0; border-radius: 12px 0 0 12px; }

/* =====================================================================
   Sprint 2 / C4 — Offline banner
   ===================================================================== */
.az-app-offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 99999998;
    background: var(--az-warning-500, #f59e0b);
    color: #fff;
    padding: calc(8px + env(safe-area-inset-top, 0)) 16px 8px;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transform: translateY(0);
    transition: transform 300ms ease;
    pointer-events: none;   /* không chặn click panel bên dưới */
}
.az-app-offline-banner.az-app-fade-out {
    transform: translateY(-100%);
}
.az-app-offline-icon {
    font-size: 16px;
    line-height: 1;
}
.az-app-offline-text {
    line-height: 1.2;
}

/* =====================================================================
   Sprint 2 / B4 — Error boundary (panel mount runtime error)
   ===================================================================== */
.az-error-boundary {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--az-text-main);
    min-height: 60vh;
}
.az-error-icon {
    font-size: 56px;
    line-height: 1;
    color: var(--az-danger-500, #ef4444);
    margin-bottom: 16px;
}
.az-error-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--az-text-main);
}
.az-error-detail {
    font-size: 13px;
    color: var(--az-text-muted);
    margin-bottom: 16px;
    max-width: 320px;
    word-break: break-word;
    line-height: 1.4;
}
.az-error-stack {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 11px;
    color: var(--az-text-subtle);
    background: var(--az-bg-surface-alt);
    padding: 10px 12px;
    border-radius: 8px;
    text-align: left;
    max-width: 320px;
    max-height: 100px;
    overflow: auto;
    margin: 0 0 20px;
    white-space: pre-wrap;
    word-break: break-word;
}
.az-error-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}
.az-error-actions .az-btn {
    min-width: 100px;
}

/* =====================================================================
   Sprint 4 / C3 — Panel transition animations
   ===================================================================== */
.PanelRemote.az-anim-forward {
    animation: az-panel-slide-forward 250ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.PanelRemote.az-anim-back {
    animation: az-panel-slide-back 250ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.PanelRemote.az-anim-refresh {
    animation: az-panel-fade-refresh 200ms ease-out;
}

@keyframes az-panel-slide-forward {
    from { opacity: 0; transform: translateX(24px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes az-panel-slide-back {
    from { opacity: 0; transform: translateX(-24px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes az-panel-fade-refresh {
    from { opacity: 0.6; }
    to   { opacity: 1; }
}

/* Reduce motion — respect user's OS preference */
@media (prefers-reduced-motion: reduce) {
    .PanelRemote.az-anim-forward,
    .PanelRemote.az-anim-back,
    .PanelRemote.az-anim-refresh {
        animation: none;
    }
}

/* =====================================================================
   Sprint 4 / C5 — Auto-update prompt overlay
   ===================================================================== */
.az-app-update-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999999;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: az-app-update-fadein 200ms ease-out;
}

@keyframes az-app-update-fadein {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.az-app-update-card {
    background: var(--az-bg-surface);
    color: var(--az-text-main);
    border-radius: 16px;
    padding: 32px 24px 24px;
    width: 100%;
    max-width: 360px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.az-app-update-icon {
    font-size: 56px;
    line-height: 1;
    color: var(--az-color-primary, #4f46e5);
    margin-bottom: 16px;
}

.az-app-update-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--az-text-main);
}

.az-app-update-detail {
    font-size: 14px;
    color: var(--az-text-muted);
    line-height: 1.5;
    margin-bottom: 24px;
}

.az-app-update-detail b {
    color: var(--az-text-main);
    font-weight: 600;
}

.az-app-update-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.az-app-update-actions .az-btn {
    width: 100%;
    min-height: 44px;
    font-size: 15px;
}

/* =====================================================================
   Sprint 5B / C1 — Pull-to-refresh indicator
   ===================================================================== */
.az-app-ptr-indicator {
    position: fixed;
    top: 0;
    left: 50%;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--az-bg-surface, #fff);
    color: var(--az-color-primary, #4f46e5);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 99999997;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transform: translate(-50%, -40px);   /* hidden initial */
    opacity: 0;
    pointer-events: none;
    transition: transform 200ms ease, opacity 200ms ease;
}

.az-app-ptr-indicator .az-app-ptr-arrow {
    transition: transform 200ms ease;
}

.az-app-ptr-indicator.az-app-ptr-ready .az-app-ptr-arrow {
    transform: rotate(180deg);
    color: var(--az-success-500, #10b981);
}

.az-app-ptr-indicator .az-app-ptr-spinner {
    display: none;
    animation: az-app-ptr-spin 800ms linear infinite;
}

.az-app-ptr-indicator.az-app-ptr-loading .az-app-ptr-arrow {
    display: none;
}

.az-app-ptr-indicator.az-app-ptr-loading .az-app-ptr-spinner {
    display: inline-block;
}

@keyframes az-app-ptr-spin {
    to { transform: rotate(360deg); }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
    .az-app-ptr-indicator,
    .az-app-ptr-indicator .az-app-ptr-arrow {
        transition: none;
    }
    .az-app-ptr-indicator .az-app-ptr-spinner {
        animation: none;
    }
}

/* =====================================================================
   D1 — Diagnostic overlay (Sprint 6)
   Slide-up panel từ bottom, ~50% screen. Tabs + JSON pretty-print.
   Trigger: Long press 2s header logo (Header.js). Dev mode only.
   ===================================================================== */
.az-diag-overlay {
    position: fixed; inset: 0; z-index: 99999;
    pointer-events: none;
}

.az-diag-overlay.az-diag-show { pointer-events: auto; }

.az-diag-backdrop {
    position: absolute; inset: 0;
    background: rgba(0, 0, 0, 0);
    transition: background-color 0.25s ease;
}
.az-diag-overlay.az-diag-show .az-diag-backdrop {
    background: rgba(0, 0, 0, 0.5);
}

.az-diag-panel {
    position: absolute; left: 0; right: 0; bottom: 0;
    height: 50vh; max-height: 600px;
    background: var(--az-bg-surface, #fff);
    border-top: 1px solid var(--az-border-color, #d5dcde);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.2);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(.2, .8, .2, 1);
    display: flex; flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.az-diag-overlay.az-diag-show .az-diag-panel { transform: translateY(0); }

.az-diag-header {
    flex: 0 0 auto;
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--az-border-color, #d5dcde);
    background: var(--az-bg-surface-alt, #f0f4f5);
}

.az-diag-tabs {
    display: flex; gap: 4px; flex-wrap: wrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.az-diag-tab {
    padding: 6px 12px;
    border: 1px solid var(--az-border-color, #d5dcde);
    border-radius: 16px;
    background: transparent;
    color: var(--az-text-muted, #6b7280);
    font-size: 12px; font-weight: 500;
    cursor: pointer; user-select: none;
    transition: all 0.15s;
    white-space: nowrap;
}

.az-diag-tab:hover {
    background: var(--az-bg-surface-hover, #e5e7eb);
    color: var(--az-text-main, #111827);
}

.az-diag-tab.active {
    background: var(--az-color-primary, #0e529e);
    border-color: var(--az-color-primary, #0e529e);
    color: white;
}

.az-diag-actions {
    display: flex; gap: 4px;
    margin-left: 8px;
}

.az-diag-actions button {
    width: 32px; height: 32px;
    border: none; background: transparent;
    color: var(--az-text-muted, #6b7280);
    font-size: 16px; line-height: 1;
    border-radius: 6px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background-color 0.15s, color 0.15s;
}

.az-diag-actions button:hover {
    background: var(--az-bg-surface-hover, #e5e7eb);
    color: var(--az-text-main, #111827);
}

.az-diag-body {
    flex: 1 1 auto;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 16px;
    background: var(--az-bg-body, #f5f8f9);
}

.az-diag-content {
    margin: 0;
    font-family: 'SF Mono', 'Monaco', 'Cascadia Code', 'Consolas', monospace;
    font-size: 11px; line-height: 1.5;
    color: var(--az-text-main, #111827);
    white-space: pre-wrap;
    word-break: break-all;
}

@media (prefers-reduced-motion: reduce) {
    .az-diag-panel,
    .az-diag-backdrop,
    .az-diag-tab {
        transition: none;
        animation: none;
    }
}

/* =====================================================================
   C8 — Sync queue banner (Sprint 7)
   Persistent banner top khi có request đang chờ đồng bộ.
   Position fixed, dismissable qua "Đồng bộ ngay" button.
   ===================================================================== */
.az-sync-banner {
    position: fixed; left: 0; right: 0; top: 0;
    z-index: 99998;     /* dưới D1 overlay (99999) */
    display: none;
    align-items: center; gap: 8px;
    padding: 8px 12px;
    padding-top: calc(8px + env(safe-area-inset-top, 0));
    background: var(--az-warning-500, #f59e0b);
    color: white;
    font-size: 13px; font-weight: 500;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transform: translateY(0);
    transition: transform 0.25s ease;
}

.az-sync-banner i {
    font-size: 16px;
    flex: 0 0 auto;
}

.az-sync-text {
    flex: 1 1 auto;
}

.az-sync-flush-btn {
    flex: 0 0 auto;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: white;
    border-radius: 6px;
    font-size: 12px; font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s;
}

.az-sync-flush-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Push down content khi banner visible — App body cần margin-top */
body.az-has-sync-banner {
    margin-top: 40px;
}

@media (prefers-reduced-motion: reduce) {
    .az-sync-banner {
        transition: none;
    }
}