/* ==========================================================================
   Instore dashboard UI layer
   Loaded after styles.css on the dashboard pages (home/*.html).
   Colours stay in the Tailwind classes of each page (theme-aware via
   isDarkMode); this file owns layout, motion, focus and shared components.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Gotham, one clean face per weight.
   The hosted stylesheet maps several cuts (XLight, Thin, Black) to weight 500
   and prefers locally installed copies, so text rendered differently from
   machine to machine. These declarations are explicit and identical everywhere.
   The metric overrides replace the files' empty ascent/descent values so
   capitals sit on the optical centre of buttons, pills and table rows.
   -------------------------------------------------------------------------- */
@font-face {
    font-family: 'Gotham';
    font-style: normal;
    font-weight: 300;
    font-display: swap;
    src: url('https://fonts.cdnfonts.com/s/14898/GothamLight.woff') format('woff');
    ascent-override: 95%;
    descent-override: 25%;
    line-gap-override: 0%;
}

@font-face {
    font-family: 'Gotham';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('https://fonts.cdnfonts.com/s/14898/GothamBook.woff') format('woff');
    ascent-override: 95%;
    descent-override: 25%;
    line-gap-override: 0%;
}

@font-face {
    font-family: 'Gotham';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url('https://fonts.cdnfonts.com/s/14898/GothamMedium.woff') format('woff');
    ascent-override: 95%;
    descent-override: 25%;
    line-gap-override: 0%;
}

@font-face {
    font-family: 'Gotham';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('https://fonts.cdnfonts.com/s/14898/GothamBold.woff') format('woff');
    ascent-override: 95%;
    descent-override: 25%;
    line-gap-override: 0%;
}

@font-face {
    font-family: 'Gotham';
    font-style: normal;
    font-weight: 900;
    font-display: swap;
    src: url('https://fonts.cdnfonts.com/s/14898/Gotham-Black.woff') format('woff');
    ascent-override: 95%;
    descent-override: 25%;
    line-gap-override: 0%;
}

/* --------------------------------------------------------------------------
   Tokens
   -------------------------------------------------------------------------- */
