:root {
    color-scheme: light;
    --bg: #ecf2fb;
    --bg-elevated: rgba(255, 255, 255, 0.6);
    --surface: rgba(255, 255, 255, 0.56);
    --surface-hover: rgba(255, 255, 255, 0.72);
    --text: #0f172a;
    --text-muted: #475569;
    --title: #020617;
    --accent: #1570ef;
    --accent-soft: rgba(21, 112, 239, 0.16);
    --danger: #dc2626;
    --success: #0e9f6e;
    --warning: #d97706;
    --panel-border: rgba(255, 255, 255, 0.45);
    --line: rgba(15, 23, 42, 0.08);
    --shadow-sm: 0 6px 20px rgba(15, 23, 42, 0.08);
    --shadow-md: 0 14px 44px rgba(15, 23, 42, 0.14);
    --radius-xl: 30px;
    --radius-lg: 22px;
    --radius-md: 16px;
    --blur-lg: 30px;
    --blur-sm: 12px;
    --transition: 320ms cubic-bezier(0.2, 0.7, 0.25, 1);
}

:root.dark-theme {
    color-scheme: dark;
    --bg: #060a11;
    --bg-elevated: rgba(13, 19, 34, 0.55);
    --surface: rgba(10, 15, 26, 0.56);
    --surface-hover: rgba(20, 28, 45, 0.74);
    --text: #e2e8f0;
    --text-muted: #93a4bb;
    --title: #f8fafc;
    --accent: #5fb3ff;
    --accent-soft: rgba(95, 179, 255, 0.22);
    --danger: #fb7185;
    --success: #34d399;
    --warning: #fbbf24;
    --panel-border: rgba(255, 255, 255, 0.12);
    --line: rgba(148, 163, 184, 0.2);
    --shadow-sm: 0 12px 30px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 18px 55px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.55;
    color: var(--text);
    background: radial-gradient(circle at 20% 10%, rgba(177, 218, 255, 0.45), transparent 40%), var(--bg);
    min-height: 100vh;
    overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }

.container {
    width: min(1220px, calc(100% - 2rem));
    margin-inline: auto;
}

.background-blobs {
    position: fixed;
    inset: 0;
    z-index: -2;
    overflow: hidden;
}

.blob {
    position: absolute;
    border-radius: 999px;
    filter: blur(70px);
    opacity: 0.55;
    animation: float 16s ease-in-out infinite alternate;
}

.blob-1 {
    width: 34rem;
    height: 34rem;
    top: -9rem;
    left: -8rem;
    background: linear-gradient(150deg, rgba(99, 102, 241, 0.5), rgba(125, 211, 252, 0.42));
}

.blob-2 {
    width: 36rem;
    height: 36rem;
    right: -12rem;
    top: 22%;
    animation-delay: -5s;
    background: linear-gradient(160deg, rgba(125, 211, 252, 0.5), rgba(56, 189, 248, 0.4));
}

.blob-3 {
    width: 28rem;
    height: 28rem;
    left: 30%;
    bottom: -10rem;
    animation-delay: -9s;
    background: linear-gradient(120deg, rgba(196, 181, 253, 0.45), rgba(165, 180, 252, 0.3));
}

.dark-theme .blob-1,
.dark-theme .blob-2,
.dark-theme .blob-3 {
    opacity: 0.35;
}

.noise-layer {
    position: absolute;
    inset: 0;
    background-image: radial-gradient(rgba(255, 255, 255, 0.15) 0.6px, transparent 0.6px);
    background-size: 4px 4px;
    opacity: 0.2;
}

.glass-panel {
    background: linear-gradient(140deg, var(--surface), var(--bg-elevated));
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(var(--blur-sm));
    -webkit-backdrop-filter: blur(var(--blur-sm));
}

.site-header {
    padding: 1rem 0 1.5rem;
}

.top-nav-wrap {
    border-radius: var(--radius-xl);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.8rem 1rem;
    position: sticky;
    top: 0.75rem;
    z-index: 10;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.8rem;
}

.brand-mark {
    width: 2.4rem;
    height: 2.4rem;
    border-radius: 12px; /* Лёгкое скругление */
    display: block;
    object-fit: cover;
    object-position: center;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.2);
    background-color: rgba(15, 23, 42, 0.75); /* Ненавязчивый тёмный фон с прозрачностью */
    /* Плавный переход для смены темы */
    transition: background-color 0.3s ease;
}

.dark-theme .brand-mark {
    background-color: transparent;
    box-shadow: none; /* В тёмной теме тень тоже можно убрать или оставить по вкусу (она там и так не видна) */
}

.brand-copy strong { display: block; color: var(--title); font-size: 1rem; }
.brand-copy small { color: var(--text-muted); font-size: 0.75rem; }

