:root {
    --bg: #090d14;
    --surface: rgba(23, 31, 44, 0.56);
    --surface2: rgba(38, 43, 92, 0.45);
    --border: rgba(196, 214, 255, 0.2);
    --text: #e2e4eb;
    --text-muted: #9aa7c5;
    --accent: #fab900;
    --accent-dim: rgba(250, 185, 0, 0.16);
    --green: #34d399;
    --green-dim: rgba(52, 211, 153, 0.15);
    --red: #f87171;
    --red-dim: rgba(248, 113, 113, 0.15);
    --yellow: #fbbf24;
    --yellow-dim: rgba(251, 191, 36, 0.15);
    --blue: #262b5c;
    --orange: #fb923c;
    --radius: 8px;
    --btn-text: #ffffff;
    --btn-green-text: #0b1320;
    --shadow-strong: 0 18px 35px rgba(4, 8, 15, 0.4);
    --glass-bg: rgba(20, 30, 46, 0.44);
    --glass-bg-strong: rgba(18, 28, 43, 0.62);
    --glass-border: rgba(214, 230, 255, 0.25);
    --glass-shadow: 0 16px 30px rgba(4, 8, 15, 0.36);
    --glass-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.3);
    --glass-hover: rgba(255, 255, 255, 0.1);
    --overlay-bg: rgba(6, 10, 18, 0.62);
    --shadow-dark: rgba(0, 0, 0, 0.5);
    --shadow-light: rgba(255, 255, 255, 0.08);
    --blur: 18px;
    --calendar-icon-filter: invert(1);
    --card-bg: var(--surface);
    --text-primary: var(--text);
    --header-control-height: 38px;
}

html[data-theme="light"] {
    --bg: #dde6f5;
    --surface: rgba(255, 255, 255, 0.58);
    --surface2: rgba(38, 43, 92, 0.2);
    --border: rgba(158, 177, 211, 0.34);
    --text: #1f2a3b;
    --text-muted: #586880;
    --accent: #fab900;
    --accent-dim: rgba(250, 185, 0, 0.16);
    --green: #149a67;
    --green-dim: rgba(20, 154, 103, 0.14);
    --red: #d24b4b;
    --red-dim: rgba(210, 75, 75, 0.12);
    --yellow: #c08a08;
    --yellow-dim: rgba(192, 138, 8, 0.14);
    --blue: #262b5c;
    --orange: #d97706;
    --btn-text: #ffffff;
    --btn-green-text: #ffffff;
    --shadow-strong: 0 15px 28px rgba(37, 57, 92, 0.18);
    --glass-bg: rgba(255, 255, 255, 0.54);
    --glass-bg-strong: rgba(255, 255, 255, 0.72);
    --glass-border: rgba(133, 155, 194, 0.35);
    --glass-shadow: 0 14px 26px rgba(36, 57, 97, 0.16);
    --glass-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.8);
    --glass-hover: rgba(255, 255, 255, 0.32);
    --overlay-bg: rgba(11, 18, 33, 0.42);
    --blur: 16px;
    --calendar-icon-filter: none;
    --shadow-dark: rgba(37, 57, 92, 0.25);
    --shadow-light: rgba(255, 255, 255, 0.9);
}

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

body {
    font-family: "Segoe UI", system-ui, sans-serif;
    background-color: var(--bg);
    background-image:
        radial-gradient(
            1200px 700px at -15% -20%,
            rgba(110, 172, 255, 0.28),
            transparent 60%
        ),
        radial-gradient(
            1000px 520px at 120% -5%,
            rgba(88, 226, 203, 0.24),
            transparent 62%
        ),
        radial-gradient(
            900px 700px at 55% 120%,
            rgba(120, 152, 220, 0.18),
            transparent 70%
        );
    background-attachment: fixed;
    color: var(--text);
    min-height: 100vh;
    padding: 24px;
    line-height: 1.5;
}