:root,
[data-theme="dark"] {
    --ui-accent: #00CC66;
    --ui-ring: #00CC66;
    --ui-scroll-thumb: rgba(255, 255, 255, 0.14);
    --ui-scroll-thumb-hover: rgba(255, 255, 255, 0.26);
    --ui-skeleton: rgba(255, 255, 255, 0.06);
    --ui-skeleton-shine: rgba(255, 255, 255, 0.07);
    --ui-select-chevron: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23a3a3a3' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    --ui-ease-out: cubic-bezier(0.32, 0.72, 0, 1);
    --ui-ease: cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
    --ui-ring: #00B359;
    --ui-scroll-thumb: rgba(17, 24, 39, 0.18);
    --ui-scroll-thumb-hover: rgba(17, 24, 39, 0.32);
    --ui-skeleton: rgba(17, 24, 39, 0.07);
    --ui-skeleton-shine: rgba(255, 255, 255, 0.65);
    --ui-select-chevron: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%234b5563' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */
html[data-theme] ::selection {
    background: rgba(0, 204, 102, 0.28);
}

/* Counts, dates and money line up */
.tabular-nums,
.nav-item-badge {
    font-variant-numeric: tabular-nums;
}

/* Scrollbars follow the theme (styles.css paints a dark track in both) */
html[data-theme] * {
    scrollbar-width: thin;
    scrollbar-color: var(--ui-scroll-thumb) transparent;
}

html[data-theme] ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

html[data-theme] ::-webkit-scrollbar-track {
    background: transparent;
}

html[data-theme] ::-webkit-scrollbar-thumb {
    background: var(--ui-scroll-thumb);
    border: 3px solid transparent;
    border-radius: 9999px;
    background-clip: padding-box;
}

html[data-theme] ::-webkit-scrollbar-thumb:hover {
    background: var(--ui-scroll-thumb-hover);
    border: 3px solid transparent;
    background-clip: padding-box;
}

/* Keyboard focus: one green ring on every control */
html[data-theme] a:focus-visible,
html[data-theme] button:focus-visible,
html[data-theme] [role="button"]:focus-visible,
html[data-theme] [tabindex]:focus-visible {
    outline: 2px solid var(--ui-ring);
    outline-offset: 2px;
}

html[data-theme] input:focus-visible,
html[data-theme] select:focus-visible,
html[data-theme] textarea:focus-visible {
    outline: 2px solid var(--ui-ring);
    outline-offset: 0;
}

/* Fields that already draw a Tailwind focus ring keep that single indicator */
html[data-theme] [class*="focus:ring-"]:focus-visible {
    outline: none;
}

/* White logos need a dark ink on light surfaces. Invert + hue-rotate turns the
   wordmark black and keeps the brand hue of the coloured marks. */
[data-theme="light"] .brand-logo {
    filter: invert(1) hue-rotate(180deg);
}

/* --------------------------------------------------------------------------
   App shell (home/index.html)
   -------------------------------------------------------------------------- */
.app-shell {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.app-sidebar {
    width: 248px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right-width: 1px;
    border-right-style: solid;
}

.sidebar-header {
    display: flex;
    align-items: center;
    height: 64px;
    padding: 0 20px;
    flex-shrink: 0;
}

.sidebar-nav {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 8px 12px 12px;
}

.nav-section-label {
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    height: 40px;
    padding: 0 12px;
    margin-bottom: 2px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    text-align: left;
    cursor: pointer;
    transition: background-color 120ms var(--ui-ease), color 120ms var(--ui-ease), transform 120ms var(--ui-ease);
}

.nav-item:active {
    transform: scale(0.98);
}

.nav-item i {
    width: 16px;
    flex-shrink: 0;
    font-size: 14px;
    text-align: center;
}

.nav-item-badge {
    margin-left: auto;
    min-width: 24px;
    padding: 3px 6px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1;
    text-align: center;
}

.sidebar-footer {
    flex-shrink: 0;
    padding: 12px;
    border-top-width: 1px;
    border-top-style: solid;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 12px 12px;
    min-width: 0;
}

.sidebar-user-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: 9999px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    text-transform: uppercase;
}

.sidebar-footer-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    height: 36px;
    padding: 0 12px;
    margin-bottom: 2px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    text-align: left;
    cursor: pointer;
    transition: background-color 120ms var(--ui-ease), color 120ms var(--ui-ease), border-color 120ms var(--ui-ease), transform 120ms var(--ui-ease);
}

.sidebar-footer-btn:last-child {
    margin-bottom: 0;
}

.sidebar-footer-btn:active {
    transform: scale(0.98);
}

.sidebar-footer-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sidebar-footer-btn i {
    width: 16px;
    flex-shrink: 0;
    font-size: 14px;
    text-align: center;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Top bar only exists where the sidebar is a drawer */
.app-topbar {
    display: none;
    align-items: center;
    gap: 12px;
    height: 56px;
    padding: 0 12px;
    flex-shrink: 0;
    border-bottom-width: 1px;
    border-bottom-style: solid;
}

.app-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: background-color 120ms var(--ui-ease), color 120ms var(--ui-ease), transform 120ms var(--ui-ease);
}

.app-icon-btn:active {
    transform: scale(0.96);
}

.app-backdrop {
    display: none;
}

.iframe-container {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
}

.iframe-container iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: none;
}

.loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    transition: opacity 200ms var(--ui-ease);
}

.loading-overlay.hidden {
    display: flex;
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 2.5px solid rgba(0, 204, 102, 0.2);
    border-top-color: var(--ui-accent);
    border-radius: 50%;
    animation: ui-spin 0.8s linear infinite;
}

.loading-text {
    font-size: 13px;
    font-weight: 500;
}

@keyframes ui-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 1023px) {
    .app-topbar {
        display: flex;
    }

    .app-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 40;
        width: min(280px, 84vw);
        transform: translateX(-100%);
        visibility: hidden;
        transition: transform 200ms cubic-bezier(0.4, 0, 1, 1), visibility 0s linear 200ms;
    }

    .app-sidebar.is-open {
        transform: translateX(0);
        visibility: visible;
        transition: transform 320ms var(--ui-ease-out), visibility 0s linear 0s;
    }

    .app-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 30;
        background: rgba(0, 0, 0, 0.5);
        -webkit-backdrop-filter: blur(2px);
        backdrop-filter: blur(2px);
        opacity: 0;
        pointer-events: none;
        transition: opacity 200ms var(--ui-ease);
    }

    .app-backdrop.is-open {
        opacity: 1;
        pointer-events: auto;
    }

    /* Finger-sized rows in the drawer */
    .nav-item,
    .sidebar-footer-btn {
        height: 44px;
    }
}

