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

:root {
  --bg: #0a0c0f;
  --bg2: #111418;
  --bg3: #181c22;
  --border: #1e2430;
  --border2: #252d3a;
  --text: #e8edf5;
  --text2: #7a8699;
  --text3: #3d4a5c;
  --accent: #f6821f;
  --accent2: #ff9a45;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --blue: #3b82f6;
  --mono: 'JetBrains Mono', monospace;
  --sans: 'DM Sans', sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100vh;
  font-size: 14px;
}

/* Setup screen */
#setup {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  overflow: hidden;
}

.setup-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem;
  max-width: 480px;
  width: 100%;
}

.setup-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

.setup-subtitle {
  color: var(--text2);
  font-size: 13px;
  margin-top: 0px;
  margin-bottom: 5px;
}

.field {
  margin-bottom: 1.25rem;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 6px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field input,
.field select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

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

.field input::placeholder {
  color: var(--text3);
}

.hint {
  font-size: 12px;
  color: var(--text2);
  margin-top: 6px;
  line-height: 1.5;
}

.hint a {
  color: var(--accent);
  text-decoration: none;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  margin-top: 0.5rem;
}

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

.btn-primary:active {
  transform: scale(0.99);
}

.error-msg {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: #fca5a5;
  margin-bottom: 1rem;
  display: none;
}

.permissions-note {
  background: rgba(246, 130, 31, 0.08);
  border: 1px solid rgba(246, 130, 31, 0.2);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 12px;
  color: #fdba74;
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.permissions-note strong {
  color: var(--accent2);
}

/* Dashboard */
#dashboard {
  display: none;
}

.topbar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-left {
  flex: 1;
  display: flex;
  justify-content: flex-start;
}

.topbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.topbar-right {
  flex: 1;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
}

.account-group {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px 2px 2px 12px;
  gap: 8px;
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.topbar-title a {
  color: var(--text);
  text-decoration: none;
}

.topbar-account {
  font-size: 12px;
  color: var(--text2);
  font-family: var(--mono);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.last-updated {
  font-size: 12px;
  color: var(--text3);
  font-family: var(--mono);
}

.btn-refresh {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 6px 12px;
  color: var(--text2);
  font-size: 12px;
  font-family: var(--sans);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-refresh:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-logout {
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 6px;
  color: var(--text3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--red);
}

.main {
  padding: 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
}

/* Summary row */
.summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 1.5rem;
}

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

.stat-label {
  font-size: 11px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: var(--mono);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
  font-family: var(--mono);
}

.stat-sub {
  font-size: 12px;
  color: var(--text3);
  margin-top: 4px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 4px;
}

.dot-green {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.dot-red {
  background: var(--red);
}

.dot-yellow {
  background: var(--yellow);
}

.section-title {
  font-size: 11px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-family: var(--mono);
  margin-bottom: 10px;
}

/* Workers grid */
.workers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
  margin-bottom: 1.5rem;
}

.worker-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  padding: 20px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

.worker-card:hover {
  transform: translateY(-4px);
  border-color: #3b82f6;
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.15);
  cursor: pointer;
}

.worker-card.selected {
  border-color: var(--accent);
}

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

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

.worker-name {
  font-size: 14px;
  font-weight: 500;
  font-family: var(--mono);
  color: var(--text);
}

.status-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-active {
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.badge-error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-idle {
  background: rgba(122, 134, 153, 0.15);
  color: var(--text2);
  border: 1px solid var(--border2);
}

.worker-metrics {
  padding: 12px 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.wm-label {
  font-size: 10px;
  color: var(--text3);
  font-family: var(--mono);
  margin-bottom: 3px;
}

.wm-value {
  font-size: 15px;
  font-weight: 500;
  font-family: var(--mono);
  color: var(--text);
}

.wm-value.red {
  color: var(--red);
}

.wm-value.yellow {
  color: var(--yellow);
}

.worker-mini-chart {
  padding: 0 16px 12px;
  height: 40px;
}

/* Detail panel */
.detail-panel {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 1.5rem;
  display: none;
}

.detail-panel.visible {
  display: block;
}

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

.detail-title {
  font-size: 14px;
  font-weight: 500;
  font-family: var(--mono);
  color: var(--text);
}

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

.detail-tab {
  padding: 10px 18px;
  font-size: 12px;
  color: var(--text2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  font-family: var(--mono);
}

.detail-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.detail-content {
  padding: 18px;
}

.chart-wrap {
  height: 200px;
  position: relative;
}

/* Logs */
.log-list {
  font-family: var(--mono);
  font-size: 12px;
}

.log-entry {
  display: flex;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  line-height: 1.4;
}

.log-entry:last-child {
  border-bottom: none;
}

.log-time {
  color: var(--text3);
  min-width: 80px;
  flex-shrink: 0;
}

.log-status {
  min-width: 36px;
  flex-shrink: 0;
}

.log-s200 {
  color: var(--green);
}

.log-s4 {
  color: var(--yellow);
}

.log-s5 {
  color: var(--red);
}

.log-path {
  color: var(--text2);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-ms {
  color: var(--text3);
  min-width: 60px;
  text-align: right;
  flex-shrink: 0;
}

/* Loading */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 0;
  color: var(--text2);
  font-family: var(--mono);
  font-size: 13px;
  width: 100%;
  grid-column: 1 / -1;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0;
  margin-bottom: 12px;
}

.api-table .loading {
  position: sticky;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

.tr-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text2);
  cursor: pointer;
  transition: all 0.15s;
}

.tr-btn.active,
.tr-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(246, 130, 31, 0.08);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Password Toggle Wrapper */
.password-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.password-wrapper input {
  width: 100%;
  padding-right: 40px;
  /* Make room for the icon */
}

.icon-btn {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--text3, #7a8699);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
}

.icon-btn:hover {
  opacity: 0.7;
}

/* Lively Button Animations */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-primary:hover {
  background-color: var(--accent2);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(246, 130, 31, 0.3);
}

.btn-primary .arrow {
  transition: transform 0.3s ease;
}

.btn-primary:hover .arrow {
  transform: translateX(4px);
}

/* Hover Lift for Stat Cards */
.hover-lift {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.hover-lift:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

/* View Toggle Button */
.view-toggle,
.time-range {
  position: relative;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  background-color: rgba(0, 0, 0, 0.2);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.time-range {
  position: relative;
  display: inline-grid;
  grid-template-columns: 1fr 1fr 1fr;
  background-color: var(--bg);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.toggle-btn,
.tr-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 16px;
  font-size: 12px;
  font-family: var(--mono);
  color: var(--text2);
  cursor: pointer;
  position: relative;
  z-index: 2;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  transition: color 0.3s ease;
}

.toggle-btn,
.tr-btn,
.toggle-btn.active,
.tr-btn.active {
  position: relative;
  z-index: 2;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

.toggle-btn.active,
.tr-btn.active {
  color: var(--text);
  font-weight: 500;
}

.toggle-btn:hover:not(.active) {
  color: var(--text);
}

.brand-link {
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.brand-link:hover {
  color: #ffffff;
}

.brand-link:active {
  transform: scale(0.98);
}

/* API Table View */
.api-table-container {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: block;
  width: 100%;
  overflow-x: auto;
  margin-bottom: 1.5rem;
}

.api-table {
  width: 100%;
  min-width: 650px;
  border-collapse: collapse;
  text-align: left;
}

.api-table th {
  padding: 12px 16px;
  font-size: 11px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--mono);
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}

.api-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  transition: background 0.2s ease;
}

.api-table tr:last-child td {
  border-bottom: none;
}

.api-table tbody tr {
  cursor: pointer;
}

.api-table tbody tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.api-table tbody tr.selected td {
  background: rgba(246, 130, 31, 0.05);
  /* Accent color transparent */
}

/* Quota Progress Bar Styles */
.quota-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text2);
  font-family: var(--mono);
  margin-bottom: 6px;
}

.quota-track {
  width: 100%;
  height: 6px;
  background: var(--bg3);
  border-radius: 4px;
  overflow: hidden;
}

.quota-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease, background-color 0.4s ease;
}

/* Color states for the progress bar */
.quota-fill.safe {
  background: var(--green);
}

.quota-fill.warn {
  background: var(--yellow);
}

.quota-fill.danger {
  background: var(--red);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}

/* Remove hover effect from API table since they don't open the detail panel */
.api-table tbody tr {
  cursor: default;
}

.api-table tbody tr:hover td {
  background: transparent;
}

.slider {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  background-color: transparent;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 6px;
  transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
  z-index: 1;
}

.view-toggle .slider {
  width: calc((100% - 8px) / 2);
}

.view-toggle.mode-api .slider {
  transform: translateX(100%);
}

.time-range .slider {
  width: calc((100% - 8px) / 3);
}

.time-range.range-6h .slider {
  transform: translateX(100%);
}

.time-range.range-24h .slider {
  transform: translateX(200%);
}

@media (max-width: 768px)
{
  .topbar
  {
    height: auto;
    padding: 16px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    row-gap: 16px;   
    column-gap: 12px;
    align-items: center;
  }
  
  .topbar-left,
  .topbar-center,
  .topbar-right
  {
    display: contents;
  }
  
  .brand-link
  {
    grid-area: 1 / 1 / 2 / 2;
    justify-self: start;
  }
  
  .account-group
  {
    grid-area: 1 / 2 / 2 / 3;
    justify-self: end;
  }
  
  .view-toggle
  {
    grid-area: 2 / 1 / 3 / 2;
    width: 100%;
  }
  
  .time-range
  {
    grid-area: 2 / 2 / 3 / 3;
    width: 100%;
  }
  
  .btn-refresh
  {
    grid-area: 3 / 1 / 4 / 2;
    justify-self: start;
    margin: 0;
  }
  
  .refresh-text
  {
    display: inline;
  }
  
  .last-updated
  {
    grid-area: 3 / 2 / 4 / 3;
    justify-self: end;
    display: block;
  }
  
  .summary
  {
    grid-template-columns: 1fr 1fr;
  }
}