:root {
  color-scheme: light;
  --bg: #f5f5f2;
  --panel: #ffffff;
  --panel-soft: #f0f0eb;
  --ink: #171716;
  --muted: #72726d;
  --line: #e4e4de;
  --accent: #ff251d;
  --accent-dark: #d91812;
  --success: #1e9d62;
  --warning: #e49618;
  --danger: #c4433c;
  --shadow: 0 18px 45px rgba(23, 23, 22, 0.08);
  --radius: 22px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); min-height: 100vh; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 37, 29, 0.13), transparent 33%),
    linear-gradient(145deg, #f8f8f4 0%, #ecece5 100%);
}

.login-card {
  width: min(430px, 100%);
  background: rgba(255,255,255,0.95);
  border: 1px solid rgba(255,255,255,0.9);
  border-radius: 30px;
  padding: 38px;
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 17px;
  background: var(--accent);
  color: white;
  font-size: 28px;
  font-weight: 900;
  margin-bottom: 26px;
}
.brand-mark.small { width: 42px; height: 42px; border-radius: 13px; font-size: 22px; margin: 0; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 12px; font-size: clamp(30px, 4vw, 44px); line-height: 1.05; letter-spacing: -0.04em; }
h2 { margin-bottom: 0; font-size: 28px; letter-spacing: -0.03em; }
h3 { margin-bottom: 0; font-size: 22px; letter-spacing: -0.02em; }
.eyebrow { margin-bottom: 8px; color: var(--accent); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .14em; }
.muted { color: var(--muted); line-height: 1.55; }

.field { display: grid; gap: 8px; margin: 22px 0; }
.field.compact { margin: 0; min-width: 190px; }
.field span { font-size: 13px; font-weight: 700; color: #4f4f4b; }
.field input, .field select, select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 13px;
  padding: 13px 14px;
  color: var(--ink);
  outline: none;
}
.field input:focus, .field select:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(255,37,29,.08); }

.button {
  border: 0;
  border-radius: 13px;
  padding: 12px 17px;
  font-weight: 800;
  transition: .18s ease;
}
.button:hover { transform: translateY(-1px); }
.button.primary { background: var(--accent); color: white; box-shadow: 0 8px 18px rgba(255,37,29,.19); }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { background: var(--panel-soft); color: var(--ink); }
.button.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.button.small { padding: 9px 12px; border-radius: 10px; font-size: 13px; }
.button.full { width: 100%; }
.text-button { border: 0; background: transparent; padding: 0; color: var(--muted); text-decoration: underline; }
.form-message { min-height: 20px; margin: 12px 0 0; color: var(--danger); font-size: 13px; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 250px;
  padding: 26px 20px;
  background: #181817;
  color: white;
  display: flex;
  flex-direction: column;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; border-bottom: 1px solid rgba(255,255,255,.09); }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 17px; }
.brand span { color: rgba(255,255,255,.55); font-size: 13px; margin-top: 2px; }
.nav-list { display: grid; gap: 7px; margin-top: 28px; }
.nav-item { border: 0; background: transparent; color: rgba(255,255,255,.62); text-align: left; padding: 13px 14px; border-radius: 12px; font-weight: 700; }
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.08); color: white; }
.sidebar-footer { margin-top: auto; display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: center; padding: 16px 8px 0; border-top: 1px solid rgba(255,255,255,.09); color: rgba(255,255,255,.63); font-size: 12px; }
.sidebar-footer .text-button { grid-column: 1 / -1; text-align: left; color: rgba(255,255,255,.48); margin-top: 6px; }
.server-dot { width: 9px; height: 9px; border-radius: 50%; background: #3bd282; box-shadow: 0 0 0 5px rgba(59,210,130,.1); }

.content { margin-left: 250px; padding: 34px clamp(24px, 4vw, 58px) 80px; }
.topbar { display: flex; justify-content: space-between; gap: 24px; align-items: flex-end; margin-bottom: 34px; }
.topbar h1 { margin-bottom: 0; }
.topbar-actions, .section-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.section { scroll-margin-top: 24px; margin-bottom: 52px; }
.section-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 20px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: 0 8px 26px rgba(23,23,22,.035); }
.stat-card span { color: var(--muted); font-size: 13px; font-weight: 700; }
.stat-card strong { display: block; margin-top: 11px; font-size: 34px; letter-spacing: -.04em; }
.stat-card small { display: block; margin-top: 8px; color: var(--muted); }

