/* =========================================================
   Navigage Activities — Main Stylesheet
   Brandbook: /activities/docs/brandbook.md
   ========================================================= */

/* ---------------------------------------------------------
   Custom Properties (brandbook §Color System, §Typography)
   --------------------------------------------------------- */
:root {
  /* Sidebar */
  --sidebar-bg:            #1a2332;
  --sidebar-hover:         #243044;
  --sidebar-active-accent: #00c9b1;
  --sidebar-text:          #94a3b8;
  --sidebar-text-active:   #ffffff;
  --sidebar-width:         240px;

  /* Content */
  --content-bg:            #ffffff;
  --card-bg:               #f8f9fa;
  --border:                #e2e8f0;
  --text-primary:          #1e293b;
  --text-secondary:        #64748b;
  --text-muted:            #94a3b8;

  /* Actions */
  --teal:                  #00c9b1;
  --teal-hover:            #00b09c;
  --teal-active:           #009e8c;
  --teal-shadow:           rgba(0, 201, 177, 0.28);
  --teal-ring:             rgba(0, 201, 177, 0.18);

  /* Semantic */
  --success:               #22c55e;
  --warning:               #f59e0b;
  --error:                 #ef4444;
  --info:                  #3b82f6;

  /* Time buckets */
  --bucket-now:            #ef4444;
  --bucket-soon:           #f59e0b;
  --bucket-later:          #94a3b8;

  /* Category badges */
  --badge-care-bg:         #dbeafe;
  --badge-care-fg:         #1d4ed8;
  --badge-people-bg:       #f3e8ff;
  --badge-people-fg:       #7c3aed;
  --badge-shop-prod-bg:    #dcfce7;
  --badge-shop-prod-fg:    #15803d;
  --badge-shop-svc-bg:     #ffedd5;
  --badge-shop-svc-fg:     #c2410c;
  --badge-default-bg:      #f1f5f9;
  --badge-default-fg:      #475569;

  /* Role badges */
  --badge-system-bg:       #dbeafe;
  --badge-system-fg:       #1d4ed8;
  --badge-user-bg:         #dcfce7;
  --badge-user-fg:         #15803d;

  /* Spacing (8px grid) */
  --space-xs:  0.25rem;
  --space-sm:  0.5rem;
  --space-md:  1rem;
  --space-lg:  1.5rem;
  --space-xl:  2rem;
  --space-2xl: 3rem;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;

  /* Transitions */
  --transition-fast:   0.15s ease;
  --transition-normal: 0.2s ease;
  --transition-slow:   0.3s ease;
}

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

html, body {
  height: 100%;
  overflow: hidden; /* shell manages scroll per-panel */
}

body {
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--sidebar-bg);
}

/* ---------------------------------------------------------
   App Shell
   --------------------------------------------------------- */
.app-shell {
  display: flex;
  height: 100vh;
}

/* ---------------------------------------------------------
   Sidebar (brandbook §Navigation Sidebar)
   --------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  padding: var(--space-lg) 0;
  overflow: hidden;
}

.sidebar__logo {
  padding: 0 var(--space-lg) var(--space-xl);
  border-bottom: 1px solid rgba(255,255,255,0.07);
  margin-bottom: var(--space-md);
}

.sidebar__logo-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--sidebar-active-accent);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.sidebar__logo-sub {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--sidebar-text);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-top: var(--space-xs);
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 var(--space-sm);
  flex: 1;
}

.sidebar__nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 0.625rem var(--space-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--sidebar-text);
  font-size: 0.875rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
  user-select: none;
}

.sidebar__nav-item:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-active);
}

.sidebar__nav-item.active {
  background: rgba(0, 201, 177, 0.08);
  color: var(--sidebar-text-active);
  border-left-color: var(--sidebar-active-accent);
}

.sidebar__nav-item.active .nav-icon {
  color: var(--sidebar-active-accent);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--sidebar-text);
  transition: color var(--transition-fast);
}

.sidebar__nav-item:hover .nav-icon {
  color: var(--sidebar-text-active);
}

.sidebar__footer {
  padding: var(--space-md) var(--space-lg) 0;
  border-top: 1px solid rgba(255,255,255,0.07);
  font-size: 0.75rem;
  color: var(--sidebar-text);
  opacity: 0.6;
}

/* ---------------------------------------------------------
   Content Area
   --------------------------------------------------------- */
.content-area {
  flex: 1;
  background: var(--content-bg);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.tab-panel {
  display: none;
  padding: var(--space-xl);
  flex-direction: column;
  gap: var(--space-xl);
  flex: 1;
}

.tab-panel.active {
  display: flex;
}

/* ---------------------------------------------------------
   Page Header
   --------------------------------------------------------- */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--border);
}

.page-header__title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.page-header__sub {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-top: var(--space-xs);
}

