:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3f56;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #00ae42;
  --accent-dim: #007a2f;
  --accent-glow: rgba(0, 174, 66, 0.25);
  --warn: #f5a623;
  --danger: #e74c3c;
  --info: #4a9eff;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

body {
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(0, 174, 66, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(74, 158, 255, 0.06), transparent);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.brand h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand p {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.brand .printer-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 6px 12px;
  background: var(--accent-glow);
  border: 1px solid var(--accent-dim);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--accent);
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:hover {
  background: #00c24a;
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-icon {
  padding: 8px 10px;
  min-width: 36px;
  justify-content: center;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(231, 76, 60, 0.4);
}

.btn-danger:hover {
  background: rgba(231, 76, 60, 0.15);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-card .label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-card .value {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 4px;
}

.printer-live {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.printer-live-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.printer-live-header h2 {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.connection-badge {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
}

.connection-badge.online {
  background: rgba(0, 174, 66, 0.15);
  color: var(--accent);
  border: 1px solid var(--accent-dim);
}

.connection-badge.offline {
  background: rgba(139, 156, 179, 0.12);
  color: var(--muted);
  border: 1px solid var(--border);
}

.connection-badge.busy {
  background: rgba(74, 158, 255, 0.12);
  color: var(--info);
  border: 1px solid rgba(74, 158, 255, 0.35);
}

.printer-live-body {
  display: grid;
  grid-template-columns: 1fr 180px;
  gap: 20px;
  align-items: start;
}

.printer-live-main .live-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.printer-live-main .live-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 14px;
}

.progress-wrap {
  margin-top: 4px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.progress-bar {
  height: 10px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: 999px;
  transition: width 0.4s ease;
}

.printer-camera {
  width: 180px;
  aspect-ratio: 4/3;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
  padding: 8px;
}

.printer-camera img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.webcam-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.webcam-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.webcam-header h2 {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.webcam-embed {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  border-radius: 10px;
  background: #000;
  border: 1px solid var(--border);
}

.webcam-embed iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.settings-section {
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.settings-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.settings-section-head h3 {
  font-size: 1rem;
}

.settings-hint {
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 10px;
  line-height: 1.45;
}

.now-printing {
  background: linear-gradient(135deg, var(--surface) 0%, rgba(0, 174, 66, 0.08) 100%);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.now-printing.empty {
  border-style: dashed;
  border-color: var(--border);
  background: var(--surface);
  text-align: center;
  color: var(--muted);
}

.now-printing h2 {
  font-size: 0.8rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

.now-printing .job-title {
  font-size: 1.3rem;
  font-weight: 700;
}

.now-printing .job-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--surface);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  width: fit-content;
}

.tab {
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
}

.tab.active {
  background: var(--surface2);
  color: var(--text);
}

.queue-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.job-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: start;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.job-card:hover {
  border-color: #3d5270;
}

.job-card.urgent {
  border-left: 3px solid var(--warn);
}

.job-card.printing {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-glow);
}

.job-card.done,
.job-card.cancelled {
  opacity: 0.65;
}

.job-position {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--muted);
  cursor: grab;
  user-select: none;
}

.job-position:active {
  cursor: grabbing;
}

.job-body h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.job-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.tag {
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.tag.user {
  color: var(--info);
  border-color: rgba(74, 158, 255, 0.3);
  background: rgba(74, 158, 255, 0.1);
}

.tag.filament {
  color: var(--accent);
  border-color: rgba(0, 174, 66, 0.3);
  background: rgba(0, 174, 66, 0.1);
}

.tag.urgent {
  color: var(--warn);
  border-color: rgba(245, 166, 35, 0.3);
  background: rgba(245, 166, 35, 0.1);
}

.tag.status-done {
  color: var(--accent);
}

.tag.status-cancelled {
  color: var(--danger);
}

.job-notes {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}

.job-link {
  color: var(--info);
  font-size: 0.85rem;
  text-decoration: none;
}

.job-link:hover {
  text-decoration: underline;
}

.job-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

.job-actions-row {
  display: flex;
  gap: 6px;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty-state .icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  transform: translateY(12px);
  transition: transform 0.2s;
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal-header {
  padding: 20px 24px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 1.2rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 20px 24px 24px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group.full {
  grid-column: 1 / -1;
}

.form-group label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.form-group input,
.form-group select,
.form-group textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group textarea {
  resize: vertical;
  min-height: 72px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 2s infinite;
}

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

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s;
  z-index: 200;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.drag-over {
  border-color: var(--accent) !important;
  background: rgba(0, 174, 66, 0.05);
}

@media (max-width: 640px) {
  .printer-live-body {
    grid-template-columns: 1fr;
  }

  .printer-camera {
    width: 100%;
    max-width: 280px;
    margin: 0 auto;
  }

  .job-card {
    grid-template-columns: 1fr;
  }

  .job-actions {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}