:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e6e9ef;
  --muted: #98a1b3;
  --accent: #4f9cf9;
  --accent-soft: #1d3a5f;
  --ok: #3fbf7f;
  --warn: #e0a33e;
  --bad: #e0645c;
  --radius: 10px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

.layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-weight: 650; font-size: 15px; letter-spacing: .2px; margin: 0 8px 22px; }
.brand small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; margin-top: 3px; }
.nav a {
  display: block; padding: 8px 10px; border-radius: 8px; color: var(--text);
  font-size: 13.5px; margin-bottom: 2px;
}
.nav a:hover { background: var(--panel-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: #cfe4ff; }
.nav .sep { height: 1px; background: var(--line); margin: 14px 8px; }
.sidebar-foot { position: absolute; bottom: 16px; left: 14px; right: 14px; color: var(--muted); font-size: 11.5px; }

.main { padding: 28px clamp(18px, 2.6vw, 48px) 60px; max-width: none; min-width: 0; }
h1 { font-size: 21px; font-weight: 600; margin: 0 0 4px; }
h2 { font-size: 15px; font-weight: 600; margin: 30px 0 12px; }
.sub { color: var(--muted); margin: 0 0 26px; font-size: 13px; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px;
}
.card h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid.two, .grid.three, .grid.four { grid-template-columns: 1fr; } .layout { grid-template-columns: 1fr; } .sidebar { position: static; height: auto; } }

.stat .k { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; }
.stat .v { font-size: 22px; font-weight: 600; margin-top: 4px; }
.stat .v small { font-size: 12px; color: var(--muted); font-weight: 400; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 11.5px;
     text-transform: uppercase; letter-spacing: .5px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.mono, .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=date], input[type=time], select, textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 13.5px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 140px; }
.row > .shrink { flex: 0 0 auto; }