/* ---------------------------------------------------------
   Cards (brandbook §Cards)
   --------------------------------------------------------- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.card__title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-md);
}

/* ---------------------------------------------------------
   Form Elements (brandbook §Form Inputs)
   --------------------------------------------------------- */
label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
  letter-spacing: 0.01em;
}

textarea,
select,
input[type="text"] {
  width: 100%;
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.625rem 0.875rem;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  color: var(--text-primary);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  appearance: none;
  -webkit-appearance: none;
}

textarea:focus,
select:focus,
input[type="text"]:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-ring);
}

textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.6;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
  cursor: pointer;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* ---------------------------------------------------------
   Buttons (brandbook §Buttons)
   --------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-normal);
  line-height: 1;
  text-decoration: none;
}

.btn--primary {
  background: var(--teal);
  color: #ffffff;
}

.btn--primary:hover:not(:disabled) {
  background: var(--teal-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--teal-shadow);
}

.btn--primary:active:not(:disabled) {
  background: var(--teal-active);
  transform: translateY(0);
  box-shadow: none;
}

.btn--primary:disabled,
.btn:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn--sm {
  padding: 0.375rem 0.875rem;
  font-size: 0.8125rem;
}

/* ---------------------------------------------------------
   Badges (brandbook §Badges)
   --------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1;
  white-space: nowrap;
}

/* Category badges */
.badge--care         { background: var(--badge-care-bg);      color: var(--badge-care-fg); }
.badge--people       { background: var(--badge-people-bg);    color: var(--badge-people-fg); }
.badge--shop-prod    { background: var(--badge-shop-prod-bg); color: var(--badge-shop-prod-fg); }
.badge--shop-svc     { background: var(--badge-shop-svc-bg);  color: var(--badge-shop-svc-fg); }
.badge--default      { background: var(--badge-default-bg);   color: var(--badge-default-fg); }

/* Role badges (prompts page) */
.badge--system       { background: var(--badge-system-bg);    color: var(--badge-system-fg); }
.badge--user         { background: var(--badge-user-bg);      color: var(--badge-user-fg); }

