*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Formuly brand tokens */
  --accent-500: #3b82f6;
  --accent-600: #2563eb;
  --accent-700: #1d4ed8;
  --green-500: #10b981;
  --green-600: #059669;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --warning: #f59e0b;

  --gray-50: #fafbfc;
  --gray-100: #f4f5f7;
  --gray-200: #e9ecef;
  --gray-300: #dee2e6;
  --gray-400: #ced4da;
  --gray-500: #adb5bd;
  --gray-600: #6c757d;
  --gray-700: #495057;
  --gray-800: #343a40;
  --gray-900: #1a1d23;

  --bg-body: var(--gray-50);
  --bg-card: #ffffff;
  --bg-elevated: #ffffff;
  --text-primary: var(--gray-900);
  --text-secondary: var(--gray-600);
  --text-tertiary: var(--gray-500);
  --border-subtle: var(--gray-200);
  --border-default: var(--gray-300);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --space-xs: 0.5rem;
  --space-sm: 0.75rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-body: #0A0A0A;
    --bg-card: #171717;
    --bg-elevated: #1f1f1f;
    --text-primary: #e5e7eb;
    --text-secondary: #9ca3af;
    --text-tertiary: #6b7280;
    --border-subtle: #2d3139;
    --border-default: #383c45;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  }
}

html {
  font-family: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-body);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  padding: 16px;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

.container {
  max-width: 520px;
  margin: 0 auto;
}

/* ── Logo header ────────────────────────────────────────────────── */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: var(--space-lg);
}

.brand-icon {
  width: 32px;
  height: 32px;
}

.brand-name {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

/* ── Page header ────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}

.page-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.025em;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(245, 158, 11, 0.12);
  color: #b45309;
}

@media (prefers-color-scheme: dark) {
  .status-badge {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
  }
}

.status-badge::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
  animation: pulse 2s ease-in-out infinite;
}

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

/* ── Cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-md);
}

.card-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-xs);
}

/* ── Reason ─────────────────────────────────────────────────────── */
.reason {
  font-size: 0.9375rem;
  color: var(--text-primary);
  line-height: 1.65;
}

/* ── Stats ──────────────────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}

.stat {
  text-align: center;
  padding: var(--space-sm) 0;
}

.stat-value {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
}

/* ── Questions ──────────────────────────────────────────────────── */
.questions-list {
  list-style: none;
  counter-reset: question;
}

.questions-list li {
  counter-increment: question;
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.questions-list li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.questions-list li::before {
  content: counter(question) '.';
  font-weight: 600;
  color: var(--text-tertiary);
  margin-right: 8px;
}

/* ── Prerequisites (input assumptions) ──────────────────────────── */
.prereq {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-xs);
}

.prereq-question {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.prereq-proposed {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.prereq-rationale {
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  font-style: italic;
  margin-bottom: var(--space-sm);
}

.prereq-input-row {
  display: flex;
  gap: var(--space-xs);
  align-items: center;
}

.prereq-input-row input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-card);
  outline: none;
  transition: border-color 0.15s;
}

.prereq-input-row input:focus {
  border-color: var(--accent-500);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

@media (prefers-color-scheme: dark) {
  .prereq-input-row input {
    background: #0A0A0A;
  }
}

.prereq-toggle {
  display: flex;
  gap: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-default);
  flex-shrink: 0;
}

.prereq-toggle button {
  border: none;
  background: var(--bg-card);
  color: var(--text-tertiary);
  padding: 5px 10px;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1;
}

.prereq-toggle button + button {
  border-left: 1px solid var(--border-default);
}

.prereq-toggle button.active-accept {
  background: rgba(16, 185, 129, 0.12);
  color: var(--green-600);
}

.prereq-toggle button.active-reject {
  background: rgba(239, 68, 68, 0.12);
  color: var(--red-600);
}

/* ── Notes textarea ─────────────────────────────────────────────── */
.notes-card {
  padding: var(--space-md);
}

.notes-card textarea {
  width: 100%;
  padding: var(--space-sm);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-card);
  resize: vertical;
  min-height: 60px;
  outline: none;
  transition: border-color 0.15s;
}

