/* --- Reset & Base --- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  width: 100%;
  background: #1a1a2e;
  color: #e6edf3;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow-x: hidden;
}

/* --- Screens --- */
.screen {
  display: none;
  min-height: 100vh;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

.screen-content {
  padding: 24px 20px;
  padding-top: max(24px, env(safe-area-inset-top));
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

/* --- Typography --- */
h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  color: #fff;
}

h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
  color: #c9d1d9;
}

.subtitle {
  color: #8b949e;
  margin-bottom: 24px;
  font-size: 15px;
}

/* --- Inputs --- */
input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 14px 16px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 10px;
  color: #e6edf3;
  font-size: 16px; /* prevents iOS zoom */
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.2s;
}

input:focus {
  border-color: #58a6ff;
}

/* --- Buttons --- */
.btn-primary {
  width: 100%;
  padding: 14px;
  background: #238636;
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.2s;
}

.btn-primary:active {
  background: #2ea043;
}

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-secondary {
  width: 100%;
  padding: 14px;
  background: transparent;
  border: 1px solid #30363d;
  border-radius: 10px;
  color: #8b949e;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.2s;
}

.btn-secondary:active {
  background: #21262d;
  color: #e6edf3;
}

.btn-icon {
  background: none;
  border: 1px solid #30363d;
  color: #8b949e;
  font-size: 18px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.btn-text {
  background: none;
  border: 1px solid #30363d;
  color: #8b949e;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-small {
  padding: 8px 16px;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 8px;
  color: #58a6ff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-small:active {
  background: #30363d;
}

/* --- Header Row --- */
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.header-row h1 {
  margin-bottom: 0;
}

/* --- Project List --- */
.project-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.project-btn {
  width: 100%;
  padding: 16px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 12px;
  color: #e6edf3;
  font-size: 16px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.15s;
}

.project-btn:active {
  background: #161b22;
  transform: scale(0.98);
}

.project-btn.selected {
  border-color: #58a6ff;
  background: #0d1117;
  box-shadow: 0 0 0 1px #58a6ff;
}

/* --- Session Form --- */
.session-form {
  padding: 20px;
  background: #0d1117;
  border-radius: 12px;
  border: 1px solid #30363d;
  margin-bottom: 24px;
}

.session-form h2 {
  color: #58a6ff;
  margin-bottom: 16px;
  font-family: 'Menlo', 'Monaco', monospace;
}

/* --- Active Sessions --- */
.active-sessions {
  margin-top: 8px;
}

.session-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 12px;
  margin-bottom: 8px;
}

.session-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.session-info strong {
  font-size: 15px;
  color: #e6edf3;
}

.session-info span {
  font-size: 13px;
  color: #8b949e;
}

.session-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-kill {
  background: #2d1216 !important;
  color: #f85149 !important;
  border-color: #f8514933 !important;
  font-size: 16px !important;
  min-width: 40px;
}

.session-connecting {
  color: #d29922;
  font-size: 12px;
  font-weight: 400;
  animation: pulse 1.5s infinite;
}

/* --- Error --- */
.error {
  color: #f85149;
  font-size: 14px;
  margin-top: 8px;
  text-align: center;
}

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

/* --- Project View --- */
.project-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: var(--viewport-height, 100vh);
  overflow: hidden;
}

.pv-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: #161b22;
  border-bottom: 1px solid #30363d;
  flex-shrink: 0;
}

.pv-header h1 {
  font-size: 20px;
  margin-bottom: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pv-header-btn {
  background: none;
  border: 1px solid #30363d;
  color: #e6edf3;
  font-size: 20px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  flex-shrink: 0;
}

.pv-header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.pv-kill-btn {
  color: #f85149 !important;
  border-color: #f8514933 !important;
}

/* Status bar */
.pv-status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #0d1117;
  border-bottom: 1px solid #30363d;
  font-size: 13px;
  color: #8b949e;
  flex-shrink: 0;
}

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

