@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg: #0d0d14;
  --bg2: #13131f;
  --bg3: #1a1a2e;
  --surface: #1e1e30;
  --border: rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.12);
  --green: #27AE60;
  --red: #C0392B;
  --amber: #E67E22;
  --blue: #2980B9;
  --purple: #8E44AD;
  --text: #f0f0f0;
  --text2: #9090a8;
  --text3: #5a5a72;
  --radius: 10px;
  --radius-lg: 14px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ═══ HEADER ═══ */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  min-height: 56px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.header-brand {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.15em;
  color: #fff;
  white-space: nowrap;
}

.header-clock {
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
  letter-spacing: 0.05em;
  font-family: 'JetBrains Mono', monospace;
}

.header-stats {
  display: flex;
  gap: 8px;
  align-items: center;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg3);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.stat-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ═══ BODY LAYOUT ═══ */
.body-wrap {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ═══ SIDEBAR ═══ */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 16px 0;
}

.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text3);
  padding: 0 16px;
  margin-bottom: 8px;
}

.cat-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.cat-pill:hover {
  background: var(--bg3);
  color: var(--text);
}

.cat-pill.active {
  background: #fff;
  color: #0d0d14;
  font-weight: 600;
}

.cat-pill .cat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cat-pill .cat-count {
  margin-left: auto;
  font-size: 10px;
  opacity: 0.6;
}

.sidebar-cost {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--border);
}

.sidebar-cost .cost-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--text3);
  margin-bottom: 4px;
}

.sidebar-cost .cost-value {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
}

/* ═══ MAIN CONTENT ═══ */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.cat-group {
  margin-bottom: 32px;
}

.cat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.cat-header h2 {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text2);
  text-transform: uppercase;
  white-space: nowrap;
}

.cat-header .divider {
  flex: 1;
  height: 1px;
  background: var(--border);
}

.cat-header .count-badge {
  font-size: 10px;
  color: var(--text3);
  white-space: nowrap;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

/* ═══ AUTOMATION CARD ═══ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}

.card:hover {
  border-color: var(--border2);
  transform: translateY(-2px);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.card-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  min-width: 0;
}

.card-name .status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.card-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-online { background: rgba(39,174,96,0.15); color: var(--green); border-color: rgba(39,174,96,0.3); }
.badge-offline { background: rgba(192,57,43,0.15); color: var(--red); border-color: rgba(192,57,43,0.3); }
.badge-stale { background: rgba(230,126,34,0.15); color: var(--amber); border-color: rgba(230,126,34,0.3); }
.badge-unknown { background: var(--bg3); color: var(--text3); border-color: var(--border); }
.badge-manual-on { background: rgba(41,128,185,0.15); color: var(--blue); border-color: rgba(41,128,185,0.3); }
.badge-manual-off { background: var(--bg3); color: var(--text3); border-color: var(--border); }

.card-meta {
  font-size: 11px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.card-desc {
  font-size: 12px;
  color: var(--text2);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 6px;
}

.card-lastseen {
  font-size: 11px;
  color: var(--text3);
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-lastseen .live-dot {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: var(--green);
  font-weight: 600;
  font-size: 10px;
}

.card-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.link-chip {
  font-size: 10px;
  padding: 2px 8px;
  background: var(--bg3);
  color: var(--text2);
  border-radius: 4px;
  text-decoration: none;
  transition: color 0.15s;
}

.link-chip:hover {
  color: var(--text);
}

/* Card flash animation */
@keyframes card-flash {
  0% { box-shadow: 0 0 0 0 rgba(39,174,96,0.4); }
  50% { box-shadow: 0 0 12px 2px rgba(39,174,96,0.3); }
  100% { box-shadow: 0 0 0 0 rgba(39,174,96,0); }
}

.card.flash {
  animation: card-flash 1s ease-out;
}

/* ═══ MODAL ═══ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  width: 600px;
  max-width: 95vw;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 0;
}

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

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 24px;
  cursor: pointer;
  padding: 0 4px;
}

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

.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.modal-tab {
  padding: 10px 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text3);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}

.modal-tab:hover { color: var(--text2); }
.modal-tab.active { color: var(--text); border-bottom-color: var(--blue); }

.modal-body {
  padding: 24px;
}

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

/* Form fields */
.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--blue);
}

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

/* Links/credentials rows */
.pair-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.pair-row input {
  flex: 1;
  padding: 6px 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  outline: none;
}

.pair-row input:focus { border-color: var(--blue); }

.btn-icon {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
}

.btn-icon:hover { color: var(--text); }

.btn-add {
  background: none;
  border: 1px dashed var(--border2);
  border-radius: var(--radius);
  color: var(--text3);
  font-size: 12px;
  padding: 6px 12px;
  cursor: pointer;
  width: 100%;
  transition: all 0.15s;
}

.btn-add:hover { border-color: var(--blue); color: var(--text2); }

/* Toggle switch for manual */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle {
  width: 48px;
  height: 26px;
  background: var(--bg3);
  border-radius: 13px;
  cursor: pointer;
  position: relative;
  transition: background 0.2s;
  border: 1px solid var(--border);
}

