/* Global UI layer (AppGlobalStyles): cross-cutting premium treatments applied on top of
   MudBlazor. Depends on tokens.css. Signature moves: soft depth, glass appbar, brand-pill
   nav, shimmer skeletons, unified micro-motion, focus-visible rings. */

/* ---- Inter self-hosted 600/700 (400/500 declared in app.css) ---- */
@font-face { font-family:'Inter'; font-style:normal; font-weight:600; font-display:swap;
    src:url('fonts/inter-vietnamese-600.woff2') format('woff2');
    unicode-range:U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB; }
@font-face { font-family:'Inter'; font-style:normal; font-weight:600; font-display:swap;
    src:url('fonts/inter-latin-600.woff2') format('woff2');
    unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+2000-206F,U+2074,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family:'Inter'; font-style:normal; font-weight:700; font-display:swap;
    src:url('fonts/inter-vietnamese-700.woff2') format('woff2');
    unicode-range:U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB; }
@font-face { font-family:'Inter'; font-style:normal; font-weight:700; font-display:swap;
    src:url('fonts/inter-latin-700.woff2') format('woff2');
    unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+2000-206F,U+2074,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }

/* ---- App canvas ---- */
.app-canvas { max-width: var(--u-canvas-max); margin: 0 auto; padding: var(--u-page-gutter); }
@media (max-width: 600px) { .app-canvas { padding: 16px; } }

/* ---- Glass appbar ---- */
.app-topbar.mud-appbar {
    background: var(--u-glass-bg) !important;
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--u-glass-border);
    color: var(--u-text-primary);
}
.app-logo-tile {
    width: 32px; height: 32px; border-radius: var(--u-radius-sm);
    background: var(--u-primary); color: #fff; display: flex; align-items: center;
    justify-content: center; font-weight: 700; flex: 0 0 auto;
}

/* ---- Soft-depth cards ---- */
.app-surface {
    background: var(--u-surface-1);
    border: 1px solid var(--u-border);
    border-radius: var(--u-radius-card);
    box-shadow: var(--u-shadow-md);
}
.app-surface--flat { box-shadow: none; }
.app-surface--interactive {
    transition: box-shadow var(--u-dur-2) var(--u-ease-standard),
                transform var(--u-dur-2) var(--u-ease-standard);
}
.app-surface--interactive:hover { box-shadow: var(--u-shadow-lg); transform: translateY(-2px); }

/* ---- Brand-pill nav (active/hover) ---- */
.app-nav .mud-nav-link,
.app-nav .mud-nav-group > .mud-nav-link {
    border-radius: var(--u-radius-sm);
    margin: 2px 6px;
    transition: background var(--u-dur-2) var(--u-ease-standard), color var(--u-dur-2) var(--u-ease-standard);
}
.app-nav .mud-nav-link:hover { background: #F1F0FA; }
.app-nav .mud-nav-link.active,
.app-nav .mud-nav-link.mud-nav-link-active {
    background: var(--u-primary-container);
    color: var(--u-primary) !important;
    font-weight: 600;
    box-shadow: inset 3px 0 0 0 var(--u-primary);
}
.app-nav .mud-nav-link.active .mud-icon-root { color: var(--u-primary) !important; }

/* ---- Shimmer skeleton engine (the ONLY shimmer definition) ---- */
.app-shimmer {
    position: relative; overflow: hidden;
    background: var(--u-skeleton-base);
    border-radius: var(--u-radius-sm);
}
.app-shimmer::after {
    content: ""; position: absolute; inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, var(--u-skeleton-highlight), transparent);
    animation: app-shimmer 1600ms linear infinite;
}
@keyframes app-shimmer { 100% { transform: translateX(100%); } }

/* ---- Card / list entrance + stagger ---- */
.app-rise { animation: app-rise var(--u-dur-4) var(--u-ease-emphasized) both; }
@keyframes app-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---- Top route progress bar ---- */
.app-page-progress {
    position: fixed; top: 0; left: 0; height: 3px; width: 100%;
    z-index: 2000; background: transparent; overflow: hidden;
}
.app-page-progress > span {
    display: block; height: 100%; width: 40%;
    background: var(--u-primary);
    animation: app-progress 1100ms var(--u-ease-emphasized) infinite;
}
@keyframes app-progress { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }

