/* SaveBox app — builds on /static/design/sb.css + sb-extra.css */

button,
input,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    opacity: 0.6;
    cursor: default;
}


/* =========================================================
   SIDEBAR
   ========================================================= */

.side-nav {
    display: grid;
    gap: 2px;
}

.side-nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: var(--hit);
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-buttons);
    background: transparent;
    color: var(--text-2);
    font: 500 14px/1 var(--font-sans);
    text-align: left;
    white-space: nowrap;
}

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

.side-nav-link[aria-current] {
    border-color: var(--color-iris-glow);
    background: var(--bg-tint);
    color: var(--text);
}

.side-nav-link[aria-current] .sb-icon {
    color: var(--accent);
}

.side-bottom {
    position: relative;
    display: grid;
    gap: 8px;
    margin-top: auto;
}

.side-login {
    width: 100%;
}

.account-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-left: 8px;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: 50%;
    background: var(--text);
    color: var(--bg);
    font: 500 16px/1 var(--font-sans);
    box-shadow: var(--shadow-subtle);
}

.account-button img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.account-menu {
    position: absolute;
    bottom: 52px;
    left: 0;
    z-index: 50;
    width: 240px;
    max-width: calc(100vw - 24px);
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--bg);
    box-shadow: var(--shadow-subtle-9);
}

.account-menu-name {
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
}

.account-menu-email {
    margin-top: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-muted);
    font-size: 13px;
}

.account-menu-logout {
    width: 100%;
    min-height: 36px;
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-buttons);
    background: var(--bg-recessed);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
}


/* =========================================================
   MAIN
   ========================================================= */

.sb-main > * {
    width: 100%;
    max-width: 880px;
}

.screen {
    display: grid;
    gap: var(--spacing-24);
    align-content: start;
}

.screen.hidden {
    display: none;
}

.page-head {
    display: grid;
    gap: 8px;
}

.page-head .sb-hint {
    margin: 0;
}

.nudge {
    flex-wrap: wrap;
}

.nudge-actions {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 6px;
}

.nudge-close {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    font-size: 18px;
    line-height: 1;
}

.nudge-close:hover {
    background: var(--bg);
    color: var(--text);
}


/* =========================================================
   SAVE CARD
   ========================================================= */

.save-card {
    display: grid;
    gap: var(--spacing-16);
    padding: var(--card-padding);
    border: 1px solid var(--border);
    border-radius: var(--radius-large-panels);
    background: var(--bg);
    box-shadow: var(--shadow-subtle-9);
}

.save-card textarea {
    display: block;
    width: 100%;
    min-height: 160px;
    padding: 0;
    resize: vertical;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    font: 400 16px/1.6 var(--font-sans);
}

.save-card textarea::placeholder {
    color: var(--text-muted);
}

.file-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding-top: var(--spacing-16);
    border-top: 1px solid var(--border);
}

.file-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 16px;
    border: 1px solid var(--color-silver);
    border-radius: var(--radius-buttons);
    background: var(--bg);
    box-shadow: var(--shadow-subtle);
    color: var(--text);
    font: 500 14px/1 var(--font-sans);
    cursor: pointer;
}

.file-button:hover {
    background: var(--bg-recessed);
}

.file-button .sb-icon {
    width: 16px;
    height: 16px;
}

.file-button input {
    display: none;
}

#fileName {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: 13px;
}

.save-button {
    margin-left: auto;
}

.ai-result {
    padding: 14px 16px;
    border: 1px solid var(--color-iris-glow);
    border-radius: var(--radius-cards);
    background: var(--bg-tint);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
}

.ai-result.error {
    border-color: #ffd5d5;
    background: #fff1f1;
    color: #b00020;
}


/* =========================================================
   LIST
   ========================================================= */

.search-container .sb-input {
    max-width: none;
}

#listContent {
    min-width: 0;
}

.items {
    display: grid;
    gap: var(--spacing-12);
}

.item {
    display: grid;
    gap: var(--spacing-12);
    padding: var(--spacing-16) var(--spacing-16) var(--spacing-16) var(--spacing-16);
    border: 1px solid var(--border);
    border-radius: var(--radius-cards);
    background: var(--bg);
    box-shadow: var(--shadow-subtle-10);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.item:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-subtle-9);
}