.nav {
    display: flex;
    gap: 0.4rem;
    padding: 0.3rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.2);
}

.nav a {
    padding: 0.5rem 0.85rem;
    border-radius: 999px;
    font-size: 0.9rem;
    color: var(--text-muted);
    transition: background var(--transition), color var(--transition);
}

.nav a:hover,
.nav a:focus-visible {
    background: var(--accent-soft);
    color: var(--title);
    outline: none;
}

.nav a[aria-current="page"] {
    background: var(--accent-soft);
    color: var(--title);
}

.nav-actions { display: flex; gap: 0.55rem; align-items: center; }

.hero-section { padding-top: 1.1rem; }

.hero {
    border-radius: var(--radius-xl);
    padding: clamp(1.2rem, 4vw, 2.6rem);
}

.hero-kicker {
    display: inline-block;
    border-radius: 999px;
    color: var(--accent);
    background: var(--accent-soft);
    padding: 0.32rem 0.7rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    font-size: 0.8rem;
    margin-bottom: 0.8rem;
}

.hero h1 {
    color: var(--title);
    max-width: 20ch;
    font-size: clamp(1.6rem, 4vw, 3rem);
    line-height: 1.15;
}

.hero-description {
    margin-top: 1rem;
    max-width: 64ch;
    color: var(--text-muted);
}

.hero-actions {
    margin-top: 1.4rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
}

.btn {
    border: none;
    border-radius: 999px;
    padding: 0.67rem 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition), background var(--transition), color var(--transition);
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
    color: white;
    background: linear-gradient(140deg, #1c7df9, #47a5ff);
    box-shadow: 0 8px 20px rgba(28, 125, 249, 0.35);
}

.btn-ghost {
    color: var(--title);
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.24);
}

.theme-toggle-btn {
    border-radius: 999px;
    width: 2.35rem;
    height: 2.35rem;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.24);
    display: grid;
    place-items: center;
    cursor: pointer;
}

.icon-moon { display: none; }

.content-grid {
    display: grid;
    gap: 1.1rem;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
    margin: 1rem 0 1.3rem;
}

.left-col,
.right-col {
    display: grid;
    gap: 0.7rem;
    align-content: start;
}

.card {
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.2rem;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.7rem;
}

.card-header h2 {
    font-size: 1.02rem;
    color: var(--title);
}

.card-body { padding: 1.1rem 1.2rem 1.2rem; }

.badge {
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 0.78rem;
    border-radius: 999px;
    padding: 0.3rem 0.6rem;
    font-weight: 600;
    white-space: nowrap;
}

.table-container { overflow-x: auto; border-radius: var(--radius-md); }

.glass-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.glass-table td {
    padding: 0.8rem 0.9rem;
    border-bottom: 1px solid var(--line);
}

.glass-table tr:last-child td { border-bottom: none; }
.glass-table td:first-child { color: var(--title); font-weight: 500; width: 62%; }

.widget-card { position: sticky; top: 5.4rem; }

.widget-fallback { margin-top: 0.8rem; text-align: center; }
.widget-fallback a { color: var(--accent); font-weight: 600; }

.loading { color: var(--text-muted); font-style: italic; animation: pulse 1.3s infinite; }

.highlight-none { color: var(--success); font-weight: 600; }
.highlight-warn { color: var(--warning); font-weight: 600; }
.highlight-danger { color: var(--danger); font-weight: 600; }

.glow-green {
    color: var(--success);
    font-weight: 600;
    text-shadow: 0 0 8px rgba(14, 159, 110, 0.4), 0 0 16px rgba(14, 159, 110, 0.2);
}

.glow-yellow {
    color: var(--warning);
    font-weight: 600;
    text-shadow: 0 0 8px rgba(217, 119, 6, 0.4), 0 0 16px rgba(217, 119, 6, 0.2);
}

.glow-red {
    color: var(--danger);
    font-weight: 600;
    text-shadow: 0 0 8px rgba(220, 38, 38, 0.4), 0 0 16px rgba(220, 38, 38, 0.2);
}

.dark-theme .glow-green {
    text-shadow: 0 0 8px rgba(52, 211, 153, 0.4), 0 0 16px rgba(52, 211, 153, 0.2);
}

.dark-theme .glow-yellow {
    text-shadow: 0 0 8px rgba(251, 191, 36, 0.4), 0 0 16px rgba(251, 191, 36, 0.2);
}

.dark-theme .glow-red {
    text-shadow: 0 0 8px rgba(251, 113, 133, 0.4), 0 0 16px rgba(251, 113, 133, 0.2);
}

