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

:root {
  --primary: #3b82f6;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --accent: #8b5cf6;
  --dark: #1f2937;
  --gray: #6b7280;
  --light-gray: #f3f4f6;
  --border: #e5e7eb;
  --white: #ffffff;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--dark);
  background: var(--light-gray);
  min-height: 100vh;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Screens */
.screen {
  display: none !important;
}

.screen.active {
  display: block !important;
}

/* Login Screen */
#login-screen {
  display: none !important;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  z-index: -1;
}

#login-screen.active {
  min-height: 100vh;
  display: flex !important;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  position: relative;
  z-index: 10;
}

.login-container {
  background: var(--white);
  padding: 2.5rem;
  border-radius: 1rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 400px;
}

.login-container h1 {
  text-align: center;
  margin-bottom: 0.5rem;
  color: var(--dark);
  font-size: 2rem;
}

.subtitle {
  text-align: center;
  color: var(--gray);
  margin-bottom: 2rem;
  font-size: 0.9rem;
}

/* Header */
.header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
}

.header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header h1 {
  font-size: 1.5rem;
  color: var(--dark);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.username {
  color: var(--gray);
  font-size: 0.9rem;
}

/* Status Bar */
.status-bar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
}

.status-item {
  display: flex;
  flex-direction: column;
}

.status-label {
  font-size: 0.8rem;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-value {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--dark);
  margin-top: 0.25rem;
}

/* Main Content */
main {
  padding: 2rem 0;
}

.panel {
  background: var(--white);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.panel h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
  color: var(--dark);
}

/* Buttons */
.btn {
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--primary);
  color: var(--white);
}

.btn-success {
  background: var(--success);
  color: var(--white);
}

.btn-danger {
  background: var(--danger);
  color: var(--white);
}

.btn-accent {
  background: var(--accent);
  color: var(--white);
}

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.btn-icon {
  font-size: 1.1rem;
}

.btn-group {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

/* Forms */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--dark);
  font-size: 0.9rem;
}

.form-group input[type="text"],
.form-group input[type="password"] {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.95rem;
  transition: border-color 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary);
}

.form-group small {
  display: block;
  margin-top: 0.25rem;
  color: var(--gray);
  font-size: 0.8rem;
}

/* Worktrees Grid */
.worktrees-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
}

.worktree-card {
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.25rem;
  transition: box-shadow 0.2s;
}

.worktree-card:hover {
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.worktree-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.worktree-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--dark);
}

.status-badge {
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.status-badge.running {
  background: #d1fae5;
  color: #065f46;
}

.status-badge.stopped {
  background: #fee2e2;
  color: #991b1b;
}

.worktree-info {
  margin-bottom: 1rem;
}

.info-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.info-label {
  color: var(--gray);
}

.info-value {
  color: var(--dark);
  font-family: monospace;
}

.worktree-links {
  margin-bottom: 1rem;
}

.link-btn {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  margin-right: 0.5rem;
  margin-bottom: 0.5rem;
  background: var(--light-gray);
  color: var(--dark);
  text-decoration: none;
  border-radius: 0.375rem;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.2s;
}

.link-btn:hover {
  background: var(--border);
}

.worktree-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--gray);
}

/* Log Area */
.log-area {
  background: var(--light-gray);
  border-radius: 0.5rem;
  padding: 1rem;
  max-height: 200px;
  overflow-y: auto;
  font-family: monospace;
  font-size: 0.85rem;
  display: none;
}

.log-area.active {
  display: block;
}

.log-entry {
  margin-bottom: 0.5rem;
  padding: 0.5rem;
  border-radius: 0.375rem;
}

.log-entry.success {
  background: #d1fae5;
  color: #065f46;
}

.log-entry.error {
  background: #fee2e2;
  color: #991b1b;
}

.log-entry.info {
  background: #dbeafe;
  color: #1e40af;
}

/* Modals */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--white);
  border-radius: 0.75rem;
  padding: 1.5rem;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.modal-header h3 {
  font-size: 1.25rem;
  color: var(--dark);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--gray);
  cursor: pointer;
  padding: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: var(--dark);
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  justify-content: flex-end;
}

/* Loading Overlay */
#loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.9);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.spinner {
  border: 4px solid var(--light-gray);
  border-top: 4px solid var(--primary);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

#loading-message {
  margin-top: 1rem;
  color: var(--gray);
  font-weight: 500;
}

/* Error Messages */
.error-message {
  background: #fee2e2;
  color: #991b1b;
  padding: 0.75rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 768px) {
  .status-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .btn-group {
    flex-direction: column;
  }

  .btn-group .btn {
    width: 100%;
  }

  .worktrees-grid {
    grid-template-columns: 1fr;
  }
}
