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

:root {
  --blue: #004578;
  --green: #00A651;
  --red: #d32f2f;
  --yellow: #f9a825;
  --gray: #888;
  --bg: #f5f5f5;
  --card: #fff;
  --radius: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: #333;
  min-height: 100vh;
}

/* --- Header --- */
.header {
  background: var(--blue);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header h1 { font-size: 18px; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.header-right button {
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

/* --- Views --- */
.view { display: none; }
.view.active { display: block; }

/* --- Login --- */
.login-container {
  max-width: 380px;
  margin: 60px auto;
  padding: 20px;
}
.login-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px 24px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}
.login-card h2 {
  color: var(--blue);
  margin-bottom: 8px;
  font-size: 22px;
}
.login-card p {
  color: var(--gray);
  font-size: 14px;
  margin-bottom: 20px;
}
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #555;
}
.form-group input {
  width: 100%;
  padding: 12px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}
.form-group input:focus { border-color: var(--blue); }
.code-input {
  text-align: center;
  letter-spacing: 8px;
  font-size: 24px !important;
  font-weight: bold;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-green { background: var(--green); color: #fff; }
.btn-red { background: var(--red); color: #fff; }
.btn-yellow { background: var(--yellow); color: #333; }
.btn-small { width: auto; padding: 8px 16px; font-size: 14px; }
.btn-outline {
  background: transparent;
  border: 2px solid #ddd;
  color: #555;
}

.error-msg {
  background: #fde8e8;
  color: var(--red);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 12px;
  display: none;
}
.error-msg.visible { display: block; }

/* --- Main View --- */
.main-container {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}

/* Preview */
.preview-wrapper {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
  aspect-ratio: 16/9;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.preview-placeholder {
  color: #666;
  font-size: 14px;
}

/* Status Badge */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.status-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
}
.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--gray);
  flex-shrink: 0;
}
.status-dot.offline { background: var(--gray); }
.status-dot.stopped { background: var(--green); }
.status-dot.started { background: var(--red); animation: pulse 1.5s infinite; }
.status-dot.paused { background: var(--yellow); }
.status-dot.stopping { background: var(--yellow); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.progress-time {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--blue);
}

/* Recording Info */
.recording-info {
  background: #e8f5e9;
  border: 2px solid var(--green);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  font-size: 14px;
  display: none;
}
.recording-info.visible { display: block; }
.recording-info .rec-label { font-weight: 700; color: var(--green); }
.recording-info .rec-detail { color: #555; margin-top: 4px; }

.recording-info-other {
  background: #fff3e0;
  border: 2px solid var(--yellow);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  font-size: 14px;
  display: none;
}
.recording-info-other.visible { display: block; }

/* Controls */
.controls {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.controls .btn { flex: 1; }

/* Start Form */
.start-form {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  display: none;
}
.start-form.visible { display: block; }
.start-form h3 { margin-bottom: 16px; color: var(--blue); }
.start-form .form-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}
.start-form .form-row .form-group { flex: 1; margin-bottom: 0; }

/* --- Admin --- */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
}
.tab {
  flex: 1;
  padding: 12px;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
  background: var(--card);
  border: none;
  cursor: pointer;
  color: var(--gray);
  border-bottom: 3px solid transparent;
}
.tab.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

.admin-section { display: none; }
.admin-section.active { display: block; }

.user-list { list-style: none; }
.user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.user-item-info { font-size: 14px; }
.user-item-name { font-weight: 600; }
.user-item-email { color: var(--gray); font-size: 13px; }
.user-item-role {
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  background: #e3f2fd;
  color: var(--blue);
}
.user-item-actions { display: flex; gap: 4px; }
.edit-btn, .delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  border-radius: 4px;
}
.edit-btn { color: var(--blue); }
.edit-btn:hover { background: #e3f2fd; }
.delete-btn { color: var(--red); }
.delete-btn:hover { background: #fde8e8; }

.add-user-form {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.add-user-form h3 { margin-bottom: 16px; color: var(--blue); font-size: 16px; }
.add-user-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.add-user-row .form-group { flex: 1; }
.add-user-row .btn { flex: 0 0 auto; margin-bottom: 16px; }

/* --- Recordings --- */
.recording-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  cursor: pointer;
  transition: box-shadow 0.2s;
}
.recording-card:hover { box-shadow: 0 2px 10px rgba(0,0,0,0.12); }
.recording-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.recording-card-date { font-size: 12px; color: var(--gray); }
.recording-card-title { font-weight: 700; font-size: 16px; margin-bottom: 4px; }
.recording-card-meta { font-size: 13px; color: var(--gray); }
.recording-status-badge {
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 10px;
}
.recording-status-badge.recording {
  background: #e8f5e9;
  color: var(--green);
  animation: pulse 1.5s infinite;
}
.recording-status-badge.stopped {
  background: #f0f0f0;
  color: var(--gray);
}

/* Encoding Badges */
.encoding-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 10px;
}
.enc-progress { background: #fff3e0; color: var(--yellow); }
.enc-done { background: #e3f2fd; color: var(--blue); }
.enc-error { background: #fde8e8; color: var(--red); }

/* MP4 Download */
.mp4-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
  text-decoration: none;
}
.mp4-link:hover { text-decoration: underline; }

/* Recording delete button */
.recording-card { position: relative; }
.recording-delete {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 20px;
  opacity: 0.3;
}
.recording-delete:hover { opacity: 1; }

/* Audit Log */
.audit-list { font-size: 13px; }
.audit-entry {
  padding: 8px 0;
  border-bottom: 1px solid #eee;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
}
.audit-date { color: var(--gray); font-size: 12px; min-width: 130px; }
.audit-action {
  background: #e3f2fd;
  color: var(--blue);
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 12px;
}
.audit-detail { color: var(--gray); font-size: 12px; }