.glass-footer { padding: 0.4rem 0 1.5rem; }
.footer-inner {
    border-radius: var(--radius-lg);
    padding: 1rem 1.2rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.fade-in {
    opacity: 0;
    transform: translateY(12px);
    animation: fade-in 700ms forwards ease;
}
.delay-1 { animation-delay: 80ms; }
.delay-2 { animation-delay: 140ms; }
.delay-3 { animation-delay: 220ms; }
.delay-4 { animation-delay: 280ms; }

@keyframes fade-in { to { opacity: 1; transform: translateY(0);} }
@keyframes pulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
@keyframes float {
    from { transform: translateY(0) translateX(0) scale(1); }
    to { transform: translateY(-24px) translateX(16px) scale(1.04); }
}

@media (max-width: 980px) {
    .content-grid { grid-template-columns: 1fr; }
    .widget-card { position: static; }
    .top-nav-wrap { flex-wrap: wrap; }
}

@media (max-width: 720px) {
    .container { width: min(1220px, calc(100% - 1rem)); }
    .top-nav-wrap { border-radius: 22px; }
    .nav {
        order: 3;
        width: 100%;
        justify-content: flex-start;
        overflow-x: auto;
        white-space: nowrap;
        flex-wrap: nowrap;
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
    .nav::-webkit-scrollbar {
        display: none;
    }
    .nav a {
        font-size: 0.82rem;
        padding: 0.45rem 0.55rem;
        flex-shrink: 0;
    }
    .hero-actions .btn { flex: 1 1 auto; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* AI Chat page */
.aichat-page {
    margin-top: 1rem;
    margin-bottom: 1.3rem;
    display: grid;
    gap: 1rem;
}

.chat-shell {
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    min-height: min(72vh, 820px);
}

.chat-shell-header {
    gap: 1rem;
}

.chat-shell-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.chat-clear-btn {
    padding: 0.45rem 0.85rem;
}

.chat-instruction-btn {
    padding: 0.45rem 0.9rem;
}

.chat-history {
    padding: 1rem 1rem 0.6rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
}

.chat-empty {
    border: 1px dashed var(--line);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    text-align: center;
    padding: 1.2rem;
    background: rgba(255, 255, 255, 0.18);
}

.chat-empty small {
    display: block;
    margin-top: 0.35rem;
}

.chat-message-row {
    display: flex;
    align-items: flex-end;
    gap: 0.6rem;
    width: 100%;
}

.chat-message-row.is-user {
    justify-content: flex-end;
}

.chat-message-row.is-assistant {
    justify-content: flex-start;
}

.chat-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 999px;
    object-fit: cover;
    object-position: center;
    display: block;
    border: 1px solid var(--line);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.chat-bubble {
    width: fit-content;
    max-width: min(80%, 700px);
    min-width: min(14rem, 100%);
    border-radius: 20px;
    padding: 0.78rem 0.95rem;
    border: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
    animation: fade-in 240ms ease;
    overflow-wrap: anywhere;
}

.chat-bubble p {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.45;
}

.chat-bubble-user {
    background: linear-gradient(140deg, #1c7df9, #47a5ff);
    color: #fff;
    border: none;
}

.chat-bubble-assistant {
    background: linear-gradient(150deg, var(--surface-hover), var(--bg-elevated));
    color: var(--text);
}

.chat-bubble-label {
    display: block;
    font-size: 0.75rem;
    margin-bottom: 0.2rem;
    color: var(--text-muted);
}

.chat-status {
    min-height: 1.3rem;
    padding: 0 1rem 0.35rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.chat-status.chat-status-error {
    color: var(--danger);
}

.chat-input-wrap {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.7rem;
    padding: 0.3rem 1rem 1rem;
    border-top: 1px solid var(--line);
}

#chat-input {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.18);
    color: var(--text);
    width: 100%;
    resize: none;
    min-height: 48px;
    max-height: 220px;
    padding: 0.75rem 0.9rem;
    font: inherit;
    line-height: 1.45;
}

#chat-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.chat-send-btn:disabled,
.chat-clear-btn:disabled,
#chat-input:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

body.modal-open {
    overflow: hidden;
}

.instruction-modal {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.instruction-modal[hidden] {
    display: none;
}

.instruction-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.68);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.instruction-modal-window {
    position: relative;
    width: min(640px, 100%);
    border-radius: 24px;
    padding: clamp(1rem, 2.8vw, 1.5rem);
    max-height: min(86vh, 760px);
    overflow: hidden;
    display: grid;
    gap: 0.9rem;
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow-md);
}

.instruction-modal-window:focus {
    outline: 2px solid var(--accent-soft);
    outline-offset: 2px;
}

.instruction-modal-window h2 {
    color: var(--title);
    font-size: clamp(1.2rem, 2.6vw, 1.65rem);
}

.instruction-modal-content {
    color: var(--text);
    overflow-y: auto;
    padding-right: 0.3rem;
    max-height: min(56vh, 470px);
    display: grid;
    gap: 0.85rem;
}

.instruction-modal-content p {
    color: var(--text-muted);
}

.instruction-modal-content ul {
    margin-left: 1.2rem;
    display: grid;
    gap: 0.45rem;
}

.instruction-modal-warning {
    color: #ef4444 !important;
    border: 1px solid rgba(239, 68, 68, 0.35);
    background: rgba(239, 68, 68, 0.1);
    border-radius: 14px;
    padding: 0.72rem 0.78rem;
    font-weight: 600;
}

.instruction-modal-confirm {
    justify-self: end;
    min-width: 132px;
}

@media (max-width: 720px) {
    .chat-shell {
        min-height: 74vh;
    }

    .chat-shell-header {
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .chat-shell-actions {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .chat-history {
        padding: 0.9rem 0.7rem 0.55rem;
    }

    .chat-input-wrap {
        grid-template-columns: 1fr;
        gap: 0.55rem;
        padding: 0.3rem 0.7rem 0.8rem;
    }

    .chat-send-btn {
        width: 100%;
        min-height: 2.8rem;
    }

    #chat-input {
        min-height: 46px;
        padding: 0.72rem 0.82rem;
        font-size: 1rem;
    }

    .chat-bubble {
        max-width: calc(100% - 2.8rem);
        min-width: min(11.5rem, 100%);
        border-radius: 17px;
        padding: 0.7rem 0.82rem;
    }

    .chat-avatar {
        width: 32px;
        height: 32px;
        min-width: 32px;
    }

    .instruction-modal {
        padding: 0.75rem;
    }

    .instruction-modal-window {
        border-radius: 20px;
        max-height: 90vh;
    }

    .instruction-modal-content {
        max-height: 62vh;
    }

    .instruction-modal-confirm {
        width: 100%;
        justify-self: stretch;
    }
}

/* Slow Load Notification */
.slow-load-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    background: linear-gradient(140deg, var(--surface), var(--bg-elevated));
    border: 1px solid var(--warning);
    box-shadow: 0 8px 32px rgba(217, 119, 6, 0.25);
    backdrop-filter: blur(var(--blur-sm));
    -webkit-backdrop-filter: blur(var(--blur-sm));
    border-radius: var(--radius-md);
    padding: 18px 20px;
    width: 360px;
    max-width: calc(100vw - 32px);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 320ms cubic-bezier(0.2, 0.7, 0.25, 1), transform 320ms cubic-bezier(0.2, 0.7, 0.25, 1);
}

.slow-load-toast.show {
    opacity: 1;
    transform: translateY(0);
}

.slow-load-toast-content {
    flex: 1;
    color: var(--text);
}

.slow-load-toast-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    color: var(--warning);
}

.slow-load-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.slow-load-toast-header strong {
    font-size: 1rem;
    font-weight: 600;
}

.slow-load-toast-content p {
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: var(--text-muted);
}

.slow-load-toast-tips {
    margin: 0;
    padding-left: 20px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.slow-load-toast-tips li {
    margin-bottom: 4px;
}

.slow-load-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    margin: -4px -4px 0 0;
    transition: color 0.2s;
}

.slow-load-close-btn:hover {
    color: var(--text);
}

@media (max-width: 480px) {
    .slow-load-toast {
        bottom: env(safe-area-inset-bottom, 0);
        right: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 20px 20px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        padding: 20px 16px max(20px, env(safe-area-inset-bottom, 20px));
        transform: translateY(100%);
    }

    .slow-load-toast.show {
        transform: translateY(0);
    }

    .slow-load-toast-header strong {
        font-size: 1.1rem;
    }

    .slow-load-toast-content p {
        font-size: 1rem;
    }

    .slow-load-toast-tips {
        font-size: 0.95rem;
    }

    .slow-load-toast-tips li {
        margin-bottom: 8px;
    }

    .slow-load-close-btn {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: -10px -10px 0 0;
        font-size: 28px;
    }
}

/* Warnings styles */
.warning-item {
    padding: 15px;
    margin-bottom: 10px;
    border-radius: 12px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    transition: box-shadow 0.3s ease;
}

.warning-item:last-child {
    margin-bottom: 0;
}

.warning-date {
    font-weight: 600;
    margin-right: 5px;
}

.warning-high {
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.4);
    border-color: rgba(239, 68, 68, 0.3);
}

.dark-theme .warning-high {
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.6);
}

.warning-medium {
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.4);
    border-color: rgba(245, 158, 11, 0.3);
}

.dark-theme .warning-medium {
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.6);
}

.warning-low {
    box-shadow: 0 0 15px rgba(34, 197, 94, 0.4);
    border-color: rgba(34, 197, 94, 0.3);
}

.dark-theme .warning-low {
    box-shadow: 0 0 15px rgba(34, 197, 94, 0.6);
}
