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

:root {
    --font-sans:    'Segoe UI', -apple-system, BlinkMacSystemFont, 'Century Gothic', Roboto, Tahoma, Geneva, Verdana, sans-serif;
    --tracking:     0.14px;
    --radius-pill:  30px;
    --radius-card:  10px;
    --radius-ctl:   8px;
    --radius-sm:    6px;
}

[data-theme="dark"] {
    --bg-page:        #000000;
    --bg-panel:       #0d0d0d;
    --bg-bubble-ai:   #121214;
    --bg-bubble-user: #1b1213;
    --bg-input:       #0d0d0d;
    --bg-chip:        rgba(255, 255, 255, 0.05);
    --bg-hint:        rgba(255, 255, 255, 0.04);
    --bg-theme-btn:   #1a1a1d;
    --bg-zebra:       rgba(255, 255, 255, 0.03);

    --border:         rgba(255, 255, 255, 0.10);
    --border-input:   rgba(255, 255, 255, 0.18);
    --border-chip:    rgba(255, 255, 255, 0.14);
    --border-theme:   rgba(255, 255, 255, 0.18);

    --text-primary:   #ffffff;
    --text-secondary: #a1a1aa;
    --text-muted:     #6b6b70;
    --text-chip:      #e9e9ec;
    --text-theme:     #a1a1aa;

    --accent:         #ff1a1a;
    --accent-soft:    rgba(255, 26, 26, 0.12);
    --accent-btn:     #e00000;
    --accent-btn-h:   #ff1a1a;

    --danger:         #ff6b6b;
    --danger-soft:    rgba(255, 107, 107, 0.40);
    --danger-tint:    rgba(255, 107, 107, 0.12);
    --success:        #3fb950;
    --warning:        #d29922;
    --dot-green:      var(--success);

    --code-bg:        #0d0d0d;
    --code-border:    rgba(255, 255, 255, 0.12);
    --code-text:      #ff8a8a;

    --scrollbar:      rgba(255, 255, 255, 0.18);

    --theme-moon-display: inline;
    --theme-sun-display:  none;
}

[data-theme="light"] {
    --bg-page:        #ffffff;
    --bg-panel:       #f4f4f5;
    --bg-bubble-ai:   #f8f8f8;
    --bg-bubble-user: #fdf1f1;
    --bg-input:       #ffffff;
    --bg-chip:        #f4f4f5;
    --bg-hint:        #f8f8f8;
    --bg-theme-btn:   #f4f4f5;
    --bg-zebra:       rgba(0, 0, 0, 0.025);

    --border:         #e4e4e7;
    --border-input:   #d4d4d8;
    --border-chip:    #d4d4d8;
    --border-theme:   #d4d4d8;

    --text-primary:   #212529;
    --text-secondary: #666666;
    --text-muted:     #9a9aa0;
    --text-chip:      #212529;
    --text-theme:     #666666;

    --accent:         #ff0000;
    --accent-soft:    rgba(255, 0, 0, 0.07);
    --accent-btn:     #ff0000;
    --accent-btn-h:   #d60000;

    --danger:         #c62828;
    --danger-soft:    rgba(198, 40, 40, 0.35);
    --danger-tint:    rgba(198, 40, 40, 0.08);
    --success:        #1a7f37;
    --warning:        #b26a00;
    --dot-green:      #1a7f37;

    --code-bg:        #f8f8f8;
    --code-border:    #e4e4e7;
    --code-text:      #c62828;

    --scrollbar:      #d4d4d8;

    --theme-moon-display: none;
    --theme-sun-display:  inline;
}

body {
    font-family: var(--font-sans);
    letter-spacing: var(--tracking);

    line-height: 1.5;
    background: var(--bg-page);
    color: var(--text-primary);
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    overflow: hidden;
    -webkit-transition: background 0.25s, color 0.25s;
    transition: background 0.25s, color 0.25s;
}

input,
textarea,
select,
button { line-height: 1.5; }

input,
textarea { letter-spacing: normal; }

