:root {
    --bg: #f5ebe0;
    --surface: #ffffff;
    --sidebar: #3d2e1f;
    --sidebar-hover: #4d3a28;
    --text: #3d2e1f;
    --text-muted: #7a6654;
    --border: #e8dcc8;
    --primary: #a67c52;
    --primary-dark: #8b6344;
    --primary-light: #f5ebe0;
    --brand-light: #d4b896;
    --success: #166534;
    --success-bg: #dcfce7;
    --error: #b91c1c;
    --error-bg: #fee2e2;
    --warning: #92400e;
    --warning-bg: #fef3c7;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(61, 46, 31, 0.08), 0 4px 16px rgba(61, 46, 31, 0.04);
    --mobile-nav-height: 64px;
    --font: 'Plus Jakarta Sans', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.hidden { display: none !important; }

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { color: var(--primary); }

/* App shell */
.app-shell {
    display: flex;
    min-height: 100vh;
    max-width: 100vw;
    overflow-x: hidden;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* Sidebar */
.sidebar {
    width: 220px;
    background: var(--sidebar);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    padding: 1rem 0.65rem;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.35rem 0.5rem 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 0.5rem;
    text-decoration: none;
    color: inherit;
}

.sidebar-brand:hover {
    text-decoration: none;
    color: inherit;
    opacity: 0.95;
}

.brand-icon {
    width: 42px;
    height: 42px;
    background: #fff;
    border-radius: 12px;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--primary-dark);
    flex-shrink: 0;
    overflow: hidden;
    border: 1px solid rgba(61, 46, 31, 0.08);
    box-shadow: 0 4px 12px rgba(61, 46, 31, 0.12), 0 1px 3px rgba(61, 46, 31, 0.06);
    padding: 5px;
    box-sizing: border-box;
}

.brand-icon:not(img) {
    background: #fff;
    color: var(--primary-dark);
}

.brand-icon-img,
img.brand-icon {
    object-fit: contain;
    padding: 5px;
    background: #fff;
}

/* Explicit logo tile (white rounded square) */
.brand-mark {
    width: 42px;
    height: 42px;
    background: #fff;
    border-radius: 12px;
    border: 1px solid rgba(61, 46, 31, 0.1);
    box-shadow: 0 6px 16px rgba(61, 46, 31, 0.14), 0 1px 3px rgba(61, 46, 31, 0.06);
    display: grid;
    place-items: center;
    padding: 5px;
    box-sizing: border-box;
    flex-shrink: 0;
    overflow: visible;
}

.brand-mark img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    object-position: center;
    display: block;
    border-radius: 0;
}

.brand-mark-initials {
    font-weight: 800;
    font-size: 0.8rem;
    color: var(--primary-dark);
    line-height: 1;
}

.brand-mark-lg {
    width: 112px;
    height: 112px;
    border-radius: 24px;
    padding: 16px;
    margin: 0 auto 1rem;
    box-shadow: 0 12px 32px rgba(61, 46, 31, 0.14), 0 2px 8px rgba(61, 46, 31, 0.06);
}

.brand-mark-lg .brand-mark-initials {
    font-size: 1.4rem;
}

.sidebar-brand strong {
    display: block;
    font-size: 0.95rem;
    color: white;
}

.sidebar-brand span {
    font-size: 0.75rem;
    color: #94a3b8;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.65rem;
    border-radius: 8px;
    color: #cbd5e1;
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.12s, color 0.12s;
    text-decoration: none;
    min-height: 42px;
    touch-action: manipulation;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.9;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: #f8fafc;
    text-decoration: none;
}

.nav-item.active {
    background: rgba(166, 124, 82, 0.28);
    color: #f5ebe0;
}

.nav-item.active svg { opacity: 1; color: var(--brand-light); }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.75rem 0.5rem 0.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin-top: 0.5rem;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
}

.user-avatar-link {
    display: block;
    text-decoration: none;
    flex-shrink: 0;
}