.notes-card textarea:focus {
  border-color: var(--accent-500);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

@media (prefers-color-scheme: dark) {
  .notes-card textarea {
    background: #0A0A0A;
  }
}

/* ── Plan JSON ──────────────────────────────────────────────────── */
details {
  cursor: pointer;
}

details summary {
  font-size: 0.8125rem;
  color: var(--accent-500);
  font-weight: 500;
  padding: var(--space-xs) 0;
}

.plan-json {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: var(--space-sm);
  font-family: 'Geist Mono', 'SF Mono', 'Fira Code', monospace;
  font-size: 0.6875rem;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 300px;
  overflow-y: auto;
  color: var(--text-secondary);
}

/* ── Action buttons ─────────────────────────────────────────────── */
.actions {
  position: sticky;
  bottom: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border-subtle);
  padding: var(--space-md);
  padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
  margin: 0 -16px;
  display: flex;
  gap: var(--space-sm);
}

.btn {
  flex: 1;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

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

.btn-approve {
  background: var(--green-500);
  color: white;
}

.btn-approve:hover:not(:disabled) {
  background: var(--green-600);
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.btn-reject {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
}

.btn-reject:hover:not(:disabled) {
  background: var(--gray-200);
  color: var(--text-primary);
}

@media (prefers-color-scheme: dark) {
  .btn-reject:hover:not(:disabled) {
    background: var(--border-default);
  }
}

/* ── Loading ────────────────────────────────────────────────────── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60dvh;
  gap: var(--space-md);
}

.loading p {
  color: var(--text-tertiary);
  font-size: 0.875rem;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--accent-600);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Error ──────────────────────────────────────────────────────── */
.error-msg {
  background: rgba(239, 68, 68, 0.08);
  color: var(--red-600);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  font-size: 0.875rem;
  text-align: center;
}

@media (prefers-color-scheme: dark) {
  .error-msg {
    background: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.25);
  }
}

/* ── Confirmed page ─────────────────────────────────────────────── */
.confirmed-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 70dvh;
  text-align: center;
  gap: var(--space-sm);
}

.confirmed-icon {
  font-size: 48px;
}

.confirmed-page h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.confirmed-page p {
  color: var(--text-secondary);
  font-size: 0.9375rem;
}

.push-prompt {
  margin-top: var(--space-xl);
  padding: var(--space-lg);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  width: 100%;
  max-width: 340px;
}

.push-prompt-text {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
}

.btn-push {
  width: 100%;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: var(--accent-600);
  color: white;
  transition: all 0.15s;
}

.btn-push:hover:not(:disabled) {
  background: var(--accent-700);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

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

.push-status {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  margin-top: var(--space-xs);
  text-align: center;
}

/* ── Submitted-by ───────────────────────────────────────────────── */
.submitted-by {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  text-align: center;
  margin-bottom: var(--space-md);
}

.submitted-by strong {
  color: var(--text-secondary);
  font-weight: 500;
}

/* -- Inbox -- */

.inbox-user {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.inbox-header {
  padding: var(--space-sm) 0 var(--space-xs);
}

.inbox-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.inbox-count {
  font-size: 0.8rem;
  color: var(--text-tertiary);
}

.inbox-refresh-bar {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-tertiary);
  padding: var(--space-xs) 0;
}

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

.inbox-empty-icon {
  font-size: 2.5rem;
  margin-bottom: var(--space-sm);
}

.inbox-empty-title {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.inbox-empty-subtitle {
  font-size: 0.85rem;
  margin-top: var(--space-xs);
}

.inbox-empty-hint {
  font-size: 0.75rem;
  margin-top: var(--space-lg);
  color: var(--gray-300);
}

.inbox-card {
  display: block;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
  text-decoration: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow 0.15s ease;
  min-height: 44px;
}

.inbox-card:active {
  box-shadow: var(--shadow-sm);
}

.inbox-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-sm);
}

.inbox-card-info {
  flex: 1;
  min-width: 0;
}

.inbox-card-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.inbox-card-task {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inbox-card-reason {
  font-size: 0.78rem;
  color: var(--text-tertiary);
  margin-top: var(--space-xs);
  line-height: 1.4;
}

.inbox-badge {
  background: #fef3c7;
  color: #92400e;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 99px;
  white-space: nowrap;
  flex-shrink: 0;
}

@media (prefers-color-scheme: dark) {
  .inbox-badge {
    background: #78350f;
    color: #fde68a;
  }
}

.inbox-card-stats {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-sm);
  font-size: 0.7rem;
  color: var(--text-tertiary);
}

.inbox-card-time {
  margin-left: auto;
}