/* ==================== TOPBAR ==================== */

.header {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 12px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--glass-shadow), var(--glass-highlight);
    backdrop-filter: blur(var(--blur)) saturate(150%);
    -webkit-backdrop-filter: blur(var(--blur)) saturate(150%);
    padding: 0;
    overflow: hidden;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 8px 16px;
}

.header-left > * {
    height: 38px;
    display: inline-flex;
    align-items: center;
}

.header-logo {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 10px;
    flex-shrink: 0;
    border: 1px solid var(--glass-border);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 8px 12px;
}

.header-actions > * {
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.header h1 {
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: -0.3px;
    white-space: nowrap;
    color: var(--text);
    height: 38px;
    display: flex;
    align-items: center;
}

.header h1 span {
    color: inherit;
    display: flex;
    align-items: center;
    gap: 10px;
}

.header h1 span::before {
    content: "";
    display: block;
    width: 2px;
    height: 28px;
    background: linear-gradient(to bottom, var(--accent), transparent);
    border-radius: 2px;
}

/* ==================== SWITCH ==================== */

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: var(--surface2);
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
    transition: all 0.25s ease;
}

.switch-slider::before {
    position: absolute;
    content: "";
    width: 18px;
    height: 18px;
    left: 2px;
    bottom: 2px;
    border-radius: calc(var(--radius) - 2px);
    background: var(--text-muted);
    transition: all 0.25s ease;
}

.switch input:checked + .switch-slider {
    background: var(--accent);
    border-color: var(--accent);
}

.switch input:checked + .switch-slider::before {
    transform: translateX(20px);
    background: #fff;
}

/* ==================== THEME TOGGLE ==================== */

.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: var(--header-control-height);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 4px 12px 4px 14px;
    box-shadow: var(--glass-highlight);
    backdrop-filter: blur(calc(var(--blur) * 0.5)) saturate(150%);
    -webkit-backdrop-filter: blur(calc(var(--blur) * 0.5)) saturate(150%);
    transition: all 0.2s ease;
}

.theme-toggle-label {
    font-weight: 600;
    color: var(--text);
    min-width: 36px;
    text-align: center;
    font-size: 0.72rem;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.theme-toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
}

.theme-toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.theme-toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--surface2);
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
    transition: all 0.25s ease;
}

.theme-toggle-slider::before {
    position: absolute;
    content: "";
    width: 18px;
    height: 18px;
    left: 2px;
    bottom: 2px;
    border-radius: calc(var(--radius) - 2px);
    background: var(--text-muted);
    transition: all 0.25s ease;
}

.theme-toggle-switch input:checked + .theme-toggle-slider {
    background: var(--accent);
    border-color: var(--accent);
}

.theme-toggle-switch input:checked + .theme-toggle-slider::before {
    transform: translateX(20px);
    background: #fff;
}

.theme-toggle:hover {
    border-color: var(--accent);
    box-shadow: 0 0 10px var(--accent-dim);
}

/* ==================== BUTTONS ==================== */

.btn {
    background: var(--accent);
    color: var(--btn-text);
    border: none;
    height: var(--header-control-height);
    min-height: var(--header-control-height);
    padding: 0 16px;
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

.btn:hover {
    background: color-mix(in srgb, var(--accent) 85%, black);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(250, 185, 0, 0.3);
}

.btn-outline {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text);
    box-shadow: var(--glass-highlight);
    backdrop-filter: blur(calc(var(--blur) * 0.75)) saturate(140%);
    -webkit-backdrop-filter: blur(calc(var(--blur) * 0.75)) saturate(140%);
}

.btn-outline:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--glass-hover);
}

.btn-green {
    background: var(--green);
    color: var(--btn-green-text);
}

.btn-green:hover {
    background: color-mix(in srgb, var(--green) 86%, black);
    color: var(--btn-green-text);
}

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