.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 15px; }
.device-card, .media-card, .playlist-panel, .playlist-editor, .upload-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 26px rgba(23,23,22,.035);
}
.device-card { padding: 20px; }
.device-card-top { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.device-location { color: var(--muted); font-size: 13px; margin: 5px 0 0; }
.status-pill { display: inline-flex; align-items: center; gap: 7px; border-radius: 999px; padding: 7px 10px; font-size: 12px; font-weight: 800; background: #f1f1ec; }
.status-pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status-pill.online { background: #e9f7f0; color: #18784c; }
.status-pill.online::before { background: var(--success); }
.status-pill.offline { background: #fff2e3; color: #9e5c08; }
.status-pill.offline::before { background: var(--warning); }
.device-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 22px 0; }
.meta-box { background: var(--panel-soft); border-radius: 13px; padding: 12px; min-width: 0; }
.meta-box span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 6px; }
.meta-box strong { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-card select { margin-bottom: 12px; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.upload-card { padding: 18px; display: grid; grid-template-columns: minmax(240px, 1.8fr) 1fr .8fr auto; gap: 14px; align-items: end; margin-bottom: 18px; }
.upload-drop { min-height: 96px; border: 1px dashed #cfcfc7; background: var(--panel-soft); border-radius: 16px; padding: 18px; display: grid; grid-template-columns: auto 1fr; column-gap: 13px; align-content: center; cursor: pointer; }
.upload-drop input { display: none; }
.upload-drop strong, .upload-drop span:last-child { grid-column: 2; }
.upload-drop span:last-child { color: var(--muted); font-size: 12px; margin-top: 4px; }
.upload-icon { grid-row: 1 / span 2; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: white; font-size: 23px; color: var(--accent); }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.media-card { overflow: hidden; }
.media-preview { aspect-ratio: 16/9; background: #1d1d1b; display: grid; place-items: center; overflow: hidden; }
.media-preview img, .media-preview video { width: 100%; height: 100%; object-fit: cover; }
.media-preview .type-badge { color: rgba(255,255,255,.75); font-size: 13px; font-weight: 800; }
.media-info { padding: 15px; }
.media-info strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-info span { display: block; margin-top: 7px; color: var(--muted); font-size: 12px; }

.playlist-layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 16px; }
.playlist-list { display: grid; align-content: start; gap: 9px; }
.playlist-panel { width: 100%; padding: 15px; text-align: left; }
.playlist-panel.active { border-color: rgba(255,37,29,.45); box-shadow: 0 0 0 4px rgba(255,37,29,.06); }
.playlist-panel strong { display: block; }
.playlist-panel span { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.playlist-editor { min-height: 340px; padding: 22px; }
.editor-header { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 20px; }
.editor-header p { color: var(--muted); margin: 6px 0 0; font-size: 13px; }
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.editor-column { border: 1px solid var(--line); border-radius: 16px; padding: 14px; min-height: 230px; }
.editor-column h4 { margin: 0 0 12px; }
.editor-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px; border-radius: 11px; background: var(--panel-soft); margin-bottom: 8px; }
.editor-item strong { display: block; font-size: 13px; }
.editor-item span { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }
.editor-item button { border: 0; background: white; width: 31px; height: 31px; border-radius: 9px; font-weight: 900; }
.empty-state { min-height: 220px; display: grid; place-items: center; text-align: center; color: var(--muted); }

.dialog { border: 0; padding: 0; border-radius: 24px; box-shadow: var(--shadow); width: min(520px, calc(100% - 30px)); }
.dialog::backdrop { background: rgba(17,17,16,.55); backdrop-filter: blur(6px); }
.dialog-card { padding: 24px; }
.dialog-heading { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.icon-button { border: 0; background: var(--panel-soft); width: 38px; height: 38px; border-radius: 12px; font-size: 22px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; }
.toast { position: fixed; right: 24px; bottom: 24px; background: #191918; color: white; border-radius: 13px; padding: 13px 16px; box-shadow: var(--shadow); transform: translateY(120px); opacity: 0; transition: .25s ease; z-index: 100; }
.toast.visible { transform: translateY(0); opacity: 1; }

@media (max-width: 1050px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .upload-card { grid-template-columns: 1fr 1fr; }
  .upload-drop { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .sidebar { position: static; width: 100%; min-height: auto; padding: 15px; }
  .brand { border: 0; padding-bottom: 12px; }
  .nav-list { display: flex; overflow-x: auto; margin: 0; }
  .nav-item { white-space: nowrap; }
  .sidebar-footer { display: none; }
  .content { margin: 0; padding: 24px 16px 60px; }
  .topbar, .section-heading { align-items: flex-start; flex-direction: column; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .playlist-layout, .editor-grid { grid-template-columns: 1fr; }
  .upload-card { grid-template-columns: 1fr; }
  .upload-drop { grid-column: auto; }
}

@media (max-width: 460px) {
  .stats-grid { grid-template-columns: 1fr; }
  .topbar-actions .button, .section-actions .button { flex: 1; }
  .login-card { padding: 28px 22px; }
}
.editor-item-actions { display: flex; gap: 5px; flex-shrink: 0; }
.editor-item-actions button { width: 29px; height: 29px; }

.dialog-hint { margin: 14px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
