:root {
  --bg: #14161a;
  --surface: #1b1e24;
  --surface-2: #23262d;
  --border: #2c3038;
  --text: #edece7;
  --muted: #8b909a;
  --accent: #ffb238;
  --accent-dim: #7a5c22;
  --teal: #3ed6d0;
  --danger: #e5484d;
  --radius: 10px;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  height: 100%;
}

.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- Signal dot (signature element) ---------- */
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  box-shadow: 0 0 0 0 rgba(255, 178, 56, 0.5);
  animation: pulse 2.2s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255, 178, 56, 0.45); }
  70%  { box-shadow: 0 0 0 7px rgba(255, 178, 56, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 178, 56, 0); }
}
.signal { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 8px; flex-shrink: 0; }
.signal.online { background: var(--teal); box-shadow: 0 0 0 0 rgba(62, 214, 208, 0.5); animation: pulse-teal 2.2s infinite; }
.signal.stale { background: var(--accent); }
.signal.offline { background: #4a4f58; }
@keyframes pulse-teal {
  0%   { box-shadow: 0 0 0 0 rgba(62, 214, 208, 0.45); }
  70%  { box-shadow: 0 0 0 6px rgba(62, 214, 208, 0); }
  100% { box-shadow: 0 0 0 0 rgba(62, 214, 208, 0); }
}

/* ---------- Login ---------- */
.login-screen {
  height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 0%, #1d2129 0%, #14161a 60%);
}
.login-card {
  width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px;
}
.login-mark { display: flex; align-items: center; gap: 10px; }
.login-mark-text { font-family: var(--mono); font-weight: 600; letter-spacing: 2px; font-size: 15px; }
.login-sub { color: var(--muted); margin: 6px 0 24px; font-size: 13px; }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 4px; }

/* ---------- App shell ---------- */
.app-shell { display: flex; height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; }
.brand-text { font-family: var(--mono); font-weight: 600; letter-spacing: 2px; font-size: 14px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  background: none; border: none; text-align: left; color: var(--muted);
  padding: 10px 12px; border-radius: 8px; font-size: 14px; cursor: pointer;
  font-family: var(--sans); font-weight: 500;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--accent); }
.sidebar-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px; border-top: 1px solid var(--border); margin-top: 10px; font-size: 13px;
}
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; text-decoration: underline; }
.link-btn:hover { color: var(--text); }

.main { flex: 1; overflow-y: auto; padding: 32px 40px; }
.view-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; }
.view-header h1 { margin: 0 0 4px; font-size: 22px; }
.view-header p { margin: 0; font-size: 13.5px; }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--sans); font-weight: 600; font-size: 13.5px;
  border-radius: 8px; padding: 9px 16px; border: 1px solid transparent;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary { background: var(--accent); color: #201400; }
.btn-primary:hover { background: #ffbf5c; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: rgba(229, 72, 77, 0.12); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; margin-top: 6px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13px; }
.field span { color: var(--muted); }
input[type=text], input[type=password], input[type=number], select {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 10px; border-radius: 7px; font-family: var(--sans); font-size: 14px;
}
input:focus, select:focus { outline: 2px solid var(--accent-dim); border-color: var(--accent); }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 12px 16px; font-size: 13.5px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
tr:last-child td { border-bottom: none; }
td.mono { font-family: var(--mono); font-size: 12.5px; color: var(--muted); }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; }
.empty-state { padding: 40px; text-align: center; color: var(--muted); background: var(--surface); border-radius: var(--radius); }

/* ---------- Media grid ---------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.media-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; position: relative;
}
.media-card .thumb { width: 100%; height: 110px; object-fit: cover; background: #000; display: block; }
.media-card .meta { padding: 8px 10px; font-size: 12px; }
.media-card .meta .name { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-card .remove {
  position: absolute; top: 6px; right: 6px; background: rgba(20,22,26,0.8); border: none;
  color: var(--text); width: 22px; height: 22px; border-radius: 6px; cursor: pointer; font-size: 13px;
}

/* ---------- Modals ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,11,13,0.6); z-index: 90; }
.modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 26px; width: 380px; z-index: 100;
}
.modal-wide { width: 720px; max-height: 80vh; overflow-y: auto; }
.modal h2 { margin: 0 0 18px; font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.url-box {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; margin: 10px 0;
}
.url-box code { font-family: var(--mono); font-size: 12.5px; word-break: break-all; }

/* ---------- Playlist editor ---------- */
.playlist-editor { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 10px; }
.playlist-editor h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin: 0 0 10px; }
.editor-media-list, .editor-item-list {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  min-height: 200px; max-height: 340px; overflow-y: auto; padding: 8px;
}
.editor-row {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 6px; font-size: 13px;
}
.editor-row:hover { background: rgba(255,255,255,0.03); }
.editor-row img, .editor-row video { width: 36px; height: 26px; object-fit: cover; border-radius: 4px; background: #000; }
.editor-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-row input[type=number] { width: 56px; padding: 5px 6px; font-size: 12.5px; }
.editor-row .btn-sm { padding: 4px 8px; }
