* {
    box-sizing: border-box;
}

:root {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-2: #f8f9fb;
    --text: #181a1f;
    --muted: #747984;
    --border: #e5e7eb;
    --accent: #5b4bdb;
    --accent-dark: #4939c9;
    --shadow: 0 14px 40px rgba(20, 23, 31, .08);
}

body.dark {
    --bg: #111318;
    --surface: #191c22;
    --surface-2: #20242c;
    --text: #f4f5f7;
    --muted: #9da3af;
    --border: #2c313b;
    --shadow: 0 18px 50px rgba(0, 0, 0, .3);
}

body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-shell {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: 270px;
    min-height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 26px 18px;
    display: flex;
    flex-direction: column;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 10px 30px;
}

.brand-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    color: white;
    background: var(--accent);
    font-size: 16px;
}

.brand strong {
    display: block;
    font-size: 15px;
}

.brand span {
    color: var(--muted);
    font-size: 12px;
}

nav {
    display: grid;
    gap: 5px;
}

.nav-item {
    border: 0;
    background: transparent;
    color: var(--muted);
    text-align: left;
    padding: 11px 12px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-item span {
    width: 20px;
    text-align: center;
}

.nav-item b {
    margin-left: auto;
    font-size: 11px;
    font-weight: 600;
}

.nav-item:hover,
.nav-item.active {
    background: var(--surface-2);
    color: var(--text);
}

.nav-item.active {
    color: var(--accent);
}

.category-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 30px 12px 10px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .12em;
}

.category-title button {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 18px;
}

#categoryList {
    display: grid;
    gap: 3px;
}

.category-item {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 9px 12px;
    text-align: left;
    border-radius: 9px;
    display: flex;
    justify-content: space-between;
    width: 100%;
}

.category-item:hover,
.category-item.active {
    background: var(--surface-2);
    color: var(--text);
}

.sidebar-footer {
    margin-top: auto;
    padding: 20px 12px 4px;
    color: var(--muted);
    font-size: 11px;
}

.sidebar-footer small {
    display: block;
    margin-top: 5px;
    opacity: .7;
}

.main {
    flex: 1;
    min-width: 0;
    padding: 0 5%;
}

.topbar {
    height: 88px;
    display: flex;
    align-items: center;
    gap: 18px;
    border-bottom: 1px solid var(--border);
}

.mobile-brand {
    display: none;
    font-weight: 800;
}

.search {
    flex: 1;
    max-width: 650px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 13px;
    color: var(--muted);
}

.search input {
    flex: 1;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
}

.search kbd {
    font-size: 10px;
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 3px 6px;
}

.add-btn,
.secondary-btn {
    border: 0;
    border-radius: 10px;
    padding: 11px 15px;
    font-weight: 700;
}

.add-btn {
    background: var(--accent);
    color: white;
}

.add-btn:hover {
    background: var(--accent-dark);
}

.secondary-btn {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}

.hero {
    display: flex;
    justify-content: space-between;
    align-items: end;
    padding: 48px 0 32px;
}

.eyebrow {
    margin: 0 0 9px;
    color: var(--accent);
    font-size: 10px;
    font-weight: 900;
    letter-spacing: .15em;
}

h1 {
    margin: 0;
    font-size: clamp(30px, 4vw, 44px);
    letter-spacing: -.04em;
}

.hero p:not(.eyebrow) {
    margin: 9px 0 0;
    color: var(--muted);
}

.stats {
    display: flex;
    gap: 28px;
    text-align: right;
}

.stats strong {
    display: block;
    font-size: 24px;
}

.stats span {
    color: var(--muted);
    font-size: 11px;
}

.site-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 16px;
    padding-bottom: 50px;
}

.site-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 18px;
    min-height: 170px;
    display: flex;
    flex-direction: column;
    transition: .18s ease;
}

.site-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow);
}

.site-link {
    text-decoration: none;
    color: inherit;
    flex: 1;
}

.site-top {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.site-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    object-fit: contain;
    padding: 7px;
}

.favorite-btn {
    border: 0;
    background: transparent;
    color: #b1b5bd;
    font-size: 19px;
}

.favorite-btn.active {
    color: #e2a61d;
}

.site-card h3 {
    margin: 17px 0 5px;
    font-size: 16px;
}

.site-card p {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

.site-category {
    display: inline-flex;
    margin-top: 12px;
    color: var(--accent);
    font-size: 10px;
    font-weight: 800;
}

.card-actions {
    display: flex;
    gap: 6px;
    margin-top: 12px;
}

.card-actions button {
    flex: 1;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--muted);
    border-radius: 8px;
    padding: 7px;
    font-size: 11px;
}

.card-actions button:hover {
    color: var(--text);
}

.empty {
    text-align: center;
    padding: 70px 20px;
    color: var(--muted);
}

.empty>div {
    font-size: 40px;
}

.empty h2 {
    color: var(--text);
    margin-bottom: 6px;
}

.hidden {
    display: none !important;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 20px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 12, 17, .5);
    backdrop-filter: blur(4px);
}

.modal-card {
    position: relative;
    width: min(650px, 100%);
    max-height: 90vh;
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 30px;
    box-shadow: var(--shadow);
}

.close-btn {
    position: absolute;
    right: 18px;
    top: 15px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 28px;
}

.modal-card h2 {
    margin: 0 0 24px;
    font-size: 28px;
}

form {
    display: grid;
    gap: 16px;
}

label {
    display: grid;
    gap: 7px;
    font-size: 12px;
    font-weight: 700;
}

label input {
    width: 100%;
    padding: 12px 13px;
    border: 1px solid var(--border);
    border-radius: 10px;
    outline: none;
    background: var(--surface-2);
    color: var(--text);
}

label input:focus {
    border-color: var(--accent);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.switch-row {
    display: flex;
    grid-template-columns: unset;
    justify-content: space-between;
    align-items: center;
    background: var(--surface-2);
    padding: 12px;
    border-radius: 10px;
}

.switch-row small {
    display: block;
    color: var(--muted);
    font-weight: 400;
    margin-top: 3px;
}

.switch-row input {
    width: 18px;
    height: 18px;
}

.form-error {
    padding: 10px 12px;
    background: #fff0f0;
    color: #b42318;
    border-radius: 8px;
    font-size: 12px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 9px;
    margin-top: 5px;
}

.toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    background: var(--text);
    color: var(--surface);
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 12px;
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: .2s;
    z-index: 50;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

@media (max-width: 800px) {
    .sidebar {
        display: none;
    }

    .main {
        padding: 0 18px;
    }

    .topbar {
        height: auto;
        padding: 14px 0;
        flex-wrap: wrap;
    }

    .mobile-brand {
        display: block;
        width: 100%;
    }

    .search {
        order: 2;
        min-width: 0;
    }

    .add-btn {
        order: 3;
    }

    .hero {
        padding: 35px 0 25px;
        display: block;
    }

    .stats {
        margin-top: 22px;
        text-align: left;
    }

    .form-row {
        grid-template-columns: 1fr;
    }
}