.user-avatar-img {
    object-fit: cover;
    object-position: center 18%;
    padding: 0;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-info strong {
    display: block;
    font-size: 0.8rem;
    color: #f1f5f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-logout {
    color: #94a3b8;
    padding: 0.35rem;
    display: grid;
    place-items: center;
    border-radius: 8px;
    transition: color 0.15s, background 0.15s;
}

.btn-logout svg { width: 20px; height: 20px; }
.btn-logout:hover { color: #fca5a5; background: rgba(255,255,255,0.06); text-decoration: none; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(61, 46, 31, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

body.sidebar-open { overflow: hidden; }

.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex: none;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--primary);
    cursor: pointer;
    touch-action: manipulation;
}

.sidebar-toggle svg { width: 22px; height: 22px; }

/* Main content */
.main-content {
    flex: 1;
    margin-left: 220px;
    padding: 1.5rem 2rem 2rem;
    max-width: 1200px;
    width: 100%;
    min-width: 0;
}

.topbar {
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

.topbar-left {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    min-width: 0;
    flex: 1;
}

.topbar-titles { min-width: 0; }

.topbar h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

.topbar p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.2rem;
}

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

.page-header h1 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 0.2rem;
}

.text-muted { color: var(--text-muted); font-size: 0.875rem; }
.header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Cards / panels */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}

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

.card-header h2 {
    font-size: 1.05rem;
    font-weight: 600;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.15rem;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    box-shadow: var(--shadow);
    transition: transform 0.15s, border-color 0.15s;
}

.stat-card:hover {
    transform: translateY(-1px);
    border-color: var(--brand-light);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    font-size: 1.35rem;
    flex-shrink: 0;
}

.stat-blue { background: var(--primary-light); }
.stat-purple { background: #e0e7ff; }
.stat-green { background: #dcfce7; }
.stat-warning { background: var(--warning-bg); }

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1rem;
    border-radius: 10px;
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
    touch-action: manipulation;
    min-height: 42px;
}

.btn:hover { text-decoration: none; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    border: 1px solid var(--primary-dark);
}

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

.btn-outline {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary-dark);
    background: var(--primary-light);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: none;
    min-height: auto;
}

.btn-danger {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid #fecaca;
}

.btn-danger:hover { background: #fecaca; }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.78rem; min-height: 34px; border-radius: 8px; }
.btn-lg { padding: 0.75rem 1.25rem; font-size: 0.95rem; }
.btn-block { width: 100%; }

/* Forms */
.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: var(--text-muted);
}

.form-group input,
.form-group select,
.form-group textarea,
.search-input,
.select-input {
    width: 100%;
    padding: 0.65rem 0.85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.9rem;
    transition: border-color 0.15s, box-shadow 0.15s;
    min-height: 44px;
}

.form-group input:focus,
.form-group select:focus,
.search-input:focus,
.select-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(166, 124, 82, 0.15);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.checkbox-group { margin-top: 0.5rem; }

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    line-height: 1.45;
}

.form-actions { margin-top: 1.25rem; }

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 10px;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.45;
}

.alert-success {
    background: var(--success-bg);
    border: 1px solid #86efac;
    color: var(--success);
}

.alert-error {
    background: var(--error-bg);
    border: 1px solid #fca5a5;
    color: var(--error);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-superadmin { background: var(--warning-bg); color: var(--warning); }
.badge-admin { background: var(--primary-light); color: var(--primary-dark); }
.badge-user { background: var(--success-bg); color: var(--success); }
.badge-type { background: var(--primary-light); color: var(--primary-dark); padding: 0.2rem 0.55rem; font-size: 0.72rem; margin-bottom: 0.35rem; }

.status-active { color: var(--success); font-size: 0.85rem; font-weight: 600; }
.status-inactive { color: var(--text-muted); font-size: 0.85rem; }

/* Tables */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -0.25rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    min-width: 520px;
}