.item-head {
    align-items: flex-start;
}

.item-title {
    overflow-wrap: anywhere;
}

.item-preview {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    margin: 2px 0 0;
    overflow: hidden;
    color: var(--text-2);
    font-size: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.favorite {
    display: grid;
    flex: none;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
}

.favorite:hover {
    background: var(--bg-recessed);
}

.favorite.active {
    color: var(--accent);
}

.favorite.active .sb-icon {
    fill: currentColor;
}

.item-extra {
    display: grid;
    gap: var(--spacing-12);
    padding-left: 52px;
}

.file-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    padding: 8px 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-cards);
    background: var(--bg-recessed);
    color: var(--text);
    font-size: 13px;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
    justify-self: start;
}

.file-link:hover {
    border-color: var(--border-strong);
}

.file-link .sb-icon {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
}

.link-card {
    display: flex;
    gap: 14px;
    padding: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-cards);
    background: var(--bg-recessed);
    color: inherit;
    text-decoration: none;
}

.link-card:hover {
    border-color: var(--border-strong);
}

.link-image {
    flex-shrink: 0;
    width: 112px;
    height: 72px;
    border-radius: 6px;
    background: var(--border);
    object-fit: cover;
}

.link-body {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    padding: 2px 4px;
}

.link-site {
    overflow: hidden;
    color: var(--text-muted);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.link-title {
    overflow: hidden;
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.link-description {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.45;
}

.item-actions {
    display: flex;
    gap: 4px;
    margin-left: -10px;
}

.item-action {
    min-height: 32px;
    padding: 0 10px;
    border: 0;
    border-radius: var(--radius-buttons);
    background: transparent;
    color: var(--text-muted);
    font: 500 13px/1 var(--font-sans);
}

.item-action:hover {
    background: var(--bg-recessed);
    color: var(--text);
}

.item-action.delete:hover {
    color: #b00020;
}


/* =========================================================
   CATEGORIES
   ========================================================= */

.categories {
    display: grid;
    gap: var(--spacing-8);
}

.category {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px 4px 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius-cards);
    background: var(--bg);
    box-shadow: var(--shadow-subtle-10);
}

.category:hover {
    border-color: var(--border-strong);
}

.category-main {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
    padding: 10px;
    border: 0;
    background: transparent;
    color: inherit;
    text-align: left;
}

.category-icon {
    display: grid;
    flex: none;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg-recessed);
    font-size: 17px;
}

.category-name {
    flex: 1;
    overflow: hidden;
    color: var(--text);
    font: 500 15px/1.4 var(--font-sans);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.category-count {
    min-width: 28px;
    padding: 3px 9px;
    border-radius: var(--radius-badges);
    background: var(--bg-recessed);
    color: var(--text-muted);
    font: 500 12px/1.2 var(--font-sans);
    text-align: center;
}

.category-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}

.category-toggle {
    min-height: 36px;
    padding: 0 18px;
    border: 1px solid var(--color-silver);
    border-radius: var(--radius-buttons);
    background: var(--bg);
    box-shadow: var(--shadow-subtle);
    color: var(--text);
    font: 500 14px/1 var(--font-sans);
}

.category-toggle.active {
    border-color: transparent;
    background: var(--accent);
    color: var(--on-accent);
    box-shadow: var(--halo);
}

.category-add-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.category-add-row input {
    flex: 1;
    min-width: 0;
    min-height: var(--hit);
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-inputs);
    outline: 0;
    background: var(--bg);
    color: var(--text);
    font: 400 16px/1.4 var(--font-sans);
}

.category-add-row input:focus {
    border-color: var(--text);
    box-shadow: var(--halo);
}

.category-add-row button {
    flex-shrink: 0;
    min-height: var(--hit);
    padding: 0 20px;
    border: 0;
    border-radius: var(--radius-buttons);
    background: var(--accent);
    color: var(--on-accent);
    font: 500 14px/1 var(--font-sans);
    box-shadow: var(--halo);
}

.category.editing {
    gap: 10px;
    padding: 6px 6px 6px 8px;
}

.category-input {
    flex: 1;
    min-width: 0;
    padding: 9px 12px;
    border: 1px solid transparent;
    border-radius: var(--radius-inputs);
    outline: 0;
    background: var(--bg-recessed);
    color: var(--text);
    font: 500 15px/1.4 var(--font-sans);
}