.toggle.on { background: var(--blue); border-color: var(--blue); }

.toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle.on::after { transform: translateX(22px); }

.toggle-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
}

/* Curl block */
.curl-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 8px;
  position: relative;
}

.curl-block code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text2);
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
}

.btn-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text3);
  font-size: 11px;
  padding: 3px 8px;
  cursor: pointer;
}

.btn-copy:hover { color: var(--text); }

/* Buttons */
.btn-save {
  width: 100%;
  padding: 10px;
  background: var(--green);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  margin-top: 16px;
  transition: opacity 0.15s;
}

.btn-save:hover { opacity: 0.9; }

.btn-delete {
  background: none;
  border: none;
  color: var(--red);
  font-size: 12px;
  cursor: pointer;
  padding: 8px 0;
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
  width: 100%;
}

.btn-delete:hover { text-decoration: underline; }

/* Log table */
.log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.log-table th {
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

.log-table td {
  padding: 6px 8px;
  color: var(--text2);
  border-bottom: 1px solid var(--border);
}

.log-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
}

.log-badge.ok { background: rgba(39,174,96,0.15); color: var(--green); }
.log-badge.error { background: rgba(192,57,43,0.15); color: var(--red); }

.empty-state {
  text-align: center;
  color: var(--text3);
  font-size: 13px;
  padding: 24px;
}

/* Credential warning */
.cred-warning {
  font-size: 11px;
  color: var(--amber);
  margin-top: 12px;
}

/* ═══ FAB ═══ */
.fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  z-index: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  transition: transform 0.15s, box-shadow 0.15s;
}

.fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

/* ═══ AUTH SCREENS ═══ */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  max-width: 400px;
  width: 100%;
}

.auth-card h1 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.15em;
  margin-bottom: 8px;
}

.auth-card p {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 24px;
}

.btn-auth {
  padding: 12px 32px;
  background: var(--blue);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-auth:hover { opacity: 0.9; }

.auth-error {
  color: var(--red);
  font-size: 12px;
  margin-top: 12px;
  display: none;
}

/* ═══ SCROLLBAR ═══ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ═══ PIPELINE VISUALIZATION ═══ */
.pipeline-chain {
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
  display: flex;
  align-items: flex-start;
  overflow-x: auto;
  padding: 24px 8px 16px;
  gap: 0;
  -webkit-overflow-scrolling: touch;
  padding-right: 40px;
}

.pipeline-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 80px;
  max-width: 100px;
  position: relative;
  flex-shrink: 0;
}

.pipeline-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--green);
  border: 3px solid rgba(39,174,96,0.3);
  z-index: 2;
  flex-shrink: 0;
  transition: all 0.3s;
  box-shadow: 0 0 8px rgba(39,174,96,0.2);
}

.pipeline-dot.red {
  background: var(--red);
  border-color: rgba(192,57,43,0.3);
  box-shadow: 0 0 8px rgba(192,57,43,0.3);
}

.pipeline-dot.gray {
  background: var(--text3);
  border-color: rgba(90,90,114,0.3);
  box-shadow: none;
}

.pipeline-dot.amber {
  background: var(--amber);
  border-color: rgba(230,126,34,0.3);
  box-shadow: 0 0 8px rgba(230,126,34,0.2);
}

.pipeline-connector {
  position: absolute;
  top: 9px;
  left: calc(50% + 9px);
  width: calc(100% - 18px);
  height: 2px;
  background: var(--green);
  z-index: 1;
  opacity: 0.5;
}

.pipeline-connector.red {
  background: var(--red);
}

.pipeline-connector.gray {
  background: var(--text3);
}

.pipeline-step:last-child .pipeline-connector {
  display: none;
}

.pipeline-label {
  margin-top: 10px;
  font-size: 10px;
  color: var(--text2);
  text-align: center;
  line-height: 1.3;
  word-wrap: break-word;
  max-width: 90px;
}

.pipeline-icon {
  font-size: 12px;
  margin-bottom: 4px;
}

.pipeline-empty {
  text-align: center;
  color: var(--text3);
  font-size: 13px;
  padding: 32px 16px;
}

.pipeline-status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 12px;
  color: var(--text2);
}

.pipeline-status-bar .steps-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text3);
}

/* Scrollbar for pipeline */
.pipeline-chain::-webkit-scrollbar { height: 4px; }
.pipeline-chain::-webkit-scrollbar-track { background: transparent; }
.pipeline-chain::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ═══ DESCRIPTION TAB ═══ */
.description-text {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  padding: 8px 0;
}

.description-empty {
  font-size: 13px;
  color: var(--text3);
  font-style: italic;
  padding: 16px 0;
}

.description-edit-wrap {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.description-edit-wrap label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.description-edit-wrap textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  resize: vertical;
  min-height: 120px;
  line-height: 1.5;
  transition: border-color 0.15s;
}

.description-edit-wrap textarea:focus {
  border-color: var(--blue);
}

.stat-pill-active {
  outline: 2px solid rgba(255,255,255,0.3);
  outline-offset: 1px;
}
.stat-pill:hover {
  opacity: 0.8;
}