/* ---- Focus-visible ring (keyboard only) ---- */
:focus-visible {
    outline: 2px solid var(--u-primary);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ---- Confirm-dialog halo (reuses .app-state__halo sizing) ---- */
.app-confirm-halo--danger { background: var(--u-error-bg); color: var(--u-error); border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.app-confirm-halo--primary { background: var(--u-primary-50); color: var(--u-primary); border-radius: 50%; display: flex; align-items: center; justify-content: center; }

/* ---- Description list (read-only detail rows) ---- */
.app-desc-list { margin: 0; }
.app-desc-row { display: grid; grid-template-columns: minmax(120px, 34%) 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--u-border); }
.app-desc-row:last-child { border-bottom: none; }
.app-desc-term { color: var(--u-text-secondary); font-size: 13px; }
.app-desc-detail { color: var(--u-text-primary); font-weight: 500; }
@media (max-width: 560px) { .app-desc-row { grid-template-columns: 1fr; gap: 2px; } }

/* ---- Permission tree (role permissions dialog) ---- */
.app-perm-tree { border: 1px solid var(--u-border); border-radius: var(--u-radius-md); padding: 4px; max-height: 52vh; overflow-y: auto; }
.app-perm-node { display: flex; align-items: center; gap: 8px; }
.app-perm-module { font-weight: 600; }
.app-perm-tree .mud-treeview-item-content { border-radius: var(--u-radius-sm); }

/* ---- User menu (avatar dropdown) ---- */
.app-usermenu-trigger { display: inline-flex; align-items: center; cursor: pointer; border-radius: 50%; }
.app-usermenu-trigger:focus-visible { outline: 2px solid var(--u-primary); outline-offset: 2px; }
.app-usermenu { min-width: 260px; padding-top: 0; }
.app-usermenu-head { display: flex; gap: 12px; align-items: flex-start; padding: 16px; }
.app-usermenu-info { min-width: 0; }
.app-usermenu-name { font-weight: 600; font-size: 14px; color: var(--u-text-primary); }
.app-usermenu-email { font-size: 12.5px; color: var(--u-text-secondary); overflow: hidden; text-overflow: ellipsis; }

/* ---- Soft-tint tiles (stat-card icons, accents) ---- */
.app-tint--primary { background: var(--u-primary-50); color: var(--u-primary); }
.app-tint--success { background: var(--u-success-bg); color: var(--u-success-text); }
.app-tint--warning { background: var(--u-warning-bg); color: var(--u-warning-text); }
.app-tint--error { background: var(--u-error-bg); color: var(--u-error-text); }
.app-tint--info { background: var(--u-info-bg); color: var(--u-info-text); }
.app-tint--neutral { background: var(--u-neutral-chip); color: var(--u-neutral-chip-fg); }

/* ---- Premium MudDataGrid ---- */
.app-grid.mud-table-outlined { border: 1px solid var(--u-border); border-radius: var(--u-radius-card); overflow: hidden; box-shadow: var(--u-shadow-sm); }
.app-grid .mud-table-head th { background: var(--u-surface-sunken); color: var(--u-text-secondary); font-weight: 600; }
.app-grid .mud-table-row:hover { background: #F8F9FC; }

/* ---- Premium dialogs / popups ---- */
.mud-dialog {
    border-radius: var(--u-radius-xl) !important;
    box-shadow: var(--u-shadow-2xl) !important;
    border: 1px solid var(--u-border);
    overflow: hidden;
    animation: app-dialog-in var(--u-dur-3) var(--u-ease-emphasized) both;
}
@keyframes app-dialog-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
.mud-dialog .mud-dialog-title { padding: 20px 24px 12px; border-bottom: 1px solid var(--u-border); }
.mud-dialog .mud-dialog-content { padding: 20px 24px; }
.mud-dialog .mud-dialog-actions { padding: 12px 24px; border-top: 1px solid var(--u-border); gap: 8px; background: var(--u-surface-2); }
.mud-overlay-dialog { backdrop-filter: blur(2px); background: var(--u-scrim) !important; }
/* All dialogs occupy a comfortable width — at least ~50% of the viewport, capped so they
   never overflow and go near-full on small screens. min-width beats MudBlazor's MaxWidth. */
.mud-dialog { width: clamp(320px, 50vw, calc(100vw - 32px)); max-width: calc(100vw - 32px) !important; }
@media (max-width: 700px) { .mud-dialog { width: calc(100vw - 24px); } }
.mud-dialog .mud-dialog-content { max-height: 70vh; overflow-y: auto; }

/* ---- Snackbar: rounded + left severity accent + soft shadow ---- */
.mud-snackbar { border-radius: var(--u-radius-md) !important; box-shadow: var(--u-shadow-lg) !important; border-left: 4px solid transparent; }
.mud-snackbar.mud-alert-filled-success { border-left-color: #0B6E38; }
.mud-snackbar.mud-alert-filled-error { border-left-color: #7A1418; }
.mud-snackbar.mud-alert-filled-warning { border-left-color: #8A5A00; }
.mud-snackbar.mud-alert-filled-info { border-left-color: #0058C7; }

/* ---- Buttons: weight + radius + press feedback ---- */
.mud-button-root { border-radius: var(--u-radius-sm) !important; font-weight: 600; letter-spacing: .01em; transition: transform var(--u-dur-1) var(--u-ease-standard), box-shadow var(--u-dur-2) var(--u-ease-standard); }
.mud-button-filled:active { transform: scale(.97); }
.mud-button-filled.mud-button-filled-primary { box-shadow: 0 2px 6px -1px rgba(13,0,157,.28); }
.mud-button-filled.mud-button-filled-primary:hover { box-shadow: 0 6px 14px -2px rgba(13,0,157,.34); }

/* ---- Inputs: focus ring in Duke Blue ---- */
.mud-input-outlined .mud-input-outlined-border { border-radius: var(--u-radius-sm); border-color: var(--u-border-control); }
.mud-input.mud-input-focused .mud-input-outlined-border { border-width: 1.5px !important; box-shadow: 0 0 0 3px rgba(13,0,157,.10); }

/* ---- Page content entrance ---- */
.mud-main-content > .mud-container { animation: app-rise var(--u-dur-4) var(--u-ease-emphasized) both; }

/* ---- Stat card top accent (liveliness) ---- */
.app-stat { position: relative; overflow: hidden; }
.app-stat::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, var(--u-primary), var(--u-primary-300)); opacity: .9; }

/* ---- MudDataGrid: uppercase headers (Figma spec) ---- */
.mud-data-grid .mud-table-head .mud-table-cell {
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--u-text-secondary, #4b5563);
}

/* ---- Table row 'View' action rendered as underlined link (Figma spec) ----
   MudButton's inner label span carries text-decoration:none by default; hit both the button
   and its inner label with !important so the underline actually paints. */
.mud-button-root.view-link,
.mud-button-root.view-link .mud-button-label,
.mud-button-root.view-link span { text-decoration: underline !important; text-underline-offset: 3px; }

/* ---- Opt-out list filter row (Figma spec) --------------------------------------------
   Layout: no card background — fields flow directly on the page surface. Static labels sit
   above each field; the search input has a square blue button glued to its right edge; the
   date range is one labeled group with a → separator; the Xóa (outlined) + Tìm kiếm (filled)
   actions sit on the far right of the SAME row. */
.optout-filter { padding: 0; margin-bottom: 12px; }
.optout-filter-grid {
    display: grid;
    grid-template-columns: minmax(220px, 1.6fr) minmax(120px, .8fr) minmax(120px, .8fr) minmax(260px, 1.4fr) auto;
    gap: 12px;
    align-items: end;
}
.optout-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.optout-label { font-size: 12px; font-weight: 500; color: var(--u-text-secondary, #6b7280); letter-spacing: 0.01em; }
.optout-field .mud-input { background: #fff; }
/* Figma spec: filter inputs use 8px radius + 40px compact height (theme default is 12px/56px). */
.optout-field .mud-input-outlined-border { border-radius: 8px !important; }
.optout-field .mud-input.mud-input-outlined input.mud-input-slot,
.optout-field .mud-input.mud-input-outlined div.mud-input-slot { padding-top: 10px !important; padding-bottom: 10px !important; font-size: 13px; font-weight: 400; }
.optout-field .mud-input.mud-input-outlined input.mud-input-slot::placeholder { font-weight: 400; color: var(--u-text-secondary, #6b7280); opacity: 1; }
.optout-field .mud-input.mud-input-outlined { min-height: 40px; }
.optout-field .mud-input-adornment svg { font-size: 18px !important; color: var(--u-text-secondary, #6b7280); }
/* Search input + button glued into one control (Figma): the input grows, the button hugs its
   right edge sharing the border. Button borders on the left are flattened; input borders on
   the right are flattened; the two ride the same 40px height with a -1px overlap so their
   1px borders collapse into a single visual seam. */
.optout-field-search > div { align-items: stretch; gap: 0 !important; }
.optout-field-search .mud-input-control { flex: 1 1 auto; min-width: 0; margin-right: -1px; }
.optout-field-search .mud-input-outlined-border {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}
.optout-search-btn.mud-button-root {
    min-width: 40px;
    height: 40px;
    padding: 0 10px;
    border-radius: 0 8px 8px 0 !important;
    box-shadow: none;
    flex: 0 0 auto;
}
.optout-field-actions { flex-direction: row; gap: 8px; align-items: end; }
.optout-field-actions .mud-button-root { height: 40px; padding: 0 20px; }
@media (max-width: 900px) {
    .optout-filter-grid { grid-template-columns: 1fr 1fr; }
    .optout-field-actions { grid-column: 1 / -1; justify-content: flex-end; }
}

/* ---- Opt-out list tabs (Figma spec: rectangular container, rectangular pills) --------- */
.optout-tabs { display: flex; gap: 4px; padding: 4px; background: #fff; border-radius: 8px;
    border: 1px solid var(--u-border, #e5e7eb); width: fit-content; }
.optout-tab-pill {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 6px 14px; border-radius: 6px; border: 1px solid transparent;
    background: transparent; color: var(--u-text-secondary, #4b5563);
    font-size: 14px; font-weight: 500; cursor: pointer; transition: background .15s, color .15s;
}
.optout-tab-pill:hover { background: rgba(13, 0, 157, .04); }
.optout-tab-pill--active {
    background: rgba(13, 0, 157, .06); border-color: rgba(13, 0, 157, .35);
    color: var(--u-primary, #0d009d);
}
.optout-tab-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 22px; height: 20px; padding: 0 6px; border-radius: 4px;
    background: rgba(0, 0, 0, .06); color: var(--u-text-primary, #111827);
    font-size: 12px; font-weight: 600;
}
.optout-tab-pill--active .optout-tab-badge {
    background: rgba(13, 0, 157, .15); color: var(--u-primary, #0d009d);
}
.optout-create-btn.mud-button-root { height: 40px; padding: 0 20px; border-radius: 8px; }

/* ---- Opt-out action dialogs (Figma spec: 357px card, radius 16, bell icon centered,
   title, body/warning text, Cancel + primary CTA). Shared by Create / Approve / Reject /
   MarkCompleted / UpdateResult. Selectors cover BOTH cases where MudBlazor applies our
   Class to the .mud-dialog root itself (compound) OR to a wrapping container (descendant). */
.mud-dialog.optout-create-dialog,
.mud-dialog.optout-action-dialog,
.optout-create-dialog .mud-dialog,
.optout-action-dialog .mud-dialog { border-radius: 16px !important; max-width: 357px !important; width: 100% !important; }
.mud-dialog.optout-create-dialog .mud-dialog-title,
.mud-dialog.optout-action-dialog .mud-dialog-title,
.optout-create-dialog .mud-dialog-title,
.optout-action-dialog .mud-dialog-title { padding: 24px 24px 0 !important; border-bottom: 0 !important; }
.mud-dialog.optout-create-dialog .mud-dialog-content,
.mud-dialog.optout-action-dialog .mud-dialog-content,
.optout-create-dialog .mud-dialog-content,
.optout-action-dialog .mud-dialog-content { padding: 16px 24px !important; }
.mud-dialog.optout-create-dialog .mud-dialog-actions,
.mud-dialog.optout-action-dialog .mud-dialog-actions,
.optout-create-dialog .mud-dialog-actions,
.optout-action-dialog .mud-dialog-actions { padding: 16px 24px 20px !important; border-top: 0 !important; gap: 12px; }
.optout-create-header { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.optout-create-icon {
    width: 56px; height: 56px; border-radius: 50%;
    background: var(--u-primary-50, #EEEDFB);
    color: var(--u-primary, #0d009d);
    display: inline-flex; align-items: center; justify-content: center;
}
.optout-required { color: var(--u-error, #E5484D); margin-left: 2px; }
.optout-hint { display: block; margin-top: 4px; }
.optout-hint--ok { color: var(--u-success-text, #0B6E38); }
.optout-hint--err { color: var(--u-error-text, #A11D22); }
.optout-create-note { color: var(--u-text-secondary, #6b7280); font-size: 13px; }
.optout-dialog-note { color: var(--u-text-secondary, #6b7280); font-size: 13px; margin-top: 8px; }
.optout-dialog-warning { color: var(--u-text-primary, #111); font-size: 13px; margin-top: 12px; }
.optout-dialog-btn.mud-button-root { flex: 1 1 0; height: 40px; border-radius: 8px; white-space: nowrap; }
/* Figma: the primary confirm CTA carries a longer label ("Yes, mark completed") and gets more
   width than the Cancel button so it stays on one line. Outlined = Cancel, Filled = confirm. */
.optout-action-dialog .mud-dialog-actions .optout-dialog-btn.mud-button-filled,
.optout-create-dialog .mud-dialog-actions .optout-dialog-btn.mud-button-filled { flex: 1.7 1 0; }

/* ---- Request-detail right-side drawer: header stays put, body scrolls, actions sticky
   at the bottom so long history logs never push CTAs out of view. ---- */
.optout-detail-drawer { display: flex; flex-direction: column; height: 100%; width: 100%; }
.optout-detail-header {
    display: flex; align-items: center;
    padding: 16px 20px; border-bottom: 1px solid var(--u-border, #e5e7eb);
    flex: 0 0 auto;
}
.optout-detail-body { flex: 1 1 auto; overflow-y: auto; padding: 16px 20px; }
/* Figma spec: CTAs pinned to the RIGHT edge, primary destructive on the left of the
   trailing group. Buttons keep intrinsic width; wrap only if the drawer is very narrow. */
.optout-detail-actions {
    display: flex; flex-wrap: wrap; gap: 12px;
    justify-content: flex-end;
    padding: 16px 20px 20px;
    border-top: 1px solid var(--u-border, #e5e7eb);
    background: #fff; flex: 0 0 auto;
}
.optout-detail-actions .mud-button-root { min-width: 96px; height: 40px; border-radius: 8px; }


/* ---- Pagination: outlined boxes for ALL buttons (Figma spec) ----
   MudPagination structure: <div.mud-pagination-item> wraps <button.mud-button-root>.
   Reset the wrapper to layout-only (no border/bg), then style the INNER button. */
.mud-data-grid .mud-pagination { gap: 1px !important; }
.mud-data-grid .mud-pagination .mud-pagination-item {
    margin: 0 !important; padding: 0 !important;
    border: 0 !important; background: transparent !important; box-shadow: none !important;
    min-width: 0 !important; width: auto !important; height: auto !important;
}
.mud-data-grid .mud-pagination .mud-pagination-item .mud-button-root {
    min-width: 28px !important; width: 28px !important; height: 28px !important;
    padding: 0 !important;
    border: 1px solid var(--u-border, #EDEEF3) !important; border-radius: 6px !important;
    background: #fff !important; color: var(--u-text-secondary, #6b7280) !important;
    font-size: 12px !important; font-weight: 500 !important;
    box-shadow: none !important;
}
.mud-data-grid .mud-pagination .mud-pagination-item .mud-button-root .mud-icon-root { font-size: 14px !important; }
.mud-data-grid .mud-pagination .mud-pagination-item .mud-button-root:hover:not(:disabled) {
    background: var(--u-neutral-50, #F6F7FB) !important;
}
.mud-data-grid .mud-pagination .mud-pagination-item.mud-pagination-item-selected .mud-button-root {
    background: var(--u-primary, #0d009d) !important; border-color: var(--u-primary, #0d009d) !important; color: #fff !important;
}
.mud-data-grid .mud-pagination .mud-pagination-item .mud-button-root::before,
.mud-data-grid .mud-pagination .mud-pagination-item .mud-button-root::after { display: none !important; }
.mud-data-grid .mud-pagination .mud-pagination-item .mud-button-root:disabled { opacity: 0.5 !important; }

/* ---- Reduced-motion kill switch ---- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important; animation-iteration-count: 1 !important;
        transition-duration: .001ms !important; scroll-behavior: auto !important;
    }
    .app-shimmer::after { animation: app-shimmer-pulse 1400ms ease-in-out infinite; }
    @keyframes app-shimmer-pulse { 0%,100% { opacity: .5; } 50% { opacity: 1; } }
}
