/* Magic UI-inspired effects — layered on design-system tokens */

:root {
    --magic-glow: radial-gradient(ellipse 60% 50% at 50% -20%, rgba(59, 130, 246, 0.18), transparent 70%);
    --magic-grid: linear-gradient(rgba(148, 163, 184, 0.06) 1px, transparent 1px),
                  linear-gradient(90deg, rgba(148, 163, 184, 0.06) 1px, transparent 1px);
}

/* ---- Animated app background ---- */
.app-layout {
    position: relative;
    background: var(--bg);
}

.app-layout::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(ellipse 50% 40% at 15% 10%, rgba(59, 130, 246, 0.12), transparent 55%),
        radial-gradient(ellipse 40% 35% at 90% 80%, rgba(56, 189, 248, 0.06), transparent 50%),
        var(--bg);
}

/* Do NOT set position on all children — that overrides .sidebar { position: fixed }
   and doubles the left offset (flex width + margin-left). */
.app-layout > .main-content {
    position: relative;
    z-index: 1;
    background: transparent;
}

.app-layout > .sidebar {
    z-index: 100;
}

.app-layout > .sidebar-overlay {
    z-index: 99;
}

.page-content {
    position: relative;
}

.page-content::before {
    content: '';
    position: absolute;
    inset: -1rem -1rem auto -1rem;
    height: 280px;
    background: var(--magic-grid);
    background-size: 48px 48px;
    mask-image: linear-gradient(180deg, rgba(0,0,0,0.35), transparent);
    -webkit-mask-image: linear-gradient(180deg, rgba(0,0,0,0.35), transparent);
    pointer-events: none;
    z-index: 0;
    opacity: 0.5;
}

.page-content > * {
    position: relative;
    z-index: 1;
}

/* ---- Animated gradient text ---- */
.gradient-text,
.landing-hero h1 span,
.auth-panel-hero h2,
.auth-card-header h1 {
    background: var(--gradient-text);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    background-size: 200% auto;
    animation: gradientShift 8s ease infinite;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

/* ---- Shimmer buttons ---- */
.btn-primary,
.btn-shimmer {
    position: relative;
    overflow: hidden;
    background: var(--gradient-primary);
    border: none;
    box-shadow: 0 2px 12px rgba(59, 130, 246, 0.35);
}

.btn-primary::after,
.btn-shimmer::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        105deg,
        transparent 40%,
        rgba(255, 255, 255, 0.22) 50%,
        transparent 60%
    );
    background-size: 200% 100%;
    animation: btnShimmer 3s ease-in-out infinite;
    pointer-events: none;
}

.btn-primary:hover,
.btn-shimmer:hover {
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.45);
    transform: translateY(-1px);
}

@keyframes btnShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.btn.is-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn.is-loading::before {
    content: '';
    position: absolute;
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    left: 50%;
    top: 50%;
    margin: -0.5rem 0 0 -0.5rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---- Border beam cards ---- */
.border-beam,
.magic-card,
.stat-card.magic-card {
    position: relative;
    isolation: isolate;
}

.border-beam::before,
.magic-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    background: linear-gradient(
        var(--beam-angle, 0deg),
        transparent 30%,
        rgba(59, 130, 246, 0.55) 50%,
        transparent 70%
    );
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    z-index: 2;
    animation: borderBeam 4s linear infinite;
    opacity: 0.7;
}

@keyframes borderBeam {
    to { --beam-angle: 360deg; }
}

@property --beam-angle {
    syntax: '<angle>';
    initial-value: 0deg;
    inherits: false;
}

/* ---- Magic cards (hover lift + glow) ---- */
.magic-card,
.stat-card,
.card.magic-card {
    transition:
        transform 0.35s cubic-bezier(0.22, 1, 0.36, 1),
        box-shadow 0.35s ease,
        border-color 0.35s ease;
    will-change: transform;
}

.magic-card:hover,
.stat-card:hover {
    transform: translateY(-4px) scale(1.01);
    box-shadow: var(--shadow-lg), var(--glow-primary);
    border-color: rgba(59, 130, 246, 0.3);
}

.magic-card.is-tilting {
    transition: none;
}

/* ---- Soft glow ---- */
.glow-orb {
    position: absolute;
    width: 320px;
    height: 320px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.25) 0%, transparent 70%);
    filter: blur(40px);
    pointer-events: none;
    z-index: 0;
}