.layout {
    display: -webkit-flex;
    display: flex;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
}

.sidebar {
    width: 240px;
    min-width: 240px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
    padding: 24px 16px;
    -webkit-transition: background 0.25s, border-color 0.25s;
    transition: background 0.25s, border-color 0.25s;
}

.sidebar-logo {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.sidebar-logo .welcome-icon {
    margin-bottom: 0;
}

.logo-title {
    display: block;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.01em;
}

.logo-sub {
    display: block;
    font-size: 12px;
    color: var(--accent);
    margin-top: 2px;
}

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin-bottom: 20px;
    -webkit-transition: background 0.25s;
    transition: background 0.25s;
}

.theme-toggle {
    width: 100%;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    background: var(--bg-theme-btn);
    border: 1px solid var(--border-theme);
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    color: var(--text-theme);
    -webkit-transition: background 0.2s, border-color 0.2s, color 0.2s;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.theme-icon {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
}

.theme-icon--moon {
    display: var(--theme-moon-display);
}

.theme-icon--sun {
    display: var(--theme-sun-display);
}

.main {
    -webkit-flex: 1;
    flex: 1;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
    overflow: hidden;
}

.welcome-icon { margin-bottom: 20px; color: var(--accent); }

.sidebar-nav {
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 20px;
}

.nav-link {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-ctl);
    font-size: 13px;
    color: var(--text-secondary);
    text-decoration: none;
    -webkit-transition: background 0.2s, color 0.2s;
    transition: background 0.2s, color 0.2s;
}

.nav-link:hover {
    background: var(--bg-chip);
    color: var(--text-primary);
}

.nav-link.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 12px;
    display: -webkit-inline-flex;
    display: inline-flex;
    -webkit-align-items: center;
    align-items: center;
    gap: 5px;
}

.spinner {
    width: 12px;
    height: 12px;
    border: 2px solid var(--border-input);
    border-top-color: var(--accent);
    border-radius: 50%;
    -webkit-animation: spin 0.7s linear infinite;
    animation: spin 0.7s linear infinite;
}

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

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

.btn-primary {
    padding: 12px 28px;
    background: var(--accent-btn);
    color: #fff;
    border: none;
    border-radius: var(--radius-pill);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    -webkit-transition: background 0.2s;
    transition: background 0.2s;
    font-weight: 500;
}

.btn-primary:hover:not(:disabled) { background: var(--accent-btn-h); }

.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary.btn-sm {
    font-size: 12px;
    padding: 5px 10px;
}

.btn-ghost {
    padding: 11px 20px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-pill);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    -webkit-transition: border-color 0.2s, color 0.2s;
    transition: border-color 0.2s, color 0.2s;
}

.btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.btn-ghost:disabled { opacity: 0.45; cursor: not-allowed; }

a.btn-ghost { text-decoration: none !important; }

a.btn-ghost:visited { color: var(--text-secondary); }

.btn-ghost.btn-sm {
    font-size: 12px;
    padding: 5px 10px;
}

