/* === Reset + Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f1117;
  color: #e1e4e8;
  min-height: 100vh;
  display: flex;
}

a { color: #58a6ff; text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Login Overlay === */
.login-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: #0f1117;
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 2.5rem;
  text-align: center;
  width: 320px;
}
.login-box h2 { margin-bottom: 0.5rem; font-size: 1.4rem; }
.login-box p { color: #8b949e; margin-bottom: 1.5rem; }
.login-box input {
  width: 100%;
  padding: 0.75rem;
  font-size: 1.5rem;
  text-align: center;
  letter-spacing: 0.3em;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #e1e4e8;
  margin-bottom: 1rem;
}
.login-box input:focus { outline: none; border-color: #58a6ff; }
.error { color: #f85149; font-size: 0.85rem; margin-top: 0.5rem; }

/* === Sidebar === */
.sidebar {
  width: 220px;
  min-height: 100vh;
  background: #161b22;
  border-right: 1px solid #30363d;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.sidebar-brand {
  padding: 1.25rem 1rem;
  font-size: 1.1rem;
  font-weight: 700;
  flex-direction: column;
  align-items: center;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid #30363d;
}
.brand-logo { width: 100%; height: auto; padding: 0 8px; }
.brand-text { white-space: nowrap; }
.brand-subtitle { display: block; text-align: center; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 2px; opacity: 0.6; margin-top: 4px; }
.nav-link {
  display: block;
  padding: 0.75rem 1rem;
  color: #8b949e;
  font-size: 0.95rem;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: #1c2128; color: #e1e4e8; text-decoration: none; }
.nav-link.active { color: #58a6ff; background: #1c2128; border-left: 3px solid #58a6ff; }
.sidebar-footer {
  margin-top: auto;
  padding: 1rem;
  border-top: 1px solid #30363d;
  color: #484f58;
  font-size: 0.8rem;
}

/* === Content — fills entire viewport minus sidebar === */
.content {
  margin-left: 220px;
  padding: 1.5rem 2rem;
  min-height: 100vh;
  width: calc(100vw - 220px);
  min-width: 0;
}

/* === Page Header === */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 600; }
.back-link { font-size: 0.85rem; color: #8b949e; display: block; margin-bottom: 0.25rem; }
.back-link:hover { color: #58a6ff; }
.header-badges { display: flex; gap: 0.5rem; margin-top: 0.25rem; }

/* === Buttons === */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: 1px solid #30363d;
  border-radius: 6px;
  background: #21262d;
  color: #e1e4e8;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn:hover { background: #30363d; text-decoration: none; }
.btn-primary { background: #238636; border-color: #2ea043; color: #fff; }
.btn-primary:hover { background: #2ea043; }
.btn-danger { background: #da3633; border-color: #f85149; color: #fff; }
.btn-danger:hover { background: #f85149; }
.btn-outline { background: transparent; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }

/* === Pipeline Cards === */
.pipeline-cards {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.pipeline-card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s;
}
.pipeline-card:hover { border-color: #58a6ff; }
.pipeline-card .count { font-size: 1.8rem; font-weight: 700; }
.pipeline-card .label { font-size: 0.8rem; color: #8b949e; text-transform: uppercase; letter-spacing: 0.05em; margin-top: 0.25rem; }
.pipeline-card.active { border-color: #58a6ff; background: #1c2128; }

/* === Filters === */
.filters {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.filters .input-sm:first-child { flex: 1; min-width: 200px; }
.input-sm {
  padding: 0.4rem 0.6rem;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #e1e4e8;
  font-size: 0.85rem;
}
.input-sm:focus { outline: none; border-color: #58a6ff; }
select.input-sm { cursor: pointer; }

/* === Data Table === */
.table-wrap { position: relative; width: 100%; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.data-table th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #30363d;
  color: #8b949e;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.data-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #21262d;
  white-space: nowrap;
}
.data-table tbody tr:hover { background: #161b22; }
.data-table .name-link { font-weight: 600; }
/* Name column gets the extra space */
.data-table th:first-child,
.data-table td:first-child { width: 22%; }

/* === Badges & Pills === */
.tier-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}
.tier-1 { background: #484f58; color: #e1e4e8; }
.tier-2 { background: #1f6feb; color: #fff; }
.tier-3 { background: #8957e5; color: #fff; }

.stage-pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}
.stage-lead   { background: #484f58; color: #e1e4e8; }
.stage-demo   { background: #1f6feb; color: #fff; }
.stage-build  { background: #d29922; color: #0d1117; }
.stage-review { background: #db6d28; color: #fff; }
.stage-live   { background: #238636; color: #fff; }
.stage-paused { background: #da3633; color: #fff; }

/* API health dots */
.api-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  vertical-align: middle;
}
.api-dot.green  { background: #3fb950; }
.api-dot.red    { background: #f85149; }
.api-dot.gray   { background: #484f58; }

/* === Actions dropdown === */
.actions-wrap { position: relative; }
.actions-toggle {
  background: none; border: 1px solid #30363d; color: #8b949e;
  padding: 0.25rem 0.5rem; border-radius: 4px; cursor: pointer; font-size: 0.8rem;
}
.actions-toggle:hover { color: #e1e4e8; border-color: #484f58; }
.actions-menu {
  display: none;
  position: absolute;
  right: 0; top: 100%;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 6px;
  min-width: 180px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.actions-menu.open { display: block; }
.actions-menu a, .actions-menu button {
  display: block; width: 100%;
  padding: 0.5rem 0.75rem;
  text-align: left;
  background: none; border: none;
  color: #e1e4e8; font-size: 0.85rem;
  cursor: pointer;
}
.actions-menu a:hover, .actions-menu button:hover { background: #1c2128; text-decoration: none; }
.actions-menu .danger { color: #f85149; }

/* === Panels === */
.panel {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.panel h3 { font-size: 0.95rem; margin-bottom: 0.75rem; color: #8b949e; text-transform: uppercase; letter-spacing: 0.03em; }

/* === Detail Grid — full width 2-col === */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}
.info-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.4rem 1rem;
  font-size: 0.85rem;
}
.info-label { color: #8b949e; }
.info-value { word-break: break-all; }
.info-value.masked { filter: blur(4px); cursor: pointer; transition: filter 0.2s; }
.info-value.masked:hover, .info-value.masked.revealed { filter: none; }

/* === Action Buttons === */
.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* === Notes === */
.notes-textarea {
  width: 100%;
  padding: 0.5rem;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #e1e4e8;
  font-size: 0.85rem;
  resize: vertical;
  margin-bottom: 0.5rem;
}
.notes-textarea:focus { outline: none; border-color: #58a6ff; }

/* === Events list === */
.events-list { font-size: 0.85rem; }
.event-item {
  padding: 0.5rem 0;
  border-bottom: 1px solid #21262d;
  display: flex;
  gap: 0.75rem;
}
.event-item:last-child { border-bottom: none; }
.event-ts { color: #484f58; white-space: nowrap; min-width: 140px; }
.event-type {
  color: #8b949e;
  font-weight: 600;
  min-width: 120px;
}
.event-msg { color: #e1e4e8; }

/* === Output Panel (script streaming) === */
.output-panel {
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}
.output-panel h3 { font-size: 0.95rem; margin-bottom: 0.75rem; color: #8b949e; }
.output-log {
  background: #010409;
  border: 1px solid #21262d;
  border-radius: 6px;
  padding: 0.75rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.8rem;
  color: #7ee787;
  max-height: 400px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.output-log .stderr { color: #f85149; }
.output-status { margin-top: 0.75rem; font-size: 0.85rem; }
.output-status.success { color: #3fb950; }
.output-status.error { color: #f85149; }

/* === Health page === */
.health-status {
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.health-loading { color: #d29922; }
.health-summary { color: #8b949e; }
.health-all-good { color: #3fb950; font-weight: 600; }

/* === Form Panel — full width, no cap === */
.form-panel {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 1.5rem 2rem;
  width: 100%;
}
.form-section { margin-bottom: 1.5rem; }
.form-section h3 { font-size: 0.95rem; color: #8b949e; margin-bottom: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
.form-row { margin-bottom: 1rem; }
.form-row label { display: block; font-size: 0.85rem; color: #e1e4e8; margin-bottom: 0.3rem; font-weight: 500; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #e1e4e8;
  font-size: 0.85rem;
}
.form-row input[type="color"] { height: 36px; padding: 2px; cursor: pointer; }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { outline: none; border-color: #58a6ff; }
.form-row small { color: #484f58; font-size: 0.75rem; }
.form-row.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.radio-group { display: flex; gap: 1.5rem; }
.radio-label { display: flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; cursor: pointer; }
.radio-label input[type="radio"] { width: auto; }
.form-actions { display: flex; gap: 0.75rem; padding-top: 0.5rem; }

/* === Color swatch === */
.color-swatch {
  display: inline-block;
  width: 16px; height: 16px;
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 0.3rem;
  border: 1px solid #30363d;
}

/* === Toast notifications === */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 0.75rem 1.25rem;
  font-size: 0.85rem;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: slideUp 0.3s ease;
}
.toast.success { border-left: 3px solid #3fb950; }
.toast.error { border-left: 3px solid #f85149; }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ============================================================
   TABLET (≤1024px)
   ============================================================ */
@media (max-width: 1024px) {
  .sidebar { width: 180px; }
  .content { margin-left: 180px; width: calc(100vw - 180px); padding: 1.25rem; }

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

  /* Table: hide less important columns */
  .data-table .col-dev,
  .data-table .col-prod,
  .data-table .col-last-deploy { display: none; }
}

/* ============================================================
   MOBILE (≤768px)
   ============================================================ */
@media (max-width: 768px) {
  body { flex-direction: column; }

  /* Sidebar → horizontal top nav */
  .sidebar {
    width: 100%;
    min-height: auto;
    position: fixed;
    top: 0; left: 0; right: 0;
    bottom: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    z-index: 100;
    height: 52px;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar-brand {
    padding: 0.5rem 0.75rem;
    border-bottom: none;
    border-right: 1px solid #30363d;
    white-space: nowrap;
    flex-shrink: 0;
    flex-direction: row;
    align-items: center;
  }
  .brand-logo { width: auto; height: 32px; padding: 0; }
  .brand-subtitle { display: none; }
  .nav-link {
    padding: 0.5rem 0.75rem;
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 0.85rem;
  }
  .nav-link.active { border-left: none; border-bottom: 2px solid #58a6ff; }
  .sidebar-footer { display: none; }

  /* Content fills full viewport under nav */
  .content {
    margin-left: 0;
    margin-top: 52px;
    padding: 1rem;
    width: 100vw;
  }

  /* Page header */
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header h1 { font-size: 1.25rem; }

  /* Pipeline cards: 3 per row */
  .pipeline-cards { grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
  .pipeline-card { padding: 0.75rem 0.5rem; }
  .pipeline-card .count { font-size: 1.4rem; }
  .pipeline-card .label { font-size: 0.7rem; }

  /* Filters: stack */
  .filters { flex-direction: column; gap: 0.5rem; }
  .filters .input-sm:first-child { min-width: auto; }
  .input-sm { width: 100%; }

  /* Table → card layout */
  .data-table thead { display: none; }
  .data-table th:first-child,
  .data-table td:first-child { width: auto; }
  .data-table tbody tr {
    display: block;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
  }
  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.3rem 0;
    border-bottom: none;
    white-space: normal;
    width: auto !important;
    text-align: left !important;
  }
  .data-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #8b949e;
    font-size: 0.75rem;
    text-transform: uppercase;
    min-width: 90px;
    flex-shrink: 0;
  }
  .data-table .col-dev,
  .data-table .col-prod,
  .data-table .col-last-deploy,
  .data-table .col-status { display: none; }

  /* Actions dropdown on mobile */
  .actions-menu { right: 0; left: auto; min-width: 160px; }

  /* Detail page */
  .detail-grid { grid-template-columns: 1fr; }
  .info-grid { gap: 0.3rem 0.75rem; font-size: 0.8rem; }
  .action-buttons { flex-direction: column; }
  .action-buttons .btn { width: 100%; justify-content: center; }

  /* Form — full width, stacked */
  .form-panel { padding: 1rem; }
  .form-row.two-col { grid-template-columns: 1fr; }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; justify-content: center; }

  /* Output log */
  .output-log { font-size: 0.7rem; max-height: 300px; }

  /* Events */
  .event-item { flex-direction: column; gap: 0.25rem; }
  .event-ts { min-width: auto; font-size: 0.75rem; }

  /* Toast */
  .toast { left: 1rem; right: 1rem; bottom: 1rem; }
}