/* ---- Blur fade entrance ---- */
.blur-fade {
    opacity: 0;
    filter: blur(8px);
    transform: translateY(16px);
    transition:
        opacity 0.6s cubic-bezier(0.22, 1, 0.36, 1),
        filter 0.6s cubic-bezier(0.22, 1, 0.36, 1),
        transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.blur-fade.is-visible {
    opacity: 1;
    filter: blur(0);
    transform: none;
}

/* ---- Particles canvas ---- */
.particles-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

/* ---- Topbar chrome ---- */
.topbar {
    background: rgba(15, 22, 40, 0.82) !important;
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
    border-bottom: 1px solid var(--border) !important;
}

.topbar h1 {
    color: var(--foreground);
}

/* ---- Sidebar refinements ---- */
.sidebar {
    background: linear-gradient(180deg, #080d18 0%, #0a1020 100%);
    box-shadow: 4px 0 32px rgba(0, 0, 0, 0.3);
}

.nav-link.active {
    background: rgba(59, 130, 246, 0.16) !important;
    color: #fff !important;
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.25);
}

.emp-layout .nav-link.active {
    background: rgba(20, 184, 166, 0.16) !important;
    box-shadow: inset 0 0 0 1px rgba(20, 184, 166, 0.25);
}

.nav-link.active::before {
    background: var(--primary) !important;
    box-shadow: 0 0 8px var(--primary);
}

/* ---- Topbar actions / dropdowns ---- */
.topbar-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    text-decoration: none;
    padding: 0;
}

.topbar-icon-btn:hover {
    color: var(--text);
    border-color: rgba(59, 130, 246, 0.35);
    background: var(--surface-hover);
    box-shadow: var(--glow-primary);
}

.topbar-icon-btn .notif-dot {
    position: absolute;
    top: 7px;
    right: 7px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--danger);
    box-shadow: 0 0 0 2px var(--surface);
    display: none;
}

.topbar-icon-btn .notif-dot.is-visible {
    display: block;
}

.topbar-icon-btn .notif-count {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    box-shadow: 0 0 0 2px var(--surface);
}

.topbar-icon-btn .notif-count[hidden] {
    display: none !important;
}

.notif-dropdown-menu {
    min-width: 320px;
    max-width: min(380px, calc(100vw - 1.5rem));
    padding: 0.35rem;
}

.notif-dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem 0.35rem;
}

.notif-mark-all {
    border: 0;
    background: transparent;
    color: var(--primary);
    font: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
}

.notif-mark-all:hover {
    text-decoration: underline;
}

.notif-list {
    max-height: 360px;
    overflow-y: auto;
}

.notif-empty {
    padding: 1.25rem 0.85rem;
    text-align: center;
}

.notif-item {
    display: block !important;
    padding: 0.7rem 0.75rem !important;
    border-radius: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    border-left: 2px solid transparent;
}

.notif-item:hover {
    background: var(--primary-subtle);
    color: var(--text);
}

.notif-item.is-unread {
    background: rgba(59, 130, 246, 0.08);
    border-left-color: var(--primary);
}

.notif-item-title {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.35;
}

.notif-item-body {
    margin-top: 0.2rem;
    font-size: 0.76rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.notif-item-meta {
    margin-top: 0.35rem;
    font-size: 0.68rem;
    color: var(--muted);
}

.topbar-dropdown {
    position: relative;
}

.topbar-dropdown-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 0.5rem);
    min-width: 240px;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 0.4rem;
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    transition: all 0.2s ease;
    z-index: 80;
}

.topbar-dropdown.is-open .topbar-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: none;
}

.topbar-dropdown-menu a,
.topbar-dropdown-menu .dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
}

.topbar-dropdown-menu a:hover {
    background: var(--primary-subtle);
    color: var(--text);
}

.topbar-dropdown-menu .dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 0.35rem 0;
}

.topbar-dropdown-menu .dropdown-label {
    padding: 0.4rem 0.75rem 0.25rem;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.topbar-user-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem 0.25rem 0.25rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all var(--transition);
}

.topbar-user-btn:hover {
    border-color: rgba(59, 130, 246, 0.35);
    box-shadow: var(--glow-primary);
}

.topbar-user-btn .avatar,
.topbar-user-btn img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
}

.topbar-user-name {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Chart containers ---- */
.chart-wrap {
    position: relative;
    height: 260px;
    width: 100%;
}

.chart-wrap canvas {
    max-width: 100%;
}

/* ---- Form focus glow ---- */
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus,
.filters-bar input:focus,
.filters-bar select:focus {
    border-color: var(--primary) !important;
    box-shadow: var(--focus-ring), 0 0 20px rgba(59, 130, 246, 0.15) !important;
    background: var(--surface-raised) !important;
}

/* ---- Empty states ---- */
.empty-state {
    color: var(--text-secondary);
}

.empty-icon {
    color: var(--muted);
    opacity: 0.6;
}

/* ---- Integration status ---- */
.integration-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.status-dot.offline {
    background: var(--danger);
    box-shadow: 0 0 8px var(--danger);
}

/* ---- Editor canvas stays light ---- */
.article-editor-fullpage .ql-container,
.article-editor-fullpage .ql-editor,
.office-doc-canvas,
.luckysheet-container,
.word-editor-surface {
    background: #ffffff !important;
    color: #1e293b !important;
}

@media (prefers-reduced-motion: reduce) {
    .gradient-text,
    .landing-hero h1 span,
    .auth-panel-hero h2,
    .auth-card-header h1,
    .btn-primary::after,
    .btn-shimmer::after,
    .border-beam::before,
    .magic-card::before {
        animation: none !important;
    }

    .magic-card:hover,
    .stat-card:hover {
        transform: none;
    }

    .blur-fade {
        opacity: 1;
        filter: none;
        transform: none;
    }
}
