/* ==========================================================================
   Cottonridge Tools - monochrome (black / white / greyscale) theme
   ========================================================================== */

:root {
    --ink:        #141414;   /* near-black text / primary  */
    --ink-soft:   #555555;
    --paper:      #fafafa;   /* page background            */
    --sand:       #f3f3f3;   /* card / panel surface       */
    --sand-deep:  #e6e6e6;
    --line:       #d7d7d7;   /* hairline borders           */
    --sage:       #141414;   /* primary accent (black)     */
    --sage-deep:  #000000;
    --clay:       #6b6b6b;   /* secondary label grey       */
    --gold:       #6b6b6b;
    --danger:     #4a4a4a;   /* destructive (dark grey)    */
    --white:      #ffffff;
    --shadow:     0 6px 24px rgba(0, 0, 0, .12);
    --radius:     14px;
    --radius-sm:  9px;
    --font:       "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--paper);
    background-image:
        radial-gradient(1200px 600px at 100% -10%, rgba(0,0,0,.05), transparent 60%),
        radial-gradient(900px 500px at -10% 110%, rgba(0,0,0,.04), transparent 55%);
    line-height: 1.55;
    display: flex;
    flex-direction: column;
}

a { color: var(--ink); }

/* ---------- Top bar ------------------------------------------------------ */
.topbar {
    background: var(--ink);
    color: var(--paper);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar__inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 12px 22px;
    display: flex;
    align-items: center;
    gap: 22px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: inherit;
}
.brand__logo {
    height: 26px;
    width: auto;
    display: block;
    /* Force the dark wordmark to pure white on the black bar. */
    filter: brightness(0) invert(1);
}
.brand__sub {
    font-size: .68rem;
    letter-spacing: 1.6px;
    text-transform: uppercase;
    color: #b8b8b8;
    padding-left: 14px;
    border-left: 1px solid rgba(255,255,255,.22);
}

.topnav {
    display: flex;
    gap: 6px;
    margin-left: 14px;
}
.topnav > a,
.topnav__item > a {
    color: #cfcfcf;
    text-decoration: none;
    padding: 8px 14px;
    border-radius: 8px;
    font-weight: 600;
    font-size: .92rem;
    display: block;
}
.topnav > a:hover,
.topnav__item > a:hover { background: rgba(255,255,255,.10); color: var(--white); }
.topnav > a.is-active,
.topnav__item.is-active > a { background: var(--white); color: var(--ink); }
.topnav > a.is-soon {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

/* Dropdown submenu */
.topnav__item {
    position: relative;
}
.topnav__sub {
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--ink);
    border-radius: 8px;
    padding: 6px;
    min-width: 160px;
    box-shadow: 0 8px 24px rgba(0,0,0,.3);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity .2s ease, transform .2s ease, visibility .2s;
    z-index: 100;
}
.topnav__item:hover .topnav__sub {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.topnav__sub a {
    color: #cfcfcf;
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-weight: 600;
    font-size: .88rem;
    display: block;
    white-space: nowrap;
}
.topnav__sub a:hover {
    background: rgba(255,255,255,.10);
    color: var(--white);
}

.topbar__user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 14px;
}
.topbar__name { color: #cfc9ba; font-size: .9rem; }

/* ---------- Layout ------------------------------------------------------- */
.page {
    flex: 1;
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 34px 22px 60px;
}
.pagehead { margin-bottom: 26px; }
.pagehead h1 { margin: 0 0 4px; font-size: 1.7rem; letter-spacing: .2px; }
.pagehead p  { margin: 0; color: var(--ink-soft); }

.sitefoot {
    text-align: center;
    padding: 22px;
    color: var(--ink-soft);
    font-size: .85rem;
    border-top: 1px solid var(--line);
}
.sitefoot__tag { color: var(--sage-deep); font-style: italic; }

/* ---------- Buttons ------------------------------------------------------ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 10px;
    padding: 11px 18px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    background: var(--sage);
    color: var(--white);
    transition: transform .05s ease, background .15s ease, box-shadow .15s ease;
}
.btn:hover { background: var(--sage-deep); box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px); }
.btn--sm { padding: 7px 13px; font-size: .85rem; border-radius: 8px; }
.btn--block { width: 100%; }
.btn--ghost { background: transparent; color: inherit; box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.35); }
.btn--ghost:hover { background: rgba(255,255,255,.12); box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.5); }
.btn--outline { background: transparent; color: var(--sage-deep); box-shadow: inset 0 0 0 1.5px var(--sage); }
.btn--outline:hover { background: rgba(0,0,0,.06); }
.btn--danger { background: var(--danger); }
.btn--danger:hover { background: #262626; }

/* Animated progress bar during upload */
#progressBar.is-uploading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255,255,255,0.3) 50%,
        transparent 100%
    );
    animation: progressShimmer 1.5s infinite;
}