/* --------------------------------------------------------------------------
   Data list (brands, retailers, digital kits)
   Header and rows share one grid template so columns always line up.
   -------------------------------------------------------------------------- */
.dt-head,
.dt-row {
    display: grid;
    grid-template-columns: var(--dt-cols);
    column-gap: 16px;
    align-items: center;
    padding-left: 24px;
    padding-right: 24px;
}

.dt-head {
    padding-top: 10px;
    padding-bottom: 10px;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.dt-row {
    min-height: 48px;
    padding-top: 8px;
    padding-bottom: 8px;
    cursor: pointer;
}

.dt-cell {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dt-edit {
    padding: 16px 24px;
}

/* Row actions appear on hover, and on keyboard focus so they are reachable */
.dt-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    opacity: 0;
    cursor: pointer;
    transition: opacity 120ms var(--ui-ease), background-color 120ms var(--ui-ease), color 120ms var(--ui-ease);
}

.group:hover .dt-action,
.dt-action:focus-visible {
    opacity: 1;
}

/* Touch screens have no hover, so the action stays visible */
@media (hover: none) {
    .dt-action {
        opacity: 1;
    }
}

@media (max-width: 767px) {
    .dt-head {
        display: none;
    }

    /* Name, status and action on the first line; supporting details below */
    .dt-row {
        grid-template-columns: minmax(0, 1fr) auto auto;
        column-gap: 8px;
        row-gap: 2px;
        padding: 10px 12px 10px 16px;
    }

    .dt-row > .dt-cell--status {
        grid-column: 2;
        grid-row: 1;
    }

    .dt-row > .dt-cell--actions {
        grid-column: 3;
        grid-row: 1;
    }

    .dt-row > .dt-cell--meta {
        grid-column: 1 / -1;
        padding-left: 32px;
    }

    .dt-row > .dt-cell--empty,
    .dt-row .dt-sm-hide {
        display: none;
    }

    .dt-action {
        width: 36px;
        height: 36px;
        opacity: 1;
    }

    .dt-edit {
        padding: 16px;
    }
}

/* Native select with a quiet chevron and room for it */
select.ui-select {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 36px;
    background-image: var(--ui-select-chevron);
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    cursor: pointer;
}

/* Press feedback for plain buttons */
.ui-press {
    transition: background-color 120ms var(--ui-ease), color 120ms var(--ui-ease), border-color 120ms var(--ui-ease), transform 120ms var(--ui-ease);
}

.ui-press:active {
    transform: scale(0.98);
}

/* Skeleton: matches the shape of the rows that are loading */
.ui-skeleton {
    position: relative;
    overflow: hidden;
    border-radius: 6px;
    background: var(--ui-skeleton);
}

.ui-skeleton::after {
    content: '';
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, var(--ui-skeleton-shine), transparent);
    animation: ui-shimmer 1.6s linear infinite;
}

@keyframes ui-shimmer {
    to {
        transform: translateX(100%);
    }
}

/* Toasts: bottom right, out of the way of the header actions */
.ui-toast-region {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(360px, calc(100vw - 32px));
    pointer-events: none;
}

.ui-toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 12px 12px 16px;
    border-width: 1px;
    border-style: solid;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    pointer-events: auto;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.16);
    animation: ui-toast-in 320ms var(--ui-ease-out);
}

.ui-toast > i {
    margin-top: 3px;
    font-size: 14px;
}

@keyframes ui-toast-in {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@media (max-width: 639px) {
    .ui-toast-region {
        right: 12px;
        bottom: 12px;
        width: calc(100vw - 24px);
    }
}

/* --------------------------------------------------------------------------
   Motion preferences
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    html[data-theme] *,
    html[data-theme] *::before,
    html[data-theme] *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .ui-skeleton::after {
        display: none;
    }
}
