* {
    box-sizing: border-box;
}

:root {
    --bg: #f3f5fb;
    --panel: #ffffff;
    --panel-2: #eef2ff;
    --text: #0f172a;
    --muted: #64748b;
    --line: #dbe2f0;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #15803d;
    --warning: #d97706;
    --danger: #dc2626;
    --radius: 20px;
    --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    max-width: 100%;
}

.app-shell {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: 300px;
    background: linear-gradient(180deg, #0f172a 0%, #172554 100%);
    color: #f8fafc;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.16);
    font-size: 1.4rem;
    font-weight: 700;
}

.brand small,
.user-card small {
    display: block;
    color: rgba(248, 250, 252, 0.75);
    margin-top: 4px;
}

.sidebar-nav {
    display: grid;
    gap: 8px;
}

.sidebar-nav a {
    border-radius: 14px;
    padding: 12px 14px;
    color: #dbeafe;
    transition: 0.2s ease;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 14px;
}

.user-card {
    display: flex;
    gap: 14px;
    align-items: center;
    padding: 14px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.08);
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.18);
    font-weight: 700;
    color: #fff;
}

.content {
    flex: 1;
    padding: 26px;
    min-width: 0;
}

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

.page-body {
    display: grid;
    gap: 20px;
}

.search-inline input,
.input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line);
    background: var(--panel);
    border-radius: 14px;
    padding: 14px 16px;
    font-size: 0.98rem;
    color: var(--text);
    outline: none;
}

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

.search-inline {
    flex: 1;
}

.card {
    background: var(--panel);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(219, 226, 240, 0.7);
}

.card.tight {
    padding: 18px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
}

.page-header h1,
.page-header h2,
.page-header h3,
h1, h2, h3 {
    margin: 0 0 8px;
}

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

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