@keyframes progressShimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* ---------- Cards / panels ---------------------------------------------- */
.panel {
    background: var(--sand);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
}
.tool-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--sand);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow);
    transition: transform .12s ease, border-color .12s ease;
}
.tool-card:hover { transform: translateY(-3px); border-color: var(--sage); }
.tool-card.is-soon { opacity: .6; cursor: default; }
.tool-card.is-soon:hover { transform: none; border-color: var(--line); }
.tool-card__icon {
    width: 52px; height: 52px;
    display: grid; place-items: center;
    border-radius: 13px;
    background: rgba(0,0,0,.06);
    font-size: 1.6rem;
    filter: grayscale(1);
}
.tool-card h3 { margin: 0; font-size: 1.15rem; }
.tool-card p  { margin: 0; color: var(--ink-soft); font-size: .92rem; }
.tool-card__tag {
    margin-top: auto;
    align-self: flex-start;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--sage-deep);
    font-weight: 700;
}
.tool-card.is-soon .tool-card__tag { color: var(--clay); }

/* ---------- Forms -------------------------------------------------------- */
.field { margin-bottom: 16px; }
.field label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: .9rem;
}
.input, select, textarea {
    width: 100%;
    padding: 11px 13px;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--white);
    font: inherit;
    color: var(--ink);
}
.input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--ink);
    box-shadow: 0 0 0 3px rgba(0,0,0,.15);
}
.field__hint { margin: 6px 0 0; font-size: .8rem; color: var(--ink-soft); }

/* ---------- Auth screen -------------------------------------------------- */
.auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px;
}
.auth__card {
    width: 100%;
    max-width: 400px;
    background: var(--sand);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 34px 32px;
    box-shadow: var(--shadow);
}
.auth__brand {
    text-align: center;
    margin-bottom: 22px;
}
.auth__logo {
    height: 34px;
    width: auto;
    margin-bottom: 14px;
    /* Force pure black wordmark on the light card. */
    filter: brightness(0);
}
.auth__brand h1 { margin: 0; font-size: 1.4rem; }
.auth__brand p  { margin: 4px 0 0; color: var(--ink-soft); font-size: .85rem; font-style: italic; }

/* ---------- Alerts ------------------------------------------------------- */
.alert {
    padding: 12px 15px;
    border-radius: var(--radius-sm);
    margin-bottom: 18px;
    font-size: .9rem;
    background: #f0f0f0;
    color: #1c1c1c;
    border: 1px solid var(--line);
    border-left: 4px solid var(--ink);
}
.alert--error   { border-left-color: #141414; background: #ededed; }
.alert--success { border-left-color: #6b6b6b; background: #f2f2f2; }
.alert--info    { border-left-color: #9a9a9a; background: #f4f4f4; }

/* ---------- Image repository -------------------------------------------- */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-size: .85rem;
}
.breadcrumb a { color: var(--ink-soft); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; color: var(--ink); }
.breadcrumb__sep { color: var(--line); font-weight: 300; }

.repo-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 26px;
    align-items: start;
}
.repo-layout.has-viewer {
    grid-template-columns: 260px 1fr 340px;
}
.repo-side .panel + .panel { margin-top: 20px; }
.catlist { list-style: none; margin: 0; padding: 0; }
.catlist li { margin: 0 0 4px; }
.catlist a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 9px 12px;
    border-radius: 9px;
    text-decoration: none;
    color: var(--ink);
    font-weight: 600;
    font-size: .92rem;
}
.catlist a:hover { background: var(--sand-deep); }
.catlist a.is-active { background: var(--sage); color: var(--white); }
.catlist .count {
    font-size: .75rem;
    background: rgba(0,0,0,.10);
    padding: 1px 8px;
    border-radius: 20px;
}
.catlist a.is-active .count { background: rgba(255,255,255,.22); }

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 18px;
}
.imgcard {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    transition: border-color .15s ease;
}
.imgcard.is-selected {
    border-color: var(--ink);
    border-width: 2px;
}
.imgcard__thumb {
    aspect-ratio: 4 / 3;
    background: #e9e9e9 center/cover no-repeat;
    display: block;
    text-decoration: none;
}
.imgcard__body { padding: 12px 13px; display: flex; flex-direction: column; gap: 6px; }
.imgcard__title { font-weight: 700; font-size: .92rem; word-break: break-word; }
.imgcard__meta { font-size: .76rem; color: var(--ink-soft); }
.imgcard__actions { display: flex; gap: 8px; margin-top: 4px; }
.imgcard__actions form { margin: 0; }

