* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0b1220;
  color: #eef2ff;
}

button, input, textarea {
  font: inherit;
}

h1, h2, p {
  margin: 0;
}

.hidden {
  display: none !important;
}

.full-width {
  width: 100%;
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(circle at top, rgba(37, 99, 235, 0.15), transparent 38%),
    radial-gradient(circle at bottom, rgba(15, 23, 42, 0.55), transparent 42%),
    #0b1220;
}

.login-card {
  width: min(440px, 100%);
  background: #111827;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 24px;
  padding: 24px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}

.auth-status {
  min-height: 24px;
}

.app-shell {
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid rgba(255,255,255,0.08);
  background: #0f172a;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.main-grid {
  padding: 20px;
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: minmax(420px, 1fr) minmax(260px, 320px);
  gap: 16px;
}

.panel {
  background: #111827;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 16px;
  min-height: 0;
  overflow: hidden;
}

.panel-detail {
  grid-column: 2;
  grid-row: 1;
}

.panel-tasks {
  grid-column: 1;
  grid-row: 1 / span 2;
}

.panel-materials {
  grid-column: 2;
  grid-row: 2;
}

.card {
  background: #0f172a;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 12px;
}

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

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-height: calc(100% - 54px);
}

.detail-grid-span-2 {
  grid-column: 1 / -1;
}

.pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
  background: #020617;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  padding: 12px;
  min-height: 0;
}

.pre-error {
  border-color: rgba(239, 68, 68, 0.35);
  box-shadow: inset 0 0 0 1px rgba(239, 68, 68, 0.08);
}

.materials-pre {
  height: calc(100% - 54px);
}

.input,
.textarea {
  width: 100%;
  background: #020617;
  color: #eef2ff;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 10px 12px;
}

.textarea {
  min-height: 140px;
  resize: vertical;
}

.btn {
  background: #1f2937;
  color: #eef2ff;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn:disabled {
  opacity: 0.7;
  cursor: default;
}

.btn-primary {
  background: #2563eb;
  border-color: #3b82f6;
}

.btn-danger {
  background: #991b1b;
  border-color: #dc2626;
}

.row { display: flex; }
.wrap { flex-wrap: wrap; }
.gap-8 { gap: 8px; }
.flex-1 { flex: 1; }
.min-h-0 { min-height: 0; display: flex; flex-direction: column; }

.stack-8 > * + * { margin-top: 8px; }
.stack-12 > * + * { margin-top: 12px; }

.label,
.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #93c5fd;
}

.section-title-error {
  color: #fca5a5;
}

.muted { color: #94a3b8; }
.small { font-size: 12px; }

.status {
  min-height: 20px;
  font-size: 13px;
  color: #cbd5e1;
  white-space: pre-wrap;
}

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

.task-item {
  background: #0f172a;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
}

.task-item.active {
  border-color: #60a5fa;
  box-shadow: 0 0 0 1px rgba(96,165,250,0.35) inset;
}

.task-item.failed {
  border-color: rgba(239, 68, 68, 0.45);
}

.task-item .top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.task-error-snippet {
  margin-top: 8px;
  color: #fca5a5;
  font-size: 12px;
  line-height: 1.45;
}

.badge {
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(255,255,255,0.08);
}

.badge.queued { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.badge.running { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }
.badge.completed { background: rgba(34, 197, 94, 0.18); color: #86efac; }
.badge.failed { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }

.recent-pill,
.browse-entry {
  display: block;
  width: 100%;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: min(920px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: hidden;
  margin: 12px auto;
  background: #111827;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.browse-list {
  margin-top: 12px;
  min-height: 280px;
  overflow: auto;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  background: #020617;
  padding: 12px;
}

.browse-entry {
  background: #0f172a;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 10px 12px;
  color: #eef2ff;
  cursor: pointer;
}

.browse-entry:hover {
  border-color: #60a5fa;
}

.task-item .expand-btn {
  background: none;
  border: none;
  color: #ccc;
  cursor: pointer;
  padding: 2px;
  margin-left: 8px;
}

.task-item .expand-btn:hover {
  color: #fff;
}

.task-item .expanded-content {
  display: none;
  margin-top: 8px;
  padding: 8px;
  background: rgba(0,0,0,0.1);
  border-radius: 4px;
  font-size: 12px;
  color: #94a3b8;
}

.task-item.expanded .expanded-content {
  display: block;
}

.task-item .task-detail-item {
  word-break: break-word;
  line-height: 1.4;
}

.task-item .task-detail-item div {
  margin-bottom: 4px;
}

.task-item .logs-preview,
.task-item .error-preview {
  margin-top: 8px;
}

.task-item .error-preview {
  color: #fca5a5;
}

.task-item .remove-btn {
  background: none;
  border: none;
  color: #fca5a5;
  cursor: pointer;
  padding: 2px;
  margin-left: 8px;
}

.task-item .remove-btn:hover {
  color: #fff;
}

.collapsible-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.collapsible-header .collapse-btn {
  background: none;
  border: none;
  color: #93c5fd;
  cursor: pointer;
  padding: 0;
  margin-left: 8px;
}

.collapsible-header .collapse-btn:hover {
  color: #fff;
}

.collapsible.collapsed .collapsible-content {
  display: none;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .main-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  .panel-tasks,
  .panel-detail,
  .panel-materials {
    grid-column: 1;
    grid-row: auto;
  }

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

  .detail-grid-span-2 {
    grid-column: auto;
  }

  .modal-dialog {
    width: calc(100vw - 16px);
    margin: 8px;
  }
}

@media (max-width: 760px) {
  .sidebar-top {
    flex-direction: column;
    align-items: stretch;
  }

  .sidebar,
  .main-grid {
    padding: 14px;
  }

  .panel,
  .card,
  .login-card {
    border-radius: 18px;
  }
}

/* Recent projects: keep about 8 visible, then scroll. */
#recentProjects {
  max-height: 368px;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
}

#recentProjects.recent-scrollable {
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 14px;
  padding: 8px;
  background: rgba(2, 6, 23, 0.28);
}

.recent-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 8px;
  align-items: center;
}

.recent-remove-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(248, 113, 113, 0.42);
  border-radius: 12px;
  background: rgba(127, 29, 29, 0.25);
  color: #fecaca;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.recent-remove-btn:hover {
  background: rgba(220, 38, 38, 0.38);
  border-color: rgba(248, 113, 113, 0.82);
  color: #ffffff;
}

