:root {
    --wine: #722433;
    --wine-dark: #541826;
    --gold: #9c7a45;
    --ink: #241910;
    --muted: #6f6258;
    --line: #eadfd3;
    --cream: #f3eee6;
    --paper: #fffcf8;
    --danger: #8d2f2f;
    --ok: #1d6844;
    --ok-bg: #e7f4ec;
    --error-bg: #fdeceb;
    --shadow: 0 18px 50px rgba(55, 28, 18, 0.06);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
    font-family: Outfit, "Segoe UI", sans-serif;
    color: var(--ink);
    font-size: 16.5px;
    line-height: 1.5;
}

button, input, textarea, select { font: inherit; }

:focus-visible {
    outline: 3px solid rgba(114, 36, 51, 0.35);
    outline-offset: 2px;
}

h1, h2, h3 {
    font-family: Fraunces, Georgia, serif;
    font-weight: 560;
    letter-spacing: -0.03em;
}

.gate {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px 16px;
    background:
        radial-gradient(900px 520px at 50% 115%, rgba(176, 92, 68, 0.42), transparent 58%),
        radial-gradient(700px 420px at 100% 0%, rgba(120, 48, 58, 0.45), transparent 52%),
        linear-gradient(165deg, #3a221c 0%, #1a1210 48%, #271612 100%);
}

.gate-card {
    width: min(440px, 100%);
    background: var(--paper);
    color: var(--ink);
    border-radius: 28px;
    padding: 44px 40px 36px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.38);
}

.gate-card h1 {
    margin: 8px 0 22px;
    text-align: center;
    font-size: 1.85rem;
    line-height: 1.15;
}

.gate .flash { margin-bottom: 16px; }

.gate .flash.ok {
    background: #f3eee4;
    color: #3d342c;
}

.app {
    min-height: 100dvh;
    background:
        radial-gradient(880px 380px at 100% -10%, rgba(174, 132, 86, 0.18), transparent 55%),
        var(--cream);
    padding-bottom: 72px;
}

.wrap {
    width: min(1080px, calc(100% - 32px));
    margin: 0 auto;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: 0 -8px;
    padding: 10px 8px 0;
    background: var(--cream);
    box-shadow: 0 1px 0 var(--line);
}

.mast {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 28px;
    padding: 0 0 10px;
}

.mast h1 {
    margin: 0;
    font-size: clamp(1.7rem, 3.2vw, 2.7rem);
    line-height: 1.15;
    white-space: nowrap;
}

.mast h1 a,
.mast h1 a:any-link,
.mast h1 a:hover,
.mast h1 a:active,
.mast h1 a:focus {
    color: var(--ink);
    text-decoration: none;
}

.mast h1 span,
.mast h1 a:any-link span,
.mast h1 a:hover span,
.mast h1 a:active span {
    display: block;
    color: var(--wine);
    text-decoration: none;
    white-space: nowrap;
}

.mast-main .tabs {
    margin: 6px 0 8px;
}

.session {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    padding-bottom: 6px;
}

.session p { margin: 0; color: var(--muted); }

.session form { margin: 0; }

.view-as .btn {
    padding: 8px 12px;
    font-size: 0.92rem;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    width: fit-content;
    max-width: 100%;
    margin: 0 0 12px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 252, 248, 0.72);
}

.tabs a {
    text-decoration: none;
    color: var(--muted);
    font-weight: 600;
    border-radius: 999px;
    padding: 8px 16px;
}

.tabs a.is-on {
    background: var(--ink);
    color: white;
}

.layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 22px;
    align-items: start;
}

.access-layout {
    display: grid;
    gap: 22px;
    width: min(760px, 100%);
}

.card {
    background: var(--paper);
    border: 1px solid rgba(70, 42, 28, 0.08);
    border-radius: 22px;
    box-shadow: var(--shadow);
    padding: 22px;
}

.library-stack {
    display: grid;
    gap: 22px;
}