/* Tree view - Mac OS / Windows Explorer style */
.tree-view {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--white);
    overflow: hidden;
}

.tree-folder {
    border-bottom: 1px solid #f5f5f5;
}
.tree-folder:last-child {
    border-bottom: none;
}
.tree-folder__header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    user-select: none;
    transition: background .15s ease;
}
.tree-folder__header:hover {
    background: #f5f5f5;
}
.tree-folder__icon {
    font-size: 10px;
    color: var(--ink-soft);
    transition: transform .2s ease;
    width: 12px;
    flex-shrink: 0;
}
.tree-folder.is-expanded .tree-folder__icon {
    transform: rotate(90deg);
}
.tree-folder__icon-folder {
    font-size: 16px;
    flex-shrink: 0;
}
.tree-folder__name {
    font-weight: 600;
    font-size: .92rem;
    flex: 1;
}
.tree-folder__count {
    font-size: .78rem;
    color: var(--ink-soft);
    background: #f3f3f3;
    padding: 2px 8px;
    border-radius: 10px;
}
.tree-folder__content {
    display: none;
    padding-left: 20px;
    border-left: 1px solid #e9e9e9;
    margin-left: 18px;
}
.tree-folder.is-expanded > .tree-folder__content {
    display: block;
}

.tree-file {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-bottom: 1px solid #f9f9f9;
    position: relative;
    transition: background .15s ease;
}
.tree-file:hover {
    background: #f5f5f5;
}
.tree-file.is-selected {
    background: #e9e9e9;
}
.tree-file.is-selected::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--ink);
}
.tree-file__checkbox {
    margin: 0;
    flex-shrink: 0;
    cursor: pointer;
    width: 18px;
    height: 18px;
}
.tree-file__link {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    text-decoration: none;
    color: var(--ink);
    min-width: 0;
}
.tree-file__icon {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 4px;
    overflow: hidden;
    background: #f3f3f3;
}
.tree-file__icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.tree-file__info {
    flex: 1;
    min-width: 0;
}
.tree-file__name {
    font-weight: 600;
    font-size: .92rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tree-file__meta {
    font-size: .78rem;
    color: var(--ink-soft);
    margin-top: 2px;
}

/* Bulk actions toolbar */
.bulk-actions {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--ink);
    color: var(--white);
    border-radius: var(--radius);
    margin-bottom: 16px;
}
.bulk-actions__info {
    font-weight: 600;
    font-size: .92rem;
}
.bulk-actions__buttons {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

/* Modal dialog */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal__overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
}
.modal__content {
    position: relative;
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}
.modal__content h2 {
    margin: 0 0 20px 0;
    font-size: 1.3rem;
}

.emptystate {
    text-align: center;
    padding: 60px 20px;
    color: var(--ink-soft);
}
.emptystate__icon { font-size: 2.6rem; }

.repo-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}
.repo-toolbar h2 { margin: 0; font-size: 1.3rem; }
.repo-toolbar .spacer { margin-left: auto; }

/* Modal-free upload reveal */
.collapsible[hidden] { display: none; }

/* Viewer panel */
.repo-viewer .panel { padding: 0; overflow: hidden; }
.viewer-close {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    text-align: right;
}
.viewer-preview {
    background: #f8f8f8;
    padding: 18px;
    text-align: center;
    border-bottom: 1px solid var(--line);
}
.viewer-preview img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 16px rgba(0,0,0,.15);
}
.viewer-info {
    padding: 18px;
}
.viewer-info h3 {
    margin: 0 0 14px;
    font-size: 1.1rem;
    word-break: break-word;
}
.viewer-meta {
    margin: 0 0 18px;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 12px;
    font-size: .85rem;
}
.viewer-meta dt {
    font-weight: 600;
    color: var(--ink-soft);
}
.viewer-meta dd {
    margin: 0;
    color: var(--ink);
}
.viewer-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

@media (max-width: 820px) {
    .repo-layout { grid-template-columns: 1fr; }
    .repo-layout.has-viewer { grid-template-columns: 1fr; }
    .repo-viewer { order: -1; }
    .topbar__name { display: none; }
    .topnav { margin-left: 0; flex-wrap: wrap; }
    .brand__sub { display: none; }
    .topnav__sub {
        position: static;
        opacity: 1;
        visibility: visible;
        transform: none;
        box-shadow: none;
        background: transparent;
        padding: 0;
        display: flex;
        flex-direction: column;
        width: 100%;
        margin-top: 4px;
    }
    .topnav__item {
        width: 100%;
    }
    .topnav__sub a {
        padding-left: 24px;
        font-size: .85rem;
    }
}
