:root {
    --bg: #ffffff;
    --bg-elevated: #f5f6f8;
    --border: #e4e7ec;
    --text: #1d1e1e;
    --text-muted: #6b7280;
    --accent: #5b8def;
    --accent-hover: #4577dd;
    --danger: #dc3d37;
    --radius: 10px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a {
    color: var(--accent);
    text-decoration: none;
}

/* ---- Public site ---- */

.menu-toggle {
    position: fixed;
    top: 1rem;
    left: 0;
    z-index: 1001;
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.6rem 0.7rem;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.15);
    transition: left 0.3s ease, background 0.12s ease;
}

.menu-toggle:hover {
    background: var(--accent-hover);
}

body.menu-open .menu-toggle {
    left: 240px;
}

.side-menu {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 240px;
    background: #ffffff;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.15);
    padding: 4rem 1.5rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 1000;
}

body.menu-open .side-menu {
    transform: translateX(0);
}

.side-menu h1 {
    font-size: 1.1rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin: 0 0 1rem;
}

.side-menu a {
    color: var(--text);
    padding: 0.5rem 0;
}

.side-menu a:hover {
    color: var(--accent);
}

.site-main {
    width: 100%;
    padding: 4rem 2rem 3rem;
}

.category-tabs {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.category-tabs button {
    background: none;
    border: none;
    text-align: left;
    color: var(--text-muted);
    padding: 0.5rem 0.6rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
}

.category-tabs button:hover {
    background: var(--bg-elevated);
    color: var(--text);
}

.category-tabs button.active {
    background: var(--accent);
    color: #fff;
}

.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
}

.tile {
    background: #ffffff;
    border: none;
    border-radius: 0;
    aspect-ratio: 1 / 1;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}

.tile:not(.tile-locked):hover {
    transform: scale(1.12);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
    z-index: 1;
}

.tile-locked {
    cursor: default;
    filter: grayscale(1);
    opacity: 0.45;
}

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

.tile .tile-fallback {
    width: 100%;
    height: 100%;
    background: #e9edf1;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 2rem;
}

.empty-state {
    color: var(--text-muted);
    padding: 2rem 0;
}

.tile-folder {
    position: relative;
    cursor: pointer;
    font: inherit;
    background: #ffffff;
}

.tile-folder-badge {
    position: absolute;
    right: 6px;
    bottom: 6px;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

body.modal-open {
    overflow: hidden;
}

.modal[hidden] {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
}

.modal-dialog {
    position: relative;
    background: var(--bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: min(720px, 100%);
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.1rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
}

.modal-close:hover {
    color: var(--text);
}

/* ---- Auth ---- */

.auth-wrapper {
    max-width: 360px;
    margin: 4rem auto;
    padding: 2rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.auth-wrapper h1 {
    margin-top: 0;
    font-size: 1.3rem;
}

/* ---- Forms ---- */

.field {
    margin-bottom: 1rem;
}

.field label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="url"],
.field input[type="number"],
.field input[type="file"],
.field select {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
}

.btn {
    display: inline-block;
    padding: 0.55rem 1.1rem;
    border-radius: 6px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn:hover {
    background: var(--accent-hover);
}

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

.btn-secondary {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}

.alert {
    padding: 0.7rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-error {
    background: rgba(224, 85, 79, 0.15);
    border: 1px solid var(--danger);
    color: #ffb3af;
}

.alert-success {
    background: rgba(91, 141, 239, 0.15);
    border: 1px solid var(--accent);
    color: #bcd2ff;
}

.error-text {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 0.25rem;
    display: block;
}

/* ---- Admin ---- */

.admin-layout {
    display: flex;
    min-height: 100vh;
}

.admin-sidebar {
    width: 220px;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    padding: 1.5rem 1rem;
    flex-shrink: 0;
}

.admin-sidebar h2 {
    font-size: 1rem;
    margin: 0 0 1.5rem;
    padding: 0 0.5rem;
}

.admin-sidebar nav a {
    display: block;
    padding: 0.6rem 0.5rem;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.15rem;
}

.admin-sidebar nav a:hover,
.admin-sidebar nav a.active {
    background: var(--bg);
    color: var(--text);
}

.admin-content {
    flex: 1;
    padding: 1.75rem 2rem;
    max-width: 1000px;
}

.admin-content h1 {
    font-size: 1.3rem;
    margin-top: 0;
}

.admin-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}

table.admin-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

table.admin-table th,
table.admin-table td {
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 0.88rem;
}

table.admin-table th {
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
}

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

table.admin-table img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    border-radius: 4px;
    vertical-align: middle;
}

table.admin-table .url-cell {
    max-width: 220px;
}

table.admin-table .url-cell a {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
}

.reorder-hint {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin: -0.5rem 0 0.75rem;
}

table.admin-table .drag-handle {
    width: 1.5rem;
    cursor: grab;
    color: var(--text-muted);
    text-align: center;
    touch-action: none;
    user-select: none;
}

table.admin-table tr.dragging {
    opacity: 0.4;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    background: var(--border);
    color: var(--text-muted);
}

.badge-public {
    background: rgba(91, 141, 239, 0.15);
    color: #bcd2ff;
}

.badge-private {
    background: rgba(224, 85, 79, 0.15);
    color: #ffb3af;
}

.badge-folder {
    background: rgba(91, 141, 239, 0.15);
    color: var(--accent);
}

table.admin-table tr.tile-child-row td {
    background: rgba(91, 141, 239, 0.1);
}

table.admin-table .tile-child-title {
    position: relative;
    padding-left: 2.25rem;
    color: var(--text-muted);
}

table.admin-table .tile-child-title::before {
    content: "↳";
    position: absolute;
    left: 1rem;
    color: var(--text-muted);
}

.actions-cell {
    white-space: nowrap;
}

.actions-cell a,
.actions-cell button {
    font-size: 0.82rem;
    margin-right: 0.5rem;
}

form.admin-form {
    max-width: 480px;
}

.current-image {
    margin-bottom: 0.75rem;
}

.current-image img {
    width: 56px;
    height: 56px;
    object-fit: contain;
    border-radius: 8px;
    border: 1px solid var(--border);
    padding: 4px;
    background: var(--bg);
}