/* ==================== CLOCK & DATE PICKER (Dashboard) ==================== */

.clock {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    font-family: "Courier New", monospace;
    background: var(--glass-bg-strong);
    padding: 0 14px;
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-highlight);
    backdrop-filter: blur(calc(var(--blur) * 0.6));
    -webkit-backdrop-filter: blur(calc(var(--blur) * 0.6));
    height: 38px;
    display: inline-flex;
    align-items: center;
}

.date-picker-wrapper {
    display: inline-flex;
    align-items: stretch;
    gap: 8px;
    height: 38px;
}

.date-picker {
    background: var(--glass-bg-strong);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 6px 12px;
    font-size: 0.9rem;
    cursor: pointer;
}

.date-picker::-webkit-calendar-picker-indicator {
    filter: var(--calendar-icon-filter);
    cursor: pointer;
}

.date-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    height: 38px;
    display: inline-flex;
    align-items: center;
}

/* ==================== PERIOD SELECTOR (Analytics) ==================== */

.period-selector {
    display: flex;
    align-items: center;
    min-height: 38px;
    height: auto;
    gap: 10px;
    flex-wrap: wrap;
}

.period-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    height: 38px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 0;
    box-shadow: var(--glass-highlight);
    backdrop-filter: blur(calc(var(--blur) * 0.5)) saturate(150%);
    -webkit-backdrop-filter: blur(calc(var(--blur) * 0.5)) saturate(150%);
}

.period-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: calc(var(--radius) - 2px);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.period-nav-btn:hover {
    background: var(--glass-hover);
    color: var(--text);
    transform: scale(1.05);
}
.period-nav-btn:active {
    transform: scale(0.95);
}
.period-nav-btn svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.5;
}

.period-display {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 160px;
    height: 36px;
    padding: 0 16px;
    background: transparent;
    border-radius: calc(var(--radius) - 2px);
    overflow: hidden;
    position: relative;
}

.period-display-text {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    transition: all 0.25s ease;
}
.period-display-text.slide-left {
    animation: slideLeft 0.25s ease;
}
.period-display-text.slide-right {
    animation: slideRight 0.25s ease;
}

