:root {
    --bg: #f4f5f7;
    --fg: #1d2330;
    --muted: #6b7385;
    --card: #fff;
    --line: #dfe2e8;
    --pri: #2563eb;
    --ok: #16a34a;
    --warn: #d97706;
    --bad: #dc2626;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font: 15px/1.45 system-ui, sans-serif;
    background: var(--bg);
    color: var(--fg);
}

header {
    display: flex;
    align-items: center;
    gap: 2rem;
    padding: .6rem 1.5rem;
    background: #111827;
    color: #fff;
}

header a {
    color: #cbd5e1;
    text-decoration: none;
}

header .brand {
    font-weight: 700;
    color: #fff;
    font-size: 1.2rem;
}

header nav {
    display: flex;
    gap: 1.2rem;
    flex: 1;
}

header nav a.on {
    color: #fff;
    border-bottom: 2px solid var(--pri);
}

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 1.5rem 3rem;
}

.flash {
    padding: .45rem .9rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    background: #dcfce7;
    border: 1px solid #86efac;
}

.flash.error {
    background: #fee2e2;
    border-color: #fca5a5;
}

form.inline {
    display: inline;
    margin: 0;
}

header form {
    margin: 0;
}

header .logout {
    background: none;
    border: 0;
    color: #cbd5e1;
    cursor: pointer;
    font: inherit;
    padding: 0;
}

.toast.err {
    background: #fee2e2;
}

.shot-img img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 6px;
}

.masks .thumb {
    object-fit: cover;
    background: #e2e8f0;
}

progress {
    width: 100%;
    margin-top: .6rem;
}

.token {
    word-break: break-all;
}

h1 {
    margin: .2rem 0 1rem;
}

h2 {
    margin: .2rem 0 .8rem;
    font-size: 1.1rem;
}

h3 {
    margin: 1rem 0 .4rem;
    font-size: .95rem;
    color: var(--muted);
}

a {
    color: var(--pri);
}

.crumb {
    margin: 0;
    color: var(--muted);
}

.muted {
    color: var(--muted);
}

small {
    font-size: .8em;
}

.row {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.between {
    justify-content: space-between;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 1rem 1.2rem;
    margin-bottom: 1rem;
}

.cols {
    display: grid;
    grid-template-columns:1fr 1fr;
    gap: 1rem;
    align-items: start;
}

.grid {
    display: grid;
    grid-template-columns:repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.tile {
    text-decoration: none;
    color: inherit;
}

.tile:hover {
    border-color: var(--pri);
}

.tile p {
    margin: .2rem 0;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
}

th, td {
    text-align: left;
    padding: .5rem .8rem;
    border-bottom: 1px solid var(--line);
}

th {
    background: #f9fafb;
    font-size: .8rem;
    color: var(--muted);
    text-transform: uppercase;
}

.card table {
    border: none;
}

button, select, input {
    font: inherit;
}

button {
    padding: .4rem .9rem;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
}

button:hover {
    border-color: var(--pri);
}

button:disabled {
    opacity: .5;
    cursor: not-allowed;
}

button.primary {
    background: var(--pri);
    color: #fff;
    border-color: var(--pri);
}

button.link {
    border: none;
    background: none;
    color: var(--pri);
    padding: 0 .3rem;
}

.btns {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin: .4rem 0;
}

fieldset {
    border: none;
    padding: 0;
    margin: 0;
}

fieldset:disabled {
    opacity: .5;
}

label {
    display: block;
    margin: .6rem 0;
    font-size: .85rem;
    color: var(--muted);
}

label input, label select {
    display: block;
    width: 100%;
    padding: .4rem;
    margin-top: .2rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--fg);
    background: var(--card);
}

.two {
    display: grid;
    grid-template-columns:1fr 1fr;
    gap: .8rem;
}

.dot {
    display: inline-block;
    width: .7rem;
    height: .7rem;
    border-radius: 50%;
    background: #9ca3af;
}

.dot.ok {
    background: var(--ok);
}

.dot.off {
    background: var(--bad);
}

.tag {
    display: inline-block;
    padding: .1rem .5rem;
    border-radius: 999px;
    background: #e5e7eb;
    font-size: .78rem;
    text-decoration: none;
}

.tag.ok {
    background: #dcfce7;
    color: #166534;
}

.tag.warn {
    background: #fef3c7;
    color: #92400e;
}

.otp-code {
    font: 700 2.4rem/1 ui-monospace, monospace;
    letter-spacing: .3em;
    padding: .6rem 0;
}

pre {
    background: #111827;
    color: #e5e7eb;
    padding: .6rem .9rem;
    border-radius: 6px;
    overflow: auto;
}

.toast {
    margin-top: .6rem;
    padding: .4rem .8rem;
    background: #dcfce7;
    border-radius: 6px;
}

.shot-img {
    min-height: 170px;
    display: grid;
    place-items: center;
    background: #111827;
    color: #6b7280;
    border-radius: 6px;
    margin-top: .8rem;
}

.masks {
    list-style: none;
    padding: 0;
}

.masks li {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .2rem 0;
}

.thumb {
    width: 40px;
    height: 26px;
    border-radius: 3px;
}

.alert.error {
    background: #fee2e2;
    border: 1px solid #fca5a5;
    padding: .5rem .9rem;
    border-radius: 6px;
    margin: .6rem 0;
}

.months {
    display: grid;
    grid-template-columns:repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.month h3 {
    margin: .2rem 0;
    color: var(--fg);
}

.week {
    display: grid;
    grid-template-columns:repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 2px;
    text-align: center;
    font-size: .75rem;
}

.week.head {
    color: var(--muted);
}

.day {
    padding: .2rem 0;
    border-radius: 3px;
    background: #f3f4f6;
    color: #9ca3af;
}

.day.exact {
    background: var(--pri);
    color: #fff;
    font-weight: 600;
}

.day.fb {
    background: #dbeafe;
    color: #1e3a8a;
}

.day.today {
    outline: 2px solid var(--warn);
}

.legend {
    display: inline-block;
    width: .8rem;
    height: .8rem;
    border-radius: 2px;
    vertical-align: middle;
}

.legend.exact {
    background: var(--pri);
}

.legend.fb {
    background: #dbeafe;
}

.legend.none {
    background: #f3f4f6;
    border: 1px solid var(--line);
}

body.login {
    display: grid;
    place-items: center;
    height: 100vh;
}

body.login .card {
    width: 320px;
}

body.login h1 {
    text-align: center;
}

body.login button {
    width: 100%;
    margin-top: .5rem;
}

@media (max-width: 800px) {
    .cols {
        grid-template-columns:1fr;
    }
}

/* icons & buttons */
.icon {
    vertical-align: -3px;
    flex: none;
}

button, .button {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
}

.button {
    padding: .4rem .9rem;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 6px;
    text-decoration: none;
    color: var(--fg);
}

.button:hover {
    border-color: var(--pri);
}

button.del {
    background: var(--bad);
    border-color: var(--bad);
    color: #fff;
    font-weight: 500;
}

button.del:hover {
    background: #b91c1c;
    border-color: #b91c1c;
}

button.del:disabled {
    background: #fca5a5;
    border-color: #fca5a5;
}

button.del.small {
    padding: .15rem .55rem;
    font-size: .82rem;
}

button.warn {
    border-color: var(--warn);
    color: var(--warn);
}

.filebtn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .4rem .9rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--fg);
    cursor: pointer;
    font-size: .95rem;
}

.filebtn:hover {
    border-color: var(--pri);
}

td.actions {
    white-space: nowrap;
    text-align: right;
}

td.actions .link {
    margin-right: .4rem;
}

.chk {
    width: 2rem;
}

input[type=checkbox] {
    width: auto;
    margin: 0;
}

.btns.end {
    justify-content: flex-end;
}

.mini {
    width: 56px;
    height: 35px;
    object-fit: cover;
    border-radius: 3px;
    display: block;
}

/* dialogs, toasts, popover */
dialog {
    border: none;
    border-radius: 12px;
    padding: 1.2rem 1.4rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
    max-width: 460px;
}

dialog::backdrop {
    background: rgba(17, 24, 39, .5);
}

dialog h3 {
    color: var(--bad);
    display: flex;
    align-items: center;
    gap: .4rem;
    margin: 0 0 .6rem;
    font-size: 1.1rem;
}

dialog.wide {
    max-width: min(1000px, 92vw);
}

dialog.wide img {
    display: block;
    max-width: 100%;
    margin-top: .6rem;
    border-radius: 6px;
}