.side-stack {
    display: grid;
    gap: 18px;
    position: sticky;
    top: 16px;
    align-self: start;
}

.add-panel { position: static; }

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.filters {
    display: grid;
    grid-template-columns: minmax(200px, 260px) minmax(0, 1fr);
    gap: 12px;
    align-items: end;
    margin-top: 8px;
}

.filters .field,
.filters .search-field {
    margin: 0;
}

.filters select,
.filters input[type="search"] {
    height: 48px;
    min-height: 48px;
    margin: 0;
    padding: 0 14px;
    line-height: 1.2;
}

.filters .field:only-child { grid-column: 1 / -1; }

.group-title {
    margin: 18px 0 0;
    font-family: Outfit, "Segoe UI", sans-serif;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--wine);
}

.category-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex: 1;
    min-width: 0;
}

.category-row input { width: auto; flex: 1; }

.category-add { margin: 10px 0 4px; }

.person:has(.category-row) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.viewer-wrap { padding-top: 28px; }

.back-row { margin: 0 0 10px; }

.viewer-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    margin-bottom: 16px;
}

.viewer-head h1 {
    margin: 0 0 6px;
    font-size: clamp(1.7rem, 3vw, 2.5rem);
    line-height: 1.15;
}

.upload-progress {
    display: grid;
    gap: 6px;
}

.upload-progress-track {
    height: 10px;
    overflow: hidden;
    border-radius: 99px;
    background: #f0e6dc;
}

.upload-progress-bar {
    width: 0%;
    height: 100%;
    border-radius: 99px;
    background: var(--wine);
}

.viewer-video {
    display: block;
    width: 100%;
    max-height: 78vh;
    border-radius: 18px;
    background: #1a1210;
}

.viewer-frame {
    width: 100%;
    height: min(78vh, 920px);
    border: 1px solid var(--line);
    border-radius: 18px;
    background: white;
}

.text-preview {
    margin: 0;
    white-space: pre-wrap;
    overflow: auto;
    max-height: 78vh;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 18px 20px;
}

.viewer-note p { margin: 0; }

.btn { white-space: nowrap; }

h2 {
    margin: 0 0 8px;
    font-size: 1.55rem;
}

h3 {
    margin: 0;
    font-family: Outfit, "Segoe UI", sans-serif;
    font-weight: 600;
    font-size: 1.02rem;
    letter-spacing: 0;
    overflow-wrap: anywhere;
}

.lede, .hint, .meta, .count {
    color: var(--muted);
}

.lede { margin: 0 0 16px; }

.hint, .meta, .count { margin: 0; font-size: 0.92rem; }

.stack { display: grid; gap: 14px; }

.field {
    display: grid;
    gap: 6px;
    font-weight: 600;
    font-size: 0.92rem;
}

.field.inline {
    grid-template-columns: 8.5rem minmax(0, 1fr);
    align-items: center;
}

.file-label {
    display: block;
    font-weight: 600;
}

.file-note {
    font-weight: 400;
    font-style: italic;
    color: var(--muted);
}

.field input,
.field textarea,
.field select {
    font-size: 1.05rem;
    font-weight: 500;
}

input[type="text"],
input[type="password"],
input[type="search"],
textarea,
select {
    width: 100%;
    color: var(--ink);
    background: white;
    border: 1px solid #e3d6c8;
    border-radius: 14px;
    padding: 12px 14px;
}

textarea {
    min-height: 110px;
    resize: vertical;
    font-weight: 400;
}

.gate input[type="password"] {
    height: 52px;
    border-radius: 14px;
}

.btn {
    appearance: none;
    border: 0;
    background: var(--wine);
    color: white;
    font-weight: 600;
    border-radius: 14px;
    padding: 12px 16px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
}

.btn:hover { background: var(--wine-dark); }

.btn.full { width: 100%; height: 52px; }

.btn.ghost, .btn.danger, .btn.link { background: transparent; }

.btn.ghost {
    color: var(--ink);
    border: 1px solid #e4d5c8;
}

