/* ============================================================
   GHZ DATE PICKER — date picker dùng chung, tự đồng bộ theme.
   ============================================================
   Vấn đề gốc: <input type="date"> dùng popup lịch của hệ điều hành —
   nền trắng, không theo theme (class `color-scheme-dark` trong index.html
   không tồn tại trong CSS đã compile → không có `color-scheme: dark`).
   Giờ: native input bị ẩn, hiển thị trigger + panel custom dùng token
   --ghz-* nên tự đổi màu theo theme (mint-fresh, mcu-*, neumorphism...).

   Token dùng:
     --ghz-card-bg / --ghz-card-border   → nền + viền panel
     --ghz-text-primary / --ghz-text-secondary / --ghz-text-muted
     --ghz-input-bg / --ghz-input-border
     --ghz-brand-color (+ -soft-12/-soft-25/-soft-45) → màu chủ đạo
   Fallback = palette tối mặc định của app khi chưa bật theme.
   ============================================================ */

/* ============================================================
   ACCENT ĐỌC ĐƯỢC (WCAG AA) — token riêng cho date picker
   ------------------------------------------------------------
   --ghz-brand-color là accent gốc của theme. Trên theme nền SÁNG nó
   quá nhạt: mint-fresh #00c37a trên nền trắng chỉ đạt 2.3:1 → dưới
   WCAG AA (4.5:1). Trên theme nền TỐI thì brand đã đủ sáng.
   Vì vậy date picker dùng 2 token riêng:
     --ghz-dp-accent      → màu accent dùng cho chữ / viền / nền ô
     --ghz-dp-accent-text → màu chữ đặt LÊN --ghz-dp-accent
   - Nhóm theme nền TỐI  : accent = brand nguyên bản (đã đạt >= 5.8:1),
                           chữ đặt trên là #0b0f14 (tương phản >= 7.4:1).
   - Nhóm theme nền SÁNG : accent = brand trộn 50% với --ghz-text-primary
                           (làm tối xuống) → đạt >= 5.1:1 trên nền sáng,
                           chữ đặt trên là #ffffff.
   Đã đo runtime cho đủ 22 theme (WCAG 2.1 AA, ngưỡng 4.5:1).
   Theme mới thêm mặc định theo nhóm dark (:root) — cần kiểm tra lại.
   ============================================================ */
:root {
    --ghz-dp-accent: #00c37a;
    --ghz-dp-accent-text: #0b0f14;
}

