/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --success: #10b981;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --border: #334155;
  --radius: 6px;
  --radius-lg: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* Top Bar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--text-primary);
}

.topbar-status {
  color: var(--success);
  font-size: 13px;
  margin-left: 16px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.topbar-nav a {
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}

.topbar-nav a:hover, .topbar-nav a.active {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.topbar-user {
  color: var(--text-secondary);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  font-family: inherit;
}

.btn-primary { background: var(--accent); color: #000; font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); }
.btn-secondary:hover { background: #475569; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }

.btn-sm { padding: 4px 10px; font-size: 12px; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 4px 8px;
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-tertiary); }

/* Grid */
.stream-grid {
  display: grid;
  gap: 2px;
  padding: 2px;
  height: calc(100vh - 49px);
  background: var(--bg-primary);
}

.stream-grid[data-count="1"] { grid-template-columns: 1fr; }
.stream-grid[data-count="2"] { grid-template-columns: 1fr 1fr; }
.stream-grid[data-count="3"],
.stream-grid[data-count="4"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.stream-grid[data-count="5"],
.stream-grid[data-count="6"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; }

/* Stream Panel */
.stream-panel {
  background: var(--bg-secondary);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

.stream-panel.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  border-radius: 0;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: var(--bg-primary);
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
}

.panel-header .server-name {
  font-weight: 600;
  font-size: 12px;
}

.panel-header .server-ip {
  color: var(--text-muted);
  font-size: 10px;
  margin-left: 8px;
}

.panel-header .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--danger); }
.status-dot.connecting { background: var(--accent); animation: pulse 1.5s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.panel-controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.panel-controls button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
}

.panel-controls button:hover { color: var(--text-primary); }

/* Video */
.panel-video-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #000;
  cursor: default;
}

.panel-video-container video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.panel-offline {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--danger);
  font-size: 14px;
  gap: 8px;
}

.panel-offline .last-seen {
  color: var(--text-muted);
  font-size: 11px;
}

/* Forms & Inputs */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  color: var(--text-secondary);
  font-size: 12px;
  margin-bottom: 4px;
  font-weight: 500;
}

.form-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus {
  border-color: var(--accent);
}

.form-input::placeholder { color: var(--text-muted); }

select.form-input {
  cursor: pointer;
}

/* Cards / Pages */
.page-container {
  max-width: 800px;
  margin: 40px auto;
  padding: 0 20px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--text-primary);
}

.card {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 20px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
}

/* Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 8px 12px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.data-table tr:last-child td { border-bottom: none; }

.data-table .actions {
  text-align: right;
  white-space: nowrap;
}

/* Role badge */
.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.role-badge.admin { background: #f59e0b22; color: var(--accent); }
.role-badge.viewer { background: #10b98122; color: var(--success); }

/* Login page */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-box {
  width: 100%;
  max-width: 380px;
  padding: 0 20px;
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 32px;
}

.login-error {
  background: #ef444422;
  color: var(--danger);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 440px;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* Utilities */
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-sm { font-size: 12px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.items-center { align-items: center; }