@keyframes slideLeft {
    0% {
        opacity: 0;
        transform: translateX(12px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}
@keyframes slideRight {
    0% {
        opacity: 0;
        transform: translateX(-12px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

.period-select {
    background: var(--glass-bg-strong);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 8px 14px;
    font-size: 0.85rem;
    cursor: pointer;
    min-width: 180px;
}

.period-select:focus {
    outline: none;
    border-color: var(--accent);
}

.custom-dates {
    display: none;
    align-items: center;
    gap: 8px;
}

.custom-dates.show {
    display: flex;
}

.date-input {
    background: var(--glass-bg-strong);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0 10px;
    font-size: 0.8rem;
    height: var(--header-control-height);
}

.date-input::-webkit-calendar-picker-indicator {
    filter: var(--calendar-icon-filter);
    cursor: pointer;
}

.period-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-left: 4px;
}

/* ==================== NOTIFICATIONS (Dashboard) ==================== */

.notification-bell {
    position: relative;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.notification-bell:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--red);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

.notification-dropdown {
    display: none;
    position: absolute;
    top: 70px;
    right: 24px;
    width: 360px;
    max-height: 400px;
    background: var(--glass-bg-strong);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--glass-shadow), var(--glass-highlight);
    backdrop-filter: blur(var(--blur)) saturate(150%);
    -webkit-backdrop-filter: blur(var(--blur)) saturate(150%);
    z-index: 1001;
    overflow: hidden;
}

.notification-dropdown.show {
    display: block;
}

.notification-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.9rem;
}

.notification-mark-all {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.75rem;
    cursor: pointer;
}

.notification-mark-all:hover {
    text-decoration: underline;
}

.notification-list {
    max-height: 340px;
    overflow-y: auto;
}

.notification-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}

.notification-item:hover {
    background: var(--surface2);
}

.notification-item:last-child {
    border-bottom: none;
}

.notification-item.unread {
    background: var(--accent-dim);
}

.notification-item.unread:hover {
    background: color-mix(in srgb, var(--accent) 20%, transparent);
}

.notification-title {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.notification-title .type-icon {
    font-size: 0.9rem;
}

.notification-message {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.notification-time {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.notification-empty {
    padding: 30px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ==================== TOAST ==================== */

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--glass-bg-strong);
    border: 1px solid var(--green);
    color: var(--green);
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 0.82rem;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 999;
    box-shadow: var(--glass-shadow);
    backdrop-filter: blur(calc(var(--blur) * 0.75)) saturate(140%);
    -webkit-backdrop-filter: blur(calc(var(--blur) * 0.75)) saturate(140%);
}

.table-wrap,
.config-card,
.stat-card,
.chart-card,
.modal,
.login-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow), var(--glass-highlight);
    backdrop-filter: blur(var(--blur)) saturate(140%);
    -webkit-backdrop-filter: blur(var(--blur)) saturate(140%);
}

thead {
    background: var(--surface2);
}

tbody tr:hover {
    background: var(--glass-hover);
}

.modal-overlay {
    background: var(--overlay-bg);
}

.toast.show {
    opacity: 1;
}

/* ==================== MOBILE ==================== */

@media (max-width: 768px) {
    :root {
        --header-control-height: 40px;
    }

    body {
        padding: 12px;
        background-attachment: scroll;
    }

    .header {
        flex-direction: column;
        align-items: stretch;
        gap: 0;
    }

    .header-left {
        flex-wrap: wrap;
        gap: 10px;
        width: 100%;
        padding: 14px 14px 12px;
    }

    .header-left > * {
        height: auto;
    }

    .header-logo {
        width: 46px;
        height: 46px;
        border-radius: 11px;
    }

    .header-actions {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--glass-border);
        padding: 10px;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: center;
        gap: 8px;
        overflow: visible;
    }

    .header h1 {
        font-size: 1.1rem;
        width: 100%;
        height: auto;
        line-height: 1.2;
    }

    .header h1 span {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        font-size: 0.9rem;
    }

    .header h1 span::before {
        height: 20px;
    }

    .clock {
        font-size: 0.9rem;
        min-height: 38px;
        padding: 0 10px;
    }

    .date-picker-wrapper {
        flex: 1 1 100%;
        height: auto;
        flex-wrap: wrap;
    }

    .date-picker {
        width: 100%;
        font-size: 0.85rem;
    }

    .theme-toggle {
        grid-column: 1;
        justify-self: start;
        width: 100%;
        min-height: 40px;
    }

    .header-actions .btn {
        min-height: 40px;
        padding: 10px 10px;
        font-size: 0.75rem;
        text-align: center;
        width: 100%;
    }

    .notification-bell {
        grid-column: 2;
        justify-self: end;
        width: 40px;
        height: 40px;
    }

    .header-actions > :not(.theme-toggle):not(.notification-bell) {
        grid-column: span 1;
    }

    .period-selector {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .period-select {
        width: 100%;
    }

    .custom-dates {
        flex-wrap: wrap;
    }

    .notification-dropdown {
        right: 12px;
        width: calc(100vw - 24px);
    }

    .toast {
        left: 12px;
        right: 12px;
        bottom: 12px;
        text-align: center;
    }
}

@media (max-width: 480px) {
    body {
        padding: 8px;
    }

    .header h1 {
        font-size: 1rem;
    }

    .header h1 span::before {
        display: none;
    }

    .header-left {
        padding: 12px 12px 10px;
    }

    .header-actions {
        padding: 8px;
        gap: 7px;
    }

    .header-actions .btn {
        font-size: 0.7rem;
        padding: 8px 6px;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}
