:root {
  --bg: #f3f5f8; --panel: #fff; --line: #dfe3ea; --text: #1b2430; --muted: #66707f;
  --primary: #1f6feb; --primary-2: #1a5fd0; --danger: #d33; --ok: #1a8f4a; --warn: #b7791f;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color: var(--primary); }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--danger); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }

/* auth */
.auth { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 380px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
label { display: block; margin: 0 0 12px; font-weight: 500; }
label > input, label > select, label > textarea {
  display: block; width: 100%; margin-top: 5px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px;
  font: inherit; background: #fff; color: var(--text);
}
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: auto; margin: 0; }
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc0ff; outline-offset: 0; border-color: var(--primary); }
.help { display: block; color: var(--muted); font-size: 12px; font-weight: 400; margin-top: 3px; }

.btn { display: inline-block; padding: 8px 14px; border-radius: 7px; border: 1px solid var(--line); background: #fff; color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; text-align: center; line-height: 1.2; }
.btn:hover { background: #f7f9fc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { color: var(--danger); border-color: #f0c0c0; }
.btn.danger:hover { background: #fff3f3; }
.btn.subtle { border-color: transparent; color: var(--muted); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { display: block; width: 100%; margin-bottom: 8px; }
.btn[disabled] { opacity: .6; cursor: default; }
form.inline { display: inline; }

/* layout */
#app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: #101828; color: #dbe2ee; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 18px 18px 10px; }
.brand-link { color: #fff; text-decoration: none; font-weight: 700; font-size: 17px; }
.nav { flex: 1; overflow: auto; padding: 6px 10px; }
.nav a { display: block; padding: 9px 10px; border-radius: 7px; color: #c7d0dd; text-decoration: none; }
.nav a:hover { background: #1b2740; color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.nav a small { display: block; font-size: 11.5px; opacity: .65; }
.nav .none { padding: 10px; color: #7d8ba0; font-size: 13px; }
.sidebar-foot { padding: 12px 14px 14px; border-top: 1px solid #1f2b44; }
.sidebar-foot .btn { background: #182238; border-color: #24304c; color: #dbe2ee; }
.sidebar-foot .btn:hover { background: #1f2c48; }
.sidebar-foot .btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.sidebar-foot .btn.subtle { background: transparent; border-color: transparent; color: #8592a8; }

#main { padding: 22px 26px 60px; min-width: 0; }
.loading { color: var(--muted); padding: 40px; text-align: center; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* dashboard */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.tile h2 { margin: 0; }
.tile .url { font-size: 12.5px; word-break: break-all; }
.tile .row { display: flex; gap: 8px; margin-top: auto; }
.mini { display: grid; gap: 3px; width: 100%; aspect-ratio: 16/9; background: #cfd6e0; padding: 3px; border-radius: 4px; }
.mini > div { background: #fff; border-radius: 2px; display: flex; align-items: center; justify-content: center; font-size: 10px; color: var(--muted); overflow: hidden; }

/* editor */
.editor { display: grid; grid-template-columns: minmax(380px, 520px) 1fr; gap: 22px; align-items: start; }
@media (max-width: 1100px) { .editor { grid-template-columns: 1fr; } }
.section { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 14px; }

.layouts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.layout-opt { border: 2px solid var(--line); border-radius: 8px; padding: 8px; background: #fff; cursor: pointer; text-align: center; font-size: 12px; color: var(--muted); }
.layout-opt:hover { border-color: #b8c7e0; }
.layout-opt.active { border-color: var(--primary); color: var(--text); }
.layout-opt .mini { margin-bottom: 6px; }

.ratios { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.ratios input { width: 64px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.ratios .lbl { font-weight: 500; min-width: 110px; }

.boxcard { border: 1px solid var(--line); border-radius: 9px; margin-bottom: 12px; overflow: hidden; }
.boxcard-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: #f7f9fc; border-bottom: 1px solid var(--line); }
.boxcard-head .letter { width: 26px; height: 26px; border-radius: 6px; background: #101828; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; text-transform: uppercase; }
.boxcard-head select { flex: 1; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; font: inherit; background: #fff; }
.boxcard-body { padding: 12px 12px 4px; }

.filefield { display: flex; gap: 6px; align-items: stretch; margin-top: 5px; }
.filefield input[type=text] { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; font: inherit; }
.filefield select { max-width: 130px; padding: 0 8px; border: 1px solid var(--line); border-radius: 7px; font: inherit; background: #fff; }
.urlrow { display: flex; gap: 6px; margin-top: 5px; }
.urlrow input { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; font: inherit; }
.check-result { margin: 6px 0 10px; font-size: 12.5px; }

.imagelist { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin: 6px 0 8px; }
.imagelist .thumb { position: relative; aspect-ratio: 16/10; background: #eef1f5 center/cover no-repeat; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.imagelist .thumb button { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 13px; line-height: 22px; padding: 0; }
.imagelist .thumb .n { position: absolute; left: 0; right: 0; bottom: 0; font-size: 10px; background: rgba(0,0,0,.55); color: #fff; padding: 2px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.imagelist .thumb .n span { opacity: .7; }
.imgactions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.imgactions select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; font: inherit; background: #fff; max-width: 180px; }

.colorfield { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.colorfield input[type=color] { width: 44px; height: 32px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.colorfield input[type=text] { width: 100px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; font: inherit; }

/* preview */
.preview-col { position: sticky; top: 18px; }
.preview-frame { position: relative; width: 100%; aspect-ratio: 16/9; background: #000; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); box-shadow: 0 8px 30px rgba(0,0,0,.15); }
.preview-frame iframe { position: absolute; left: 0; top: 0; width: 1920px; height: 1080px; border: 0; transform-origin: 0 0; pointer-events: none; }
.preview-tools { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.preview-tools .url { font-size: 13px; word-break: break-all; }
.preview-tools .url code { font-size: 13px; }
.notes { font-size: 12.5px; color: var(--muted); }
.notes li { margin-bottom: 4px; }

.savebar { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.savebar .status { color: var(--muted); font-size: 12.5px; margin-left: auto; }
.dirty .savebar .status::before { content: "Unsaved changes"; color: var(--warn); }

/* files */
table.files { width: 100%; border-collapse: collapse; font-size: 13px; }
table.files th, table.files td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
table.files td.name { word-break: break-all; }

/* toast */
#toast { position: fixed; right: 18px; bottom: 18px; z-index: 50; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #101828; color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13.5px; box-shadow: 0 6px 20px rgba(0,0,0,.25); opacity: 0; transform: translateY(8px); transition: all .2s; max-width: 380px; }
.toast.show { opacity: 1; transform: none; }
.toast.err { background: #b22; }
.toast.ok { background: var(--ok); }
