:root {
  --bg-primary: #0a0a1a;
  --bg-secondary: #12122a;
  --bg-card: #1a1a3e;
  --bg-hover: #222255;
  --text-primary: #e8e8f0;
  --text-secondary: #9090b0;
  --text-muted: #606080;
  --accent: #7c6cf0;
  --accent-hover: #6a5ce0;
  --border: #2a2a5a;
  --color-task: #4fc3f7;
  --color-decision: #ffb74d;
  --color-worry: #ef5350;
  --color-idea: #ab47bc;
  --color-conversation: #26a69a;
  --color-reflection: #ff8a65;
  --color-unclear: #78909c;
  --color-close: #66bb6a;
  --color-schedule: #42a5f5;
  --color-park: #ffa726;
  --color-release: #78909c;
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 0.2s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  flex-direction: column;
}

.app-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

.app-subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.loop-count {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  gap: 6px;
  font-family: inherit;
}

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

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

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

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 10px;
  font-size: 1.1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-clear {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.btn-clear:hover {
  color: var(--color-worry);
  background: rgba(239, 83, 80, 0.1);
  border-color: rgba(239, 83, 80, 0.3);
}

.btn-small {
  padding: 4px 10px;
  font-size: 0.75rem;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

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

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.main-content {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 24px;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  min-height: calc(100vh - 60px);
}

.left-column {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.right-column {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 0;
}

section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.section-title {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

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

.section-header .section-title {
  margin-bottom: 0;
}

.section-count {
  background: var(--bg-card);
  color: var(--text-muted);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
}

.meter-container {
  position: relative;
  width: 180px;
  height: 180px;
  margin: 0 auto;
}

.meter-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.meter-bg {
  fill: none;
  stroke: var(--bg-card);
  stroke-width: 8;
}

.meter-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s ease, stroke 0.6s ease;
}

.meter-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.meter-percentage {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.meter-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
}

.brain-dump-textarea {
  width: 100%;
  min-height: 160px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 12px;
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
  line-height: 1.6;
}

.brain-dump-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.brain-dump-textarea::placeholder {
  color: var(--text-muted);
}

.brain-dump-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.btn-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.shortcut-hint {
  font-size: 0.7rem;
  padding: 2px 6px;
  background: var(--bg-card);
  border-radius: 4px;
  color: var(--text-muted);
  font-family: monospace;
}

.stats-section {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.stat-item {
  text-align: center;
  padding: 12px;
  background: var(--bg-card);
  border-radius: var(--radius);
}

.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  display: block;
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
}

.classification-output {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 8px;
}

.classification-output-inner {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.85rem;
  line-height: 1.9;
}

.class-row {
  padding: 3px 0;
  display: flex;
  gap: 8px;
}

.class-cat {
  font-weight: 600;
  white-space: nowrap;
  min-width: 130px;
  text-align: right;
  flex-shrink: 0;
}

.class-texts {
  color: var(--text-primary);
  word-break: break-word;
}

.class-row-decision .class-cat { color: var(--color-decision); }
.class-row-worry .class-cat { color: var(--color-worry); }
.class-row-conversation_to_have .class-cat { color: var(--color-conversation); }
.class-row-idea .class-cat { color: var(--color-idea); }
.class-row-task .class-cat { color: var(--color-task); }
.class-row-reflection .class-cat { color: var(--color-reflection); }
.class-row-unclear .class-cat { color: var(--color-unclear); }

.loops-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 4px 4px;
  border-bottom: 1px solid var(--border);
  margin-top: 4px;
}

.group-header:first-child {
  margin-top: 0;
}

.group-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.group-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 1px 8px;
  border-radius: 10px;
  font-weight: 600;
}

.loop-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: all var(--transition);
}

.loop-card:hover {
  border-color: var(--accent);
}

.loop-card.resolving {
  opacity: 0.5;
  transform: scale(0.98);
}

.loop-card.resolved {
  animation: slideOut 0.3s ease forwards;
}

@keyframes slideOut {
  to {
    opacity: 0;
    transform: translateX(20px);
    height: 0;
    padding: 0;
    margin: 0;
    overflow: hidden;
  }
}

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

.category-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.category-task { background: rgba(79, 195, 247, 0.15); color: var(--color-task); }
.category-decision { background: rgba(255, 183, 77, 0.15); color: var(--color-decision); }
.category-worry { background: rgba(239, 83, 80, 0.15); color: var(--color-worry); }
.category-idea { background: rgba(171, 71, 188, 0.15); color: var(--color-idea); }
.category-conversation_to_have { background: rgba(38, 166, 154, 0.15); color: var(--color-conversation); }
.category-reflection { background: rgba(255, 138, 101, 0.15); color: var(--color-reflection); }
.category-unclear { background: rgba(120, 144, 156, 0.15); color: var(--color-unclear); }

