:root {
  --bg: #0f1216;
  --fg: #e8eef4;
  --muted: #9aa6b2;
  --accent: #ffd24a;
  --panel: #171b22;
  --tab: #1d232d;
  --border: #2a3140;
  --danger: #ff6b6b;
  --ok: #28c76f;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: #0d1014;
}
h1 { margin: 0; font-size: 18px; }
.status { color: var(--muted); }

.tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px 0 12px;
  border-bottom: 1px solid var(--border);
  background: #0d1014;
  overflow-x: auto; /* Allow horizontal scrolling on mobile */
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}
.tabs::-webkit-scrollbar {
  height: 4px;
}
.tabs::-webkit-scrollbar-track {
  background: transparent;
}
.tabs::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}
.tab {
  background: var(--tab);
  border: 1px solid var(--border);
  border-bottom: none;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap; /* Prevent text wrapping in tabs */
  flex-shrink: 0; /* Prevent tabs from shrinking */
}
.tab.active { background: var(--panel); }
.tab .close {
  opacity: 0.6;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
}
.tab.add { font-weight: 700; }

/* Tab status indicator */
.tab-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.tab-status.running { background: var(--ok); }
.tab-status.stopped { background: var(--danger); }

.panel { padding: 12px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
}

.grid { display: grid; gap: 10px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-2-mobile { 
  grid-template-columns: 1fr; 
  gap: 12px;
}

.row { 
  display: flex; 
  gap: 8px; 
  align-items: center; 
  flex-wrap: wrap; /* Allow wrapping on small screens */
}
.row input[type="text"] { width: 100%; }

input, button, select, textarea {
  background: #0f131a;
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px; /* Slightly larger for mobile touch */
}
/* Make number inputs more mobile-friendly */
input[type="number"] {
  -moz-appearance: textfield; /* Firefox */
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none; /* Safari and Chrome */
  margin: 0;
}

button { 
  cursor: pointer; 
  font-size: 14px;
  touch-action: manipulation; /* Better touch handling */
}
button.primary { 
  background: var(--accent); 
  color: #14120c; 
  border: none; 
  font-weight: 500;
}
button.danger { 
  background: var(--danger); 
  color: white; 
  border: none; 
  font-weight: 500;
}
button.ghost { background: transparent; }
button:disabled { 
  opacity: 0.6; 
  cursor: not-allowed; 
}
button.small {
  padding: 4px 8px;
  font-size: 12px;
}

.console {
  background: #0a0d11;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  height: 280px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.35;
  white-space: pre-wrap;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}
.console .stderr { color: #ff8a8a; }
.console .stdout { color: #c6e3ff; }

/* Modal */
.modal { display: grid; place-items: center; }
.modal.hidden { display: none; }
.modal {
  position: fixed; 
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 1000;
  padding: 16px; /* Add padding for mobile */
}
.modal-card {
  width: min(900px, 92vw);
  max-height: 90vh; /* Limit height on mobile */
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head, .modal-foot {
  display: flex; 
  align-items: center; 
  justify-content: space-between; 
  gap: 8px;
  flex-shrink: 0;
}
.modal-head .path { 
  display: flex; 
  gap: 6px; 
  flex: 1; 
  flex-wrap: wrap; /* Allow wrapping on small screens */
}
.modal-head .close {
  background: transparent; 
  border: none; 
  color: var(--fg); 
  font-size: 18px; 
  cursor: pointer;
  padding: 4px 8px;
}
.modal-body { 
  margin: 10px 0; 
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.columns {
  display: grid; 
  grid-template-columns: 1fr 1fr; 
  gap: 12px;
}
.list {
  list-style: none; 
  padding: 0; 
  margin: 0;
  border: 1px solid var(--border); 
  border-radius: 8px;
  height: 340px; 
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.list li { 
  padding: 8px 10px; 
  border-bottom: 1px solid #212937; 
  cursor: pointer; 
}
.list li:last-child { border-bottom: none; }
.list li:hover { background: #121821; }
.list li .type { color: var(--muted); font-size: 12px; margin-left: 6px; }

/* Table */
.table-wrap { 
  overflow: auto; 
  border: 1px solid var(--border); 
  border-radius: 8px; 
  -webkit-overflow-scrolling: touch;
}
.table { 
  width: 100%; 
  border-collapse: collapse; 
  font-size: 13px; 
  min-width: 600px; /* Ensure table has minimum width */
}
.table thead th {
  text-align: left; 
  position: sticky; 
  top: 0; 
  background: #0e131a;
  border-bottom: 1px solid var(--border); 
  padding: 8px 10px;
  white-space: nowrap;
}
.table tbody td {
  border-bottom: 1px solid #212937; 
  padding: 6px 10px; 
  vertical-align: top;
}
.table tbody tr:hover { background: #121821; }
.table .cmd { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.ok { color: var(--ok); }

/* Mobile-specific adjustments */
@media (max-width: 768px) {
  .grid.cols-2,
  .grid.cols-2-mobile {
    grid-template-columns: 1fr;
  }
  
  .columns {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .modal-card {
    width: 100%;
    max-height: 85vh;
    padding: 8px;
  }
  
  .card {
    padding: 10px;
  }
  
  input, button, select {
    padding: 10px 12px; /* Larger touch targets on mobile */
    font-size: 16px; /* Prevent zoom on iOS */
  }
  
  button {
    min-height: 44px; /* Minimum touch target size */
  }
  
  .tabs {
    padding: 8px 8px 0 8px;
  }
  
  .tab {
    padding: 8px;
  }
  
  .console {
    height: 240px;
  }
}

/* Small mobile screens */
@media (max-width: 480px) {
  .panel {
    padding: 8px;
  }
  
  .row {
    gap: 6px;
  }
  
  .tabs {
    gap: 4px;
  }
  
  .tab {
    padding: 6px 8px;
    font-size: 13px;
  }
  
  .tab .close {
    font-size: 14px;
    padding: 0 1px;
  }
}