.kpi {
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    border-radius: 20px;
    padding: 22px;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.kpi strong {
    display: block;
    font-size: 1.8rem;
    margin-bottom: 8px;
}

.grid {
    display: grid;
    gap: 20px;
}

.grid.two {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.grid.three {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.btn {
    border: 0;
    border-radius: 14px;
    padding: 12px 18px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: 0.2s ease;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-light {
    background: #f8fafc;
    color: var(--text);
    border: 1px solid var(--line);
}

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

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-warning {
    background: var(--warning);
    color: #fff;
}

.btn-block {
    width: 100%;
}

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

.form-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.form-grid .full {
    grid-column: 1 / -1;
}

.flash {
    padding: 14px 16px;
    border-radius: 14px;
    font-weight: 600;
}

.flash-success {
    background: #dcfce7;
    color: #166534;
}

.flash-warning {
    background: #fef3c7;
    color: #92400e;
}

.flash-danger {
    background: #fee2e2;
    color: #991b1b;
}

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

.list-item {
    padding: 16px 18px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: #fff;
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.83rem;
    font-weight: 700;
    background: #e2e8f0;
    color: #334155;
}

.badge.photo {
    background: #dbeafe;
    color: #1d4ed8;
}
.badge.video {
    background: #ede9fe;
    color: #6d28d9;
}
.badge.owner {
    background: #dbeafe;
    color: #1e40af;
}
.badge.admin {
    background: #ede9fe;
    color: #6d28d9;
}
.badge.member {
    background: #ecfccb;
    color: #3f6212;
}

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

.media-card {
    display: block;
    background: #fff;
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.media-thumb {
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #e2e8f0, #cbd5e1);
    overflow: hidden;
}

.media-thumb img,
.media-thumb video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.media-meta {
    padding: 14px;
    display: grid;
    gap: 8px;
}

.hero-media {
    background: #0f172a;
    border-radius: 22px;
    overflow: hidden;
    min-height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hero-media img,
.hero-media video {
    width: 100%;
    max-height: 72vh;
    object-fit: contain;
    background: #0f172a;
}

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

.tag {
    padding: 8px 12px;
    border-radius: 999px;
    background: #eff6ff;
    color: #1d4ed8;
    font-weight: 600;
    font-size: 0.88rem;
}

.comment {
    border-top: 1px solid var(--line);
    padding: 14px 0 0;
    margin-top: 14px;
}

.table-wrap {
    overflow: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    text-align: left;
    padding: 14px 12px;
    border-bottom: 1px solid var(--line);
}

.auth-screen {
    background: radial-gradient(circle at top, #dbeafe 0%, #f3f5fb 45%, #eef2ff 100%);
}

.auth-screen .content {
    display: grid;
    place-items: center;
    width: 100%;
    padding: 24px;
}

.auth-box {
    width: min(100%, 520px);
}

.upload-dropzone {
    border: 2px dashed #93c5fd;
    background: linear-gradient(180deg, #eff6ff 0%, #f8fbff 100%);
    border-radius: 22px;
    padding: 28px;
    text-align: center;
    display: grid;
    gap: 14px;
}

.upload-dropzone.dragover {
    border-color: var(--primary);
    background: #dbeafe;
}

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

.preview-card {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 18px;
    overflow: hidden;
}

.preview-thumb {
    aspect-ratio: 1 / 1;
    background: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.preview-thumb img,
.preview-thumb video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-meta {
    padding: 12px;
    font-size: 0.9rem;
}

.progress {
    height: 10px;
    border-radius: 999px;
    background: #e2e8f0;
    overflow: hidden;
}

.progress > span {
    display: block;
    height: 100%;
    width: 0;
    background: var(--primary);
    transition: width 0.15s ease;
}

.install-banner {
    display: none;
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 40;
    max-width: 320px;
}

.empty-state {
    padding: 36px;
    border: 2px dashed var(--line);
    border-radius: 20px;
    background: rgba(255,255,255,0.5);
    text-align: center;
    color: var(--muted);
}

@media (max-width: 1080px) {
    .sidebar {
        width: 250px;
        padding: 20px;
    }
}

@media (max-width: 860px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        width: auto;
        border-radius: 0 0 28px 28px;
    }

    .content {
        padding: 18px;
    }

    .topbar {
        flex-direction: column;
        align-items: stretch;
    }
}

/* =========================
   V1.1 photo-first layout
   ========================= */
body:not(.auth-screen) {
    overflow-x: hidden;
}

body.nav-locked {
    overflow: hidden;
    touch-action: none;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.42);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 79;
}

.nav-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
}

.app-shell {
    display: block;
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(320px, calc(100vw - 28px));
    z-index: 80;
    transform: translateX(calc(-100% - 16px));
    transition: transform 0.22s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0 28px 28px 0;
    box-shadow: 0 30px 80px rgba(15, 23, 42, 0.35);
}

.nav-open .sidebar {
    transform: translateX(0);
}

.sidebar-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.sidebar-close,
.menu-toggle {
    border: 0;
    background: transparent;
    cursor: pointer;
}

.sidebar-close {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    color: #f8fafc;
    background: rgba(255, 255, 255, 0.12);
    font-size: 1.6rem;
    line-height: 1;
}

.content {
    padding: 16px 18px 28px;
    max-width: 100%;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
    padding: 10px 0 14px;
    margin-bottom: 8px;
    background: linear-gradient(180deg, rgba(243, 245, 251, 0.96) 70%, rgba(243, 245, 251, 0));
    backdrop-filter: blur(12px);
}

.topbar-start {
    display: flex;
    align-items: center;
    gap: 12px;
}

.menu-toggle {
    width: 46px;
    height: 46px;
    padding: 0;
    border-radius: 16px;
    background: #fff;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
}

.menu-toggle span {
    width: 18px;
    height: 2px;
    background: var(--text);
    border-radius: 999px;
    display: block;
    margin: 0 auto;
}

.topbar-brand {
    display: grid;
    gap: 2px;
}

.topbar-brand strong {
    font-size: 1rem;
}

.topbar-brand small {
    color: var(--muted);
    font-size: 0.82rem;
}

.search-inline input {
    padding: 14px 18px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: var(--shadow);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-body {
    gap: 16px;
}

.page-header,
.section-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.section-head.compact h2,
.home-toolbar h1,
.page-header h1 {
    margin-bottom: 4px;
}

.home-toolbar {
    display: grid;
    gap: 14px;
}

.stat-chips,
.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.stat-chip,
.chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 999px;
    background: #fff;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    font-weight: 600;
}

.stat-chip strong {
    font-size: 1rem;
}

.chip {
    color: var(--text);
}

.chip.active {
    background: #dbeafe;
    color: #1e40af;
    border-color: #bfdbfe;
}

.media-section {
    display: grid;
    gap: 14px;
}

.media-grid {
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
}

.media-grid-photo-first {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

.media-card {
    position: relative;
    border-radius: 22px;
    border: 1px solid rgba(219, 226, 240, 0.9);
}

.media-thumb {
    aspect-ratio: 1 / 1;
}

.media-meta {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    padding: 26px 14px 14px;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0) 0%, rgba(15, 23, 42, 0.82) 62%, rgba(15, 23, 42, 0.94) 100%);
}

.media-meta strong,
.media-meta .muted {
    color: #fff;
}

.media-meta .muted {
    opacity: 0.76;
    font-size: 0.82rem;
}

.compact-columns {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.compact-panel {
    padding: 18px;
}

.mini-panel-row {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.mini-panel {
    display: grid;
    gap: 6px;
    padding: 16px;
    border-radius: 18px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    border: 1px solid var(--line);
    min-height: 110px;
}

.mini-panel small {
    color: var(--muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.mini-panel strong {
    font-size: 1rem;
    line-height: 1.35;
}

.compact-card-grid .card {
    padding: 18px;
}

.group-tile small {
    color: var(--muted);
    font-weight: 700;
    text-transform: uppercase;
}

.install-banner {
    bottom: 24px;
    right: 24px;
}

.fab-add {
    position: fixed;
    right: 18px;
    bottom: 18px;
    width: 58px;
    height: 58px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-size: 2rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 20px 40px rgba(37, 99, 235, 0.3);
    z-index: 45;
}

@media (min-width: 1100px) {
    .content {
        padding: 18px 24px 34px;
    }

    .media-grid-photo-first {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

@media (max-width: 860px) {
    .topbar {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .topbar-actions {
        justify-content: space-between;
    }

    .topbar-link {
        display: none;
    }

    .sidebar {
        width: min(320px, calc(100vw - 20px));
        border-radius: 0 24px 24px 0;
    }

    .media-grid,
    .media-grid-photo-first {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .compact-columns {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .content {
        padding: 14px 12px 90px;
    }

    .search-inline input {
        padding: 13px 15px;
    }

    .media-grid,
    .media-grid-photo-first {
        gap: 10px;
    }

    .media-meta {
        padding: 22px 10px 10px;
    }

    .media-meta strong {
        font-size: 0.92rem;
    }

    .media-meta .badge {
        font-size: 0.74rem;
        padding: 5px 8px;
    }

    .mini-panel-row {
        grid-template-columns: 1fr 1fr;
    }
}


/* =========================
   Mobile/PWA drawer + gallery
   ========================= */
html.nav-locked,
html.lightbox-open,
body.lightbox-open {
    overflow: hidden;
}

.sidebar {
    will-change: transform;
}

body:not(.nav-open) .sidebar {
    transform: translateX(calc(-100% - 16px)) !important;
}

body.nav-open .sidebar {
    transform: translateX(0) !important;
}

.topbar {
    padding-top: max(10px, env(safe-area-inset-top));
}

.media-grid,
.media-grid-photo-first {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

.media-card {
    overflow: hidden;
}

.media-card.js-lightbox-item {
    cursor: zoom-in;
}

.media-meta {
    padding: 18px 12px 12px;
}

.media-meta strong {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 120;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
}

.lightbox.is-open {
    opacity: 1;
    pointer-events: auto;
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.88);
}

.lightbox-shell {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr) 72px;
    grid-template-rows: 1fr auto;
    align-items: center;
}

.lightbox-stage {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 18px;
}

.lightbox-stage img,
.lightbox-stage video {
    max-width: 100%;
    max-height: calc(100vh - 130px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 18px;
    box-shadow: 0 20px 70px rgba(0, 0, 0, 0.45);
    background: #000;
}

.lightbox-caption {
    grid-column: 1 / -1;
    grid-row: 2;
    padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
    color: #fff;
    display: grid;
    gap: 4px;
    background: linear-gradient(180deg, rgba(2,6,23,0) 0%, rgba(2,6,23,0.72) 32%, rgba(2,6,23,0.92) 100%);
}

.lightbox-caption .muted {
    color: rgba(255,255,255,0.75);
}

.lightbox-close,
.lightbox-nav {
    position: relative;
    z-index: 2;
    border: 0;
    border-radius: 999px;
    width: 52px;
    height: 52px;
    background: rgba(255,255,255,0.16);
    color: #fff;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    backdrop-filter: blur(10px);
}

.lightbox-close {
    position: absolute;
    top: max(14px, env(safe-area-inset-top));
    right: 14px;
}

.lightbox-nav.prev {
    grid-column: 1;
    justify-self: center;
}

.lightbox-nav.next {
    grid-column: 3;
    justify-self: center;
}

.lightbox-nav:disabled {
    opacity: 0.45;
}

@media (max-width: 860px) {
    .content {
        padding: 12px 10px 90px;
    }

    .topbar {
        grid-template-columns: auto 1fr auto;
        gap: 10px;
    }

    .topbar-brand small,
    .topbar-link,
    .home-toolbar p,
    .section-head .muted {
        display: none;
    }

    .search-inline {
        order: 2;
        grid-column: 1 / -1;
    }

    .topbar-actions {
        order: 1;
    }

    .home-toolbar {
        gap: 8px;
    }

    .stat-chips {
        gap: 8px;
    }

    .stat-chip {
        padding: 8px 12px;
        font-size: 0.88rem;
    }

    .card {
        padding: 16px;
        border-radius: 18px;
    }

    .media-grid,
    .media-grid-photo-first {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .media-meta {
        padding: 16px 9px 9px;
    }

    .media-meta .muted,
    .media-meta .badge {
        display: none;
    }

    .lightbox-shell {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }

    .lightbox-stage {
        grid-column: 1;
        grid-row: 2;
        padding: 8px;
    }

    .lightbox-stage img,
    .lightbox-stage video {
        max-height: calc(100vh - 120px);
        width: 100%;
        border-radius: 14px;
    }

    .lightbox-nav {
        position: absolute;
        bottom: calc(76px + env(safe-area-inset-bottom));
        width: 46px;
        height: 46px;
        font-size: 1.7rem;
    }

    .lightbox-nav.prev {
        left: 10px;
    }

    .lightbox-nav.next {
        right: 10px;
    }

    .fab-add {
        bottom: calc(16px + env(safe-area-inset-bottom));
    }
}

@media (max-width: 560px) {
    .menu-toggle,
    .sidebar-close {
        width: 44px;
        height: 44px;
    }

    .topbar-actions .btn-primary {
        padding: 11px 14px;
    }

    .media-grid,
    .media-grid-photo-first {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .media-thumb {
        aspect-ratio: 1 / 1;
    }
}