/* Status badges */
.badge--success      { background: #dcfce7; color: #15803d; }
.badge--error        { background: #fee2e2; color: #b91c1c; }
.badge--info         { background: #dbeafe; color: #1d4ed8; }

/* ---------------------------------------------------------
   Tables (brandbook §Tables)
   --------------------------------------------------------- */
.table-container {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead tr {
  background: var(--card-bg);
}

thead th {
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition-fast);
}

tbody tr:last-child {
  border-bottom: none;
}

tbody tr:hover {
  background: #f8fafc;
}

tbody tr.expandable {
  cursor: pointer;
}

tbody td {
  padding: 0.75rem 1rem;
  font-size: 0.9375rem;
  color: var(--text-primary);
  vertical-align: top;
}

.td--muted {
  color: var(--text-secondary);
  font-size: 0.8125rem;
}

.td--mono {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

/* ---------------------------------------------------------
   Time Bucket Sections (brandbook §Time Bucket Sections)
   --------------------------------------------------------- */
.bucket-section {
  margin-bottom: var(--space-lg);
}

.bucket-section:last-child {
  margin-bottom: 0;
}

.bucket-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 0 0 var(--space-sm) var(--space-md);
  border-left: 4px solid;
  margin-bottom: var(--space-sm);
}

.bucket-header--now   { border-left-color: var(--bucket-now); }
.bucket-header--soon  { border-left-color: var(--bucket-soon); }
.bucket-header--later { border-left-color: var(--bucket-later); }

.bucket-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.bucket-header--now   .bucket-label { color: var(--bucket-now); }
.bucket-header--soon  .bucket-label { color: var(--bucket-soon); }
.bucket-header--later .bucket-label { color: var(--bucket-later); }

.bucket-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ---------------------------------------------------------
   Activity Table (inside result / history expand)
   --------------------------------------------------------- */
.activity-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.activity-table th {
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  text-align: left;
  background: transparent;
  border-bottom: 1px solid var(--border);
}

.activity-table td {
  padding: 0.625rem 0.75rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  line-height: 1.5;
}

.activity-table tbody tr:last-child td {
  border-bottom: none;
}

.activity-table__rationale {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ---------------------------------------------------------
   Pipeline Progress (brandbook §Progress / Loading States)
   --------------------------------------------------------- */
.pipeline-status {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.pipeline-status__header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid var(--border);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

.pipeline-status__text {
  font-weight: 500;
  color: var(--text-primary);
}

.pipeline-steps {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding-left: var(--space-md);
  border-left: 2px solid var(--border);
}

.pipeline-step {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.875rem;
  color: var(--text-secondary);
  transition: color var(--transition-fast);
}

.pipeline-step__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
  transition: background var(--transition-fast);
}

.pipeline-step.step--active {
  color: var(--text-primary);
  font-weight: 500;
}

.pipeline-step.step--active .pipeline-step__dot {
  background: var(--teal);
  animation: pulse-dot 1s ease-in-out infinite;
}

.pipeline-step.step--done .pipeline-step__dot {
  background: var(--success);
}

.pipeline-step.step--done {
  color: var(--text-secondary);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.3); }
}

/* ---------------------------------------------------------
   Result Card
   --------------------------------------------------------- */
.result-summary {
  display: flex;
  gap: var(--space-lg);
  flex-wrap: wrap;
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--border);
}

.result-stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.result-stat__label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.result-stat__value {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* ---------------------------------------------------------
   Sources section
   --------------------------------------------------------- */
.sources-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.source-item {
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  font-size: 0.8125rem;
}

.source-item__name {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
}

.source-item__guideline {
  color: var(--text-secondary);
  font-size: 0.75rem;
  margin-bottom: var(--space-xs);
}

.source-item__urls {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.source-item__url {
  color: var(--teal-hover);
  font-size: 0.75rem;
  word-break: break-all;
  text-decoration: none;
}

.source-item__url:hover {
  text-decoration: underline;
}

/* ---------------------------------------------------------
   History row expansion
   --------------------------------------------------------- */
.history-expand-row {
  display: none;
}

.history-expand-row.open {
  display: table-row;
}

.history-expand-cell {
  padding: var(--space-lg) !important;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.chevron {
  display: inline-block;
  transition: transform var(--transition-normal);
  color: var(--text-muted);
}

.chevron.open {
  transform: rotate(90deg);
}

/* ---------------------------------------------------------
   Prompts page
   --------------------------------------------------------- */
.prompt-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.prompt-group__title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--border);
}

.prompt-card {
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.prompt-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.prompt-card__meta {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.prompt-card__step {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text-primary);
}

.prompt-card__actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.prompt-card__body {
  padding: var(--space-md) var(--space-lg);
}

.prompt-card__body textarea {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  min-height: 160px;
  background: #fafbfc;
  border-color: transparent;
  border-radius: var(--radius-sm);
}

.prompt-card__body textarea:focus {
  border-color: var(--teal);
  background: var(--content-bg);
}

.save-feedback {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--success);
  opacity: 0;
  transition: opacity var(--transition-slow);
}

.save-feedback.show {
  opacity: 1;
}

/* ---------------------------------------------------------
   Empty state
   --------------------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl);
  text-align: center;
  color: var(--text-muted);
  gap: var(--space-sm);
}

.empty-state__icon {
  width: 40px;
  height: 40px;
  opacity: 0.4;
}

.empty-state__title {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.9375rem;
}

.empty-state__text {
  font-size: 0.875rem;
  max-width: 280px;
}

/* ---------------------------------------------------------
   Alert / Feedback bars
   --------------------------------------------------------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  border-left: 4px solid;
}

.alert--error   { background: #fef2f2; border-left-color: var(--error);   color: #7f1d1d; }
.alert--success { background: #f0fdf4; border-left-color: var(--success); color: #14532d; }
.alert--info    { background: #eff6ff; border-left-color: var(--info);    color: #1e3a8a; }
.alert--warning { background: #fffbeb; border-left-color: var(--warning); color: #78350f; }

/* ---------------------------------------------------------
   Divider
   --------------------------------------------------------- */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-lg) 0;
}

/* ---------------------------------------------------------
   Utility classes
   --------------------------------------------------------- */
.flex        { display: flex; }
.flex-col    { flex-direction: column; }
.items-center { align-items: center; }
.gap-sm      { gap: var(--space-sm); }
.gap-md      { gap: var(--space-md); }
.mt-md       { margin-top: var(--space-md); }
.mt-lg       { margin-top: var(--space-lg); }
.text-muted  { color: var(--text-muted); font-size: 0.8125rem; }
.text-mono   { font-family: var(--font-mono); font-size: 0.8125rem; }
.hidden      { display: none !important; }

/* ---------------------------------------------------------
   Responsive — tablet (brandbook §Responsive)
   --------------------------------------------------------- */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 200px;
  }
  .tab-panel {
    padding: var(--space-lg);
  }
}

@media (max-width: 768px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    min-width: 100%;
    flex-direction: row;
    padding: var(--space-sm) var(--space-md);
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.07);
  }
  .sidebar__logo {
    padding: 0;
    border: none;
    margin: 0;
    margin-right: var(--space-lg);
  }
  .sidebar__logo-sub { display: none; }
  .sidebar__nav {
    flex-direction: row;
    gap: var(--space-xs);
    padding: 0;
  }
  .sidebar__nav-item {
    border-left: none;
    border-bottom: 3px solid transparent;
    border-radius: 0;
    padding: var(--space-sm) var(--space-md);
  }
  .sidebar__nav-item.active {
    border-bottom-color: var(--sidebar-active-accent);
    background: transparent;
  }
  .sidebar__footer { display: none; }
  .content-area {
    height: calc(100vh - 60px);
  }
}
