:root {
  --bg: #f4f3ef; --card: #fff; --ink: #17171a; --muted: #6b6b73; --line: #e4e2dc;
  --accent: #e8442e; --accent-ink: #fff; --ok: #138a4c; --bad: #c62828; --side: #141416;
  --r: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 Inter, system-ui, sans-serif; color: var(--ink); background: var(--bg); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.warn { color: #b26a00; }
.error { color: var(--bad); margin-top: 10px; }
.ok { color: var(--ok); margin-top: 10px; font-weight: 600; }
code { background: #f0eee8; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
h1 { font: 800 26px/1.1 Montserrat, Inter, sans-serif; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 15px; margin: 0 0 12px; text-transform: uppercase; letter-spacing: .06em; }

.brand { font: 900 20px Montserrat, sans-serif; color: #fff; letter-spacing: -.02em; }
.brand span { color: var(--accent); }
.brand.big { font-size: 30px; color: var(--ink); }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: var(--side); }
.login-card { width: 100%; max-width: 380px; }

/* Layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100%; }
.side { background: var(--side); color: #ddd; padding: 22px 16px; display: flex; flex-direction: column; gap: 28px; position: sticky; top: 0; height: 100vh; }
.side nav { display: flex; flex-direction: column; gap: 4px; }
.side nav a { color: #bbb; text-decoration: none; padding: 9px 12px; border-radius: 8px; font-weight: 600; }
.side nav a:hover { background: #222226; color: #fff; }
.side nav a.on { background: var(--accent); color: #fff; }
.side-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.side-foot .btn { color: #ddd; border-color: #333; }
body:not(.is-admin) .admin-only { display: none; }
.main { padding: 26px 28px 60px; min-width: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; margin-bottom: 18px; }
.col .card { margin-bottom: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

label { display: block; font-size: 13px; font-weight: 600; color: #3a3a40; margin: 10px 0; }
label.inline { display: flex; align-items: center; gap: 8px; font-weight: 500; }
input, textarea, select { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
label.inline input { width: auto; margin: 0; }
textarea { resize: vertical; }
#tplJson { font: 12px/1.4 ui-monospace, Menlo, monospace; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.row { display: flex; gap: 8px; align-items: center; margin: 10px 0; }
.row input { margin: 0; }
.row.wrap { flex-wrap: wrap; gap: 14px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 8px; border: 1px solid var(--ink); background: var(--ink); color: #fff; font: 600 14px Inter, sans-serif; cursor: pointer; white-space: nowrap; margin: 0; }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.wide { width: 100%; margin-top: 14px; padding: 13px; font-size: 15px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .6; cursor: wait; }

.tabs, .seg { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button, .seg button { border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 999px; font: 600 14px Inter, sans-serif; cursor: pointer; color: var(--ink); display: inline-flex; align-items: center; gap: 8px; }
.tabs button i { width: 10px; height: 10px; border-radius: 50%; background: var(--pc, #999); }
.tabs button.on, .seg button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.seg.small button { padding: 5px 11px; font-size: 13px; }
#genFormat { margin: 10px 0; }

/* Media */
.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; border: 2px dashed #cfccc3; border-radius: 10px; padding: 34px 16px; cursor: pointer; background: #faf9f6; margin: 0; }
.drop strong { font-size: 16px; }
.drop.over { border-color: var(--accent); background: #fff3f0; }
.media-list { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.mitem { position: relative; width: 110px; height: 138px; border-radius: 8px; overflow: hidden; background: #000; }
.mitem img, .mitem video { width: 100%; height: 100%; object-fit: cover; }
.mitem button { position: absolute; top: 5px; right: 5px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.7); color: #fff; cursor: pointer; font-size: 16px; line-height: 1; }
.media-list p { width: 100%; margin: 0; }

.articles { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow: auto; margin: 6px 0 12px; }
.art { display: flex; gap: 10px; align-items: center; text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px; cursor: pointer; font: inherit; color: inherit; }
.art:hover { border-color: var(--ink); }
.art img, .art .noimg { width: 72px; height: 48px; object-fit: cover; border-radius: 5px; flex: none; background: #ddd; }
.art b { display: block; font-size: 13px; line-height: 1.3; }
.art small { color: var(--muted); }
.previews { margin: 10px 0; }
.previews canvas, #tplCanvas { display: block; width: 100%; max-width: 320px; height: auto; border-radius: 8px; box-shadow: 0 4px 18px rgba(0,0,0,.15); margin-bottom: 10px; }
.canvas-story { max-width: 240px !important; }

/* Channels */
.channels { display: flex; flex-direction: column; gap: 6px; }
.ch { display: flex; align-items: center; gap: 10px; margin: 0; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-weight: 500; }
.ch input { width: auto; margin: 0; accent-color: var(--accent); }
.ch img, .int img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }
.ch.on { border-color: var(--ink); background: #faf9f6; }
.ch.blocked { opacity: .45; cursor: not-allowed; }
.ch-name { font-weight: 600; }
.ch-net { margin-left: auto; color: var(--muted); font-size: 13px; }
.ch-actions { display: flex; gap: 6px; margin-top: 4px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
#scheduleAt { margin-top: 12px; }

/* Historiku */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl .cap { max-width: 320px; }
.thumb { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; display: grid; place-items: center; background: #222; color: #fff; }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: color-mix(in srgb, var(--c) 14%, white); color: var(--c); font-weight: 600; margin: 1px 0; }
.st { font-weight: 700; font-size: 13px; }
.st.ok { color: var(--ok); } .st.bad { color: var(--bad); cursor: help; }

/* Admin */
.plist { display: flex; flex-wrap: wrap; gap: 8px; }
.plist button { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: #fff; padding: 10px 14px; border-radius: 10px; cursor: pointer; font: 600 14px Inter, sans-serif; color: var(--ink); }
.plist button i { width: 12px; height: 12px; border-radius: 50%; background: var(--pc); }
.plist button small { color: var(--muted); font-weight: 500; }
.plist button.on { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.form2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; margin-bottom: 12px; }
.logo-row { display: flex; align-items: center; gap: 12px; }
.logo-prev { height: 40px; background: #333; padding: 4px; border-radius: 6px; }
.int { padding: 8px 0; border-bottom: 1px solid var(--line); }
.int .inline { margin: 0 0 6px; flex-wrap: wrap; }
.int.off { opacity: .5; }
.int-set { margin: 0; font-size: 13px; padding: 7px 10px; }
#intList { margin-bottom: 14px; }
.tpl-grid { display: grid; grid-template-columns: 1fr 340px; gap: 20px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 30px); background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 8px; opacity: 0; transition: .25s; pointer-events: none; z-index: 10; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); }

@media (max-width: 960px) {
  .grid, .tpl-grid, .form2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; padding: 12px 16px; gap: 12px; }
  .side nav { flex-direction: row; }
  .side-foot { margin: 0 0 0 auto; }
  .main { padding: 18px 16px 60px; }
  .tbl { display: block; overflow-x: auto; }
}

[hidden] { display: none !important; }
.side-foot .btn.ghost { color: #ddd; border-color: #3a3a40; }
input[type=color] { height: 44px; padding: 4px; cursor: pointer; }

/* Reel */
.reel-box { border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin: 12px 0; background: #faf9f6; }
.reel-head { font-weight: 800; margin-bottom: 4px; }
.form2.tight { margin-bottom: 4px; }
#reelAudio, .mini-audio { width: 100%; height: 36px; margin: 6px 0 10px; }
.mini-audio { max-width: 260px; margin: 0; }
.reel-video { display: block; width: 100%; max-width: 260px; border-radius: 10px; margin: 12px 0; background: #000; }
#reelStatus { margin-top: 8px; }
#useGenerated { margin-top: 6px; }
.mitem.big, .mitem:has(video[controls]) { width: 180px; height: 320px; }
#upReel { margin-top: 14px; }

/* Foto Reel / Video Reel */
.mode-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.mode-pick button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 14px 16px; border: 2px solid var(--line); background: #fff; border-radius: 12px; cursor: pointer; font: inherit; color: var(--ink); }
.mode-pick button span { font-size: 22px; line-height: 1; margin-bottom: 4px; }
.mode-pick button b { font-size: 16px; }
.mode-pick button small { color: var(--muted); }
.mode-pick button.on { border-color: var(--accent); background: #fff4f1; }
.art.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.articles { max-height: 460px; }
.reel-wrap { display: grid; grid-template-columns: 240px 1fr; gap: 18px; align-items: start; }
.reel-stage { position: relative; width: 240px; aspect-ratio: 9 / 16; background: #111; border-radius: 12px; overflow: hidden; }
.reel-stage video { width: 100%; height: 100%; object-fit: cover; display: block; }
.reel-busy { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: rgba(17,17,17,.82); color: #fff; font-weight: 600; text-align: center; padding: 16px; }
.reel-busy.show { display: flex; }
.spin { width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.25); border-top-color: #fff; border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.reel-side label:first-child { margin-top: 0; }
.ok-text { color: var(--ok); font-weight: 600; }
#rAudio { width: 100%; height: 36px; margin: 2px 0 6px; }
@media (max-width: 1200px) { .reel-wrap { grid-template-columns: 1fr; } .reel-stage { width: 100%; max-width: 280px; } }
.story-opt { margin-top: 12px; }
.dl-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; } .dl-row a { text-decoration: none; }

/* Kontrollet e titullit te templata */
.tpl-form { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin: 12px 0; background: #faf9f6; }
.tpl-form h3 { margin: 0 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; }
.tf-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.tf-grid label { margin: 8px 0; }
.tf-grid label b { float: right; font-weight: 600; color: var(--muted); }
.tf-grid input[type=range] { padding: 0; margin-top: 10px; accent-color: var(--accent); }
.tpl-adv { margin: 8px 0 12px; }
.tpl-adv summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted); }
@media (max-width: 960px) { .tf-grid { grid-template-columns: 1fr; } }