#flash {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    z-index: 50;
}

#pop {
    position: fixed;
    z-index: 60;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: .6rem .7rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
    pointer-events: none;
    max-width: 340px;
}

#pop[hidden] {
    display: none;
}

#pop .thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: .4rem;
}

#pop img {
    width: 96px;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
}

#pop .more {
    display: grid;
    place-items: center;
    width: 96px;
    height: 60px;
    background: #f3f4f6;
    border-radius: 4px;
    color: var(--muted);
}

.day[data-item] {
    cursor: pointer;
}

/* file browser */
.path {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin: .4rem 0 1rem;
}

.path a {
    text-decoration: none;
}

.selall {
    margin: 0 0 0 auto;
    display: flex;
    gap: .3rem;
    align-items: center;
}

.files {
    display: grid;
    grid-template-columns:repeat(auto-fill, minmax(170px, 1fr));
    gap: .9rem;
}

.tile-file, .tile-folder {
    position: relative;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: .5rem;
}

.tile-file {
    cursor: zoom-in;
}

.tile-file:hover, .tile-folder:hover {
    border-color: var(--pri);
}

.tile-file.picked, .tile-folder.picked {
    outline: 2px solid var(--pri);
}

.tile-file > img {
    width: 100%;
    aspect-ratio: 16/10;
    object-fit: cover;
    border-radius: 6px;
    display: block;
}

.tile-file input.sel, .tile-folder input.sel {
    position: absolute;
    top: .8rem;
    left: .8rem;
    z-index: 2;
    width: 1.1rem;
    height: 1.1rem;
}

.tile-folder a {
    color: inherit;
    text-decoration: none;
    display: block;
}

.stack {
    display: grid;
    grid-template-columns:1fr 1fr;
    gap: 3px;
    aspect-ratio: 16/10;
    background: #eef0f4;
    border-radius: 6px;
    overflow: hidden;
}

.stack img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.cap {
    margin-top: .4rem;
    font-size: .85rem;
    display: flex;
    align-items: center;
    gap: .3rem;
    word-break: break-all;
}

/* table polish */
table {
    border-collapse: separate;
    border-spacing: 0;
    margin-bottom: 1rem;
}

tr:last-child > td {
    border-bottom: none;
}

.card table, .card .tablewrap {
    margin-bottom: 0;
}

.tablewrap {
    overflow-x: auto;
    margin-bottom: 1rem;
}

.tablewrap table {
    margin-bottom: 0;
}

.tablewrap + form.row, table + form.card, .tablewrap + form.card {
    margin-top: 1rem;
}

td.actions .btns {
    margin: 0;
    flex-wrap: nowrap;
}

td.actions form.inline {
    display: inline-flex;
}

td.actions button, button.small {
    padding: .15rem .55rem;
    font-size: .82rem;
    line-height: 1.4;
    min-height: 1.9rem;
}

th input[type=checkbox], td input[type=checkbox] {
    vertical-align: middle;
}

/* prominent primary action */
button.big {
    padding: .55rem 1.2rem;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(37, 99, 235, .35);
}

button.primary:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

/* form rows: inputs fill the row, button matches their height */
.formrow {
    flex-wrap: wrap;
    gap: .6rem;
    margin-top: 1rem;
    align-items: stretch;
}

.formrow input {
    flex: 1 1 9rem;
    min-width: 0;
    padding: .4rem;
    border: 1px solid var(--line);
    border-radius: 6px;
}

.formrow button {
    flex: none;
    white-space: nowrap;
    justify-content: center;
}

.row.end {
    justify-content: flex-end;
}

/* live control groups */
.btns.group {
    gap: .8rem;
    padding: .6rem;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 10px;
}

.seg {
    display: inline-flex;
}

.seg button {
    border-radius: 0;
    background: #1e293b;
    color: #fff;
    border-color: #1e293b;
}

.seg button + button {
    border-left-color: #475569;
}

.seg button:first-child {
    border-radius: 6px 0 0 6px;
}

.seg button:last-child {
    border-radius: 0 6px 6px 0;
}

.seg button:hover {
    background: #334155;
    border-color: #334155;
}

button.active {
    background: #fef3c7;
    border-color: var(--warn);
    color: #92400e;
    font-weight: 600;
    box-shadow: 0 0 0 2px rgba(217, 119, 6, .35);
}

