:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --text: #111827;
  --muted: #64748b;
  --border: #dbe3ee;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #047857;
  --warning: #b45309;
  --danger: #b91c1c;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
}

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

body {
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.hidden {
  display: none !important;
}

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

.sidebar {
  background: #0f172a;
  color: #e5edf7;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #1d4ed8;
  color: white;
}

.brand h1 {
  font-size: 1.25rem;
  line-height: 1.2;
}

.brand p,
.support-card p {
  color: #94a3b8;
  font-size: 0.85rem;
  line-height: 1.5;
}

.tabs {
  display: grid;
  gap: 8px;
}

.tab {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #cbd5e1;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.tab:hover,
.tab.active {
  background: #172554;
  border-color: #1e40af;
  color: white;
}

.tab-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
}

.support-card {
  margin-top: auto;
  padding: 16px;
  border: 1px solid #24324a;
  border-radius: 8px;
  background: #111c31;
}

.support-label,
.eyebrow,
.metric-label {
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 700;
  font-size: 0.72rem;
}

.support-label {
  color: #dbeafe;
  margin-bottom: 6px;
}

.workspace {
  padding: 28px;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 22px;
}

.eyebrow {
  color: var(--muted);
  margin-bottom: 6px;
}

.topbar h2 {
  font-size: 2rem;
  line-height: 1.1;
}

.system-state,
.connection-badge,
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}

.connection-badge.connected {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: var(--success);
}

.connection-badge.offline {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--danger);
}

.state-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #22c55e;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

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

.metric-label {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}

.metric strong {
  font-size: 1.05rem;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.primary-panel {
  min-height: 520px;
}

.activity-panel {
  position: sticky;
  top: 28px;
  padding: 22px;
}

.tab-content {
  display: none;
  padding: 28px;
}

.tab-content.active {
  display: block;
}

.section-heading,
.projects-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 22px;
}

.section-heading h3,
.projects-header h3 {
  font-size: 1.45rem;
}

.section-heading.compact {
  margin-bottom: 16px;
}

.upload-area {
  border: 2px dashed #bfd0e7;
  border-radius: 8px;
  padding: 54px 28px;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
  cursor: pointer;
  background: #f8fafc;
}

.upload-area:hover,
.upload-area.drag-over {
  border-color: var(--primary);
  background: #eff6ff;
}

.upload-icon {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin: 0 auto 18px;
  border-radius: 8px;
  background: #dbeafe;
  color: var(--primary);
}

.upload-area h3 {
  font-size: 1.35rem;
  margin-bottom: 8px;
}

.upload-area p {
  color: var(--muted);
  margin-bottom: 18px;
}

.hint {
  font-size: 0.88rem;
  margin-top: 18px;
}

.btn-primary,
.btn-secondary,
.btn-small {
  border: none;
  border-radius: 8px;
  font-weight: 700;
  transition: background 0.2s, color 0.2s, opacity 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
  padding: 12px 18px;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-secondary:disabled,
.btn-small:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface-muted);
  color: #334155;
  padding: 10px 14px;
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.auth-link {
  text-decoration: none;
}

.disabled-link {
  opacity: 0.55;
  pointer-events: none;
}

.form-grid {
  display: grid;
  gap: 16px;
  max-width: 620px;
}

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

label {
  display: grid;
  gap: 8px;
  color: #334155;
  font-weight: 700;
  font-size: 0.9rem;
}

.input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--text);
  background: white;
}

.input:focus {
  outline: 3px solid #bfdbfe;
  border-color: var(--primary);
}

.status {
  margin-top: 18px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.status.hidden {
  display: none;
}

.status.loading {
  background: #fffbeb;
  border-color: #fde68a;
  color: var(--warning);
}

.status.success {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: var(--success);
}

.status.error {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--danger);
}

.status a {
  font-weight: 800;
}

.projects-list {
  display: grid;
  gap: 12px;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 44px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px dashed var(--border);
}

.project-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  background: white;
}

.project-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.project-info h4 {
  font-size: 1.05rem;
  margin-bottom: 6px;
}

.project-meta {
  color: var(--muted);
  font-size: 0.86rem;
}

.badge {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1e40af;
  font-size: 0.75rem;
  font-weight: 800;
  margin-right: 8px;
}

.project-url {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 11px;
  margin-bottom: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  word-break: break-word;
}

.project-url a {
  flex: 1;
  color: var(--primary);
  text-decoration: none;
  font-weight: 700;
}

.project-url a:hover {
  text-decoration: underline;
}

.project-actions {
  display: flex;
  gap: 8px;
}

.btn-small {
  padding: 8px 12px;
  font-size: 0.85rem;
}

.btn-danger {
  background: #fee2e2;
  color: var(--danger);
}

.btn-danger:hover {
  background: #fecaca;
}

.activity-feed {
  height: 380px;
  overflow: auto;
  border-radius: 8px;
  background: #0f172a;
  color: #dbeafe;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.83rem;
}

.log-line {
  padding: 6px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
  line-height: 1.5;
}

.log-line.muted {
  color: #94a3b8;
}

.recent-deployments {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.deployment-row,
.deployment-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}

.deployment-row strong,
.deployment-card strong {
  display: block;
  margin-bottom: 5px;
  font-size: 0.9rem;
}

.deployment-row span,
.deployment-card span {
  color: var(--muted);
  font-size: 0.8rem;
}

.deployments-list {
  display: grid;
  gap: 12px;
}

.deployment-card {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.deployment-card-main {
  min-width: 0;
}

.deployment-card-main strong,
.deployment-card-main span {
  overflow-wrap: anywhere;
}

.deployment-card-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.deployment-status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  margin-top: 8px;
  font-size: 0.72rem;
  font-weight: 800;
  background: #dbeafe;
  color: #1e40af;
}

.deployment-status.failed {
  background: #fee2e2;
  color: var(--danger);
}

.deployment-status.deployed {
  background: #dcfce7;
  color: var(--success);
}

.deployment-status.running,
.deployment-status.cloning,
.deployment-status.extracting,
.deployment-status.detecting,
.deployment-status.installing,
.deployment-status.building,
.deployment-status.deploying {
  background: #fef3c7;
  color: var(--warning);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.55);
}

.modal-backdrop.hidden {
  display: none;
}

.log-modal {
  width: min(920px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.log-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.log-modal-header h3 {
  font-size: 1.25rem;
  overflow-wrap: anywhere;
}

.log-modal-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}

.saved-log-feed {
  min-height: 260px;
  overflow: auto;
  background: #0f172a;
  color: #dbeafe;
  padding: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.83rem;
}

.saved-log-line {
  padding: 7px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.saved-log-line.muted {
  color: #94a3b8;
}

.saved-log-line.error {
  color: #fecaca;
}

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

  .sidebar {
    position: static;
  }

  .tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .content-grid,
  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .activity-panel {
    position: static;
  }
}

@media (max-width: 640px) {
  .workspace,
  .sidebar {
    padding: 18px;
  }

  .topbar,
  .section-heading,
  .projects-header {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .deployment-card,
  .deployment-card-actions,
  .log-modal-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .tab-content {
    padding: 20px;
  }

  .upload-area {
    padding: 36px 18px;
  }
}
