/* AlveeMods — flat, palette-locked (black / red / white / gray), responsive-first */

:root {
    --black: #000000;
    --red: #EC1C24;
    --white: #FFFFFF;
    --gray: #2E2E2E;

    --bg: var(--white);
    --surface: var(--white);
    --surface-alt: rgba(46, 46, 46, 0.05);
    --text: var(--black);
    --muted: rgba(46, 46, 46, 0.68);
    --border: rgba(46, 46, 46, 0.16);
    --radius: 12px;
    --radius-sm: 8px;
    --maxw: 1100px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: var(--black);
        --surface: var(--gray);
        --surface-alt: rgba(255, 255, 255, 0.06);
        --text: var(--white);
        --muted: rgba(255, 255, 255, 0.7);
        --border: rgba(255, 255, 255, 0.16);
        --shadow: none;
    }
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.55;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
a:hover { color: var(--red); }

img { max-width: 100%; display: block; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 .35rem; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.4rem, 4vw, 1.9rem); }
h2 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }

:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; border-radius: 4px; }

.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 1rem; }

.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; }
.hint { color: var(--muted); font-size: .82rem; display: block; }

/* ---------- App bar ---------- */
.appbar {
    background: var(--black);
    color: var(--white);
    border-bottom: 2px solid var(--red);
    position: sticky;
    top: 0;
    z-index: 30;
}
.appbar__inner { display: flex; align-items: center; gap: .75rem 1rem; min-height: 58px; padding-top: .5rem; padding-bottom: .5rem; flex-wrap: wrap; }
.appbar__actions { margin-left: auto; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.appbar__actions form { margin: 0; }
@media (max-width: 640px) {
    .appbar__actions { width: 100%; margin-left: 0; }
    .appbar__actions .btn { flex: 1 1 auto; }
}

.brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; font-size: 1.1rem; color: var(--white); }
.brand:hover { color: var(--white); }
.brand__logo {
    width: 34px; height: 34px; border-radius: 8px; object-fit: cover; display: block;
    background: var(--red);
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    min-height: 40px; padding: .55rem 1rem; border-radius: var(--radius-sm);
    background: var(--black); color: var(--white); border: 1px solid var(--black);
    font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--gray); border-color: var(--gray); color: var(--white); }
.btn--red { background: var(--red); border-color: var(--red); }
.btn--red:hover { background: #c8161d; border-color: #c8161d; }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn--ghost:hover { background: var(--surface-alt); color: var(--text); border-color: var(--text); }
.btn--ghost-light { background: transparent; color: var(--white); border-color: rgba(255, 255, 255, .35); }
.btn--ghost-light:hover { background: rgba(255, 255, 255, .14); color: var(--white); }
.btn--ghost-light.is-active { background: rgba(255, 255, 255, .18); }
.btn--danger { background: transparent; color: var(--red); border-color: var(--red); }
.btn--danger:hover { background: var(--red); color: var(--white); }
.btn--sm { min-height: 34px; padding: .35rem .7rem; font-size: .84rem; }
.btn--block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Main / cards ---------- */
main { flex: 1 0 auto; padding: 1.5rem 0 3rem; }

.dashboard { display: flex; flex-direction: column; gap: 1.5rem; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.page-head .hint { margin: 0; }

.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 1.25rem;
}
.card__head { margin-bottom: 1.1rem; }
.card__head h2 { margin: 0; }
.card__head .hint { margin-top: .15rem; }

.form-grid { display: grid; gap: 0 1.25rem; grid-template-columns: 1fr; }
@media (min-width: 720px) { .form-grid { grid-template-columns: 1fr 1fr; } }

.setup-grid { display: grid; grid-template-columns: 1fr 110px; gap: 0 .75rem; }
.connection-status { margin: .6rem 0 0; min-height: 1.1em; }
.connection-status.is-ok { color: var(--text); font-weight: 600; }
.connection-status.is-error { color: var(--red); font-weight: 600; }

/* ---------- Forms ---------- */
.form-row { margin-bottom: 1rem; }
label { display: block; font-weight: 600; margin-bottom: .35rem; font-size: .88rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
    width: 100%; min-height: 44px; padding: .6rem .75rem; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 92px; resize: vertical; padding-top: .6rem; }
input:focus, select:focus, textarea:focus { border-color: var(--red); outline: none; box-shadow: 0 0 0 3px rgba(236, 28, 36, .18); }
.checkbox { display: flex; align-items: center; gap: .5rem; }
.checkbox input { width: auto; min-height: 0; }
.checkbox label { margin: 0; font-weight: 500; }

.error { color: var(--red); font-size: .84rem; margin: 0 0 .75rem; }
.alert {
    border: 1px solid var(--border); border-left: 4px solid var(--red); border-radius: var(--radius-sm);
    padding: .7rem 1rem; margin-bottom: 1.25rem; background: var(--surface);
}
.alert--success { border-left-color: var(--gray); }
.alert ul { margin: 0; padding-left: 1.1rem; }

/* ---------- Uploader ---------- */
.type-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin-bottom: 1.1rem; }
.type-toggle button { background: transparent; border: 0; padding: .45rem 1.15rem; font: inherit; font-weight: 600; cursor: pointer; color: var(--muted); min-height: 40px; }
.type-toggle button[aria-pressed="true"] { background: var(--red); color: var(--white); }

