/* OMG admin — small, dependency-free stylesheet */
:root {
    --bg: #f6f4f0;
    --surface: #ffffff;
    --surface-2: #faf8f5;
    --text: #1f1b16;
    --muted: #6e665c;
    --border: #e6e0d6;
    --primary: #c2410c;
    --primary-hover: #9a3412;
    --app-primary: #c2410c;
    --danger: #b91c1c;
    --green: #15803d;
    --blue: #1d4ed8;
    --gold: #a16207;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(31, 27, 22, .06), 0 2px 8px rgba(31, 27, 22, .04);
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
    color: var(--text);
    background: var(--bg);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
code, .mono { font-family: var(--mono); font-size: .88em; }
code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: .05em .35em; }
img { max-width: 100%; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.inline { display: inline; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- top bar & shell ---------- */
.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: 1rem;
    padding: .6rem 1.25rem;
    background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: .45rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--primary); color: #fff; font-size: 16px; }
.topnav { display: flex; gap: .25rem; flex: 1; }
.topnav a { padding: .35rem .7rem; border-radius: 7px; color: var(--muted); font-weight: 500; }
.topnav a:hover, .topnav a.active { background: var(--surface-2); color: var(--text); text-decoration: none; }
.topbar-user { display: flex; align-items: center; gap: .75rem; }

.shell { display: block; max-width: 1400px; margin: 0 auto; }
.shell.with-sidebar { display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.main { padding: 1.5rem 1.25rem 3rem; min-width: 0; }

.sidebar { padding: 1.25rem .75rem; border-right: 1px solid var(--border); min-height: calc(100vh - 53px); }
.sidebar-app { display: flex; gap: .6rem; align-items: center; padding: 0 .5rem 1rem; border-bottom: 1px solid var(--border); margin-bottom: .75rem; }
.sidebar-app-name { font-weight: 600; line-height: 1.2; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav a { padding: .45rem .7rem; border-radius: 7px; color: var(--text); border-left: 3px solid transparent; }
.sidebar-nav a:hover { background: var(--surface); text-decoration: none; }
.sidebar-nav a.active { background: var(--surface); border-left-color: var(--app-primary); font-weight: 600; box-shadow: var(--shadow); }

/* ---------- common blocks ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head p { margin: .25rem 0 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card h2:not(:first-child) { margin-top: .75rem; }
.card-danger { border-color: #f3c4c4; }
.stack > * + * { margin-top: .9rem; }
.stack > h2 + * { margin-top: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1.25rem; }
.align-start { align-items: start; }
.empty { text-align: center; padding: 2.5rem 1rem; border: 2px dashed var(--border); border-radius: var(--radius); color: var(--muted); }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash-success { background: #effaf2; border-color: #bfe5ca; color: #14532d; }
.flash-error { background: #fdf0f0; border-color: #f1c4c4; color: #7f1d1d; }
.flash-info { background: #eff4ff; border-color: #c7d6fb; color: #1e3a8a; }

/* ---------- buttons & badges ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
    padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
    cursor: pointer; white-space: nowrap; line-height: 1.2;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.btn-sm { padding: .3rem .6rem; font-size: .85rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #991b1b; }
.btn-danger-ghost { color: var(--danger); background: transparent; border-color: transparent; }
.btn-danger-ghost:hover { background: #fdf0f0; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.badge-green { background: #effaf2; border-color: #bfe5ca; color: var(--green); }
.badge-grey { background: #f1efec; color: #6b645b; }
.badge-blue { background: #eff4ff; border-color: #c7d6fb; color: var(--blue); }
.badge-gold { background: #fdf8e8; border-color: #eedc9c; color: var(--gold); }
.badge-red { background: #fdf0f0; border-color: #f1c4c4; color: var(--danger); }
.badge-button { cursor: pointer; font-family: inherit; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: .3rem; }
.field > span:first-child { font-weight: 600; font-size: .9rem; }
.field-inline { flex-direction: row; align-items: center; gap: .5rem; }
input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=file]), select, textarea {
    width: 100%; padding: .5rem .65rem; font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
textarea { resize: vertical; }
input[type=file] { font: inherit; }
.check { display: flex; align-items: center; gap: .45rem; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.field-error { color: var(--danger); font-size: .85rem; }
.form-actions { display: flex; gap: .5rem; padding-top: .5rem; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: .75rem 1rem; margin: 0; }
legend { font-weight: 600; padding: 0 .35rem; }
.radio-group .check + .check { margin-top: .35rem; }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .4rem 1rem; }
.color-input { display: flex; gap: .4rem; align-items: center; }
.color-input input[type=color] { width: 42px; height: 38px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); flex: none; }
.current-image { display: flex; align-items: center; gap: .75rem; margin-bottom: .35rem; }
.settings-editor { display: flex; flex-direction: column; gap: .4rem; align-items: flex-start; }
.settings-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) auto; gap: .4rem; width: 100%; }
.markdown-editor { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.markdown-editor textarea { min-height: 320px; font-family: var(--mono); font-size: .9rem; }
.markdown-preview { width: 100%; min-height: 320px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.countdown-preview { color: var(--primary); font-weight: 600; }

.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.toolbar select, .toolbar input[type=search] { width: auto; min-width: 140px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .table-wrap { box-shadow: none; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .6rem .8rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .col-actions { text-align: right; white-space: nowrap; }
.table .col-handle { width: 28px; color: var(--muted); cursor: grab; user-select: none; }
.table tr.dragging { opacity: .45; }
.table tr.drag-over td { box-shadow: inset 0 2px 0 var(--primary); }
.thumb-sm { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; display: block; background: var(--surface-2); }
.thumb-empty { border: 1px dashed var(--border); }
.thumb-md { width: 120px; border-radius: 8px; }
.pagination { display: flex; gap: .75rem; align-items: center; justify-content: center; margin-top: 1rem; }

/* ---------- apps grid ---------- */
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 1rem; }
.app-card { background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--card-accent, var(--primary)); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .8rem; min-width: 0; }
.app-card-main { display: flex; gap: .75rem; align-items: center; color: inherit; }
.app-card-main:hover { text-decoration: none; }
.app-card-text { flex: 1; min-width: 0; }
.app-card h2 { margin: 0; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-icon { width: 52px; height: 52px; border-radius: 12px; object-fit: cover; flex: none; }
.app-icon-sm { width: 36px; height: 36px; border-radius: 9px; object-fit: cover; flex: none; }
.app-icon-fallback { display: grid; place-items: center; background: var(--card-accent, var(--app-primary)); color: #fff; font-weight: 700; font-size: 1.3rem; }
.app-card-stats { display: flex; gap: 1.5rem; }
.app-card-stats div { display: flex; flex-direction: column; }
.app-card-stats strong { font-size: 1.25rem; line-height: 1.1; }
.app-card-stats span { color: var(--muted); font-size: .8rem; }
.app-card-actions { display: flex; gap: .4rem; }
.copy-row { display: flex; gap: .4rem; align-items: center; min-width: 0; }
.copy-row code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: .35rem .5rem; }
.kv { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: .5rem 1rem; align-items: center; margin-bottom: .75rem; }
.kv-label { font-weight: 600; color: var(--muted); font-size: .9rem; }

/* ---------- wallpapers ---------- */
.uploader-options { display: flex; flex-wrap: wrap; gap: .75rem 1.25rem; align-items: center; margin-bottom: .75rem; }
.uploader-options select { width: auto; min-width: 180px; }
.dropzone {
    display: flex; flex-direction: column; align-items: center; gap: .3rem; text-align: center;
    padding: 1.75rem 1rem; border: 2px dashed var(--border); border-radius: var(--radius);
    background: var(--surface-2); cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone.is-over { border-color: var(--primary); background: #fff4ec; }
.dropzone input { display: none; }
.upload-queue { list-style: none; padding: 0; margin: .75rem 0 0; display: grid; gap: .35rem; }
.upload-item { display: grid; grid-template-columns: minmax(0, 1fr) 140px 90px; gap: .75rem; align-items: center; font-size: .85rem; }
.upload-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; background: var(--primary); transition: width .15s; }
.upload-item.is-done .progress > span { background: var(--green); }
.upload-item.is-error { color: var(--danger); }
.upload-item.is-error .progress > span { background: var(--danger); width: 100% !important; }
.upload-done { display: flex; gap: .75rem; align-items: center; margin-top: .75rem; }

.bulk-bar { display: flex; flex-wrap: wrap; gap: .5rem .75rem; align-items: center; padding: .6rem .8rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .75rem; position: sticky; top: 53px; z-index: 5; }
.bulk-bar select { width: auto; min-width: 160px; }
.wallpaper-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .8rem; }
.wallpaper-card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.wallpaper-card.is-inactive .wallpaper-thumb img { opacity: .45; }
.wallpaper-card:has([data-select-item]:checked) { outline: 2px solid var(--primary); }
.wallpaper-thumb { display: block; aspect-ratio: 9 / 16; background: var(--surface-2); }
.wallpaper-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.wallpaper-select { position: absolute; top: .45rem; left: .45rem; background: rgba(255, 255, 255, .92); border-radius: 6px; padding: .2rem; line-height: 0; }
.wallpaper-select input { width: 18px; height: 18px; accent-color: var(--primary); }
.wallpaper-badges { position: absolute; top: .45rem; right: .45rem; display: flex; flex-direction: column; gap: .2rem; align-items: flex-end; }
.wallpaper-meta { padding: .5rem; display: flex; flex-direction: column; gap: .25rem; }
.inline-edit { border-color: transparent !important; padding: .2rem .35rem !important; background: transparent !important; }
.inline-edit:hover, .inline-edit:focus { border-color: var(--border) !important; background: var(--surface) !important; }
.inline-edit.is-saved { box-shadow: 0 0 0 2px #bfe5ca; }
.inline-edit.is-error { box-shadow: 0 0 0 2px #f1c4c4; }
.edit-layout { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 1rem; align-items: start; }
.edit-preview { margin: 0; text-align: center; }
.edit-preview img { border-radius: 8px; max-height: 70vh; }

/* ---------- api preview & stats ---------- */
.api-preview { display: grid; grid-template-columns: minmax(0, 380px) minmax(0, 1fr); gap: 1rem; align-items: start; }
.endpoint-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.endpoint { width: 100%; text-align: left; display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: .1rem .5rem; padding: .5rem .6rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font: inherit; color: inherit; }
.endpoint:hover, .endpoint.active { border-color: var(--primary); }
.endpoint code { background: none; border: 0; padding: 0; overflow-wrap: anywhere; }
.endpoint .muted { grid-column: 2; }
.method { font-size: .7rem; font-weight: 700; padding: .1rem .3rem; border-radius: 4px; text-align: center; align-self: start; }
.method-get { background: #eff4ff; color: var(--blue); }
.method-post { background: #effaf2; color: var(--green); }
.preview-pane { position: sticky; top: 70px; min-width: 0; }
.preview-head { display: flex; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.preview-head code { overflow-wrap: anywhere; }
pre.json, pre.log { background: #1f1b16; color: #f3ede4; padding: .9rem; border-radius: 8px; overflow: auto; max-height: 65vh; font: .8rem/1.5 var(--mono); margin: .6rem 0 0; white-space: pre-wrap; word-break: break-word; }
pre.log { max-height: 240px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat strong { font-size: 1.7rem; line-height: 1.2; }
.stat small { color: var(--muted); }
.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: .5rem; height: 180px; align-items: end; }
.bar-col { display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; gap: .25rem; min-width: 0; }
.bar { width: 100%; max-width: 48px; background: var(--app-primary); border-radius: 5px 5px 0 0; min-height: 2px; }
.bar-value, .bar-label { font-size: .75rem; color: var(--muted); white-space: nowrap; }

/* ---------- login & errors ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 2rem; box-shadow: var(--shadow); }
.login-card h1 { margin: 1rem 0 1.25rem; font-size: 1.25rem; }
.login-brand { font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.error-card { max-width: 720px; text-align: center; }
.error-card pre { text-align: left; }
.error-code { font-size: 3.5rem; font-weight: 800; color: var(--primary); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
    .shell.with-sidebar { grid-template-columns: 1fr; }
    .sidebar { min-height: 0; border-right: 0; border-bottom: 1px solid var(--border); padding: .75rem; }
    .sidebar-app { padding-bottom: .5rem; margin-bottom: .5rem; }
    .sidebar-nav { flex-direction: row; overflow-x: auto; gap: .25rem; scrollbar-width: thin; }
    .sidebar-nav a { white-space: nowrap; border-left: 0; border-bottom: 3px solid transparent; }
    .sidebar-nav a.active { border-bottom-color: var(--app-primary); }
    .api-preview, .edit-layout, .markdown-editor { grid-template-columns: 1fr; }
    .preview-pane { position: static; }
}
@media (max-width: 640px) {
    .main { padding: 1rem .75rem 2.5rem; }
    .topbar { padding: .5rem .75rem; gap: .5rem; }
    .hide-mobile { display: none; }
    .grid-2 { grid-template-columns: 1fr; }
    .kv { grid-template-columns: 1fr; }
    .settings-row { grid-template-columns: 1fr 1fr auto; }
    .wallpaper-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .upload-item { grid-template-columns: minmax(0, 1fr) 70px; }
    .upload-item .status { grid-column: 1 / -1; }
    .bulk-bar { top: 45px; }
}