button.warn-fill {
    background: var(--warn);
    border-color: var(--warn);
    color: #fff;
}

dialog h3.plain {
    color: var(--fg);
}

dialog {
    width: min(460px, calc(100vw - 2rem));
}

dialog .row {
    margin-top: 1rem;
}

dialog #confirm-text {
    margin: 0;
}

/* switch */
label.switch {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    column-gap: .6rem;
    color: var(--fg);
    cursor: pointer;
}

label.switch small {
    grid-column: 2;
}

label.switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    grid-row: 1;
    position: relative;
    width: 2.4rem;
    height: 1.35rem;
    border-radius: 999px;
    background: #9ca3af;
    transition: background .15s;
}

.slider::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: calc(1.35rem - 4px);
    height: calc(1.35rem - 4px);
    border-radius: 50%;
    background: #fff;
    transition: transform .15s;
}

label.switch input:checked + .slider {
    background: var(--ok);
}

label.switch input:checked + .slider::after {
    transform: translateX(1.05rem);
}

label.switch input:focus-visible + .slider {
    outline: 2px solid var(--pri);
    outline-offset: 2px;
}

/* mobile */
@media (max-width: 700px) {
    body {
        font-size: 16px;
    }

    header {
        flex-wrap: wrap;
        gap: .5rem 1rem;
        padding: .6rem 1rem;
    }

    header nav {
        order: 3;
        flex: 1 0 100%;
        gap: 1rem;
        overflow-x: auto;
    }

    header .who {
        margin-left: auto;
    }

    main {
        padding: .8rem 1rem 2.5rem;
    }

    .row.between {
        flex-wrap: wrap;
        gap: .6rem;
    }

    .card.row, .row {
        flex-wrap: wrap;
    }

    .two {
        grid-template-columns: 1fr;
    }

    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    button, .button, .filebtn {
        min-height: 2.5rem;
    }

    input, select {
        font-size: 16px;
    }

    .btns.group {
        flex-direction: column;
        align-items: stretch;
    }

    .seg button {
        flex: 1;
        justify-content: center;
    }

    #flash {
        left: 1rem;
    }

    .shot-img {
        height: 200px;
    }

    .files {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
}

/* round 3 */
td.actions {
    padding-right: .4rem;
}

body.login button {
    justify-content: center;
}

.copyline {
    display: flex;
    align-items: center;
    gap: .6rem;
}

.copyline pre, .copyline .otp-code {
    flex: 1;
    margin: 0;
    min-width: 0;
}

.copyline pre {
    white-space: pre-wrap;
    word-break: break-all;
}

.copyline button {
    flex: none;
}

.seg button {
    min-height: 2.2rem;
}

@media (max-width: 700px) {
    .seg {
        display: flex;
        width: 100%;
    }

    .seg button {
        min-height: 2.5rem;
        line-height: 1.4;
    }
}

/* round 4: mobile fit */
.cols > *, .card, main {
    min-width: 0;
}

@media (max-width: 800px) {
    .cols {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 700px) {
    table {
        display: table;
        width: 100%;
        white-space: normal;
        font-size: .88rem;
    }

    th, td {
        padding: .4rem .5rem;
        overflow-wrap: anywhere;
    }

    th {
        font-size: .7rem;
    }

    td.actions {
        white-space: nowrap;
    }

    .copyline {
        flex-wrap: wrap;
    }
}

/* mobile row folding */
tr.detail {
    display: none;
}

@media (max-width: 700px) {
    .sec {
        display: none;
    }

    tr.foldable {
        cursor: pointer;
    }

    tr.foldable > td:first-child::before, tr.foldable > td:first-of-type::before {
        content: none;
    }

    tr.foldable.open > td {
        border-bottom-color: transparent;
        background: #f9fafb;
    }

    tr.detail {
        display: table-row;
    }

    tr.detail[hidden] {
        display: none;
    }

    tr.detail > td {
        background: #f9fafb;
        padding: .2rem .8rem .6rem;
    }

    .kv {
        display: flex;
        gap: .8rem;
        padding: .15rem 0;
    }

    .kv > span:first-child {
        flex: 0 0 6.5rem;
        color: var(--muted);
        font-size: .75rem;
        text-transform: uppercase;
        padding-top: .15rem;
    }
}