/* Tasks: show roughly 5 cards, then scroll instead of stretching the page. */
#tasksList {
  max-height: 560px;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
}

.panel-tasks {
  min-height: 0;
}

.task-item.working {
  border-color: rgba(96, 165, 250, 0.55);
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.16), 0 0 22px rgba(59, 130, 246, 0.16);
}

.stream-working {
  position: relative;
  border-color: rgba(96, 165, 250, 0.72) !important;
  animation: streamPulseGlow 1.35s ease-in-out infinite;
}

.stream-working::before {
  content: "working";
  position: absolute;
  top: 10px;
  right: 42px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1.4;
  color: #bfdbfe;
  background: rgba(30, 64, 175, 0.35);
  border: 1px solid rgba(147, 197, 253, 0.28);
  pointer-events: none;
}

.stream-pre-working {
  outline: 1px solid rgba(96, 165, 250, 0.42);
  outline-offset: -1px;
}

@keyframes streamPulseGlow {
  0%, 100% {
    box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.18), 0 0 14px rgba(37, 99, 235, 0.16);
  }
  50% {
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.52), 0 0 34px rgba(37, 99, 235, 0.38);
  }
}

/* Project-style scrollbars for every scrollable panel. */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(96, 165, 250, 0.78) rgba(2, 6, 23, 0.86);
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: rgba(2, 6, 23, 0.88);
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.08);
}

*::-webkit-scrollbar-thumb {
  min-height: 44px;
  border: 2px solid rgba(2, 6, 23, 0.88);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(96, 165, 250, 0.88), rgba(37, 99, 235, 0.72));
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.22);
}

*::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, rgba(147, 197, 253, 0.96), rgba(59, 130, 246, 0.9));
  box-shadow: 0 0 18px rgba(59, 130, 246, 0.36);
}

*::-webkit-scrollbar-corner {
  background: rgba(2, 6, 23, 0.88);
}

.btn-warning {
  background: rgba(180, 83, 9, 0.92);
  border-color: rgba(245, 158, 11, 0.88);
}

.restore-dialog {
  width: min(980px, calc(100vw - 24px));
}

.restore-warning {
  border-color: rgba(248, 113, 113, 0.25);
  background:
    linear-gradient(135deg, rgba(127, 29, 29, 0.18), rgba(15, 23, 42, 0.86)),
    #0f172a;
}

.restore-warning p {
  color: #cbd5e1;
  line-height: 1.5;
}

.restore-list {
  margin-top: 12px;
  min-height: 280px;
  max-height: min(58vh, 620px);
  overflow: auto;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  background: #020617;
  padding: 12px;
}

.restore-entry {
  display: block;
  width: 100%;
  text-align: left;
  color: #e5e7eb;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
}

.restore-entry + .restore-entry {
  margin-top: 10px;
}

.restore-entry:hover {
  border-color: rgba(96, 165, 250, 0.75);
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.18), 0 0 22px rgba(37, 99, 235, 0.12);
}

.restore-entry.active {
  border-color: rgba(96, 165, 250, 0.95);
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.28), transparent 36%),
    rgba(15, 23, 42, 0.98);
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.34), 0 0 28px rgba(37, 99, 235, 0.22);
}

.restore-entry-top,
.restore-entry-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.restore-entry-meta {
  margin-top: 8px;
  color: #94a3b8;
  font-size: 12px;
}

.restore-tag {
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(248, 113, 113, 0.34);
  color: #fecaca;
  background: rgba(127, 29, 29, 0.24);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.restore-tag-normal {
  border-color: rgba(96, 165, 250, 0.34);
  color: #bfdbfe;
  background: rgba(30, 64, 175, 0.22);
}