.data-table th {
    text-align: left;
    padding: 0.65rem 0.85rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
    background: #faf7f2;
}

.data-table td {
    padding: 0.75rem 0.85rem;
    border-bottom: 1px solid var(--border);
}

.data-table tr:hover td { background: #faf7f2; }

.file-cell { display: flex; align-items: center; gap: 0.5rem; }
.file-icon { font-size: 1.15rem; }

.actions {
    display: flex;
    gap: 0.35rem;
    align-items: center;
    flex-wrap: wrap;
}

.inline-form { display: inline; }

/* File grid */
.filter-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.filter-bar .search-input { flex: 1; min-width: 160px; }
.filter-bar .select-input { width: auto; min-width: 140px; }

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

.file-card {
    background: #faf7f2;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0;
    overflow: hidden;
    transition: border-color 0.15s, box-shadow 0.15s;
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
}

.file-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow);
}

.file-card.is-selected {
    border-color: var(--primary-dark);
    box-shadow: 0 0 0 2px rgba(166, 124, 82, 0.25);
}

.file-card-icon { font-size: 2rem; margin: 1rem 1rem 0.65rem; }

.file-card-body {
    padding: 0 1rem;
    flex: 1;
    min-width: 0;
}

.file-card-body h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
    word-break: break-word;
}

.file-desc { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.5rem; }

.file-meta {
    display: flex;
    gap: 0.65rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.file-uploader { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.25rem; }

.file-card-actions {
    display: flex;
    gap: 0.35rem;
    margin-top: 0.85rem;
    padding: 0 1rem 1rem;
    flex-wrap: wrap;
}

.file-card-thumb {
    display: block;
    width: 100%;
    height: 160px;
    min-height: 160px;
    max-height: 160px;
    background: #ece6dc;
    overflow: hidden;
    flex-shrink: 0;
    text-decoration: none;
}

.file-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 20%;
    display: block;
    transition: transform 0.2s;
}

.file-card-thumb:hover img { transform: scale(1.03); }

.file-card-thumb.is-broken {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    background: var(--primary-light);
}

.file-card-thumb.is-broken::after { content: '🖼️'; }

.table-thumb {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

/* View mode toggle */
.view-mode-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.view-mode-toggle {
    display: inline-flex;
    background: #faf7f2;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px;
    gap: 2px;
}

.view-mode-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    min-height: 40px;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.15s;
}

.view-mode-btn svg { width: 16px; height: 16px; }

.view-mode-btn:hover {
    color: var(--text);
    text-decoration: none;
    background: rgba(255,255,255,0.6);
}

.view-mode-btn.active {
    background: var(--primary);
    color: #fff;
}

.view-mode-hint {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* Photo gallery */
.photo-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.65rem;
}

.gallery-item {
    position: relative;
    padding: 0;
    border: none;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    background: #ece6dc;
    aspect-ratio: 1;
    min-height: 120px;
    touch-action: manipulation;
    content-visibility: auto;
    contain-intrinsic-size: 140px;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 20%;
    display: block;
    transition: transform 0.2s;
    background: #e8e0d4;
}

.gallery-item:hover img { transform: scale(1.05); }

.gallery-item-overlay {
    position: absolute;
    inset: auto 0 0 0;
    padding: 0.45rem 0.5rem;
    background: linear-gradient(transparent, rgba(61, 46, 31, 0.75));
    opacity: 0;
    transition: opacity 0.2s;
}

.gallery-item:hover .gallery-item-overlay,
.gallery-item:focus-visible .gallery-item-overlay { opacity: 1; }

.gallery-item-name {
    font-size: 0.72rem;
    color: #fff;
    font-weight: 600;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-item-wrap {
    position: relative;
}

.gallery-item-wrap .gallery-item {
    width: 100%;
}

.gallery-item-wrap.is-selected .gallery-item {
    box-shadow: 0 0 0 2px var(--primary-dark);
}

.bulk-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    margin: 0 0 0.85rem;
    background: #faf7f2;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.bulk-select-all {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    user-select: none;
}

