:root {
    --border: #d8dde3;
    --line: #e9edf1;
    --text: #20242a;
    --muted: #6d7680;
    --bg: #f6f7f9;
    --ok: #4db865;
    --warn: #f3c745;
    --fail: #d9534f;
    --blue: #2f78c4;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font: 13px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}
a { color: #1d5fa7; text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; }

.topbar {
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    background: linear-gradient(#fff, #e7ebef);
    border-bottom: 1px solid #bdc6cf;
}
.topbar nav { display: flex; gap: 14px; }
.main { padding: 10px; }
.two-col {
    display: grid;
    grid-template-columns: minmax(520px, 1fr) 360px;
    gap: 14px;
    align-items: start;
}

.nav-button {
    border: 0;
    background: transparent;
    color: #1d5fa7;
    padding: 0;
}
.nav-button:hover { text-decoration: underline; }
.file-input { display: none; }
.page-drop-overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: none;
    place-items: center;
    border: 4px dashed rgba(47, 120, 196, .55);
    background: rgba(238, 247, 255, .82);
    color: #1d5fa7;
    font-size: 22px;
    font-weight: 700;
    pointer-events: none;
}
.page-drop-overlay.visible { display: grid; }

.matrix-wrap {
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #fff;
    box-shadow: 0 6px 18px rgba(31, 42, 55, .08);
}
.matrix {
    border-collapse: collapse;
    min-width: 100%;
    table-layout: fixed;
}
.matrix th, .matrix td {
    border-bottom: 1px solid var(--line);
    border-right: 1px solid var(--line);
    padding: 3px 5px;
    height: 42px;
    vertical-align: middle;
}
.matrix th {
    height: 42px;
    background: linear-gradient(#fff, #eef1f5);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}
.thumb-col { width: 54px; text-align: center; }
.title-col { width: 245px; text-align: left; }
.dest-col { width: 68px; text-align: center; }
.delete-col { width: 34px; text-align: center; }
.dest-link {
    display: inline-grid;
    place-items: center;
    width: 24px;
    height: 20px;
}
.dest-link img { width: 18px; height: 18px; object-fit: contain; }
.dest-name {
    display: block;
    width: 62px;
    margin: 0 auto;
    color: var(--muted);
    font-size: 9px;
    font-weight: 500;
    line-height: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.thumb-button {
    display: inline-block;
    border: 0;
    padding: 0;
    background: transparent;
    cursor: pointer;
    width: 42px;
    height: 36px;
}
.thumb-button img {
    width: 42px;
    height: 36px;
    object-fit: cover;
    border: 1px solid #c9d0d8;
}
.image-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
}
.image-meta {
    color: var(--muted);
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.empty-row td { color: var(--muted); padding: 18px; }

.delete-image {
    position: relative;
    width: 22px;
    height: 22px;
    border: 0;
    padding: 0;
    background: transparent;
    cursor: pointer;
}
.delete-image::before {
    content: "";
    position: absolute;
    left: 6px;
    top: 5px;
    width: 10px;
    height: 2px;
    background: #8b96a3;
}
.delete-image span {
    position: absolute;
    left: 7px;
    top: 8px;
    width: 8px;
    height: 10px;
    border: 2px solid #8b96a3;
    border-top: 0;
}
.delete-image:hover::before,
.delete-image:hover span {
    border-color: var(--fail);
    background: var(--fail);
}

.status {
    width: 22px;
    height: 22px;
    border: 0;
    padding: 0;
    background: transparent;
    cursor: pointer;
    position: relative;
}
.status span {
    display: block;
    width: 17px;
    height: 17px;
    margin: 2px auto;
    border-radius: 50%;
    border: 2px solid #b6bcc4;
    background: #f8f9fa;
}
.status-uploaded span {
    border-color: var(--ok);
    background: var(--ok);
}
.status-uploaded span::after {
    content: "";
    position: absolute;
    left: 8px;
    top: 5px;
    width: 5px;
    height: 9px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.status-failed span {
    border-color: var(--fail);
    background: #fff;
}
.status-failed span::before, .status-failed span::after {
    content: "";
    position: absolute;
    left: 10px;
    top: 5px;
    width: 2px;
    height: 12px;
    background: var(--fail);
}
.status-failed span::before { transform: rotate(45deg); }
.status-failed span::after { transform: rotate(-45deg); }
.status-queued span, .status-uploading span {
    border-color: var(--warn);
    border-top-color: transparent;
    animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.auth-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
}
.auth-box {
    width: min(360px, calc(100vw - 30px));
    background: #fff;
    border: 1px solid var(--border);
    padding: 18px;
}
h1 { font-size: 18px; margin: 0 0 12px; }
.auth-box form, .dest-form {
    display: grid;
    gap: 9px;
}
label { display: grid; gap: 3px; color: #303842; }
input, select {
    width: 100%;
    border: 1px solid #bfc8d2;
    padding: 6px 7px;
    background: #fff;
}
button, .button {
    border: 1px solid #9ca8b4;
    background: linear-gradient(#fff, #e7ebef);
    padding: 5px 9px;
    cursor: pointer;
}
button:hover { border-color: #6f7d89; }
.flash {
    padding: 7px 9px;
    border: 1px solid;
    margin: 0 0 10px;
}
.flash.ok { background: #eef8f0; border-color: #b8ddc0; }
.flash.error { background: #fff0f0; border-color: #e1b1b1; }

.dest-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid var(--border);
}
.dest-table th, .dest-table td {
    border-bottom: 1px solid var(--line);
    padding: 6px;
    text-align: left;
}
.dest-table th { background: #eef1f5; }
.dest-table tr.dragging {
    opacity: .55;
}
.sorting-destinations {
    user-select: none;
}
.drag-col {
    width: 34px;
    text-align: center;
}
.drag-handle {
    display: inline-grid;
    gap: 2px;
    place-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    cursor: grab;
    touch-action: none;
}
.drag-handle:active { cursor: grabbing; }
.drag-handle span { pointer-events: none; }
.drag-handle span {
    display: block;
    width: 12px;
    height: 2px;
    background: #71808e;
}
.actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.actions form { display: inline-flex; gap: 4px; margin: 0; }
.editor {
    background: #fff;
    border: 1px solid var(--border);
    padding: 12px;
}
.check {
    display: flex;
    align-items: center;
    gap: 6px;
}
.check input { width: auto; }
fieldset {
    border: 1px solid var(--border);
    padding: 9px;
}
.size-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-top: 8px;
}
dialog {
    border: 1px solid #9ca8b4;
    padding: 14px;
    width: min(520px, calc(100vw - 28px));
}
.dialog-close {
    float: right;
    width: 26px;
    height: 26px;
    padding: 0;
}

@media (max-width: 880px) {
    .two-col { grid-template-columns: 1fr; }
    .title-col { width: 180px; }
}
