:root {
    color-scheme: light;
    --bg: #f5f6f4;
    --panel: #ffffff;
    --text: #202421;
    --muted: #68726b;
    --line: #d9ded8;
    --brand: #2f6f4e;
    --brand-dark: #24563d;
    --danger: #a73535;
    --shadow: 0 10px 28px rgba(25, 34, 28, 0.10);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    letter-spacing: 0;
}

a {
    color: inherit;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 60px;
    padding: 0 24px;
    background: #fff;
    border-bottom: 1px solid var(--line);
}

.brand {
    font-size: 20px;
    font-weight: 700;
}

.layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: calc(100vh - 60px);
}

.sidebar {
    padding: 22px 18px;
    border-right: 1px solid var(--line);
    background: #fff;
}

.nav-link {
    display: block;
    padding: 12px 14px;
    margin-bottom: 6px;
    border-radius: 6px;
    color: var(--text);
    text-decoration: none;
}

.nav-link.active,
.nav-link:hover {
    background: #e5efe8;
    color: var(--brand-dark);
}

.content {
    padding: 26px;
}

.page-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

h1 {
    margin: 0;
    font-size: 28px;
}

.muted {
    color: var(--muted);
}

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

.photo-grid {
    display: block;
    columns: 260px;
    column-gap: 18px;
}

.tile {
    overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.photo-tile {
    display: inline-block;
    width: 100%;
    margin: 0 0 18px;
    break-inside: avoid;
}

.photo-button {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    text-align: left;
}

.tile img {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: contain;
    background: #e8ece8;
}

.tile .gallery-photo {
    height: auto;
    aspect-ratio: auto;
    object-fit: contain;
}

.photo-caption {
    padding: 12px;
    min-height: 44px;
    color: var(--text);
    background: #fff;
    line-height: 1.35;
    overflow-wrap: anywhere;
    white-space: normal;
}

.tile-body {
    padding: 12px;
    min-height: 48px;
}

.doc-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-height: 92px;
    padding: 16px;
    text-decoration: none;
    overflow: visible;
}

.doc-title {
    display: block;
    min-width: 0;
    line-height: 1.35;
    overflow-wrap: anywhere;
    white-space: normal;
}

.doc-icon {
    display: grid;
    place-items: center;
    width: 44px;
    height: 56px;
    flex: 0 0 auto;
    border-radius: 4px;
    background: #dfe9e3;
    color: var(--brand-dark);
    font-weight: 700;
}

.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-box,
.admin-panel {
    width: min(440px, 100%);
    padding: 28px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

label {
    display: block;
    margin: 14px 0 6px;
    font-weight: 700;
}

input,
textarea,
select,
button {
    font: inherit;
}

input,
textarea,
select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd2cc;
    border-radius: 6px;
    background: #fff;
}

textarea {
    min-height: 76px;
    resize: vertical;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 14px;
    border: 1px solid var(--brand);
    border-radius: 6px;
    background: var(--brand);
    color: #fff;
    text-decoration: none;
    cursor: pointer;
}

.button.secondary,
button.secondary {
    background: #fff;
    color: var(--brand);
}

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

.flash {
    margin-bottom: 18px;
    padding: 12px 14px;
    border-radius: 6px;
    background: #e5efe8;
    color: var(--brand-dark);
}

.flash.error {
    background: #f2dddd;
    color: var(--danger);
}

.admin-nav {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.admin-wrap {
    max-width: 1160px;
    margin: 0 auto;
    padding: 26px;
}

.toolbar {
    display: flex;
    align-items: end;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.toolbar > * {
    min-width: 220px;
}

.order-actions {
    display: flex;
    justify-content: flex-end;
    margin: -4px 0 12px;
}

.list {
    display: grid;
    gap: 12px;
}

.item {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.item.dragging {
    opacity: .55;
}

.drag-handle {
    display: grid;
    place-items: center;
    height: 34px;
    border-radius: 6px;
    background: #eef2ef;
    color: var(--muted);
    cursor: grab;
    user-select: none;
}

.admin-photo {
    width: 120px;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 6px;
}

.item.media {
    grid-template-columns: 34px 120px minmax(0, 1fr) auto;
}

.actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    grid-template-rows: auto 1fr auto;
    background: rgba(0, 0, 0, .92);
    color: #fff;
}

.lightbox.open {
    display: grid;
}

.lightbox-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
}

.lightbox-stage {
    display: grid;
    grid-template-columns: 60px 1fr 60px;
    align-items: center;
    min-height: 0;
}

.lightbox img {
    max-width: 100%;
    max-height: calc(100vh - 150px);
    margin: auto;
    object-fit: contain;
}

.lightbox-caption {
    min-height: 48px;
    padding: 0 18px 18px;
    text-align: center;
}

.lightbox button {
    border-color: rgba(255,255,255,.35);
    background: rgba(255,255,255,.12);
}

@media (max-width: 760px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .content,
    .admin-wrap {
        padding: 18px;
    }

    .item,
    .item.media {
        grid-template-columns: 34px 1fr;
    }

    .item.media .admin-photo,
    .item .actions {
        grid-column: 2;
    }
}
