:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --text: #20252d;
    --muted: #6c7480;
    --line: #d9dee7;
    --accent: #0f766e;
    --accent-soft: #e3f5f1;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}

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

.topbar {
    height: 58px;
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
    align-items: center;
    gap: 16px;
    padding: 0 22px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}

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

.topbar-center {
    display: flex;
    justify-content: center;
    min-width: 0;
}

.user-menu {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.user-menu .button {
    min-height: 32px;
    padding: 6px 10px;
}

.account-expiry {
    padding: 4px 8px;
    border-radius: 6px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.account-expiry.expiry-warning {
    background: #fff1f0;
    color: #9f2d24;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(135deg, #f7f8fa 0%, #eef4f2 100%);
}

.login-shell {
    width: min(420px, 100%);
}

.login-panel {
    padding: 28px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 20px 50px rgba(32, 37, 45, .12);
}

.login-brand {
    color: var(--accent);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.login-panel h1 {
    margin: 8px 0 10px;
}

.login-form {
    display: grid;
    gap: 14px;
    margin-top: 22px;
}

.login-form label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.login-form input,
.login-form select {
    min-height: 42px;
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #ffffff;
    color: var(--text);
    font: inherit;
}

.login-form input:focus,
.login-form select:focus {
    outline: 2px solid rgba(15, 118, 110, .18);
    border-color: var(--accent);
}

.primary-button {
    width: 100%;
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

.primary-button:hover {
    background: #0d635d;
    color: #ffffff;
}

.login-error {
    margin: 18px 0 0;
    padding: 10px 12px;
    background: #fff1f0;
    border: 1px solid #f1b8b4;
    border-radius: 6px;
    color: #9f2d24;
    font-weight: 700;
    white-space: pre-line;
}

.password-rules {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
}

.password-option {
    display: inline-flex !important;
    align-items: center;
    gap: 8px;
    width: fit-content;
    color: var(--text) !important;
    font-size: 13px;
}

.password-option input {
    width: auto;
    min-height: 0;
    padding: 0;
    accent-color: var(--accent);
}

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

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

.sidebar-title,
.eyebrow {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.project-list {
    display: grid;
    gap: 6px;
    margin-top: 14px;
}

.project-list a {
    min-height: 40px;
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 14px;
}

.project-list a:hover,
.project-list a.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.content {
    padding: 28px;
}

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

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 8px 13px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
}

.button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.button:disabled {
    cursor: not-allowed;
    opacity: .58;
}

h1 {
    margin: 6px 0 0;
    font-size: 28px;
    line-height: 1.2;
}

h2 {
    margin: 28px 0 12px;
    font-size: 18px;
}

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

.message {
    margin: 0 0 16px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.message p {
    margin: 6px 0 0;
}

.warning-message {
    border-color: #e7b263;
    background: #fff8eb;
    color: #7d4f00;
}

.diagnostic-message {
    border-color: #9bb7df;
    background: #f0f6ff;
    color: #233b5e;
}

.success-message {
    border-color: #8bc7a0;
    background: #effaf3;
    color: #285c3a;
}

.upload-panel {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(190px, auto) minmax(190px, auto) auto;
    align-items: end;
    gap: 14px;
    margin: 0 0 22px;
    padding: 14px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.upload-panel strong,
.upload-panel small {
    display: block;
}

.upload-panel small {
    margin-top: 4px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
}

.upload-picker {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.upload-picker input {
    max-width: 100%;
    color: var(--text);
    font: inherit;
}

.upload-button.primary-button {
    width: auto;
    white-space: nowrap;
}

.upload-status {
    grid-column: 1 / -1;
    display: grid;
    gap: 8px;
    padding-top: 2px;
}

.upload-status[hidden] {
    display: none;
}

.upload-status-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: var(--muted);
    font-size: 13px;
}

.upload-status-head strong {
    color: var(--text);
}

.upload-progress {
    overflow: hidden;
    height: 10px;
    background: #eef1f5;
    border: 1px solid var(--line);
    border-radius: 999px;
}

.upload-progress span {
    width: 0;
    height: 100%;
    display: block;
    background: var(--accent);
    transition: width .2s ease;
}

.upload-status p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
}

.upload-status ul {
    max-height: 92px;
    margin: 0;
    padding-left: 18px;
    overflow: auto;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.settings-page {
    padding: 28px;
}

.settings-section {
    margin-top: 22px;
}

.settings-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 14px;
}

.settings-toolbar h2 {
    margin: 0;
}

.settings-section-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
}

.settings-subsection {
    margin-bottom: 18px;
}

.settings-subsection h3 {
    margin: 0 0 10px;
    font-size: 15px;
}

.settings-form {
    display: grid;
    gap: 16px;
}

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

.settings-fields label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.settings-fields input[type="text"],
.settings-fields input[type="date"],
.settings-fields select,
.access-table select,
.date-input,
.compact-input {
    min-height: 36px;
    width: 100%;
    padding: 7px 9px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #ffffff;
    color: var(--text);
    font: inherit;
}

.settings-fields input:focus,
.settings-fields select:focus,
.access-table select:focus,
.date-input:focus,
.compact-input:focus {
    outline: 2px solid rgba(15, 118, 110, .18);
    border-color: var(--accent);
}

.checkbox-line {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
}

.checkbox-line input,
.access-table input[type="checkbox"] {
    width: 17px;
    height: 17px;
    accent-color: var(--accent);
}

.primary-action {
    width: max-content;
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

.primary-action:hover {
    background: #0d635d;
    color: #ffffff;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(32, 37, 45, .42);
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-shell {
    width: min(440px, 100%);
}

.new-user-modal,
.new-project-modal {
    display: grid;
    gap: 18px;
}

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

.modal-head h1 {
    margin-top: 8px;
}

.icon-action {
    width: 34px;
    min-height: 34px;
    padding: 0;
    font-size: 22px;
    line-height: 1;
}

.password-generate-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.access-table-wrap {
    overflow: auto;
    margin-bottom: 14px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.access-table {
    width: 100%;
    min-width: 920px;
    border-collapse: collapse;
    font-size: 13px;
}

.account-table {
    min-width: 860px;
}

.permissions-table {
    min-width: max(680px, 100%);
}

.access-table th,
.access-table td {
    padding: 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.access-table th:nth-child(3),
.access-table td:nth-child(3) {
    min-width: 132px;
}

.access-table th:nth-child(4),
.access-table td:nth-child(4) {
    min-width: 92px;
}

.access-table th:nth-child(5),
.access-table td:nth-child(5) {
    min-width: 138px;
}

.access-table th:nth-child(6),
.access-table td:nth-child(6) {
    min-width: 278px;
}

.access-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #eef4f2;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.access-table th:not(:first-child),
.access-table td:not(:first-child) {
    border-left: 1px solid var(--line);
}

.access-table tbody tr:last-child td {
    border-bottom: 0;
}

.account-table td:nth-child(1),
.permissions-table td:not(:first-child) {
    text-align: center;
}

.access-table.permissions-table th,
.access-table.permissions-table td {
    min-width: 112px;
}

.permissions-table th:first-child,
.permissions-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    min-width: 160px;
    background: var(--panel);
}

.permissions-table th:first-child {
    z-index: 3;
    background: #eef4f2;
}

.access-table small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-weight: 700;
}

.access-table select {
    min-width: 112px;
}

.date-input {
    min-width: 118px;
}

.row-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.small-action,
.danger-action {
    min-height: 30px;
    padding: 5px 9px;
    font-size: 12px;
}

.danger-action {
    border-color: #e3aaa5;
    color: #9f2d24;
}

.danger-action:hover {
    border-color: #9f2d24;
    color: #9f2d24;
}

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

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(112px, 112px));
    gap: 10px;
    align-items: start;
}

.photo-grid a {
    overflow: hidden;
    width: 112px;
    max-width: 112px;
    display: grid;
    grid-template-rows: 84px auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.photo-grid a img {
    width: 112px !important;
    max-width: 112px !important;
    height: 84px !important;
    max-height: 84px !important;
    display: block;
    object-fit: cover;
    background: var(--accent-soft);
}

.thumb-placeholder {
    width: 112px;
    height: 84px;
    display: grid;
    place-items: center;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 18px;
    font-weight: 800;
}

.photo-grid a span {
    min-height: 34px;
    max-height: 48px;
    padding: 6px 7px;
    color: var(--text);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    overflow-wrap: anywhere;
    overflow: hidden;
}

.photo-card {
    overflow: hidden;
    display: grid;
    grid-template-rows: 84px auto;
    width: 112px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.photo-card:hover {
    border-color: var(--accent);
}

.photo-card img {
    width: 100%;
    height: 84px;
    display: block;
    object-fit: cover;
    background: var(--accent-soft);
}

.photo-card.missing-thumb {
    border-style: dashed;
}

.photo-card span {
    min-height: 34px;
    max-height: 48px;
    padding: 6px 7px;
    color: var(--text);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    overflow-wrap: anywhere;
    overflow: hidden;
}

.tile {
    min-height: 78px;
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 14px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.tile:hover {
    border-color: var(--accent);
}

.muted-tile:hover {
    border-color: var(--line);
}

.tile-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 6px;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 700;
}

.tile strong,
.tile small {
    display: block;
}

.tile small {
    margin-top: 4px;
    color: var(--muted);
}

.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
    margin-bottom: 12px;
}

.breadcrumbs a {
    color: var(--accent);
    font-weight: 700;
}

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

.file-row {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
}

.file-name {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 11px;
}

.file-name strong,
.file-name small {
    display: block;
}

.file-name strong {
    overflow-wrap: anywhere;
}

.file-icon {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 6px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
}

.file-thumb {
    overflow: hidden;
    width: 52px;
    height: 42px;
    display: block;
    flex: 0 0 auto;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--accent-soft);
}

.file-thumb img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.file-thumb span {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    color: var(--accent);
    font-size: 11px;
    font-weight: 800;
}

.file-thumb.missing-thumb {
    border-style: dashed;
}

.file-row:last-child {
    border-bottom: 0;
}

.file-row small {
    color: var(--muted);
    font-weight: 700;
}

.file-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.file-actions a {
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
}

.file-actions a:hover {
    border-color: var(--accent);
}

.has-preview {
    overflow: hidden;
}

.preview-modal[hidden] {
    display: none;
}

.preview-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 20px;
}

.preview-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(22, 28, 36, .72);
}

.preview-dialog {
    position: relative;
    width: min(1100px, 96vw);
    max-height: 94vh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    overflow: hidden;
    background: var(--panel);
    border-radius: 8px;
    box-shadow: 0 20px 70px rgba(0, 0, 0, .28);
}

.preview-header,
.preview-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
}

.preview-footer {
    justify-content: flex-end;
    border-top: 1px solid var(--line);
    border-bottom: 0;
}

.preview-close {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.preview-close:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.preview-body {
    min-height: 220px;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: #111820;
}

.preview-body img {
    max-width: 100%;
    max-height: calc(94vh - 126px);
    display: block;
    object-fit: contain;
}

.preview-body iframe {
    width: 100%;
    height: calc(94vh - 126px);
    border: 0;
    background: #ffffff;
}

.preview-nav {
    position: absolute;
    top: 50%;
    width: 42px;
    height: 54px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .35);
    border-radius: 6px;
    background: rgba(0, 0, 0, .35);
    color: #ffffff;
    font-size: 34px;
    line-height: 1;
    cursor: pointer;
    transform: translateY(-50%);
}

.preview-nav:hover {
    background: rgba(0, 0, 0, .55);
}

.preview-nav[hidden] {
    display: none;
}

.preview-prev {
    left: 14px;
}

.preview-next {
    right: 14px;
}

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

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

    .file-row {
        align-items: flex-start;
        flex-direction: column;
    }

    .file-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .upload-panel {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .settings-toolbar,
    .settings-section-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .password-generate-row {
        grid-template-columns: 1fr;
    }

    .password-generate-row .button {
        width: 100%;
    }

    .preview-modal {
        padding: 10px;
    }

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

    .preview-footer .button {
        width: 100%;
    }
}