.dropzone {
    border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.5rem 1rem;
    text-align: center; background: var(--surface-alt);
    transition: border-color .15s ease, background .15s ease;
}
.dropzone--over { border-color: var(--red); background: rgba(236, 28, 36, .08); }
.dropzone__badge {
    display: inline-grid; place-items: center; min-width: 54px; height: 54px; padding: 0 .6rem;
    border-radius: 12px; background: var(--red); color: var(--white); font-weight: 800; font-size: .85rem;
    letter-spacing: .06em;
}
.dropzone__text { margin: .6rem 0; }
.dropzone .link { color: var(--red); font-weight: 600; }
.dropzone .btn { margin-bottom: .5rem; }

.upload-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.upload-actions .btn { flex: 0 1 auto; }

.progress { height: 10px; border-radius: 999px; background: var(--surface-alt); overflow: hidden; margin-bottom: .9rem; }
.upload-status { margin: -.4rem 0 .9rem; }
.progress__bar { height: 100%; background: var(--red); width: 0; transition: width .15s ease; }

.upload-result {
    margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--border);
}
.upload-result__actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .6rem; }

/* ---------- Copy fields ---------- */
.copyfield { display: flex; gap: .4rem; align-items: center; }
.copyfield input { flex: 1 1 auto; min-width: 0; font-size: .85rem; }

.link-cell { display: flex; flex-direction: column; gap: .4rem; min-width: 250px; }
.link-cell .link-input { font-size: .82rem; }
.link-actions { display: flex; gap: .3rem; flex-wrap: wrap; }

/* ---------- Overview ---------- */
.stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat-card {
    display: block; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow);
}
a.stat-card:hover { border-color: var(--red); color: inherit; }
.stat-card .value { font-size: 1.7rem; font-weight: 800; line-height: 1.1; }
.stat-card .label { color: var(--muted); font-size: .85rem; }

.recent-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.recent-list li { display: flex; align-items: center; gap: .8rem; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.recent-list li:last-child { border-bottom: 0; }
.recent-list__thumb img { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); }
.recent-list__info { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.recent-list__info .file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 620px) {
    .recent-list li { flex-wrap: wrap; }
    .recent-list__info { flex-basis: calc(100% - 56px); }
    .recent-list .link-actions { width: 100%; }
}

/* ---------- Images gallery ---------- */
.gallery { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.gallery-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.gallery-card__media { position: relative; display: block; aspect-ratio: 4 / 3; background: var(--surface-alt); }
.gallery-card__media img { width: 100%; height: 100%; object-fit: cover; }
.gallery-card__media:hover img { opacity: .92; }
.gallery-card__badge { position: absolute; top: .5rem; left: .5rem; background: var(--surface); }
.gallery-card__body { padding: .7rem .8rem .8rem; display: flex; flex-direction: column; gap: .2rem; flex: 1; }
.gallery-card__body .file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gallery-card__actions { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: auto; padding-top: .55rem; }

/* ---------- APK list ---------- */
.apk-cell { display: flex; align-items: center; gap: .65rem; }
.apk-cell .file-name { display: block; }
.apk-cell .badge { margin-top: .15rem; }

/* ---------- Files list ---------- */
.files-card { padding: 1.25rem; }
.files-card__head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.files-search { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.files-search input[type="search"] { min-width: 200px; }
.files-search select { width: auto; }
@media (max-width: 560px) {
    .files-search { width: 100%; }
    .files-search input[type="search"] { flex: 1 1 auto; min-width: 0; }
}

.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .7rem .7rem; border-bottom: 1px solid var(--border); font-size: .9rem; vertical-align: middle; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-alt); }

.thumb { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); }
.thumb--apk { display: grid; place-items: center; background: var(--surface-alt); color: var(--red); font-weight: 800; font-size: .7rem; }
.file-name { display: block; font-weight: 600; word-break: break-word; }
.row-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.row-actions form { margin: 0; }

.badge {
    display: inline-flex; align-items: center; font-size: .7rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .05em; padding: .15rem .5rem; border-radius: 999px;
    border: 1px solid var(--border); color: var(--muted);
}
.badge--image { border-color: var(--gray); color: var(--text); }
.badge--apk { background: var(--red); border-color: var(--red); color: var(--white); }

.empty { text-align: center; padding: 2.5rem 1rem; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--muted); }
.empty p { margin: .25rem 0; }

