/* ============================================
   Agents Control — PWA Stylesheet
   Dark theme matching dashboard.html
   Mobile-first, iPhone optimized
   ============================================ */

/* --- Reset & Base --- */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-primary: #0d1117;
  --bg-card: #161b22;
  --bg-input: #21262d;
  --border: #30363d;
  --border-hover: #484f58;
  --text-primary: #e6edf3;
  --text-secondary: #c9d1d9;
  --text-muted: #8b949e;
  --text-dim: #484f58;
  --green: #3fb950;
  --green-bg: #0d3d1f;
  --green-border: #238636;
  --blue: #58a6ff;
  --blue-bg: #0c2d6b;
  --blue-border: #1f6feb;
  --yellow: #d29922;
  --yellow-bg: #3d2e00;
  --yellow-border: #9e6a03;
  --red: #f85149;
  --red-bg: #3d1117;
  --red-border: #da3633;
  --idle-bg: #1c1f23;
  --idle-border: #30363d;
  --idle-color: #6e7681;

  /* Safe area for iPhone notch */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-secondary);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
  overscroll-behavior-y: contain;
}

/* --- Login Screen --- */
.login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  padding: 24px;
  gap: 24px;
}

.login-screen h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.login-screen .subtitle {
  font-size: 14px;
  color: var(--text-muted);
}

.login-input {
  width: 100%;
  max-width: 360px;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 16px; /* prevent iOS zoom */
  outline: none;
  transition: border-color 0.2s;
}

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

.login-input::placeholder {
  color: var(--text-dim);
}

.btn-login {
  width: 100%;
  max-width: 360px;
  padding: 14px;
  background: var(--green-border);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-login:active {
  opacity: 0.8;
}

.login-error {
  color: var(--red);
  font-size: 14px;
  min-height: 20px;
}

/* --- App Container --- */
.app {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  min-height: -webkit-fill-available;
}

.app.active {
  display: flex;
}

/* --- Header --- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.3s;
}

.connection-dot.connected { background: var(--green); }
.connection-dot.disconnected { background: var(--red); }
.connection-dot.polling { background: var(--yellow); }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  padding: 4px;
  cursor: pointer;
  line-height: 1;
}

/* --- Tabs --- */
.tab-bar {
  display: flex;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-bar::-webkit-scrollbar { display: none; }

.tab {
  flex: 1;
  min-width: 0;
  padding: 10px 0;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
  white-space: nowrap;
}

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

.tab .tab-badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  margin-left: 4px;
  background: var(--red-bg);
  color: var(--red);
  border-radius: 9px;
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
}

/* --- Content Area --- */
.content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px calc(12px + var(--sab));
}

.tab-content {
  display: none;
}

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

/* --- Pull to Refresh --- */
.pull-indicator {
  text-align: center;
  padding: 8px;
  color: var(--text-dim);
  font-size: 12px;
  display: none;
}

.pull-indicator.visible {
  display: block;
}

/* --- Agent Cards --- */
.agent-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
  transition: border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.agent-card.glow-active { border-left: 3px solid var(--green-border); }
.agent-card.glow-paused { border-left: 3px solid var(--yellow-border); }
.agent-card.glow-done   { border-left: 3px solid var(--blue-border); }

.agent-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.agent-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-active  { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }
.badge-idle    { background: var(--idle-bg); color: var(--idle-color); border: 1px solid var(--idle-border); }
.badge-done    { background: var(--blue-bg); color: var(--blue); border: 1px solid var(--blue-border); }
.badge-paused  { background: var(--yellow-bg); color: var(--yellow); border: 1px solid var(--yellow-border); }

.agent-task {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.agent-task.empty {
  font-style: italic;
  color: var(--text-dim);
}

.agent-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #21262d;
}

/* --- Expandable body --- */
.agent-body {
  display: none;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #21262d;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.agent-body.expanded {
  display: block;
}

/* --- Approval Cards --- */
.approval-card {
  background: var(--bg-card);
  border: 1px solid var(--red-border);
  border-left: 3px solid var(--red);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
}

.approval-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.approval-agent {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.approval-label {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 12px;
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid var(--red-border);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.approval-task {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 12px;
}

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

.btn-approve, .btn-reject, .btn-comment {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-approve:active, .btn-reject:active, .btn-comment:active {
  opacity: 0.7;
}

.btn-approve {
  background: var(--green-border);
  color: #fff;
}

.btn-reject {
  background: var(--red-border);
  color: #fff;
}

.btn-comment {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

/* --- Comment Modal --- */
.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.active {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 16px;
  font-family: inherit;
  resize: vertical;
  outline: none;
}

.modal textarea:focus {
  border-color: var(--blue-border);
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.btn-modal-cancel {
  padding: 8px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
}

.btn-modal-send {
  padding: 8px 16px;
  background: var(--blue-border);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

/* --- Empty state --- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-dim);
  font-size: 14px;
}

/* --- Stats row --- */
.stats-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.stat-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.stat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.stat-dot.green { background: var(--green); }
.stat-dot.yellow { background: var(--yellow); }
.stat-dot.blue { background: var(--blue); }
.stat-dot.gray { background: var(--idle-color); }

.stat-count {
  font-weight: 600;
  color: var(--text-primary);
}

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: calc(20px + var(--sab));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 14px;
  color: var(--text-secondary);
  z-index: 300;
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.success { border-color: var(--green-border); }
.toast.error { border-color: var(--red-border); }

/* --- Skeleton loading --- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-input) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-card {
  height: 80px;
  margin-bottom: 10px;
  border-radius: 10px;
}