.category-input:focus {
    border-color: var(--text);
    background: var(--bg);
    box-shadow: var(--halo);
}

.category-input:disabled {
    background: transparent;
}

.category-delete,
.category-lock {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
}

.category-delete {
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
}

.category-delete:hover {
    background: #fff1f1;
}

.category-lock {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    opacity: 0.5;
    cursor: help;
}


/* =========================================================
   EMPTY
   ========================================================= */

.empty {
    padding: 56px 20px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-cards);
    color: var(--text-muted);
    text-align: center;
}

.empty-icon {
    margin-bottom: 10px;
    font-size: 32px;
}

.empty h3 {
    margin: 0;
    color: var(--text);
    font: 500 16px/1.4 var(--font-sans);
}

.empty p {
    margin: 6px 0 0;
    font-size: 14px;
}


/* =========================================================
   MODAL
   ========================================================= */

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(29, 29, 32, 0.3);
    backdrop-filter: blur(4px);
}

.modal-box {
    width: 100%;
    max-width: 420px;
    padding: 24px;
    border-radius: var(--radius-large-panels);
    background: var(--bg);
    box-shadow: var(--shadow-subtle-9);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.close-button {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: var(--bg-recessed);
    color: var(--text);
    font-size: 20px;
    line-height: 1;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 20px;
}

.stat {
    padding: 16px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-cards);
    background: var(--bg-recessed);
    text-align: center;
}

.stat strong {
    display: block;
    color: var(--text);
    font: 300 28px/1.1 var(--font-sans);
    letter-spacing: -0.5px;
}

.stat span {
    display: block;
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 12px;
}


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

.app-tabbar {
    display: none;
}

@media (max-width: 900px) {

    .sb-app {
        grid-template-columns: minmax(0, 1fr);
    }

    .sb-side {
        position: sticky;
        top: 0;
        z-index: 20;
        display: flex;
        flex-direction: row;
        align-items: center;
        height: auto;
        padding: 10px 16px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .sb-side .sb-brand {
        padding: 0;
    }

    .side-nav {
        display: none;
    }

    .side-bottom {
        display: flex;
        align-items: center;
        gap: 4px;
        margin: 0 0 0 auto;
        position: static;
    }

    .side-stats {
        width: auto;
        min-height: 40px;
        padding: 0 10px;
    }

    .side-stats span {
        display: none;
    }

    .side-login {
        width: auto;
        min-height: 40px;
        padding: 0 16px;
    }

    .account-button {
        width: 36px;
        height: 36px;
        margin: 0;
    }

    .account-menu {
        position: fixed;
        top: 62px;
        right: 12px;
        bottom: auto;
        left: auto;
    }

    .sb-main {
        padding: var(--spacing-24) var(--spacing-16) calc(var(--tabbar-h) + 32px);
    }

    .page-head .sb-h1 {
        font-size: 32px;
    }

    .app-tabbar {
        position: fixed;
        inset: auto 0 0 0;
        z-index: 30;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        min-height: var(--tabbar-h);
        padding-bottom: env(safe-area-inset-bottom);
        border-top: 1px solid var(--border);
        background: var(--bg);
    }

    .tab-link {
        display: grid;
        place-items: center;
        align-content: center;
        gap: 3px;
        min-height: var(--hit);
        border: 0;
        background: transparent;
        color: var(--text-muted);
        font: 500 11px/1.2 var(--font-sans);
    }

    .tab-link[aria-current] {
        color: var(--text);
    }

    .tab-link[aria-current] .sb-icon {
        color: var(--accent);
    }

    .item-extra {
        padding-left: 0;
    }

    .item-actions {
        margin-left: -10px;
    }

    .nudge .nudge-actions {
        width: 100%;
    }

    .nudge .sb-btn {
        flex: 1;
    }
}

@media (max-width: 480px) {

    .save-button {
        width: 100%;
    }

    .link-image {
        width: 72px;
        height: 72px;
    }

    .search-container .sb-btn {
        width: 100%;
    }
}

@media (prefers-color-scheme: dark) {

    .ai-result.error {
        border-color: #5a2a2a;
        background: #3a1c1c;
        color: #ff8a8a;
    }

    .category-delete:hover {
        background: #3a1c1c;
    }
}