.btn.ghost:hover { background: #f7f1ea; }

.btn.danger {
    color: var(--danger);
    border: 1px solid #f0d0d0;
}

.btn.danger:hover { background: #fdf4f4; }

.btn.link {
    color: var(--muted);
    padding: 0;
    border-radius: 8px;
}

.btn.link:hover { color: var(--ink); background: transparent; }

.drop {
    display: grid;
    gap: 8px;
    padding: 14px;
    border: 1.5px dashed #ddcfc0;
    border-radius: 16px;
    background: #fbf8f4;
}

.drop.is-over {
    border-color: var(--wine);
    background: #f8eef0;
}

input[type="file"] { width: 100%; font-weight: 500; }

input[type="file"]::file-selector-button {
    font: inherit;
    font-weight: 600;
    margin-right: 12px;
    border: 0;
    border-radius: 10px;
    padding: 10px 14px;
    background: var(--ink);
    color: white;
    cursor: pointer;
}

.library-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
}

.empty {
    padding: 28px 8px;
    text-align: center;
}

.empty p { margin: 0 0 4px; }

.items, .people {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
}

.item {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 14px;
    align-items: center;
    padding: 16px 0;
    border-top: 1px solid var(--line);
}

.item:first-child { border-top: 0; }

.file-badge {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.file-badge.pdf { background: #f6e6ea; color: var(--wine); }
.file-badge.doc { background: #e7eef6; color: #1e4f86; }
.file-badge.xls { background: #e5f3ea; color: #1d6b3a; }
.file-badge.ppt { background: #f8efe1; color: #8a5a12; }
.file-badge.video { background: #efe7f6; color: #5b3d78; }
.file-badge.other { background: #f0ebe4; color: #5c5148; }

.comment {
    margin: 4px 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.item-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    order: -1;
}

.item-actions form { margin: 0; }

.item .file-badge { order: 1; }

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 3px 9px;
    background: #f6e6ea;
    color: var(--wine);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.badge.quiet {
    background: #f0ebe4;
    color: var(--muted);
}

.person {
    display: grid;
    gap: 12px;
    padding: 18px 0;
    border-top: 1px solid var(--line);
}

.person:first-child {
    border-top: 0;
    padding-top: 4px;
}

.person-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.person-top h3 .meta {
    font-weight: 400;
    margin-left: 6px;
}

.person-forms {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.person-forms form {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 0;
}

.person-forms input[type="text"] { width: 190px; }

.access-layout .field.inline {
    grid-template-columns: 9.5rem minmax(0, 1fr);
}

.roles {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
}

.choice {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
}

.flash {
    border-radius: 14px;
    padding: 12px 14px;
    margin: 0 0 16px;
}

.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.error { background: var(--error-bg); color: var(--danger); }

.site-footer {
    margin-top: 28px;
    padding: 8px 16px 4px;
    color: var(--muted);
    font-size: 0.9rem;
    text-align: center;
}

.gate .site-footer {
    position: fixed;
    right: 0;
    bottom: 14px;
    left: 0;
    margin: 0;
    color: rgba(255, 248, 240, 0.72);
}

@media (max-width: 840px) {
    .layout { grid-template-columns: 1fr; }
    .add-panel, .side-stack { position: static; }
    .mast {
        flex-direction: column;
        align-items: flex-start;
        gap: 14px;
    }
    .session { align-items: flex-start; }
}

@media (max-width: 640px) {
    .gate-card { padding: 32px 22px 26px; }
    .filters { grid-template-columns: 1fr; }
    .field.inline,
    .access-layout .field.inline { grid-template-columns: 1fr; }
    .viewer-head { flex-direction: column; align-items: flex-start; }
    .mast h1,
    .mast h1 span { white-space: normal; }
    .item, .person-top { grid-template-columns: 1fr; }
    .item { align-items: start; }
    .item-actions { flex-direction: row; flex-wrap: wrap; }
    .person-forms form { width: 100%; }
    .person-forms input[type="text"] { width: auto; flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto !important; }
}