.bulk-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-right: auto;
}

.file-check {
    position: absolute;
    top: 0.55rem;
    left: 0.55rem;
    z-index: 3;
    cursor: pointer;
    display: block;
}

.file-check input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.file-check-box {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: #fff;
    border: 2px solid rgba(61, 46, 31, 0.35);
    box-shadow: 0 1px 4px rgba(61, 46, 31, 0.15);
    display: grid;
    place-items: center;
}

.file-check input:checked + .file-check-box {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.file-check input:checked + .file-check-box::after {
    content: '';
    width: 5px;
    height: 9px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg) translate(-1px, -1px);
}

.file-check input:focus-visible + .file-check-box {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.gallery-check {
    top: 0.45rem;
    left: 0.45rem;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Lightbox */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox.hidden { display: none !important; }

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(61, 46, 31, 0.88);
}

.lightbox-panel {
    position: relative;
    z-index: 1;
    width: min(960px, 100vw);
    height: min(90vh, 100dvh);
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
}

.lightbox-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    color: #fff;
}

.lightbox-info strong {
    display: block;
    font-size: 0.95rem;
    margin-bottom: 0.15rem;
    word-break: break-word;
}

.lightbox-info span { font-size: 0.8rem; opacity: 0.85; }

.lightbox-actions { display: flex; gap: 0.5rem; align-items: center; flex-shrink: 0; }

.lightbox-close {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

.lightbox-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

.lightbox-stage img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.35);
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
}

.lightbox-prev { left: 0.5rem; }
.lightbox-next { right: 0.5rem; }

.lightbox-counter {
    text-align: center;
    color: rgba(255,255,255,0.85);
    font-size: 0.82rem;
    font-weight: 600;
    margin-top: 0.5rem;
}

/* Upload */
.dropzone {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 1.25rem;
    text-align: center;
    margin-bottom: 1.25rem;
    transition: all 0.15s;
    cursor: pointer;
    background: #faf7f2;
}

.dropzone:hover,
.dropzone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.dropzone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.dropzone-icon { font-size: 2.5rem; margin-bottom: 0.65rem; }
.dropzone-content p { margin-bottom: 0.25rem; font-size: 0.9rem; }

.selected-file {
    margin-top: 0.65rem;
    font-size: 0.85rem;
    color: var(--primary-dark);
    font-weight: 600;
}

.upload-progress-hint {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.upload-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.25rem;
}

.upload-tabs::-webkit-scrollbar { display: none; }