.loop-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.loop-text {
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.loop-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.btn-close { background: rgba(102, 187, 106, 0.15); color: var(--color-close); border: 1px solid transparent; }
.btn-close:hover { background: rgba(102, 187, 106, 0.3); }
.btn-schedule { background: rgba(66, 165, 245, 0.15); color: var(--color-schedule); border: 1px solid transparent; }
.btn-schedule:hover { background: rgba(66, 165, 245, 0.3); }
.btn-park { background: rgba(255, 167, 38, 0.15); color: var(--color-park); border: 1px solid transparent; }
.btn-park:hover { background: rgba(255, 167, 38, 0.3); }
.btn-release { background: rgba(120, 144, 156, 0.15); color: var(--color-release); border: 1px solid transparent; }
.btn-release:hover { background: rgba(120, 144, 156, 0.3); }
.btn-ai { background: rgba(124, 108, 240, 0.15); color: var(--accent); border: 1px solid transparent; }
.btn-ai:hover { background: rgba(124, 108, 240, 0.3); }

.empty-state {
  text-align: center;
  padding: 40px 20px;
}

.empty-state.small {
  padding: 20px;
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-text {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.empty-hint {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 8px;
  opacity: 0.7;
}

.log-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.log-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-card);
  border-radius: var(--radius);
  opacity: 0.8;
}

.log-entry:hover {
  opacity: 1;
}

.log-content {
  flex: 1;
  min-width: 0;
  overflow-wrap: break-word;
}

.log-text {
  font-size: 0.85rem;
  word-break: break-word;
}

.log-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}

.log-status {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.status-closed { color: var(--color-close); }
.status-scheduled { color: var(--color-schedule); }
.status-parked { color: var(--color-park); }
.status-released { color: var(--color-release); }

.log-time {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.log-reopen {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  padding: 4px 8px;
  font-size: 0.7rem;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}

.log-reopen:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.error-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: rgba(239, 83, 80, 0.15);
  border-bottom: 1px solid rgba(239, 83, 80, 0.3);
  color: var(--color-worry);
  font-size: 0.85rem;
}

.error-banner.hidden { display: none; }

#error-dismiss {
  background: none;
  border: none;
  color: inherit;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 26, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.loading-overlay.hidden { display: none; }

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

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

.loading-text {
  margin-top: 16px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.settings-group {
  margin-bottom: 20px;
}

.settings-group:last-child {
  margin-bottom: 0;
}

.optional-badge {
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--color-park);
  background: rgba(255, 167, 38, 0.15);
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: none;
  letter-spacing: normal;
  vertical-align: middle;
  margin-left: 4px;
}

.settings-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.settings-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
}

.settings-input:focus {
  outline: none;
  border-color: var(--accent);
}

.settings-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.settings-hint a {
  color: var(--accent);
}

.guidance-loop-text {
  font-size: 0.9rem;
  font-style: italic;
  color: var(--text-secondary);
  margin-bottom: 16px;
  padding: 12px;
  background: var(--bg-card);
  border-radius: var(--radius);
}

.guidance-list {
  list-style: none;
  padding: 0;
}

.guidance-item {
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
  font-size: 0.85rem;
  line-height: 1.4;
}

.guidance-reasoning {
  margin-top: 16px;
  padding: 12px;
  background: rgba(124, 108, 240, 0.1);
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.guidance-reasoning strong {
  color: var(--accent);
}

.guidance-best-action {
  display: inline-block;
  margin-top: 12px;
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* API Key row */
.api-key-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.api-key-row .settings-input {
  flex: 1;
}
.api-key-row .btn-sm {
  padding: 8px 14px;
  font-size: 0.8rem;
  white-space: nowrap;
}

/* API status */
.api-status {
  margin-top: 6px;
  font-size: 0.8rem;
  min-height: 1.2em;
}
.api-status-testing { color: var(--text-secondary); }
.api-status-success { color: var(--color-close); }
.api-status-error { color: var(--color-worry); }

/* AI Badge in header */
.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
  background: rgba(120, 144, 156, 0.15);
  color: var(--color-unclear);
}
.ai-badge-active {
  background: rgba(102, 187, 106, 0.15);
  color: var(--color-close);
}

/* Onboarding banner */
.onboarding-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(255, 183, 77, 0.12);
  border-bottom: 1px solid rgba(255, 183, 77, 0.2);
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.onboarding-banner a {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
.onboarding-banner button {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.onboarding-banner.hidden {
  display: none;
}

/* Classification source tag */
.classification-source {
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: rgba(124, 108, 240, 0.06);
  border-radius: var(--radius);
  text-align: center;
}
.classification-source a {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

.hidden { display: none !important; }

select.settings-input {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23909090' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}

select.settings-input option {
  background: var(--bg-card);
  color: var(--text-primary);
}

@media (max-width: 768px) {
  .main-content {
    grid-template-columns: 1fr;
    padding: 16px;
  }
  .app-header {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .app-title {
    font-size: 1.1rem;
  }
}