/* Responsive table -> cards */
@media (max-width: 820px) {
    .files-table thead { display: none; }
    .files-table, .files-table tbody, .files-table tr, .files-table td { display: block; width: 100%; }
    .files-table tr { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .5rem .7rem; margin-bottom: .75rem; }
    .files-table tbody tr:hover { background: transparent; }
    .files-table td {
        border: 0; border-bottom: 1px dashed var(--border); padding: .5rem 0;
        display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    }
    .files-table td:last-child { border-bottom: 0; }
    .files-table td::before {
        content: attr(data-label); flex: 0 0 auto; font-size: .72rem; text-transform: uppercase;
        letter-spacing: .04em; font-weight: 700; color: var(--muted);
    }
    .files-table td[data-label="Name"], .files-table td[data-label="Hosted link"], .files-table td[data-label="Actions"] { flex-direction: column; align-items: stretch; }
    .files-table td[data-label="Name"]::before, .files-table td[data-label="Hosted link"]::before, .files-table td[data-label="Actions"]::before { margin-bottom: .35rem; }
    .link-cell { min-width: 0; width: 100%; }
    .row-actions { width: 100%; }
    .row-actions .btn, .row-actions form { flex: 1 1 auto; }
    .row-actions form .btn { width: 100%; }
}

/* ---------- Pagination ---------- */
.pagination-wrap { margin-top: 1.25rem; }
.pagination { display: flex; gap: .3rem; list-style: none; padding: 0; margin: 0; flex-wrap: wrap; }
.pagination a, .pagination span {
    display: inline-flex; min-width: 38px; height: 38px; align-items: center; justify-content: center;
    padding: 0 .5rem; border: 1px solid var(--border); border-radius: 8px; font-size: .88rem; font-weight: 600;
}
.pagination .is-active span { background: var(--red); border-color: var(--red); color: var(--white); }
.pagination .is-disabled span { opacity: .45; }

/* ---------- Detail (edit) ---------- */
.detail { display: grid; gap: 1.25rem; grid-template-columns: 1fr; }
@media (min-width: 860px) { .detail { grid-template-columns: 1.3fr 1fr; align-items: start; } }
.preview-box { margin: 1rem 0; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .5rem; display: grid; place-items: center; background: var(--surface-alt); }
.preview-box img { max-height: 320px; width: auto; border-radius: 6px; }
.meta-list { display: grid; grid-template-columns: auto 1fr; gap: .3rem .75rem; margin: 1rem 0; font-size: .88rem; }
.meta-list dt { color: var(--muted); font-weight: 600; }
.meta-list dd { margin: 0; text-align: right; }

.settings-subhead { margin: 1.25rem 0 .35rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.settings-subhead:first-of-type { margin-top: 0; }

.settings-form { display: flex; flex-direction: column; gap: 1.25rem; align-items: flex-start; }
.settings-form .card { width: 100%; }

/* ---------- Login ---------- */
.login-page { background: var(--black); }
.login { flex: 1 0 auto; display: grid; place-items: center; padding: 1.25rem; min-height: 100vh; }
.login__card {
    width: 100%; max-width: 400px; background: var(--white); color: var(--black);
    border-radius: var(--radius); padding: 1.75rem; border-top: 3px solid var(--red);
}
.login__brand { display: flex; align-items: center; gap: .55rem; font-weight: 800; margin-bottom: 1rem; }
.login__card h1 { font-size: 1.35rem; }
.login__card .hint { margin-bottom: 1.25rem; }

/* ---------- Database panel ---------- */
.db-grid { display: grid; gap: 1.25rem; grid-template-columns: 1fr; }
@media (min-width: 900px) { .db-grid { grid-template-columns: 1fr 1fr; } }

.kv-list { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; margin: 0; font-size: .9rem; }
.kv-list dt { color: var(--muted); font-weight: 600; }
.kv-list dd { margin: 0; word-break: break-word; }

.table-list { list-style: none; margin: 0; padding: 0; }
.table-list li { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.table-list li:last-child { border-bottom: 0; }
.table-list a { font-weight: 600; }
.table-list .count { color: var(--muted); font-size: .82rem; white-space: nowrap; }

.migration-list { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow: auto; }
.migration-list li { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .4rem 0; border-bottom: 1px solid var(--border); font-size: .85rem; }
.migration-list li:last-child { border-bottom: 0; }
.migration-list code { font-size: .78rem; word-break: break-all; }

.output { margin-top: 1rem; background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .75rem; font-size: .8rem; white-space: pre-wrap; word-break: break-word; max-height: 260px; overflow: auto; }

.db-table { min-width: 640px; }
.db-table td { font-size: .85rem; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-table td.masked { color: var(--muted); font-style: italic; }
.db-table th { position: sticky; top: 0; background: var(--surface); }

.danger-zone { border: 1px solid var(--red); border-radius: var(--radius); }
.danger-zone .card__head h2 { color: var(--red); }

.file-input { padding: .5rem; border: 1px solid var(--border); border-radius: var(--radius-sm); width: 100%; background: var(--surface); }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--border); padding: 1.25rem 0; color: var(--muted); font-size: .82rem; }