.btn {
  display: inline-block; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit;
  font-size: 13px; cursor: pointer;
}
.btn:hover { border-color: #3c4454; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; }
.btn.danger { color: #ffc9c5; border-color: #5a2a28; background: #2a1615; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: .2px; }
.badge.ok { background: #123526; color: #7ee2ae; }
.badge.off { background: #2a2f3a; color: var(--muted); }
.badge.warn { background: #3a2c12; color: #f0c273; }
.badge.bad { background: #3a1a18; color: #f09b95; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 18px; font-size: 13.5px; }
.flash.ok { background: #123526; color: #a9efc9; border: 1px solid #1d5237; }
.flash.err { background: #3a1a18; color: #ffc9c5; border: 1px solid #5a2a28; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.empty { color: var(--muted); padding: 26px 0; text-align: center; font-size: 13px; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 16px; }
.media-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
              display: flex; flex-direction: column; }
.media-card .thumb { aspect-ratio: 16/9; background: #000 center/cover no-repeat; display: block; position: relative; }
.media-card .meta { padding: 8px 11px; font-size: 11.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.media-card .meta.used { border-top: 1px solid var(--line); padding-top: 7px; margin-top: 2px; }
.media-card .name { padding: 9px 11px 4px; font-size: 13px; word-break: break-word; font-weight: 500; }
.media-card .notes { padding: 0 11px 8px; font-size: 11.5px; color: var(--muted); }
.media-card .card-actions { display: flex; gap: 6px; padding: 8px 11px 11px; margin-top: auto; }
.media-card .card-actions .btn { flex: 1; text-align: center; }
.media-card .card-actions form { flex: 1; display: flex; }

.kind-badge { position: absolute; top: 7px; left: 7px; background: rgba(5, 8, 12, .78);
              border: 1px solid rgba(255,255,255,.14); color: #dfe6f1; font-size: 10.5px;
              letter-spacing: .04em; text-transform: uppercase; padding: 2px 7px; border-radius: 999px; }

.text-thumb { display: flex !important; flex-direction: column; align-items: center; justify-content: center;
              gap: 5px; padding: 20px 14px; text-align: center;
              background: linear-gradient(135deg, #14263b 0%, #0a0f18 70%) !important; }
.text-thumb-title { font-size: 14px; font-weight: 600; color: #eaf2ff; line-height: 1.25;
                    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.text-thumb-excerpt { font-size: 11px; color: #98a9c4; line-height: 1.35;
                      display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mini-text { display: flex !important; align-items: center; justify-content: center; color: #cfe4ff;
             background: linear-gradient(135deg, #14263b, #0a0f18) !important; font-weight: 600; }

.media-filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 4px 0 16px; }
.media-filters input[type=search] { flex: 1 1 260px; max-width: 420px; background: var(--panel);
                                    border: 1px solid var(--line); color: var(--text); border-radius: 8px;
                                    padding: 8px 11px; font: inherit; font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--panel); border: 1px solid var(--line); color: var(--muted); border-radius: 999px;
        padding: 6px 11px; font: inherit; font-size: 12px; cursor: pointer; text-decoration: none;
        display: inline-flex; gap: 4px; align-items: center; }
.chip:hover { text-decoration: none; }
.chip span { opacity: .65; margin-left: 3px; }
.chip.active { background: var(--accent-soft); border-color: #2c5b8f; color: #d6e8ff; }
.chip:hover { border-color: #3c4454; }

.items { display: flex; flex-direction: column; gap: 10px; }
.item-row {
  display: grid;
  grid-template-columns: 34px minmax(190px, 1.7fr) 74px 118px 94px 94px 94px minmax(150px, auto);
  gap: 8px 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.item-row .idx { color: var(--muted); font-size: 12px; text-align: center; }
.item-row .media-cell { display: flex; gap: 10px; align-items: center; min-width: 0; }
.item-row .media-info { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.item-row .media-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-row .media-info .small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-thumb { width: 76px; aspect-ratio: 16/9; border-radius: 6px; background: #000 center/cover no-repeat;
              flex: 0 0 auto; font-size: 20px; }
.item-row .switches { display: flex; flex-direction: column; gap: 3px; }
.switches label { display: flex; gap: 6px; align-items: center; margin: 0; font-size: 11.5px; color: var(--muted);
                  cursor: pointer; }
.switches input:disabled + span { opacity: .3; }
.item-row .hint { margin-top: 3px; font-size: 10.5px; color: var(--muted); }
.item-row .actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.item-row select { padding: 6px 7px; font-size: 12.5px; }
.item-row input[type=number] { padding: 6px 7px; font-size: 12.5px; }

@media (max-width: 1280px) {
  .item-row { grid-template-columns: 30px minmax(180px, 1.6fr) 70px 112px 88px 88px 88px; }
  .item-row .actions { grid-column: 2 / -1; justify-content: flex-start; }
}
@media (max-width: 860px) {
  .item-row { grid-template-columns: 1fr 1fr; }
  .item-row .idx { display: none; }
  .item-row .media-cell { grid-column: 1 / -1; }
  .item-row .actions { grid-column: 1 / -1; }
}

.code-box { font-family: ui-monospace, monospace; font-size: 34px; letter-spacing: .28em;
            padding: 14px 18px; background: #05070a; border: 1px dashed var(--line); border-radius: 10px;
            display: inline-block; }

.footer-note { color: var(--muted); font-size: 11.5px; margin-top: 30px; }

/* ------------------------------------------------------------- page header */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px;
             flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { margin-bottom: 0; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.checkline { display: flex; align-items: center; gap: 7px; margin: 0; font-size: 12.5px; color: var(--text); }
.notice { border-radius: 8px; padding: 10px 12px; font-size: 12.5px; line-height: 1.45; margin-bottom: 14px; }
.notice.warn { background: #33280f; border: 1px solid #5a461c; color: #f0c273; }

/* -------------------------------------------------------------- media edit */
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(340px, 1fr);
               gap: 18px; align-items: start; }
.detail-main, .detail-side { min-width: 0; }
.detail-side { position: sticky; top: 24px; }
@media (max-width: 1100px) {
  .detail-grid { grid-template-columns: 1fr; }
  .detail-side { position: static; }
}
.preview-stage { display: flex; align-items: center; justify-content: center; min-height: 300px;
                 max-height: 64vh; background: #000; border: 1px solid var(--line); border-radius: 9px;
                 overflow: hidden; }
.preview-stage img, .preview-stage video { max-width: 100%; max-height: 64vh; display: block; }
.meta-list { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 7px 14px;
             font-size: 12.5px; align-items: baseline; }
.meta-list > span:nth-child(odd) { color: var(--muted); }
.meta-list > span:nth-child(even) { word-break: break-word; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid .field { margin: 0; }
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 720px) { .form-grid, .form-grid.four { grid-template-columns: 1fr; } .form-grid .span-2 { grid-column: auto; } }
.advanced { margin: 14px 0 4px; border-top: 1px solid var(--line); padding-top: 12px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 12.5px; margin-bottom: 8px; }
.advanced summary:hover { color: var(--text); }

/* ---------------------------------------------------------------- add item */
.add-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); gap: 20px; align-items: start; }
@media (max-width: 1050px) { .add-layout { grid-template-columns: 1fr; } }
.add-fields { border-left: 1px solid var(--line); padding-left: 20px; }
@media (max-width: 1050px) { .add-fields { border-left: none; padding-left: 0; border-top: 1px solid var(--line); padding-top: 16px; } }
.add-fields .switches { display: flex; gap: 16px; margin-bottom: 12px; }

.picker { display: grid; grid-template-columns: minmax(0, 1fr) 210px; gap: 12px; align-items: start; }
@media (max-width: 720px) { .picker { grid-template-columns: 1fr; } }
.picker-tools { display: flex; gap: 8px; margin-bottom: 9px; }
.picker-tools input, .picker-tools select { padding: 7px 9px; font-size: 12.5px; }
.picker-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 8px;
               max-height: 318px; overflow-y: auto; padding: 2px; }
.pick { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 0;
        overflow: hidden; cursor: pointer; text-align: left; font: inherit; color: var(--text); }
.pick:hover { border-color: #3c4454; }
.pick.selected { border-color: var(--accent); box-shadow: 0 0 0 2px #1d3a5f; }
.pick .pick-thumb { display: block; aspect-ratio: 16/9; background: #000 center/cover no-repeat; font-size: 18px; }
.pick .pick-name { display: block; padding: 5px 7px 6px; font-size: 11px; line-height: 1.25;
                   overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-preview { background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 10px; }
.pv-stage { aspect-ratio: 16/9; background: #000; border-radius: 6px; overflow: hidden;
            display: flex; align-items: center; justify-content: center; }
.pv-stage img, .pv-stage video { width: 100%; height: 100%; object-fit: contain; display: block; }
.pv-name { font-size: 12.5px; font-weight: 500; margin-top: 8px; overflow: hidden; text-overflow: ellipsis;
           white-space: nowrap; }
.pv-meta { font-size: 11px; margin-top: 2px; }
.pv-notes { font-size: 11px; margin-top: 6px; border-top: 1px solid var(--line); padding-top: 6px; }

/* ------------------------------------------------------------- rich editor */
.rich-toolbar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
                background: var(--panel-2); border: 1px solid var(--line); border-bottom: none;
                border-radius: 8px 8px 0 0; padding: 7px; }
.tool { background: transparent; border: 1px solid transparent; color: var(--text); border-radius: 6px;
        padding: 5px 8px; font: inherit; font-size: 12.5px; cursor: pointer; line-height: 1.2; }
.tool:hover { background: #262c37; border-color: var(--line); }
.tool.b { font-weight: 700; }
.tool.i { font-style: italic; }
.tool.u { text-decoration: underline; }
.tool.s { text-decoration: line-through; }
.tool-sep { width: 1px; height: 20px; background: var(--line); margin: 0 3px; }
.tool-select { width: auto; padding: 5px 6px; font-size: 12px; background: var(--panel); }
.tool-color { display: inline-flex; align-items: center; gap: 3px; color: var(--muted); font-size: 12px;
              cursor: pointer; margin: 0; padding: 0 3px; }
.tool-color input[type=color] { width: 26px; height: 24px; padding: 0; border: 1px solid var(--line);
                                border-radius: 5px; background: transparent; cursor: pointer; }
.rich-editor { min-height: 300px; background: #07090d; color: #eef3fb; border: 1px solid var(--line);
               border-radius: 0 0 8px 8px; padding: 30px 34px; font-size: 18px; line-height: 1.55;
               outline: none; overflow-wrap: break-word; }
.rich-editor:focus { border-color: var(--accent); }
.rich-editor:empty:before { content: attr(data-placeholder); color: #5b6678; }
.rich-editor h1, .instant-frame .im h1 { font-size: 2.1em; line-height: 1.15; margin: .35em 0; }
.rich-editor h2, .instant-frame .im h2 { font-size: 1.55em; line-height: 1.2; margin: .4em 0; }
.rich-editor h3, .instant-frame .im h3 { font-size: 1.25em; line-height: 1.25; margin: .45em 0; }
.rich-editor h4, .instant-frame .im h4 { font-size: 1.1em; margin: .45em 0; }
.rich-editor p, .instant-frame .im p { margin: .45em 0; }
.rich-editor ul, .rich-editor ol, .instant-frame .im ul, .instant-frame .im ol { margin: .5em 0; padding-left: 1.4em; }
.rich-editor blockquote, .instant-frame .im blockquote { margin: .6em 0; padding: .2em 0 .2em 1em;
                                                     border-left: 3px solid #3c5a7c; color: #c8d6e9; }
.rich-editor hr, .instant-frame .im hr { border: none; border-top: 1px solid #33445c; margin: 1em 0; }
.rich-editor a, .instant-frame .im a { color: #7db6ff; }

.instant-frame { aspect-ratio: 16/9; background: #000; border: 1px solid var(--line); border-radius: 9px;
                 overflow: hidden; }
/* The preview is the message document itself, so the operator sees the real
   background and typeface. Same rules as player/css/player.css. */
.instant-frame .im { height: 100%; width: 100%; color: #fff; display: flex; flex-direction: column;
                     align-items: center; justify-content: center; text-align: center; padding: 6% 8%;
                     font-size: clamp(12px, 1.15vw, 21px); line-height: 1.5; overflow: hidden;
                     overflow-wrap: break-word; background-size: cover; background-position: center; }
.instant-frame .im > * { max-width: 100%; }
.instant-frame .im ul, .instant-frame .im ol { text-align: left; }
.instant-frame .im img { display: block; max-width: 100%; max-height: 42%; object-fit: contain;
                         margin: .5em auto; border-radius: 4px; }

/* --------------------------------------------------------- message look */
.look-head h3 { margin: 0 0 2px; }
.look-head p { margin: 0 0 14px; }
.look-row { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 10px; }
.look-label { flex: 0 0 96px; color: var(--muted); font-size: 12.5px; padding-top: 6px; }
.look-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px;
             margin-bottom: 12px; }
.look-field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }
.look-field input[type=color] { width: 52px; height: 34px; padding: 0; border: 1px solid var(--line);
                                border-radius: 6px; background: transparent; cursor: pointer; }
.look-panel { border-top: 1px solid var(--line); padding-top: 14px; margin: 14px 0; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg-item { margin: 0; cursor: pointer; }
.seg-item input { position: absolute; opacity: 0; pointer-events: none; }
.seg-item span { display: inline-block; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px;
                 font-size: 12.5px; color: var(--muted); background: var(--panel-2); }
.seg-item input:checked + span { border-color: var(--accent); color: var(--text); background: #1d3350; }
.range-row { display: flex; align-items: center; gap: 8px; }
.range-row input[type=range] { flex: 1; min-width: 90px; accent-color: var(--accent); }
.range-row input[type=number] { width: 74px; }

.image-insert { background: var(--panel-2); border: 1px solid var(--line); border-bottom: none;
                padding: 10px; }
.image-insert-foot { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 10px; }
.image-insert-foot .look-field { flex-direction: row; align-items: center; gap: 8px; }
.upload-label { margin: 0; cursor: pointer; }
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px;
              max-height: 252px; overflow-y: auto; padding: 2px; }
.image-grid:empty:after { content: "No pictures in the library yet — upload one.";
                          color: var(--muted); font-size: 12.5px; }
.image-pick { padding: 0; border: 2px solid transparent; border-radius: 8px; background: #10141b;
              cursor: pointer; overflow: hidden; display: flex; flex-direction: column; }
.image-pick img { width: 100%; aspect-ratio: 16/10; object-fit: cover; display: block; }
.image-pick span { font-size: 10.5px; color: var(--muted); padding: 3px 4px; white-space: nowrap;
                   overflow: hidden; text-overflow: ellipsis; }
.image-pick:hover { border-color: #40506a; }
.image-pick.selected { border-color: var(--accent); }
.image-pick.selected span { color: var(--text); }
.tips { margin: 0; padding-left: 18px; color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.tips li { margin-bottom: 6px; }
