html { scroll-behavior: smooth; }
body {
    -webkit-tap-highlight-color: transparent;
    background-color: rgb(var(--theme-brand-50, 245 243 255)) !important;
    transition: background-color 180ms ease;
}
.dark body {
    background-color: #020617 !important;
}
::-webkit-scrollbar { height: 8px; width: 8px; }
::-webkit-scrollbar-thumb { background: rgba(100,116,139,.4); border-radius: 4px; }
#sidebar { transform: translateX(100%); transition: transform .25s ease; }
#sidebar.is-open { transform: translateX(0); }
@media (min-width: 1024px) {
    #sidebar { transform: none; }
    #sidebar-backdrop { display: none !important; }
}

:root {
    --dashboard-brightness-color: 0 0 0;
    --dashboard-brightness-opacity: 0;
}

body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 80;
    pointer-events: none;
    background: rgb(var(--dashboard-brightness-color));
    opacity: var(--dashboard-brightness-opacity);
}

body.appearance-settings-open { overflow: hidden; }

.theme-login-gradient {
    background: linear-gradient(135deg,
        rgb(var(--theme-brand-500)) 0%,
        rgb(var(--theme-brand-600)) 25%,
        rgb(var(--theme-accent-500)) 50%,
        rgb(var(--theme-brand-500)) 75%,
        rgb(var(--theme-brand-700)) 100%);
    background-size: 200% 200%;
}