/* --- Theme nền TỐI: brand đã đủ sáng, giữ nguyên độ đậm gốc --- */
html[data-theme="classic"],
html[data-theme="midnight"],
html[data-theme="deep-space"],
html[data-theme="charcoal"],
html[data-theme="purple-haze"],
html[data-theme="mcu-iron"],
html[data-theme="mcu-cap"],
html[data-theme="mcu-thanos"],
html[data-theme="mcu-panther"],
html[data-theme="mcu-shield"],
html[data-theme="mcu-asgard"] {
    --ghz-dp-accent: var(--ghz-brand-color, #00c37a);
    --ghz-dp-accent-text: #0b0f14;
}

/* --- Theme nền SÁNG: brand gốc quá nhạt → trộn 50% với màu chữ chính --- */
html[data-theme="mint-fresh"],
html[data-theme="peach-cream"],
html[data-theme="lavender-mist"],
html[data-theme="sky-blue"],
html[data-theme="sunset"],
html[data-theme="pink-bloom"],
html[data-theme="cherry-blossom"],
html[data-theme="coffee-cream"],
html[data-theme="rose-pastel"],
html[data-theme="aurora-pastel"],
html[data-theme="neumorphism-wellness"] {
    --ghz-dp-accent: color-mix(in srgb, var(--ghz-brand-color, #00c37a) 50%, var(--ghz-text-primary, #1a202c));
    --ghz-dp-accent-text: #ffffff;
}

/* ---------- input native: ẩn nhưng vẫn giữ layout & giá trị ---------- */
input.ghz-dp-native {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
    border: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Input đã ẩn → trigger phải chiếm đúng chỗ của input gốc.
   - Nằm trong <label>/<div> block  → trigger full width.
   - Nằm trong flex row ngang (label + input) → trigger giữ width gốc.
   Input gốc bị position:absolute nên không còn chiếm chỗ; trigger được
   chèn ngay sau input nên vẫn nằm đúng vị trí trong flow. */
.ghz-dp-trigger {
    width: 100%;
}

/* Ô chọn ngày nằm trong hàng flex ngang (vd "Tìm theo ngày" + input):
   input gốc có width theo nội dung, trigger cũng nên hẹp vừa đủ. */
label > .ghz-dp-trigger,
.flex > .ghz-dp-trigger {
    width: auto;
    min-width: 9.5rem;
}

/* Trong <label> dạng block (nhãn ở trên, input ở dưới) → trigger full width. */
label > .ghz-dp-trigger {
    margin-top: 4px;
}

/* Khoảng cách giữa trigger và input gốc bị ẩn: nếu input nằm giữa 2 phần tử
   flex, trigger sẽ chen vào giữa → dùng order để giữ thứ tự. */
.ghz-dp-trigger {
    flex-shrink: 0;
}

/* ---------- date range picker (2 ô: Từ ngày → Đến ngày) ----------
   2 input nằm cạnh nhau trong .date-range-picker. Input gốc bị ẩn
   (position:absolute) nên trigger chèn sau nó sẽ chen giữa 2 input
   → dùng order để giữ đúng thứ tự: from → separator → to. */
.date-range-picker .ghz-dp-trigger {
    width: auto;
    min-width: 7.5rem;
    flex: 1 1 auto;
    min-height: 32px;
    padding: 5px 9px;
    font-size: 12.5px;
    background: transparent;
    border-color: transparent;
}

.date-range-picker .ghz-dp-trigger:hover {
    border-color: var(--ghz-dp-accent, #00c37a);
    background: var(--ghz-brand-soft-06, rgba(0, 195, 122, 0.06));
}

.date-range-picker .ghz-dp-trigger .ghz-dp-icon {
    font-size: 11px;
}

.date-range-picker .ghz-dp-trigger .ghz-dp-caret {
    display: none;
}

/* ---------- trigger (nút hiển thị ngày) ---------- */
.ghz-dp-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 38px;
    padding: 8px 12px;
    background: var(--ghz-input-bg, #14171b);
    border: 1px solid var(--ghz-input-border, #2a2e35);
    border-radius: 10px;
    color: var(--ghz-text-primary, #e5e7eb);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.35;
    text-align: left;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.ghz-dp-trigger:hover {
    border-color: var(--ghz-dp-accent, #00c37a);
    background: var(--ghz-brand-soft-06, rgba(0, 195, 122, 0.06));
}

.ghz-dp-trigger:focus-visible {
    border-color: var(--ghz-dp-accent, #00c37a);
    box-shadow: 0 0 0 3px var(--ghz-brand-soft-25, rgba(0, 195, 122, 0.25));
}

.ghz-dp-trigger.is-empty {
    color: var(--ghz-text-muted, #6b7280);
}

/* Trạng thái lỗi (app gọi setFieldError → aria-invalid trên input gốc). */
.ghz-dp-trigger.is-invalid {
    border-color: var(--ghz-danger, #ef4444);
    background: var(--ghz-danger-bg, rgba(239, 68, 68, 0.12));
}

.ghz-dp-trigger.is-invalid:hover {
    border-color: var(--ghz-danger, #ef4444);
    background: var(--ghz-danger-bg, rgba(239, 68, 68, 0.18));
}

.ghz-dp-trigger.is-invalid .ghz-dp-icon {
    color: var(--ghz-danger, #ef4444);
}

/* Icon lịch: dùng currentColor để không cần filter invert (filter làm
   icon tối trên nền sáng của theme pastel).
   Dùng --ghz-dp-accent (accent tương phản >= 4.5:1 trên mọi theme). */
.ghz-dp-trigger .ghz-dp-icon {
    color: var(--ghz-dp-accent, #00c37a);
    font-size: 13px;
    flex-shrink: 0;
    opacity: 0.9;
}

.ghz-dp-trigger .ghz-dp-text {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

.ghz-dp-trigger .ghz-dp-caret {
    flex-shrink: 0;
    font-size: 10px;
    color: var(--ghz-text-muted, #6b7280);
    opacity: 0.75;
    transition: transform 0.18s ease;
}

.ghz-dp-trigger[aria-expanded="true"] .ghz-dp-caret {
    transform: rotate(180deg);
}

/* Kích thước ô chọn ngày trong form marketing (mkt-input) */
.mkt-input.ghz-dp-native + .ghz-dp-trigger,
input.mkt-input.ghz-dp-native ~ .ghz-dp-trigger {
    width: 100%;
}

/* ---------- panel lịch ---------- */
.ghz-dp-panel {
    position: fixed;
    z-index: 2147483000; /* cao hơn modal (1000) và overlay (21474) */
    width: 296px;
    padding: 12px;
    /* --ghz-card-bg là linear-gradient() ở nhiều theme → phải dùng shorthand
       `background` (background-color không nhận gradient).
       Chọn card-bg (gần đục) chứ không phải glass-bg (0.45-0.5 alpha) vì
       popup nổi trên nền trang, nền quá trong suốt làm chữ khó đọc.
       backdrop-filter cho hiệu ứng kính mờ như card của app. */
    background: var(--ghz-card-bg, #181b20);
    -webkit-backdrop-filter: blur(18px) saturate(1.4);
    backdrop-filter: blur(18px) saturate(1.4);
    border: 1px solid var(--ghz-card-border, #2a2e35);
    border-radius: 14px;
    box-shadow: var(--ghz-card-glass-shadow, 0 18px 44px rgba(0, 0, 0, 0.55));
    color: var(--ghz-text-primary, #e5e7eb);
    font-family: inherit;
    overscroll-behavior: contain;
    /* Transition CHỈ cho transform, KHÔNG animate opacity.
       Lý do: nếu animation/transition bị "đóng băng" ở frame đầu (tab mất
       focus → renderer bị throttle → timeline tạm dừng), panel sẽ kẹt ở
       opacity:0 → tồn tại trong DOM + hit-test được nhưng VÔ HÌNH.
       Giữ opacity luôn = 1 để panel luôn nhìn thấy được; chỉ scale/translate
       để có hiệu ứng nhẹ mà không rủi ro biến mất. */
    opacity: 1;
    transform: translateY(-4px) scale(0.98);
    transition: transform 0.14s ease-out;
}

.ghz-dp-panel.is-open {
    transform: translateY(0) scale(1);
}

/* Trạng thái mở nhưng chưa được frame nào vẽ (rất hiếm) → vẫn phải thấy.
   Không dùng !important để không phá transition. */
.ghz-dp-panel[hidden] {
    display: none !important;
}

@media (prefers-reduced-motion: reduce) {
    .ghz-dp-panel {
        transition: none;
        transform: none;
    }
}

/* header: điều hướng tháng/năm */
.ghz-dp-header {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-bottom: 10px;
}

.ghz-dp-title {
    flex: 1 1 auto;
    background: none;
    border: none;
    padding: 4px 6px;
    color: var(--ghz-text-primary, #e5e7eb);
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    text-align: center;
    cursor: default;
    letter-spacing: 0.01em;
}

.ghz-dp-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--ghz-text-secondary, #9ca3af);
    font-size: 11px;
    cursor: pointer;
    transition: background 0.14s, color 0.14s, border-color 0.14s;
}

.ghz-dp-nav:hover {
    background: var(--ghz-brand-soft-12, rgba(0, 195, 122, 0.12));
    border-color: var(--ghz-brand-soft-25, rgba(0, 195, 122, 0.25));
    color: var(--ghz-dp-accent, #00c37a);
}

.ghz-dp-nav:focus-visible {
    outline: 2px solid var(--ghz-dp-accent, #00c37a);
    outline-offset: 1px;
}

/* header tháng/năm — 2 nút đầu & 2 nút sau gộp chung, nút đầu = lùi 1 năm */
.ghz-dp-nav[data-act="prev-year"] i,
.ghz-dp-nav[data-act="next-year"] i {
    font-size: 10px;
    opacity: 0.7;
}

/* tiêu đề thứ 2 và thứ 4 (chevron đơn) */
.ghz-dp-nav[data-act="prev"] { margin-left: 2px; }
.ghz-dp-nav[data-act="next"] { margin-right: 2px; }

/* ---------- lưới ngày ---------- */
.ghz-dp-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 4px;
}

.ghz-dp-wd {
    text-align: center;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ghz-text-muted, #6b7280);
    padding: 2px 0;
}

.ghz-dp-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

/* app.min.css có rule `button { color: inherit }` → ghi đè màu token của
   theme. Phải khai báo lại (và dùng !important để thắng rule đó) để màu
   chữ ô ngày bám theo theme, đặc biệt với theme nền sáng. */
.ghz-dp-cell,
.ghz-dp-chip,
.ghz-dp-nav,
.ghz-dp-clear,
.ghz-dp-title,
.ghz-dp-trigger {
    color: var(--ghz-text-primary, #e5e7eb);
}

.ghz-dp-cell {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 34px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 9px;
    font-family: inherit;
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}

/* ô ngày dùng màu chữ chính, nhưng theme sáng cần màu đậm hơn */
.ghz-dp-cell {
    color: var(--ghz-text-primary, #e5e7eb) !important;
}

.ghz-dp-cell.is-blank {
    cursor: default;
    pointer-events: none;
}

.ghz-dp-cell:hover:not(.is-blank) {
    background: var(--ghz-brand-soft-12, rgba(0, 195, 122, 0.12));
    border-color: var(--ghz-brand-soft-25, rgba(0, 195, 122, 0.25));
    color: var(--ghz-dp-accent, #00c37a) !important;
}

.ghz-dp-cell:focus-visible {
    outline: 2px solid var(--ghz-dp-accent, #00c37a);
    outline-offset: -2px;
}

/* hôm nay: viền mảnh + chữ đậm
   Cần !important vì rule .ghz-dp-cell ở trên dùng color:... !important
   (để thắng `button { color: inherit }` của app.min.css) — không có
   !important ở đây thì ô "hôm nay" bị mất màu accent. */
.ghz-dp-cell.is-today {
    border-color: var(--ghz-brand-soft-45, rgba(0, 195, 122, 0.45));
    color: var(--ghz-dp-accent, #00c37a) !important;
    font-weight: 700;
}

/* đang chọn: nền accent + chữ tương phản
   Nền = --ghz-dp-accent (đã tối hoá trên theme sáng), chữ = --ghz-dp-accent-text
   → cả 2 đều đạt >= 4.5:1 (WCAG AA). */
.ghz-dp-cell.is-selected,
.ghz-dp-cell.is-selected:hover {
    background: var(--ghz-dp-accent, #00c37a);
    border-color: var(--ghz-dp-accent, #00c37a);
    color: var(--ghz-dp-accent-text, #ffffff) !important;
    font-weight: 700;
}

/* chế độ month: ô tròn hơn, dày hơn */
.ghz-dp-cell.is-month-mode {
    height: 30px;
    border-radius: 7px;
    font-size: 11.5px;
}

/* chế độ month: lưới 12 tháng */
.ghz-dp-panel.is-month-mode .ghz-dp-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.ghz-dp-panel.is-month-mode .ghz-dp-cell.ghz-dp-month {
    height: 44px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 4px;
    text-align: center;
}

.ghz-dp-panel.is-month-mode .ghz-dp-quick {
    display: none;
}

.ghz-dp-panel.is-month-mode .ghz-dp-header {
    justify-content: center;
}

/* ---------- quick pick ---------- */
.ghz-dp-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--ghz-card-border, #2a2e35);
}

.ghz-dp-chip {
    padding: 4px 9px;
    background: var(--ghz-brand-soft-08, rgba(0, 195, 122, 0.08));
    border: 1px solid var(--ghz-brand-soft-25, rgba(0, 195, 122, 0.25));
    border-radius: 999px;
    /* Dùng --ghz-dp-accent (accent tương phản >= 4.5:1 trên mọi theme)
       thay vì --ghz-brand-color: trên theme nền sáng, brand gốc chỉ đạt
       ~2.3:1 so với nền → dưới WCAG AA. */
    color: var(--ghz-dp-accent, #00c37a);
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.14s, transform 0.1s;
}

.ghz-dp-chip:hover {
    background: var(--ghz-brand-soft-25, rgba(0, 195, 122, 0.25));
}

.ghz-dp-chip:active {
    transform: scale(0.96);
}

.ghz-dp-chip:focus-visible {
    outline: 2px solid var(--ghz-dp-accent, #00c37a);
    outline-offset: 1px;
}

/* ---------- footer: nhập nhanh + xóa ---------- */
.ghz-dp-foot {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 9px;
    padding-top: 9px;
    border-top: 1px solid var(--ghz-card-border, #2a2e35);
}

.ghz-dp-typed {
    flex: 1 1 auto;
    min-width: 0;
    padding: 5px 9px;
    background: var(--ghz-input-bg, #14171b);
    border: 1px solid var(--ghz-input-border, #2a2e35);
    border-radius: 8px;
    color: var(--ghz-text-primary, #e5e7eb);
    font-family: inherit;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.ghz-dp-typed::placeholder {
    color: var(--ghz-text-muted, #6b7280);
}

.ghz-dp-typed:focus {
    border-color: var(--ghz-dp-accent, #00c37a);
    box-shadow: 0 0 0 2px var(--ghz-brand-soft-25, rgba(0, 195, 122, 0.25));
}

.ghz-dp-typed.is-error {
    border-color: var(--ghz-danger, #ef4444);
    box-shadow: 0 0 0 2px var(--ghz-danger-glow, rgba(239, 68, 68, 0.2));
    animation: ghz-dp-shake 0.28s ease;
}

@keyframes ghz-dp-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.ghz-dp-clear {
    flex-shrink: 0;
    padding: 5px 10px;
    background: transparent;
    border: 1px solid var(--ghz-card-border, #2a2e35);
    border-radius: 8px;
    color: var(--ghz-text-secondary, #9ca3af);
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.14s, border-color 0.14s, background 0.14s;
}

.ghz-dp-clear:hover {
    color: var(--ghz-danger, #ef4444);
    border-color: var(--ghz-danger, #ef4444);
    background: var(--ghz-danger-bg, rgba(239, 68, 68, 0.12));
}

.ghz-dp-clear:focus-visible {
    outline: 2px solid var(--ghz-danger, #ef4444);
    outline-offset: 1px;
}

/* ---------- mobile ----------
   Oct 24, 2026 (UX responsive):
   - Ô ngày 38px → 42px (gần chuẩn Apple HIG 44px, vẫn vừa 6 hàng trong panel).
   - Chip quick-pick & nút Xóa: min-height 34px (chạm thoải mái, không quá cao).
   - Panel rộng tối đa theo viewport, canh giữa khi hẹp.
   - Ô nhập dd/mm/yyyy: font-size 16px để iOS KHÔNG tự zoom khi focus. */
@media (max-width: 640px) {
    .ghz-dp-panel {
        width: min(340px, calc(100vw - 16px));
        padding: 10px;
    }

    .ghz-dp-cell {
        height: 42px;              /* chạm tối thiểu ~42px cho ngón tay */
        font-size: 13px;
    }

    /* Chế độ tháng: 12 ô 3 cột → giữ chiều cao ô nhưng thu gọn font */
    .ghz-dp-panel.is-month-mode .ghz-dp-cell.ghz-dp-month {
        height: 46px;
        font-size: 12px;
    }

    .ghz-dp-chip {
        padding: 7px 11px;
        font-size: 11.5px;
        min-height: 32px;
        display: inline-flex;
        align-items: center;
    }

    /* Nút điều hướng tháng/năm: vùng chạm 36px */
    .ghz-dp-nav {
        width: 36px;
        height: 36px;
        font-size: 12px;
    }

    .ghz-dp-clear {
        min-height: 34px;
        padding: 7px 12px;
        font-size: 11.5px;
    }

    /* 16px để iOS Safari không zoom khi focus input */
    .ghz-dp-typed {
        font-size: 16px;
        padding: 8px 10px;
        min-height: 38px;
    }

    /* Trigger: min-height 44px để chạm dễ trên mobile */
    .ghz-dp-trigger {
        min-height: 44px;
        font-size: 15px;
    }
}

/* Màn hình rất hẹp (iPhone SE 320px) → panel full-width trừ 8px mỗi bên */
@media (max-width: 359px) {
    .ghz-dp-panel {
        width: calc(100vw - 8px);
        padding: 8px;
    }

    .ghz-dp-cell {
        height: 40px;
        font-size: 12.5px;
    }
}

/* ---------- dark scheme cho native input còn sót lại (vd .date-range-picker) ---------- */
.ghz-dp-panel,
.ghz-dp-trigger {
    color-scheme: dark;
}

/* ---------- class `color-scheme-dark` ----------
   Class này đã có sẵn trong index.html (19 chỗ: input date/month + select)
   nhưng KHÔNG tồn tại trong CSS đã compile — Tailwind không có utility
   `color-scheme-dark` (utility chính thức là `scheme-dark`).
   → Chrome dựng dropdown <select> theo LIGHT scheme, lệch theme.
   Khai báo rule thật ở đây để các control này dùng dark scheme.
   Với input date/month, date picker tùy chỉnh đã thay thế nên popup native
   không còn xuất hiện; rule này có tác dụng với <select>. */
.color-scheme-dark {
    color-scheme: dark;
}

/* Danh sách option của select: nền + chữ theo theme.
   `background-color` (không phải `background`) vì --ghz-card-bg có thể là
   linear-gradient() → không hợp lệ cho background-color. Dùng nền card
   phẳng để option luôn đọc được ở cả theme sáng lẫn theme tối. */
select.color-scheme-dark option {
    background-color: var(--ghz-input-bg, #14171b);
    color: var(--ghz-text-primary, #e5e7eb);
}
