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

:root {
  --bg: #0a0a0a;
  --bg-card: #1a1a2e;
  --bg-input: #16213e;
  --bg-modal: #1a1a2e;
  --accent: #0f7dff;
  --accent-hover: #0a5fcc;
  --green: #00d26a;
  --red: #ff4757;
  --orange: #ffa502;
  --text: #e8e8e8;
  --text-dim: #8888aa;
  --border: #2a2a4a;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* === Screens === */
.screen { display: none; height: 100%; }
.screen.active { display: flex; flex-direction: column; }

/* === Login === */
#login-screen {
  justify-content: center;
  align-items: center;
  padding: 24px;
}

.login-container {
  width: 100%;
  max-width: 360px;
}

.login-logo {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 4px;
}

.login-subtitle {
  text-align: center;
  color: var(--text-dim);
  margin-bottom: 32px;
  font-size: 14px;
}

/* === Forms === */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 500;
}

input[type="url"], input[type="text"], input[type="password"], input[type="search"] {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

input:focus {
  border-color: var(--accent);
}

.input-suffix {
  display: flex;
  align-items: center;
  gap: 0;
}

.input-suffix input {
  border-radius: var(--radius) 0 0 var(--radius);
  flex: 1;
}

.input-suffix span {
  padding: 12px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-dim);
  font-size: 13px;
  white-space: nowrap;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text);
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; pointer-events: none; }

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

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

.btn-danger { background: var(--red); }
.btn-ghost { background: transparent; color: var(--accent); }

.btn-full { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: 50%; font-size: 18px; }

/* === Header === */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  padding-top: calc(var(--safe-top) + 8px);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}

#header-title {
  font-size: 18px;
  font-weight: 700;
}

.header-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* === Tab Bar === */
#tab-bar {
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 10px;
  transition: color 0.15s;
}

.tab-btn.active { color: var(--accent); }
.tab-icon { font-size: 20px; }
.tab-label { font-weight: 500; }

/* === Main Content === */
#app-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-content {
  display: none;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-content.active { display: flex; flex-direction: column; }

/* === Terminal === */
#terminal-tabs {
  display: flex;
  gap: 4px;
  padding: 8px;
  background: var(--bg-card);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.terminal-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.terminal-tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.terminal-tab .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.terminal-tab .close-tab {
  margin-left: 4px;
  opacity: 0.6;
  cursor: pointer;
}

.terminal-tab .close-tab:hover { opacity: 1; }

#terminal-container {
  flex: 1;
  background: #1e1e1e;
  padding: 4px;
  display: none;
}

#terminal-container.active { display: block; }

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-dim);
}

.loading-state {
  padding: 32px;
  text-align: center;
  color: var(--text-dim);
}

/* === Dashboard === */
.card-list {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.container-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

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

.status-running { background: var(--green); }
.status-exited { background: var(--red); }
.status-other { background: var(--orange); }

.card-name {
  font-weight: 600;
  font-size: 15px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-running { background: rgba(0,210,106,0.15); color: var(--green); }
.badge-exited { background: rgba(255,71,87,0.15); color: var(--red); }

.card-details {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.card-details p { margin-bottom: 2px; }

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

/* === Logs === */
.logs-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.log-output {
  flex: 1;
  background: #1e1e1e;
  padding: 12px;
  font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
  font-size: 12px;
  line-height: 1.5;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  color: #ccc;
  -webkit-overflow-scrolling: touch;
}

/* === Deploy === */
.deploy-form {
  padding: 16px;
}

/* === Settings === */
.settings-list {
  padding: 16px;
}

.settings-section {
  margin-bottom: 24px;
}

.settings-section h3 {
  font-size: 13px;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

/* === Modal === */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
}

.modal-content {
  position: relative;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: calc(100% - 48px);
  max-width: 360px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-content h2 {
  margin-bottom: 8px;
}

.modal-large {
  max-width: 480px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.modal-actions .btn { flex: 1; }

/* 2FA Code input */
#twofa-code {
  text-align: center;
  font-size: 28px;
  font-family: 'SF Mono', monospace;
  letter-spacing: 8px;
  font-weight: 700;
  margin: 16px 0 8px;
}

/* === Repo List === */
.repo-list {
  max-height: 50vh;
  overflow-y: auto;
  margin: 12px 0;
}

.repo-item {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.repo-item:hover { background: var(--bg-input); }
.repo-item:last-child { border-bottom: none; }

.repo-item-name {
  font-weight: 600;
  font-size: 15px;
}

.repo-item-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 2px;
}

.repo-item-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* === Utility === */
.hidden { display: none !important; }

.error-text {
  color: var(--red);
  font-size: 13px;
  margin-top: 8px;
}

.hint-text {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 4px;
}

.success-text {
  color: var(--green);
  font-size: 13px;
  margin-top: 8px;
}

/* Pull-to-refresh indicator */
.refresh-hint {
  text-align: center;
  padding: 12px;
  color: var(--text-dim);
  font-size: 13px;
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
