:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #dde3ea;
    --text: #1d2733;
    --muted: #677485;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: #e0eaff;
    --danger: #dc2626;
    --danger-soft: #fde8e8;
    --ok: #15803d;
    --ok-soft: #e3f6e8;
    --warn: #a16207;
    --warn-soft: #fdf4d8;
    --row-hover: #f1f5fb;
    --row-selected: #e4edff;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f141a;
        --surface: #171e26;
        --surface-2: #1c252f;
        --border: #2b3643;
        --text: #e3e9f0;
        --muted: #8e9aa8;
        --primary: #4f86f7;
        --primary-hover: #6b9bff;
        --primary-soft: #1d2d4d;
        --danger: #f26363;
        --danger-soft: #3a1c1f;
        --ok: #4ccb7a;
        --ok-soft: #173024;
        --warn: #e0b341;
        --warn-soft: #362d14;
        --row-hover: #1e2833;
        --row-selected: #1f3150;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.45rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 0; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono, code { font-family: var(--mono); font-size: .9em; }
code { word-break: break-all; }

/* Layout ------------------------------------------------------------------ */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .7rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 1.7rem;
    height: 1.7rem;
    border-radius: 7px;
    background: var(--primary);
    color: #fff;
    margin-right: .35rem;
}

.topbar nav { display: flex; align-items: center; gap: 1.1rem; }

.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.container-wide { max-width: 1500px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.4rem;
}

.narrow { max-width: 420px; margin: 2rem auto; }
.wide { max-width: 760px; margin: 0 auto; }
.empty { text-align: center; padding: 3rem 1rem; }

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}
.page-head h1 { margin: 0; }

.inline { display: inline; margin: 0; }
.spacer { flex: 1; }

/* Forms ------------------------------------------------------------------- */

.form { display: flex; flex-direction: column; gap: .9rem; }
.form label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; }
.form label.check { flex-direction: row; align-items: flex-start; gap: .5rem; font-weight: 400; }
.form label.check input { margin-top: .3rem; }

input, select, textarea {
    font: inherit;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: .5rem .65rem;
    width: 100%;
}
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--primary); }
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary-soft);
    border-color: var(--primary);
}
textarea { resize: vertical; }

fieldset {
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: .6rem .9rem .8rem;
    display: flex;
    gap: 1.5rem;
    margin: 0;
}
legend { padding: 0 .3rem; font-weight: 500; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.grid-host { display: grid; grid-template-columns: 1fr 120px; gap: .9rem; }

.secret-box {
    display: flex;
    flex-direction: column;
    gap: .6rem;
    padding: .9rem;
    border-radius: 8px;
    background: var(--surface-2);
    border: 1px dashed var(--border);
}

[hidden] { display: none !important; }

/* Buttons ----------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    padding: .45rem .9rem;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}
.btn:hover { background: var(--row-hover); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-small { padding: .2rem .6rem; font-size: .85rem; }

button.link {
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    color: var(--primary);
    cursor: pointer;
}

.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* Alerts & badges ------------------------------------------------------------ */

.alert {
    padding: .65rem .9rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    overflow-wrap: anywhere;
}
.form .alert { margin-bottom: 0; }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-info { background: var(--primary-soft); color: var(--primary); }

.badge {
    display: inline-block;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .04em;
    padding: .15rem .45rem;
    border-radius: 5px;
    background: var(--primary-soft);
    color: var(--primary);
}
.badge-ftp { background: var(--warn-soft); color: var(--warn); }
.badge-ftps { background: var(--ok-soft); color: var(--ok); }

/* Server list ------------------------------------------------------------------ */

.server-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}
.server { display: flex; flex-direction: column; gap: .35rem; }
.server p { margin: 0; overflow-wrap: anywhere; }
.server-head { display: flex; align-items: center; gap: .6rem; }
.server-head h2 { overflow-wrap: anywhere; }
.server .actions { margin-top: .6rem; }

/* Server list: view switch, search, table view ------------------------------------ */

.count { font-weight: 400; font-size: 1rem; }

.list-tools {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1rem;
}
.list-tools input[type=search] { flex: 1; max-width: 420px; }
.list-tools .segmented { margin-left: auto; }