.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.modal.modal--wide {
    width: 1080px;
    max-width: 95vw;
    padding: 0;
    align-items: stretch;
    text-align: left;
    overflow: hidden;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.btn-danger {
    background: none;
    border: 1px solid var(--danger-soft);
    border-radius: var(--radius-pill);
    color: var(--danger);
    font-size: 13px;
    font-family: inherit;
    padding: 11px 20px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
}

.btn-danger:hover {
    background: var(--danger-tint);
    border-color: var(--danger);
}

.btn-danger.btn-sm {
    font-size: 12px;
    padding: 5px 10px;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.modal {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px 30px;
    max-width: 420px;
    width: 92%;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    text-align: center;
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-text {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    width: 100%;
    justify-content: center;
}

.app-view {
    -webkit-flex: 1;
    flex: 1;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 14px;
    font-size: 12.5px;
}

.stats-table th {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-muted);
    text-align: left;
    padding: 0 10px 6px 0;
    border-bottom: 1px solid var(--border);
}

.stats-table td {
    padding: 7px 10px 7px 0;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.stats-table tr:last-child td { border-bottom: none; }

::-webkit-scrollbar { width: 6px; height: 6px; }

::-webkit-scrollbar-track { background: transparent; }

::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }

::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

::-webkit-scrollbar-button { display: none; width: 0; height: 0; }

::-webkit-scrollbar-corner { background: transparent; }

* { scrollbar-width: thin; scrollbar-color: var(--scrollbar) transparent; }

::selection { background: var(--accent-soft); color: var(--text-primary); }

::-moz-selection { background: var(--accent-soft); color: var(--text-primary); }

button:focus-visible,
a:focus-visible,
select:focus-visible,
summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

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

}

.nav-toggle,
.sidebar-backdrop { display: none; }

@media (max-width: 860px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 60;
        width: 260px;
        min-width: 260px;
        overflow-y: auto;
        -webkit-transform: translateX(-100%);
        transform: translateX(-100%);
        -webkit-transition: -webkit-transform 0.2s, background 0.25s, border-color 0.25s;
        transition: transform 0.2s, background 0.25s, border-color 0.25s;
    }

    .layout.nav-open .sidebar {
        -webkit-transform: none;
        transform: none;
        box-shadow: 0 0 24px rgba(0, 0, 0, 0.25);
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 50;
        background: rgba(0, 0, 0, 0.4);
        opacity: 0;
        pointer-events: none;
        -webkit-transition: opacity 0.2s;
        transition: opacity 0.2s;
    }

    .layout.nav-open .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .nav-toggle {
        display: -webkit-flex;
        display: flex;
        -webkit-align-items: center;
        align-items: center;
        -webkit-justify-content: center;
        justify-content: center;
        position: fixed;
        top: 8px;
        left: 10px;
        z-index: 40;
        width: 34px;
        height: 34px;
        padding: 0;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--bg-panel);
        color: var(--text-secondary);
        cursor: pointer;
    }

    .nav-toggle:hover { color: var(--accent); border-color: var(--accent); }

}

@media (max-width: 860px) {
    .stats-table { display: block; overflow-x: auto; }

}

@supports not (gap: 1px) {
    .sidebar-logo > * + * { margin-left: 12px; }

    .sidebar-logo > svg:first-child { margin-right: 12px; }

    .sidebar-logo > svg:first-child + * { margin-left: 0; }

    .theme-toggle > * + * { margin-left: 8px; }

    .theme-toggle > svg:first-child { margin-right: 8px; }

    .theme-toggle > svg:first-child + * { margin-left: 0; }

    .sidebar-nav > * + * { margin-top: 4px; }

    .nav-link > * + * { margin-left: 10px; }

    .nav-link > svg:first-child { margin-right: 10px; }

    .nav-link > svg:first-child + * { margin-left: 0; }

    .btn-sm > * + * { margin-left: 5px; }

    .btn-sm > svg:first-child { margin-right: 5px; }

    .btn-sm > svg:first-child + * { margin-left: 0; }

    .btn-ghost > * + * { margin-left: 6px; }

    .btn-ghost > svg:first-child { margin-right: 6px; }

    .btn-ghost > svg:first-child + * { margin-left: 0; }

    .sidebar-footer > * + * { margin-left: 8px; }

    .sidebar-footer > svg:first-child { margin-right: 8px; }

    .sidebar-footer > svg:first-child + * { margin-left: 0; }

    .modal.modal--wide > * + * { margin-top: 0; }

    .btn-danger > * + * { margin-left: 6px; }

    .btn-danger > svg:first-child { margin-right: 6px; }

    .btn-danger > svg:first-child + * { margin-left: 0; }

    .modal > * + * { margin-top: 14px; }

    .modal-actions > * + * { margin-left: 10px; }

    .modal-actions > svg:first-child { margin-right: 10px; }

    .modal-actions > svg:first-child + * { margin-left: 0; }

}
