:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
}

.login-card h1 { font-size: 1.75rem; margin-bottom: 0.25rem; }
.subtitle { color: var(--muted); margin-bottom: 1.5rem; font-size: 0.95rem; }
.hint { margin-top: 1rem; font-size: 0.8rem; color: var(--muted); }

label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.35rem; margin-top: 1rem; }
input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: white;
  width: 100%;
  margin-top: 1.5rem;
  padding: 0.75rem;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #111; }

.alert { padding: 0.75rem; border-radius: 8px; margin-bottom: 1rem; }
.alert-error { background: rgba(239, 68, 68, 0.15); color: #fca5a5; border: 1px solid var(--danger); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand { font-weight: 700; font-size: 1.1rem; }
.stats { color: var(--muted); font-size: 0.9rem; margin-right: 1rem; }

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: calc(100vh - 57px);
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
}

.sidebar h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 0.75rem; }

.device-item {
  padding: 0.85rem;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 0.35rem;
  border: 1px solid transparent;
}
.device-item:hover { background: var(--surface2); }
.device-item.active { background: var(--surface2); border-color: var(--accent); }
.device-item .name { font-weight: 600; flex: 1; min-width: 0; word-break: break-all; }
.device-item .name-row {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
}
.device-item .rename-btn {
  padding: 0.15rem 0.4rem;
  flex-shrink: 0;
  line-height: 1.2;
}
.device-item .meta { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }
.device-item .device-id { margin-top: 0.2rem; font-size: 0.72rem; opacity: 0.85; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.badge-online { color: var(--success); }
.badge-offline { color: var(--muted); }

.content { padding: 1.25rem 1.5rem; overflow-y: auto; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.toolbar.hidden { display: none; }
.filters { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.filter-btn {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
}
.filter-btn.active, .filter-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }

.selection-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 0.65rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.selection-bar .select-all {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  color: var(--text);
  font-size: 0.9rem;
}
.selection-bar .btn-primary { width: auto; margin-top: 0; }
.selection-bar .btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

.media-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
}
.media-card.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.media-check {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 2;
  background: rgba(15, 20, 25, 0.65);
  border-radius: 6px;
  padding: 0.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.media-check input { width: auto; margin: 0; accent-color: var(--accent); }

.media-thumb {
  aspect-ratio: 1;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  color: var(--muted);
  overflow: hidden;
}
.media-thumb img { width: 100%; height: 100%; object-fit: cover; }

.media-info { padding: 0.75rem; }
.media-info .filename {
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.media-info .details { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }
.media-actions { padding: 0 0.75rem 0.75rem; display: flex; gap: 0.35rem; }

.empty-state, .muted { color: var(--muted); }
.hidden { display: none !important; }

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.85rem 1.25rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 100;
  max-width: 360px;
}

@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); max-height: 200px; }
}