.segmented {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface);
    flex: none;
}
.segmented a {
    padding: .42rem .85rem;
    color: var(--text);
    font-weight: 500;
    white-space: nowrap;
}
.segmented a + a { border-left: 1px solid var(--border); }
.segmented a:hover { background: var(--row-hover); text-decoration: none; }
.segmented a.active { background: var(--primary); color: #fff; }

.card.flush { padding: 0; overflow: hidden; }
.table-wrap-plain { overflow-x: auto; }

.server-table { width: 100%; border-collapse: collapse; }
.server-table th, .server-table td {
    padding: .4rem .9rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.server-table tbody tr:last-child td { border-bottom: 0; }
.server-table tbody tr:hover { background: var(--row-hover); }
.server-table th {
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    font-weight: 600;
}
.server-table .st-name { font-weight: 600; overflow-wrap: break-word; min-width: 200px; }
/* The address takes whatever width is left and is shortened with an ellipsis. */
.server-table .st-addr { width: 100%; max-width: 0; }
.server-table .st-auth { white-space: nowrap; }
.ellipsis {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.show-sm { display: none; }
.server-table .col-actions { width: 1%; white-space: nowrap; }
.server-table .actions { flex-wrap: nowrap; justify-content: flex-end; gap: .35rem; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

@media (max-width: 1000px) {
    .hide-md { display: none; }
}

@media (max-width: 640px) {
    .hide-sm { display: none; }
    .show-sm { display: inline-block; margin-left: .3rem; vertical-align: middle; }
    .server-table .lbl { display: none; }
    .list-tools { flex-wrap: wrap; }
    .list-tools input[type=search] { max-width: none; flex-basis: 100%; }
    .list-tools .segmented { margin-left: 0; }
    .server-table th, .server-table td { padding: .5rem .6rem; }
}

/* File browser ------------------------------------------------------------------ */

.browser-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: .5rem;
}
.server-title { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }

.crumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .15rem;
    font-family: var(--mono);
    font-size: .92rem;
    padding: .5rem .75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: 0;
}
.crumbs a { padding: .1rem .3rem; border-radius: 4px; }
.crumbs a:hover { background: var(--row-hover); text-decoration: none; }
.crumbs .crumb-sep { color: var(--muted); }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .4rem;
    padding: .55rem .75rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.toolbar .sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 .2rem; }
.toolbar input[type=search] { width: 200px; padding: .4rem .6rem; }

.dropzone { position: relative; }
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    overflow-x: auto;
    min-height: 240px;
}

.files { width: 100%; border-collapse: collapse; }
.files th, .files td {
    padding: .45rem .75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.files th {
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    font-weight: 600;
    background: var(--surface);
    position: sticky;
    top: 0;
}
.files tbody tr { cursor: default; }
.files tbody tr:hover { background: var(--row-hover); }
.files tbody tr.selected { background: var(--row-selected); }
.files .col-check { width: 2.5rem; }
.files .col-name { width: 100%; white-space: normal; overflow-wrap: anywhere; }
.files .col-size { text-align: right; }
.files td.col-size, .files td.col-date, .files td.col-perm { color: var(--muted); font-size: .88rem; }
.files td.col-perm { font-family: var(--mono); }
.files .name { display: inline-flex; align-items: center; gap: .5rem; color: var(--text); cursor: pointer; }
.files .name:hover { color: var(--primary); text-decoration: none; }
.files .icon { width: 1.3rem; text-align: center; flex: none; }
.files .link-target { color: var(--muted); font-size: .8rem; }

.status { padding: 2rem; text-align: center; color: var(--muted); }
.status.error { color: var(--danger); }

.drop-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 5;
    border: 3px dashed var(--primary);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--primary-soft) 88%, transparent);
    color: var(--primary);
    font-size: 1.15rem;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1rem;
    pointer-events: none;
}
.dropzone.dragging .drop-overlay { display: flex; }

/* Upload queue ------------------------------------------------------------------ */

.queue {
    margin-top: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.queue-head {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem .9rem;
    border-bottom: 1px solid var(--border);
}
.queue ul { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }
.queue li {
    display: grid;
    grid-template-columns: 1fr 180px 150px;
    gap: .75rem;
    align-items: center;
    padding: .4rem .9rem;
    border-bottom: 1px solid var(--border);
    font-size: .88rem;
}
.queue li:last-child { border-bottom: 0; }
.queue .q-name { font-family: var(--mono); overflow-wrap: anywhere; }
.queue .q-state { color: var(--muted); text-align: right; }
.queue li.done .q-state { color: var(--ok); }
.queue li.error .q-state { color: var(--danger); }
.queue li.skipped .q-state { color: var(--warn); }

progress {
    width: 100%;
    height: .5rem;
    appearance: none;
    border: 0;
    border-radius: 999px;
    overflow: hidden;
    background: var(--surface-2);
}
progress::-webkit-progress-bar { background: var(--border); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--primary); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--primary); border-radius: 999px; }
li.done progress::-webkit-progress-value { background: var(--ok); }
li.done progress::-moz-progress-bar { background: var(--ok); }

/* Dialog -------------------------------------------------------------------------- */

dialog {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    padding: 1.5rem;
    width: min(420px, calc(100vw - 2rem));
    box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(10, 15, 25, .55); }
dialog form { display: flex; flex-direction: column; gap: .8rem; }
dialog label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; }
dialog h2 { margin: 0; }
dialog p { margin: 0; }

/* Responsive ------------------------------------------------------------------------- */

@media (max-width: 760px) {
    .grid-2, .grid-host { grid-template-columns: 1fr; }
    .files .col-date, .files .col-perm { display: none; }
    .queue li { grid-template-columns: 1fr; gap: .25rem; }
    .queue .q-state { text-align: left; }
    .toolbar input[type=search] { width: 100%; }
    .topbar { padding: .6rem .8rem; }
    .topbar nav { gap: .7rem; }
}