.appearance-settings[hidden] { display: none; }
.appearance-settings {
    position: fixed;
    inset: 0;
    z-index: 100;
    direction: rtl;
}
.appearance-settings__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 180ms ease;
}
.appearance-settings__panel {
    position: absolute;
    top: 76px;
    left: 16px;
    width: min(430px, calc(100vw - 24px));
    max-height: calc(100vh - 92px);
    overflow-y: auto;
    border: 1px solid rgb(226 232 240);
    border-radius: 24px;
    background: rgba(255, 255, 255, .98);
    color: rgb(30 41 59);
    box-shadow: 0 24px 64px rgba(15, 23, 42, .22);
    transform: translateY(-10px) scale(.98);
    opacity: 0;
    transition: transform 180ms ease, opacity 180ms ease;
}
.dark .appearance-settings__panel {
    border-color: rgb(51 65 85);
    background: rgba(15, 23, 42, .98);
    color: rgb(241 245 249);
    box-shadow: 0 24px 64px rgba(0, 0, 0, .5);
}
.appearance-settings.is-open .appearance-settings__backdrop { opacity: 1; }
.appearance-settings.is-open .appearance-settings__panel {
    transform: translateY(0) scale(1);
    opacity: 1;
}
.appearance-settings__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgb(226 232 240);
}
.dark .appearance-settings__header { border-color: rgb(51 65 85); }
.appearance-settings__heading {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.appearance-settings__heading-icon {
    display: flex;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    color: rgb(var(--theme-brand-700));
    background: rgb(var(--theme-brand-100));
}
.dark .appearance-settings__heading-icon {
    color: rgb(var(--theme-brand-300));
    background: rgb(var(--theme-brand-500) / .15);
}
.appearance-settings__heading-icon svg { width: 22px; height: 22px; }
.appearance-settings__heading h2 {
    margin: 0;
    font-size: 17px;
    line-height: 1.5;
    font-weight: 800;
}
.appearance-settings__heading p {
    margin: 2px 0 0;
    color: rgb(100 116 139);
    font-size: 12px;
    line-height: 1.7;
}
.dark .appearance-settings__heading p { color: rgb(148 163 184); }
.appearance-settings__close {
    display: flex;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: rgb(100 116 139);
    cursor: pointer;
    transition: color 180ms ease, background-color 180ms ease;
}
.appearance-settings__close:hover { color: rgb(15 23 42); background: rgb(241 245 249); }
.dark .appearance-settings__close:hover { color: white; background: rgb(30 41 59); }
.appearance-settings__close svg { width: 20px; height: 20px; }
.appearance-settings__content {
    display: grid;
    gap: 18px;
    padding: 18px 20px;
}
.appearance-fieldset {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}
.appearance-fieldset legend,
.appearance-brightness__label label {
    display: block;
    margin-bottom: 9px;
    color: rgb(51 65 85);
    font-size: 13px;
    font-weight: 800;
}
.dark .appearance-fieldset legend,
.dark .appearance-brightness__label label { color: rgb(226 232 240); }
.appearance-mode {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 4px;
    border: 1px solid rgb(226 232 240);
    border-radius: 15px;
    background: rgb(248 250 252);
}
.dark .appearance-mode {
    border-color: rgb(51 65 85);
    background: rgb(2 6 23 / .55);
}
.appearance-mode button {
    display: flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: 11px;
    background: transparent;
    color: rgb(100 116 139);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: color 180ms ease, background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}
.appearance-mode button svg { width: 18px; height: 18px; }
.appearance-mode button.is-selected {
    border-color: rgb(var(--theme-brand-200));
    background: white;
    color: rgb(var(--theme-brand-700));
    box-shadow: 0 3px 10px rgb(var(--theme-brand-900) / .08);
}
.dark .appearance-mode button.is-selected {
    border-color: rgb(var(--theme-brand-500) / .35);
    background: rgb(var(--theme-brand-500) / .14);
    color: rgb(var(--theme-brand-200));
    box-shadow: none;
}
.appearance-palettes {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}
.appearance-palette {
    position: relative;
    display: flex;
    min-height: 56px;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    overflow: hidden;
    border: 1px solid rgb(226 232 240);
    border-radius: 14px;
    background: white;
    color: rgb(71 85 105);
    text-align: right;
    font: inherit;
    cursor: pointer;
    transition: border-color 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
}
.dark .appearance-palette {
    border-color: rgb(51 65 85);
    background: rgb(30 41 59 / .65);
    color: rgb(203 213 225);
}
.appearance-palette:hover { border-color: rgb(var(--theme-brand-300)); }
.appearance-palette.is-selected {
    border-color: rgb(var(--theme-brand-500));
    background: rgb(var(--theme-brand-50));
    color: rgb(var(--theme-brand-800));
    box-shadow: 0 0 0 2px rgb(var(--theme-brand-500) / .1);
}
.dark .appearance-palette.is-selected {
    border-color: rgb(var(--theme-brand-400));
    background: rgb(var(--theme-brand-500) / .12);
    color: rgb(var(--theme-brand-200));
}
.appearance-palette__colors {
    display: flex;
    flex: 0 0 auto;
    direction: ltr;
}
.appearance-palette__colors span {
    display: block;
    width: 18px;
    height: 28px;
    border: 2px solid white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .15);
}
.dark .appearance-palette__colors span { border-color: rgb(30 41 59); }
.appearance-palette__colors span + span { margin-left: -7px; }
.appearance-palette__label {
    min-width: 0;
    flex: 1;
    font-size: 11px;
    line-height: 1.5;
    font-weight: 800;
}
.appearance-palette__check {
    display: none;
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgb(var(--theme-brand-600));
    color: white;
}
.appearance-palette.is-selected .appearance-palette__check { display: flex; }
.appearance-palette__check svg { width: 12px; height: 12px; }
.appearance-brightness__label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.appearance-brightness__label output {
    direction: ltr;
    color: rgb(var(--theme-brand-700));
    font-size: 13px;
    font-weight: 800;
}
.dark .appearance-brightness__label output { color: rgb(var(--theme-brand-300)); }
.appearance-brightness {
    display: flex;
    min-height: 44px;
    align-items: center;
    gap: 12px;
}
.appearance-brightness > svg {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
    color: rgb(var(--theme-brand-600));
}
.appearance-brightness input {
    width: 100%;
    height: 6px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    appearance: none;
    -webkit-appearance: none;
    background: linear-gradient(to left,
        rgb(var(--theme-brand-500)) 0 var(--range-progress),
        rgb(226 232 240) var(--range-progress) 100%);
    cursor: pointer;
}
.dark .appearance-brightness input {
    background: linear-gradient(to left,
        rgb(var(--theme-brand-400)) 0 var(--range-progress),
        rgb(51 65 85) var(--range-progress) 100%);
}
.appearance-brightness input::-webkit-slider-thumb {
    width: 20px;
    height: 20px;
    border: 3px solid white;
    border-radius: 50%;
    appearance: none;
    -webkit-appearance: none;
    background: rgb(var(--theme-brand-600));
    box-shadow: 0 2px 8px rgb(var(--theme-brand-900) / .25);
}
.appearance-brightness input::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border: 3px solid white;
    border-radius: 50%;
    background: rgb(var(--theme-brand-600));
    box-shadow: 0 2px 8px rgb(var(--theme-brand-900) / .25);
}
.appearance-help {
    margin: 4px 0 0;
    color: rgb(100 116 139);
    font-size: 11px;
    line-height: 1.6;
}
.dark .appearance-help { color: rgb(148 163 184); }
.appearance-settings__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 20px 18px;
    border-top: 1px solid rgb(226 232 240);
}
.dark .appearance-settings__footer { border-color: rgb(51 65 85); }
.appearance-reset,
.appearance-done {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border-radius: 12px;
    padding: 9px 14px;
    font: inherit;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
    transition: color 180ms ease, background-color 180ms ease, border-color 180ms ease;
}
.appearance-reset {
    border: 1px solid rgb(226 232 240);
    background: transparent;
    color: rgb(71 85 105);
}
.appearance-reset:hover { border-color: rgb(203 213 225); background: rgb(248 250 252); color: rgb(15 23 42); }
.dark .appearance-reset { border-color: rgb(51 65 85); color: rgb(203 213 225); }
.dark .appearance-reset:hover { background: rgb(30 41 59); color: white; }
.appearance-reset svg { width: 16px; height: 16px; }
.appearance-done {
    border: 1px solid rgb(var(--theme-brand-600));
    background: rgb(var(--theme-brand-600));
    color: white;
}
.appearance-done:hover {
    border-color: rgb(var(--theme-brand-700));
    background: rgb(var(--theme-brand-700));
}
.appearance-settings button:focus-visible,
.appearance-settings input:focus-visible {
    outline: 3px solid rgb(var(--theme-brand-400) / .38);
    outline-offset: 2px;
}

@media (max-width: 480px) {
    .appearance-settings__panel {
        top: 64px;
        left: 12px;
        max-height: calc(100vh - 76px);
        border-radius: 20px;
    }
    .appearance-settings__header { padding: 16px 16px 14px; }
    .appearance-settings__content { gap: 15px; padding: 16px; }
    .appearance-settings__footer { padding: 12px 16px 16px; }
    .appearance-palettes { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    .appearance-settings__backdrop,
    .appearance-settings__panel,
    .appearance-settings button { transition: none !important; }
}

@media print {
    body::after,
    .appearance-settings,
    #theme-toggle { display: none !important; }
}
