/*
 * Marketing Dashboard — supplemental styles.
 *
 * Base CSS is generated from theme.yaml and injected inline in base.html.
 * This file contains styles that are specific to the FastAPI/HTMX version.
 *
 * Loaded AFTER Tailwind CDN to ensure overrides take effect.
 */

/* =================================================================
   Font size — match NiceGUI's 18px desktop base (from theme.yaml)
   Tailwind CDN resets html to 16px, so we must re-apply.
   ================================================================= */

html {
    font-size: 16px;
}

@media (min-width: 640px) {
    html {
        font-size: 18px;
    }
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-variant-numeric: tabular-nums lining-nums;
    font-feature-settings: 'tnum' 1, 'lnum' 1, 'kern' 1;
    text-rendering: optimizeLegibility;
}

/* =================================================================
   HTMX loading indicator
   ================================================================= */

.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: inline-block;
}

/* Skeleton shimmer for lazy-loaded sections */
.skeleton-shimmer {
    background: linear-gradient(90deg, #eef0f5 25%, #dfe2e8 50%, #eef0f5 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: 6px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* =================================================================
   Alpine.js x-cloak (hide until Alpine initializes)
   ================================================================= */

[x-cloak] {
    display: none !important;
}

/* =================================================================
   Vertical grid lines for tables
   ================================================================= */

.md-table--vgrid th + th,
.md-table--vgrid td + td {
    border-left: 1px solid var(--md-sys-color-outline-variant);
}

/* =================================================================
   Login page
   ================================================================= */

.login-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f7f8fa;
    padding: 1.5rem;
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 3rem 2.5rem 2.5rem;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 1px 4px rgba(25, 30, 40, 0.06), 0 8px 32px rgba(25, 30, 40, 0.08);
}

.login-brand-mark {
    width: 56px;
    height: 56px;
    background: #2d4a8a;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-error {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 1.5rem;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    font-size: 0.875rem;
    color: #c06060;
    background: rgba(192, 96, 96, 0.06);
    border: 1px solid rgba(192, 96, 96, 0.15);
}

.login-input-group { position: relative; display: flex; align-items: center; }

.login-input {
    width: 100%;
    height: 56px;
    padding: 20px 48px 8px 16px;
    font-size: 0.9375rem;
    color: #2a2a35;
    background: #f7f8fa;
    border: 1.5px solid #dfe2e8;
    border-radius: 14px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    -webkit-appearance: none;
}
.login-input:hover { border-color: #c5c8d0; }
.login-input:focus { border-color: #5070b8; box-shadow: 0 0 0 3px rgba(80, 112, 184, 0.12); background: #fff; }

.login-label {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.9375rem;
    color: #8a8a96;
    pointer-events: none;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.login-input:focus + .login-label,
.login-input:not(:placeholder-shown) + .login-label {
    top: 14px; transform: translateY(0) scale(0.75); color: #5070b8; font-weight: 500;
}
.login-input:not(:focus):not(:placeholder-shown) + .login-label { color: #8a8a96; }

.login-eye-toggle {
    position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
    width: 40px; height: 40px; min-height: 40px !important; min-width: 40px !important;
    display: flex; align-items: center; justify-content: center;
    color: #8a8a96; background: transparent; border: none; border-radius: 10px; cursor: pointer;
}
.login-eye-toggle:hover { color: #5c5c6a; background: rgba(0, 0, 0, 0.04); }

.login-submit {
    width: 100%;
    height: 52px;
    min-height: 52px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9375rem;
    font-weight: 600;
    color: #ffffff;
    background: #2d4a8a;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.login-submit:hover:not(:disabled) { background: #243d73; }
.login-submit:active:not(:disabled) { transform: scale(0.98) !important; }
.login-submit:disabled { opacity: 0.7; cursor: not-allowed; }

.login-footer { margin-top: 2rem; font-size: 0.75rem; color: #8a8a96; letter-spacing: 0.04em; }

@media (max-width: 480px) {
    .login-card { padding: 2.5rem 1.75rem 2rem; border-radius: 16px; max-width: 100%; }
}

/* =================================================================
   Period pills — compact, touch-friendly
   ================================================================= */

.period-pill {
    padding: 6px 16px;
    border-radius: 9999px;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: all 0.15s ease;
    cursor: pointer;
    border: 1px solid transparent;
    white-space: nowrap;
}

.period-pill:hover {
    background-color: rgba(45, 74, 138, 0.04);
}

.period-pill.active {
    background-color: #475569;
    color: #f8fafc;
    border-color: #475569;
}

.period-pill.inactive {
    background-color: transparent;
    color: #64748b;
    border-color: #cbd5e1;
}

.period-pill.inactive:hover {
    background-color: #f1f5f9;
    color: #1e293b;
}

/* =================================================================
   NLG prose — markdown rendered content
   ================================================================= */

.nlg-prose h1 {
    font-size: 0.9375rem;
    font-weight: 700;
    margin: 0 0 0.25rem;
}

.nlg-prose h2 {
    font-size: 0.875rem;
    font-weight: 600;
    margin: 0.75rem 0 0.25rem;
}

.nlg-prose p {
    margin: 0.25rem 0;
}

.nlg-prose strong {
    font-weight: 600;
}

/* =================================================================
   Tabular numbers for all metric displays
   ================================================================= */

.metric-num {
    font-variant-numeric: tabular-nums lining-nums;
    letter-spacing: -0.01em;
}

/* =================================================================
   MD3 Typography — type scale
   18px desktop base, proportional sizing.
   ================================================================= */

.md-display-small {
    font-size: 2rem;
    line-height: 2.5rem;
    font-weight: 400;
    letter-spacing: 0;
}

.md-headline-small {
    font-size: 1.5rem;
    line-height: 2rem;
    font-weight: 400;
    letter-spacing: 0;
}

.md-title-large {
    font-size: 1.375rem;
    line-height: 1.75rem;
    font-weight: 400;
    letter-spacing: 0;
}

.md-title-medium {
    font-size: 1rem;
    line-height: 1.5rem;
    font-weight: 500;
    letter-spacing: 0.009em;
}

.md-body-large {
    font-size: 1rem;
    line-height: 1.5rem;
    font-weight: 400;
    letter-spacing: 0.009em;
}

.md-body-medium {
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 400;
    letter-spacing: 0.016em;
}

.md-label-large {
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 500;
    letter-spacing: 0.006em;
}

.md-label-medium {
    font-size: 0.75rem;
    line-height: 1rem;
    font-weight: 500;
    letter-spacing: 0.03em;
}

/* =================================================================
   MD3 Component classes
   ================================================================= */

/* --- Buttons ---------------------------------------------------- */

.md-btn-filled {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    min-width: 48px;
    padding: 0 24px;
    border: none;
    border-radius: var(--md-sys-shape-corner-full, 9999px);
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.006em;
    cursor: pointer;
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    transition: box-shadow 0.2s ease, background-color 0.2s ease;
    position: relative;
    overflow: hidden;
}

.md-btn-filled::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: currentColor;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.md-btn-filled:hover::before { opacity: 0.08; }
.md-btn-filled:focus-visible::before { opacity: 0.10; }
.md-btn-filled:active::before { opacity: 0.12; }
.md-btn-filled:hover { box-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 1px 3px 1px rgba(0,0,0,0.15); }

.md-btn-tonal {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    min-width: 48px;
    padding: 0 24px;
    border: none;
    border-radius: var(--md-sys-shape-corner-full, 9999px);
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.006em;
    cursor: pointer;
    background: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
    transition: box-shadow 0.2s ease;
    position: relative;
    overflow: hidden;
}

.md-btn-tonal::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: currentColor;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.md-btn-tonal:hover::before { opacity: 0.08; }
.md-btn-tonal:focus-visible::before { opacity: 0.10; }
.md-btn-tonal:active::before { opacity: 0.12; }
.md-btn-tonal:hover { box-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 1px 3px 1px rgba(0,0,0,0.15); }

.md-btn-outlined {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    min-width: 48px;
    padding: 0 24px;
    background: transparent;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: var(--md-sys-shape-corner-full, 9999px);
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.006em;
    cursor: pointer;
    color: var(--md-sys-color-primary);
    transition: background-color 0.15s ease;
    position: relative;
    overflow: hidden;
}

.md-btn-outlined::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: currentColor;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.md-btn-outlined:hover::before { opacity: 0.08; }
.md-btn-outlined:focus-visible::before { opacity: 0.10; }
.md-btn-outlined:active::before { opacity: 0.12; }

.md-btn-text {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    min-width: 48px;
    padding: 0 12px;
    background: transparent;
    border: none;
    border-radius: var(--md-sys-shape-corner-full, 9999px);
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.006em;
    cursor: pointer;
    color: var(--md-sys-color-primary);
    position: relative;
    overflow: hidden;
}

.md-btn-text::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: currentColor;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.md-btn-text:hover::before { opacity: 0.08; }
.md-btn-text:focus-visible::before { opacity: 0.10; }
.md-btn-text:active::before { opacity: 0.12; }

/* --- Card ------------------------------------------------------- */

.md-card {
    background: var(--md-sys-color-surface-container-low, #f3f4f8);
    border-radius: var(--md-sys-shape-corner-medium, 12px);
    position: relative;
    overflow: hidden;
}

.md-card-elevated {
    background: var(--md-sys-color-surface-container-low, #f3f4f8);
    border-radius: var(--md-sys-shape-corner-medium, 12px);
    box-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 1px 3px 1px rgba(0,0,0,0.15);
    position: relative;
    overflow: hidden;
}

.md-card-filled {
    background: var(--md-sys-color-surface-container-highest, #e1e3e9);
    border-radius: var(--md-sys-shape-corner-medium, 12px);
    position: relative;
    overflow: hidden;
}

.md-card-outlined {
    background: var(--md-sys-color-surface, #fafbfc);
    border: 1px solid var(--md-sys-color-outline-variant, #c4c6d0);
    border-radius: var(--md-sys-shape-corner-medium, 12px);
    position: relative;
    overflow: hidden;
}

/* --- Chip ------------------------------------------------------- */

.md-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 32px;
    padding: 0 12px;
    border-radius: var(--md-sys-shape-corner-small, 8px);
    font-size: 0.8125rem;
    font-weight: 500;
    border: 1px solid var(--md-sys-color-outline);
    background: transparent;
    color: var(--md-sys-color-on-surface-variant);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.md-chip.selected {
    background: var(--md-sys-color-secondary-container);
    border-color: transparent;
    color: var(--md-sys-color-on-secondary-container);
}

/* --- Nav item (full-radius pill for navigation) ----------------- */

.md-nav-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 16px;
    border-radius: var(--md-sys-shape-corner-full, 9999px);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    white-space: nowrap;
    transition: background-color 0.15s ease, color 0.15s ease;
    position: relative;
    overflow: hidden;
    text-decoration: none;
}

.md-nav-item::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: currentColor;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.md-nav-item:hover::before { opacity: 0.08; }

.md-nav-item.active {
    background: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}

.md-nav-item:not(.active) {
    background: transparent;
    color: var(--md-sys-color-on-surface-variant);
}

/* --- State layer (hover overlay per MD3 spec) ------------------ */

.md-state-hover {
    position: relative;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.md-state-hover::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: var(--md-sys-color-on-surface, #1c1b1f);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.md-state-hover:hover::after {
    opacity: 0.08;
}

/* --- Shape utilities ------------------------------------------- */

.rounded-md-sm {
    border-radius: var(--md-sys-shape-corner-small, 8px);
}

.rounded-md-md {
    border-radius: var(--md-sys-shape-corner-medium, 12px);
}

/* --- Material Symbols icon sizing ------------------------------- */

.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    vertical-align: middle;
}

/* =================================================================
   MD3 Navigation Drawer (Sidebar)
   ================================================================= */

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    height: 56px;
    border-radius: var(--md-sys-shape-corner-full, 9999px);
    color: var(--md-sys-color-on-surface-variant);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.006em;
    position: relative;
    overflow: hidden;
    transition: background-color 0.15s ease, color 0.15s ease;
    cursor: pointer;
    white-space: nowrap;
}

.sidebar-item::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: currentColor;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.sidebar-item:hover::before {
    opacity: 0.08;
}

.sidebar-item.active {
    background: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}

.sidebar-item.active .material-symbols-outlined {
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* Sidebar group overline */
.sidebar-group-label {
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--md-sys-color-on-surface-variant);
    padding: 16px 16px 4px;
}

/* Sidebar scrollbar */
.sidebar-scroll {
    scrollbar-width: thin;
    scrollbar-color: var(--md-sys-color-outline-variant) transparent;
}

.sidebar-scroll::-webkit-scrollbar {
    width: 4px;
}

.sidebar-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-scroll::-webkit-scrollbar-thumb {
    background: var(--md-sys-color-outline-variant);
    border-radius: 2px;
}

/* =================================================================
   MD3 Switch toggle
   ================================================================= */

.md-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 52px;
    height: 32px;
    cursor: pointer;
}

.md-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.md-switch-track {
    position: absolute;
    inset: 0;
    border-radius: 16px;
    background: var(--md-sys-color-surface-container-highest);
    border: 2px solid var(--md-sys-color-outline);
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.md-switch-thumb {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--md-sys-color-outline);
    transition: transform 0.2s ease, background-color 0.2s ease, width 0.15s ease, height 0.15s ease, top 0.15s ease, left 0.15s ease;
}

.md-switch input:checked ~ .md-switch-track {
    background: var(--md-sys-color-primary);
    border-color: var(--md-sys-color-primary);
}

.md-switch input:checked ~ .md-switch-thumb {
    transform: translateX(20px);
    background: var(--md-sys-color-on-primary);
}

.md-switch:hover .md-switch-thumb {
    width: 22px;
    height: 22px;
    top: 5px;
    left: 5px;
}

.md-switch input:checked:hover ~ .md-switch-thumb {
    width: 22px;
    height: 22px;
    top: 5px;
    left: 5px;
}

/* =================================================================
   MD3 Outlined text field
   ================================================================= */

.md-text-field {
    position: relative;
    display: flex;
    align-items: center;
    height: 56px;
    padding: 0 16px;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: var(--md-sys-shape-corner-extra-small, 4px);
    background: transparent;
    transition: border-color 0.15s ease;
    font-size: 0.875rem;
    color: var(--md-sys-color-on-surface);
}

.md-text-field:focus-within {
    border-color: var(--md-sys-color-primary);
    border-width: 2px;
    padding: 0 15px;
}

.md-text-field input,
.md-text-field select {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-size: inherit;
    color: inherit;
}

.md-text-field-label {
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 4px;
}

/* =================================================================
   MD3 Linear progress indicator
   ================================================================= */

.md-progress-track {
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--md-sys-color-surface-container-highest);
    overflow: hidden;
}

.md-progress-indicator {
    height: 100%;
    border-radius: 2px;
    transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

/* =================================================================
   MD3 Expansion panel (details/summary)
   ================================================================= */

details.md-expansion-panel {
    border-radius: var(--md-sys-shape-corner-medium, 12px);
    overflow: hidden;
}

details.md-expansion-panel > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    cursor: pointer;
    list-style: none;
    user-select: none;
    position: relative;
    transition: background-color 0.15s ease;
}

details.md-expansion-panel > summary::-webkit-details-marker {
    display: none;
}

details.md-expansion-panel > summary:hover {
    background: rgba(0, 0, 0, 0.04);
}

details.md-expansion-panel > summary .md-expand-icon {
    transition: transform 0.2s ease;
    color: var(--md-sys-color-on-surface-variant);
}

details.md-expansion-panel[open] > summary .md-expand-icon {
    transform: rotate(180deg);
}

details.md-expansion-panel > .md-expansion-content {
    padding: 0 24px 16px;
    border-top: 1px solid var(--md-sys-color-outline-variant);
}

/* Print: hide sidebar */
@media print {
    #sidebar, .sidebar-mobile-toggle { display: none !important; }
    .sidebar-offset { margin-left: 0 !important; }
}
