:root {
  --accent: #4f46e5;
  --accent-dark: #4338ca;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e3e5ea;
  --ok: #16a34a;
  --err: #dc2626;
  --warn: #d97706;
  --info: #2563eb;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
code { background: #eef0f4; padding: 2px 8px; border-radius: 6px; font-size: 13px; }
small { color: var(--muted); display: block; margin-top: 3px; }

/* ---- Topbar ---- */
.topbar { background: #171a23; color: #fff; }
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 20px; height: 54px;
  display: flex; align-items: center; gap: 24px;
}
.brand { color: #fff; font-weight: 700; font-size: 16px; letter-spacing: .02em; }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar nav a { color: #c6c9d4; font-weight: 500; }
.topbar nav a:hover { color: #fff; text-decoration: none; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-right a { color: #c6c9d4; }
.langs a { padding: 3px 7px; border-radius: 6px; font-size: 12.5px; font-weight: 600; }
.langs a.on { background: var(--accent); color: #fff; }
.btn-link {
  background: none; border: 0; color: #c6c9d4; cursor: pointer;
  font: inherit; padding: 0;
}
.btn-link:hover { color: #fff; }
form.inline { display: inline; }

.container { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }

/* ---- Common bits ---- */
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 18px; flex-wrap: wrap;
}
.head-badges { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.muted-link { color: var(--muted); font-size: 13px; }

.flash {
  padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-weight: 500;
}
.flash.ok { background: #e8f7ee; color: #166534; border: 1px solid #bbe7cb; }
.flash.err { background: #fdeaea; color: #991b1b; border: 1px solid #f5c6c6; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  background: #eef0f4; color: var(--muted);
  border-radius: 999px; padding: 3px 11px; font-size: 12.5px; font-weight: 600;
}
.badge.ok { background: #e8f7ee; color: var(--ok); }
.badge.err { background: #fdeaea; color: var(--err); }
.badge.accent { background: #eceafd; color: var(--accent); }
.badge.muted { background: #eef0f4; color: var(--muted); }

/* ---- Buttons & forms ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 15px; font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; box-shadow: var(--shadow); text-decoration: none;
}
.btn:hover { background: #f8f9fb; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--err); border-color: #f0caca; }
.btn.danger:hover { background: #fdf2f2; }
.btn.small { padding: 4px 10px; font-size: 12.5px; box-shadow: none; }
.btn.wide { width: 100%; justify-content: center; }

label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 13.5px; }
label.check { display: flex; align-items: center; gap: 8px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="datetime-local"], select {
  width: 100%; margin-top: 5px; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 8px;
  font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus { outline: 2px solid #c9c5f8; border-color: var(--accent); }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); }
fieldset {
  border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin: 0 0 14px;
}
legend { font-size: 12.5px; color: var(--muted); font-weight: 600; padding: 0 6px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .row2 { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; max-width: 620px; margin-bottom: 20px;
}

/* ---- Table ---- */
.table {
  width: 100%; border-collapse: collapse; background: var(--panel);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.table th, .table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #fafbfc; }
.table tr:last-child td { border-bottom: 0; }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.actions .btn { margin-left: 4px; }
@media (max-width: 760px) {
  .table { display: block; overflow-x: auto; }
}

/* ---- URL bar / toolbar ---- */
.url-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.url-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.toolbar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-bottom: 14px;
}
.bulk { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13.5px; color: var(--muted); }
.bulk input { width: 90px; margin-top: 0; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }

/* ---- Screen info card ---- */
.screen-card {
  display: flex; gap: 28px; align-items: flex-start; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 20px; margin-bottom: 18px;
}
.screen-col { min-width: 130px; }
.screen-col.grow { flex: 1; min-width: 260px; }
.screen-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); font-weight: 700; margin-bottom: 7px;
}
.url-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.url-row code { padding: 6px 10px; }
.meter {
  width: 150px; height: 8px; background: #e8eaef; border-radius: 999px; overflow: hidden;
}
.meter-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.meter-fill.hot { background: var(--err); }
.meter-text { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

/* ---- Section head ---- */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin: 26px 0 10px;
}
.section-head h2 { margin: 0; display: flex; align-items: center; gap: 8px; }
.section-head .count {
  background: #eceafd; color: var(--accent); border-radius: 999px;
  padding: 1px 10px; font-size: 13px; font-weight: 700;
}

/* ---- Dropzone & upload progress ---- */
.dropzone {
  display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap;
  border: 2px dashed #c9cdd6; border-radius: var(--radius);
  padding: 18px; text-align: center; color: var(--muted);
  margin-bottom: 10px; cursor: pointer; transition: border-color .15s, background .15s;
  background: #fbfbfd;
}
.dropzone.over { border-color: var(--accent); background: #f4f2ff; }
.dropzone p { margin: 0; }
.dropzone .btn { pointer-events: none; }
#uploadList { margin-bottom: 10px; }
.upload-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 12px; margin-bottom: 6px; font-size: 13.5px;
}
.upload-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-row progress { width: 160px; height: 8px; }
.upload-row.done { color: var(--ok); }
.upload-row.fail { color: var(--err); }

/* ---- Media grid ---- */
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  cursor: grab; transition: transform .1s, box-shadow .15s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(16, 24, 40, .12); }
.card.dragging { opacity: .35; }
.card.drop-target { outline: 2px solid var(--accent); }
.card .thumb {
  position: relative; aspect-ratio: 16/10; background: #14161c;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-fallback { font-size: 34px; }
.card.is-hidden .thumb img { opacity: .3; filter: grayscale(1); }
.card.is-expired .thumb img { opacity: .45; }
.type-badge {
  position: absolute; left: 8px; top: 8px;
  background: rgba(0, 0, 0, .65); color: #fff; border-radius: 6px;
  padding: 2px 8px; font-size: 12px;
}
.state-badge {
  position: absolute; right: 8px; top: 8px;
  background: rgba(60, 60, 70, .85); color: #fff; border-radius: 6px;
  padding: 2px 8px; font-size: 11.5px; font-weight: 600;
}
.state-badge.warn { background: rgba(217, 119, 6, .9); }
.state-badge.info { background: rgba(37, 99, 235, .9); }
.edit-hint {
  position: absolute; right: 8px; bottom: 8px;
  background: rgba(0, 0, 0, .6); color: #fff; border-radius: 6px;
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  font-size: 13px; opacity: 0; transition: opacity .15s;
}
.card:hover .edit-hint { opacity: 1; }
.card-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; font-size: 12.5px; color: var(--muted);
}
.card-foot .ord {
  background: #eef0f4; border-radius: 6px; padding: 1px 7px; font-weight: 700;
}
.card-foot .dur { flex: 1; }
.empty-state {
  background: var(--panel); border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 40px; text-align: center; color: var(--muted); margin-bottom: 16px;
}

/* ---- Modal ---- */
.modal-wrap {
  position: fixed; inset: 0; background: rgba(15, 18, 25, .5);
  display: none; align-items: flex-start; justify-content: center;
  padding: 6vh 16px; z-index: 50; overflow-y: auto;
}
.modal-wrap.open { display: flex; }
.modal {
  background: var(--panel); border-radius: 14px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
  padding: 22px; width: 100%; max-width: 520px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal-actions.space { justify-content: space-between; }
.modal-media-head { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }
.modal-media-head img {
  width: 92px; height: 58px; object-fit: cover; border-radius: 8px; background: #14161c;
}
.modal-media-name { font-size: 13px; color: var(--muted); word-break: break-all; }

/* ---- Login ---- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #171a23 0%, #232c45 100%);
}
.login-card {
  background: var(--panel); border-radius: 16px; box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
  padding: 34px 32px; width: 100%; max-width: 380px; margin: 20px;
}
.login-brand { font-weight: 800; color: var(--accent); margin-bottom: 6px; letter-spacing: .02em; }
.login-card h1 { margin-bottom: 18px; }
.login-langs { margin-top: 16px; text-align: center; font-size: 13px; }

/* ---- Toast ---- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: #171a23; color: #fff; border-radius: 10px; padding: 11px 20px;
  font-size: 14px; font-weight: 600; opacity: 0; transition: all .25s; z-index: 99;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