.upload-tab {
    flex: 1;
    min-width: max-content;
    padding: 0.55rem 1rem;
    min-height: 44px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.upload-tab:hover { border-color: var(--primary); color: var(--text); }

.upload-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.upload-panel { display: none; }
.upload-panel.active { display: block; }

/* Preview */
.preview-card { padding: 0; overflow: hidden; }

.preview-image {
    display: flex;
    justify-content: center;
    padding: 1.25rem;
    background: #faf7f2;
}

.preview-image img {
    max-width: 100%;
    max-height: 70vh;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.preview-pdf {
    width: 100%;
    height: 75vh;
    border: none;
    background: #fff;
}

.preview-text {
    padding: 1.25rem;
    background: #faf7f2;
    font-family: ui-monospace, monospace;
    font-size: 0.82rem;
    line-height: 1.6;
    overflow: auto;
    max-height: 70vh;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
}

.empty-icon { font-size: 2.5rem; margin-bottom: 0.65rem; }
.empty-state p { color: var(--text-muted); margin-bottom: 1rem; font-size: 0.9rem; }

/* Storage stats */
.storage-overview-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.storage-overview-head h2 { font-size: 1.05rem; margin-bottom: 0.25rem; }

.storage-percent-badge {
    font-size: 1.25rem;
    font-weight: 800;
    padding: 0.35rem 0.75rem;
    border-radius: 10px;
    background: var(--primary-light);
    color: var(--primary-dark);
}

.storage-bar-track {
    height: 14px;
    background: #f1f5f9;
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.storage-bar-sm { height: 10px; }

.storage-bar-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.5s ease;
    min-width: 2%;
}

.storage-bar-normal { background: linear-gradient(90deg, var(--primary), var(--primary-dark)); }
.storage-bar-warning { background: linear-gradient(90deg, #f59e0b, #d97706); }
.storage-bar-danger { background: linear-gradient(90deg, #ef4444, #b91c1c); }

.storage-meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 0.65rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.storage-meta-row strong { color: var(--text); }

.storage-widget .storage-meta-row { margin-top: 0.75rem; }

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}

.bar-chart { display: flex; flex-direction: column; gap: 0.75rem; }

.bar-row {
    display: grid;
    grid-template-columns: 72px 1fr 88px;
    align-items: center;
    gap: 0.65rem;
}

.bar-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bar-track {
    height: 24px;
    background: #f1f5f9;
    border-radius: 6px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--primary), var(--primary-dark));
    min-width: 4px;
    transition: width 0.4s ease;
}

.bar-fill-alt { background: linear-gradient(90deg, #6366f1, #4f46e5); }
.bar-fill-teal { background: linear-gradient(90deg, #0d9488, #059669); }

.bar-value {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text);
    text-align: right;
    white-space: nowrap;
}

.mini-bar-track {
    height: 8px;
    background: #f1f5f9;
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 0.25rem;
    min-width: 80px;
}

.mini-bar-fill {
    height: 100%;
    border-radius: 999px;
    min-width: 4px;
}

/* Chart cards */
.chart-card h2 { margin-bottom: 0.25rem; }

.chart-desc {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 0.85rem;
}

.chart-card-wide { margin-bottom: 1.25rem; }

.chart-wrap {
    position: relative;
    height: 260px;
    width: 100%;
}

.chart-wrap-donut { height: 280px; max-width: 320px; margin: 0 auto; }

.chart-wrap-line { height: 300px; }

/* Mobile bottom nav */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 180;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 0.35rem 0.5rem;
    padding-bottom: max(0.35rem, env(safe-area-inset-bottom));
    box-shadow: 0 -4px 16px rgba(61, 46, 31, 0.08);
}

.mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    padding: 0.35rem 0.25rem;
    min-height: 52px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    border-radius: 10px;
    touch-action: manipulation;
}

.mobile-nav-item svg {
    width: 22px;
    height: 22px;
}

.mobile-nav-item.active,
.mobile-nav-item:hover {
    color: var(--primary-dark);
    background: var(--primary-light);
    text-decoration: none;
}

/* Auth / Login — gaya MANIS */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 1.25rem;
    padding-top: max(1.25rem, env(safe-area-inset-top));
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
    background: var(--bg);
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2rem 1.75rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
}

.auth-card-wide { max-width: 440px; }

.auth-logo {
    text-align: center;
    margin-bottom: 1.75rem;
}

.brand-icon-lg {
    width: 88px;
    height: 88px;
    background: #fff;
    border-radius: 22px;
    display: inline-grid;
    place-items: center;
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--primary-dark);
    margin-bottom: 1rem;
    border: 1px solid rgba(61, 46, 31, 0.08);
    box-shadow: 0 10px 28px rgba(61, 46, 31, 0.12), 0 2px 8px rgba(61, 46, 31, 0.06);
    padding: 14px;
    box-sizing: border-box;
    overflow: hidden;
    vertical-align: top;
}

img.brand-icon-lg,
.brand-icon-lg.brand-icon-img {
    object-fit: contain;
    padding: 14px;
    background: #fff;
}

.auth-logo h1 {
    font-size: 1.65rem;
    font-weight: 800;
    color: var(--primary-dark);
    letter-spacing: 0.04em;
    margin-bottom: 0.25rem;
}

.auth-tagline {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 0.65rem;
}

.auth-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.auth-form .form-group { margin-bottom: 1rem; }

.auth-form .form-group label {
    font-size: 0.82rem;
    color: var(--text);
}

.auth-footer {
    margin-top: 1.25rem;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.password-wrap {
    position: relative;
}

.password-wrap input { padding-right: 7rem; }

.toggle-password {
    position: absolute;
    right: 0.65rem;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: none;
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.25rem;
}

/* Responsive */
@media (max-width: 900px) {
    .sidebar-toggle { display: inline-flex; }

    .sidebar {
        width: min(280px, 88vw);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        padding-top: max(1rem, env(safe-area-inset-top));
        padding-bottom: max(0.65rem, env(safe-area-inset-bottom));
        max-height: 100dvh;
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: 8px 0 32px rgba(61, 46, 31, 0.28);
    }

    body.sidebar-open .sidebar-overlay {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    body.has-mobile-bottom-nav.sidebar-open .sidebar-overlay {
        bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px));
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: max(1rem, env(safe-area-inset-top));
        padding-bottom: calc(var(--mobile-nav-height) + 1rem + env(safe-area-inset-bottom, 0px));
        max-width: 100%;
    }

    .mobile-bottom-nav {
        display: flex;
    }

    .topbar {
        margin-bottom: 1rem;
        padding-bottom: 0.75rem;
        border-bottom: 1px solid var(--border);
    }

    .topbar h1 { font-size: 1.25rem; }

    .page-header h1 { font-size: 1.05rem; }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.65rem;
    }

    .stat-card { padding: 0.85rem; gap: 0.65rem; }
    .stat-icon { width: 40px; height: 40px; font-size: 1.1rem; }
    .stat-value { font-size: 1.25rem; }
    .stat-label { font-size: 0.72rem; }

    .card { padding: 1rem; }
    .form-row { grid-template-columns: 1fr; }

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

    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar .search-input,
    .filter-bar .select-input { width: 100%; min-width: 0; }

    .page-header { flex-direction: column; }
    .page-header .btn { width: 100%; }

    .header-actions { width: 100%; }
    .header-actions .btn { flex: 1; }

    .file-card-actions .btn { flex: 1; min-width: calc(50% - 0.2rem); }

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

    .bar-row { grid-template-columns: 56px 1fr 72px; gap: 0.45rem; }
    .bar-value { font-size: 0.68rem; }

    .photo-gallery {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
        gap: 0.5rem;
    }

    .gallery-item-overlay { opacity: 1; }

    .lightbox-nav { width: 36px; height: 36px; font-size: 1.4rem; }

    .chart-wrap { height: 220px; }
    .chart-wrap-donut { height: 240px; max-width: 100%; }
    .chart-wrap-line { height: 260px; }

    .actions { flex-direction: column; align-items: stretch; }
    .actions .btn { width: 100%; justify-content: center; }

    .data-table { font-size: 0.82rem; }
}

@media (max-width: 560px) {
    .main-content { padding: 0.75rem; padding-bottom: calc(var(--mobile-nav-height) + 0.75rem + env(safe-area-inset-bottom, 0px)); }

    .auth-card { padding: 1.5rem 1.25rem; }

    .dropzone { padding: 1.75rem 1rem; }

    .upload-tab { font-size: 0.78rem; padding: 0.5rem 0.75rem; }

    .topbar h1 { font-size: 1.15rem; }
}

/* Settings / profile */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

.settings-form .form-group { margin-bottom: 1rem; }

.profile-photo-row {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1.25rem;
}

.profile-photo-preview {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 1.5rem;
    font-weight: 700;
    overflow: hidden;
    flex-shrink: 0;
    border: 2px solid var(--border);
}

.profile-photo-preview.brand-preview {
    border-radius: 14px;
}

.profile-photo-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 18%;
}

.profile-photo-preview.brand-preview img {
    object-fit: contain;
    object-position: center;
    padding: 8px;
    background: #fff;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