.status-dot.online { background: #3fb950; }
.status-dot.offline { background: #8b949e; }
.status-dot.connecting { background: #d29922; animation: pulse 1.5s infinite; }
.status-dot.starting { background: #58a6ff; animation: pulse 1s infinite; }
.status-dot.error { background: #f85149; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* No session state */
.pv-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 16px;
}

.pv-center input[type="text"] {
  max-width: 320px;
}

.pv-center .btn-primary {
  max-width: 320px;
}

.pv-empty-text {
  color: #8b949e;
  font-size: 16px;
}

.pv-existing-label {
  color: #8b949e;
  font-size: 14px;
}

.pv-existing-name {
  color: #58a6ff;
  font-size: 20px;
  font-weight: 600;
  font-family: 'Menlo', 'Monaco', 'SF Mono', monospace;
}

/* Output area */
.pv-output {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 16px;
  font-family: 'Menlo', 'Monaco', 'SF Mono', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.5;
  -webkit-overflow-scrolling: touch;
}

.pv-line {
  color: #c9d1d9;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 1px 0;
  line-height: 1.6;
}

.pv-sent {
  color: #58a6ff;
  font-weight: 600;
  padding: 6px 0;
  border-top: 1px solid #21262d;
  margin-top: 4px;
}

.pv-system {
  color: #d29922;
  font-style: italic;
  padding: 4px 0;
  font-size: 12px;
}

/* --- Markdown rendering --- */

/* Headers */
.pv-md-header {
  color: #fff;
  font-weight: 700;
  margin: 12px 0 6px 0;
  line-height: 1.3;
}

h2.pv-md-header { font-size: 18px; }
h3.pv-md-header { font-size: 16px; }
h4.pv-md-header { font-size: 14px; color: #c9d1d9; }

/* Code blocks */
.pv-code-block {
  position: relative;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 8px;
  margin: 8px 0;
  overflow: hidden;
}

.pv-code-lang {
  font-size: 11px;
  color: #8b949e;
  padding: 6px 12px 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.pv-code-block pre {
  margin: 0;
  padding: 10px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.pv-code-block code {
  font-family: 'Menlo', 'Monaco', 'SF Mono', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.5;
  color: #e6edf3;
  white-space: pre;
}

.pv-code-copy {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 3px 10px;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #8b949e;
  font-size: 11px;
  cursor: pointer;
  touch-action: manipulation;
  opacity: 0;
  transition: opacity 0.2s;
}

.pv-code-block:hover .pv-code-copy,
.pv-code-block:active .pv-code-copy {
  opacity: 1;
}

/* On mobile always show copy button */
@media (hover: none) {
  .pv-code-copy { opacity: 1; }
}

.pv-code-copy:active {
  background: #30363d;
  color: #e6edf3;
}

/* Inline code */
.pv-inline-code {
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 4px;
  padding: 1px 5px;
  font-family: 'Menlo', 'Monaco', 'SF Mono', 'Consolas', monospace;
  font-size: 0.9em;
  color: #f0883e;
}

/* Lists */
.pv-list-item {
  color: #c9d1d9;
  padding: 2px 0;
  line-height: 1.6;
  display: flex;
  gap: 6px;
}

.pv-bullet {
  color: #8b949e;
  flex-shrink: 0;
  min-width: 14px;
}

/* Horizontal rule */
.pv-hr {
  border: none;
  border-top: 1px solid #30363d;
  margin: 12px 0;
}

/* Links */
.pv-link {
  color: #58a6ff;
  text-decoration: none;
}

.pv-link:active {
  text-decoration: underline;
}

/* Bold/emphasis in output */
.pv-line strong,
.pv-list-item strong {
  color: #fff;
  font-weight: 600;
}

.pv-line em,
.pv-list-item em {
  color: #d2a8ff;
  font-style: italic;
}

/* Input area */
.pv-input-area {
  flex-shrink: 0;
  border-top: 1px solid #30363d;
  background: #161b22;
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.pv-quick-actions {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.qa-btn {
  padding: 6px 14px;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 16px;
  color: #c9d1d9;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
  flex-shrink: 0;
}

.qa-btn:active {
  background: #30363d;
}

.pv-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.pv-input-row textarea {
  flex: 1;
  padding: 10px 14px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 20px;
  color: #e6edf3;
  font-size: 16px; /* prevents iOS zoom */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
  transition: border-color 0.2s;
}

.pv-input-row textarea:focus {
  border-color: #58a6ff;
}

.pv-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #238636;
  border: none;
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pv-send-btn:active {
  background: #2ea043;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #30363d;
  border-radius: 2px;
}
