:root {
  --bg: #f4f6f3;
  --card: #ffffff;
  --text: #1d2420;
  --muted: #66706a;
  --line: #dde3dd;
  --accent: #2f7d32;
  --accent-dark: #22602a;
  --danger: #c0392b;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}
a { color: var(--accent-dark); }

.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 20px; text-decoration: none; color: var(--accent); }
.topbar nav { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.topbar nav a { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--text); }
.topbar nav a.active, .topbar nav a:hover { background: var(--bg); }
.logout { margin: 0; }
.account { text-decoration: none; color: var(--text); text-align: right; line-height: 1.2; padding: 4px 8px; border-radius: 8px; }
.account small { display: block; color: var(--muted); font-size: 12px; }
.account:hover, .account.active { background: var(--bg); }
table.list tr.off td { opacity: .55; }
.link-card { border-color: #1f4e79; background: #f3f7fc; }
.rename-inline { display: inline-block; margin: 0; }
.rename-inline input { border-color: transparent; background: transparent; font-weight: 600; padding: 4px 6px; width: auto; }
.rename-inline input:hover, .rename-inline input:focus { border-color: var(--line); background: #fff; }
.foreign-bar { background: #1f4e79; color: #fff; padding: 8px 20px; font-size: 14px; }
.foreign-bar button.link { color: #fff; text-decoration: underline; }

main { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
main.narrow { max-width: 420px; margin-top: 10vh; }
h1 { font-size: 26px; margin: 0 0 16px; }
h2 { font-size: 19px; margin: 0 0 12px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px;
}
.muted { color: var(--muted); font-size: 14px; }

label { display: block; font-weight: 600; margin: 12px 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], select {
  width: 100%; padding: 10px 12px; font: inherit; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
input[type=file] { font: inherit; }
button, .btn {
  display: inline-block; padding: 10px 18px; font: inherit; font-weight: 600; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; cursor: pointer; text-decoration: none;
}
button:hover, .btn:hover { background: var(--accent-dark); }
button.secondary { background: var(--bg); color: var(--text); border: 1px solid var(--line); }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); padding: 6px 12px; }
button.link { background: none; color: var(--muted); padding: 6px; font-weight: 400; }
button.link:hover { color: var(--text); }
.actions { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }
.flash.ok { background: #e3f3e4; color: #1d5a21; }
.flash.error { background: #fbe4e1; color: #8a2419; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tile .thumb {
  aspect-ratio: 16 / 9; background: #222 center / contain no-repeat; display: flex; align-items: center;
  justify-content: center; color: #fff; font-size: 14px;
}
.tile .thumb video { width: 100%; height: 100%; object-fit: contain; }
.tile .body { padding: 10px 12px; }
.tile .name { font-weight: 600; word-break: break-word; }
.tile form { margin: 8px 0 0; }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); }

.stats { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat b { display: block; font-size: 30px; }

.badge.on { background: #e3f3e4; color: #1d5a21; }
button:disabled { opacity: .35; cursor: default; }
.btn.small { padding: 6px 12px; font-size: 14px; }
.right { text-align: right; white-space: nowrap; }

.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.inline-form > div { flex: 1 1 200px; }
.inline-form > div:last-child { flex: 0 0 auto; }

table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.list td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }

.item {
  display: grid; grid-template-columns: 32px 140px 1fr auto; gap: 14px; align-items: start;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px;
}
.item.off { opacity: .55; }
.item-num { font-size: 20px; font-weight: 700; color: var(--muted); text-align: center; padding-top: 18px; }
.item-thumb .thumb { aspect-ratio: 16 / 9; border-radius: 6px; background: #222 center / contain no-repeat; display: flex;
  align-items: center; justify-content: center; color: #fff; font-size: 12px; overflow: hidden; }
.item-thumb video { width: 100%; height: 100%; object-fit: contain; }
.item .name { font-weight: 600; }
.item details { margin-top: 6px; }
.item summary { cursor: pointer; color: var(--accent-dark); font-size: 14px; }
.item-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.item-actions form { margin: 0; }
button.icon { padding: 6px 10px; }
.item-actions button.secondary { padding: 6px 12px; }
.item-form .row { display: flex; gap: 12px; flex-wrap: wrap; }
.item-form .row > div { flex: 1 1 140px; }
.item-form input[type=time], .item-form input[type=date] {
  width: 100%; padding: 8px 10px; font: inherit; border: 1px solid var(--line); border-radius: 8px; }
label.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; margin: 6px 12px 0 0; }
.days { display: flex; flex-wrap: wrap; }
@media (max-width: 760px) {
  .item { grid-template-columns: 24px 90px 1fr; }
  .item-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

.grid.pick .tile { cursor: pointer; position: relative; display: block; margin: 0; font-weight: 400; }
.grid.pick input { position: absolute; top: 8px; left: 8px; width: 22px; height: 22px; z-index: 1; }
.grid.pick .tile:has(input:checked) { outline: 3px solid var(--accent); }

.badge.warn { background: #fdecc8; color: #7a4d00; }

.modes { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.mode {
  display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 14px; font-weight: 400;
  border: 2px solid var(--line); border-radius: var(--radius); cursor: pointer;
}
.mode:has(input:checked) { border-color: var(--accent); background: #f3faf3; }
.mode input { position: absolute; opacity: 0; }
.mode-pic { display: flex; gap: 4px; height: 44px; margin-bottom: 6px; }
.mode-pic i { width: 70px; border-radius: 4px; background: #2f7d32; }
.mode-separate i:last-child { background: #1f4e79; }
.mode-stretch i { background: linear-gradient(90deg, #2f7d32, #1f4e79); background-size: 144px 100%; }
.mode-stretch i:last-child { background-position: -74px 0; }

.previews { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.preview { margin: 0; flex: 1 1 320px; max-width: 100%; }
.preview iframe {
  display: block; width: 100%; aspect-ratio: var(--ratio, 16 / 9);
  border: 6px solid #111; border-radius: 8px; background: #000;
}
.thumb.video-thumb { position: relative; }
.thumb.video-thumb:not(.need-thumb)::after {
  content: "▶"; position: absolute; right: 8px; bottom: 6px; font-size: 14px; color: #fff;
  background: rgba(0, 0, 0, .6); border-radius: 4px; padding: 1px 7px;
}
.thumb.clock-thumb { flex-direction: column; gap: 2px; }
.thumb.clock-thumb b { font-size: 34px; line-height: 1; }
.thumb.clock-thumb small { font-size: 11px; opacity: .85; }
.clock-themes { display: flex; gap: 10px; flex-wrap: wrap; }
.clock-theme { display: flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; cursor: pointer; }
.clock-theme span { padding: 4px 10px; border-radius: 6px; border: 1px solid var(--line); font-weight: 700; }
.badge.insert { background: #e6eefb; color: #1f4e79; }
.insert-box { background: var(--bg); border-radius: 8px; padding: 10px 12px; margin-top: 12px; }
.insert-box .row > div { flex: 0 1 160px; }
.badge.err { background: #fbe4e1; color: #8a2419; }
.flash.warn { background: #fdecc8; color: #7a4d00; }
.health { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-top: 14px; }
.health > div { background: var(--bg); border-radius: 8px; padding: 10px 12px; }
.health span { display: block; font-size: 13px; color: var(--muted); }
.health b { display: block; font-size: 22px; line-height: 1.3; }
.health small { color: var(--muted); font-size: 12px; }
table.checks td { padding: 6px 4px; font-size: 15px; }
table.checks td:first-child { width: 28px; }
.preview.portrait { flex: 0 1 260px; }
.preview figcaption { margin-top: 6px; color: var(--muted); font-size: 14px; text-align: center; }
.title-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.two-col { display: grid; gap: 20px; grid-template-columns: 1fr 1fr; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }
