/* =====================================================
   Freelance Business Dashboard — Styles
   ===================================================== */

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

/* --- Light Theme (default) --- */
:root {
  --color-bg: #f5f6f8;
  --color-white: #ffffff;
  --color-header: #1a1a2e;
  --color-header-text: #e0e0e0;
  --color-primary: #4a6cf7;
  --color-primary-hover: #3a5ce5;
  --color-green: #16a34a;
  --color-green-bg: #f0fdf4;
  --color-red: #dc2626;
  --color-red-bg: #fef2f2;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-border: #e2e8f0;
  --color-danger: #dc2626;
  --color-danger-hover: #b91c1c;
  --color-card: #ffffff;
  --color-surface: #ffffff;
  --color-surface-hover: #fafbfc;
  --color-input-bg: #ffffff;
  --color-modal-overlay: rgba(0, 0, 0, 0.5);
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --transition: 150ms ease;
}

/* --- Dark Theme --- */
[data-theme="dark"] {
  --color-bg: #0f172a;
  --color-white: #1e293b;
  --color-header: #0f172a;
  --color-header-text: #cbd5e1;
  --color-primary: #6381f7;
  --color-primary-hover: #7b93f9;
  --color-green: #22c55e;
  --color-green-bg: rgba(34, 197, 94, 0.1);
  --color-red: #ef4444;
  --color-red-bg: rgba(239, 68, 68, 0.1);
  --color-text: #e2e8f0;
  --color-text-muted: #94a3b8;
  --color-border: #334155;
  --color-danger: #ef4444;
  --color-danger-hover: #dc2626;
  --color-card: #1e293b;
  --color-surface: #1e293b;
  --color-surface-hover: #263349;
  --color-input-bg: #1e293b;
  --color-modal-overlay: rgba(0, 0, 0, 0.7);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
}

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

.hidden { display: none !important; }

/* --- Login Screen --- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-header);
}

.login-card {
  background: var(--color-surface);
  padding: 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  margin: 20px;
}

.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
}

.login-logo {
  display: block;
  max-width: 220px;
  height: auto;
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--color-text-muted);
  margin-bottom: 24px;
  font-size: 14px;
}

/* --- Header --- */
.app-header {
  background: var(--color-header);
  color: var(--color-header-text);
  padding: 0 24px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--color-border);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.header-logo {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.header-logo-img {
  height: 44px;
  width: auto;
}

[data-theme="dark"] .header-logo-img {
  filter: brightness(1.1);
}

.header-tagline-img {
  height: 28px;
  max-height: 28px;
  width: auto;
  margin-left: 8px;
  opacity: 0.85;
  object-fit: contain;
  align-self: flex-end;
  margin-bottom: 2px;
}
[data-theme="dark"] .header-tagline-img {
  filter: brightness(1.1);
}

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

.nav-link {
  color: var(--color-header-text);
  text-decoration: none;
  font-size: 14px;
  opacity: 0.8;
  transition: opacity var(--transition);
}
.nav-link:hover { opacity: 1; }

/* --- Header buttons (sign-out on dark header) --- */
.app-header .btn-outline {
  color: var(--color-header-text);
  border-color: rgba(255,255,255,0.2);
}
.app-header .btn-outline:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.35);
}

/* --- Theme Toggle --- */
.theme-toggle {
  color: var(--color-header-text);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
  transition: background var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.theme-toggle:hover {
  background: rgba(255,255,255,0.1);
}

/* Show/hide the correct icon + label */
.theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: inline; }

/* --- Container --- */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

/* --- Summary Bar --- */
.summary-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 32px;
  flex-wrap: wrap;
  align-items: center;
}
#btn-summary-period {
  flex-shrink: 0;
  align-self: center;
  white-space: nowrap;
}

.summary-item {
  flex: 1;
  min-width: 180px;
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  border-left: 4px solid transparent;
}

.summary-revenue { border-left-color: var(--color-green); }
.summary-costs { border-left-color: var(--color-red); }
.summary-net { border-left-color: var(--color-primary); }

.summary-label {
  display: block;
  font-size: 13px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.summary-value {
  font-size: 28px;
  font-weight: 700;
}

.summary-revenue .summary-value { color: var(--color-green); }
.summary-costs .summary-value { color: var(--color-red); }

/* --- Pipeline Section Container --- */
#pipelines-container {
  display: flex;
  flex-direction: column;
  gap: 32px;
}
.pipeline-section {
  /* No wrapper around the whole section — just spacing */
}
.pipeline-section .section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .pipeline-section .section-header {
  background: rgba(255, 255, 255, 0.04);
  box-shadow: none;
}
.pipeline-section.collapsed .section-header {
  margin-bottom: 0;
}
.pipeline-section .section-header h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}
.pipeline-body {
  /* No extra padding — stream grid handles its own spacing */
}
.pipeline-body > p:first-child {
  margin-top: 0 !important;
  margin-bottom: 12px;
}

/* --- Stream Grid (Dashboard Panes) --- */
/* --- View Mode Toggle --- */
.view-mode-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 4px;
  width: fit-content;
}
.view-mode-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.view-mode-btn:hover {
  background: rgba(74, 108, 247, 0.08);
  color: var(--color-text);
}
.view-mode-btn.active {
  background: var(--color-primary);
  color: #fff;
}
[data-theme="dark"] .view-mode-btn:hover:not(.active) {
  background: rgba(74, 108, 247, 0.15);
}

.stream-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

/* --- Compact Mode --- */
.stream-grid.compact {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}
.stream-grid.compact .stream-pane {
  padding: 12px 16px;
  gap: 4px;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.stream-grid.compact .stream-pane-name {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.stream-grid.compact .stream-pane-meta {
  display: none;
}
.stream-grid.compact .stream-pane-summary {
  padding-top: 0;
  border-top: none;
  gap: 8px;
  flex-shrink: 0;
}
.stream-grid.compact .stream-pane-net {
  font-size: 14px;
}
.stream-grid.compact .stream-pane-summary > span:last-child {
  display: none;
}
/* --- Pipeline Collapse --- */
.section-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.btn-pipeline-collapse {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}
.btn-pipeline-collapse:hover {
  color: var(--color-text);
  background: rgba(0,0,0,0.06);
}
[data-theme="dark"] .btn-pipeline-collapse:hover {
  background: rgba(255,255,255,0.08);
}
.section-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.pipeline-collapsed-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 500;
}
.pipeline-body.hidden {
  display: none;
}
.stream-pane {
  position: relative;
  --_r: var(--stream-r, 74);
  --_g: var(--stream-g, 108);
  --_b: var(--stream-b, 247);
  background: rgba(var(--_r), var(--_g), var(--_b), 0.12);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  cursor: pointer;
  transition: box-shadow var(--transition), transform var(--transition), background var(--transition);
  border: 1px solid rgba(var(--_r), var(--_g), var(--_b), 0.25);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

[data-theme="dark"] .stream-pane {
  background: rgba(var(--_r), var(--_g), var(--_b), 0.18);
  border-color: rgba(var(--_r), var(--_g), var(--_b), 0.3);
}

.stream-pane:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
  background: rgba(var(--_r), var(--_g), var(--_b), 0.2);
}

[data-theme="dark"] .stream-pane:hover {
  background: rgba(var(--_r), var(--_g), var(--_b), 0.28);
}

.stream-pane-name {
  font-size: 18px;
  font-weight: 600;
  color: var(--stream-color, var(--color-primary));
}

[data-theme="dark"] .stream-pane-name {
  color: var(--stream-color, var(--color-primary));
  filter: brightness(1.2);
}

.stream-pane-meta {
  font-size: 13px;
  color: var(--color-text-muted);
}

.stream-pane-summary {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(var(--_r), var(--_g), var(--_b), 0.2);
  font-size: 14px;
}

.stream-pane-net {
  font-size: 20px;
  font-weight: 700;
}

.positive { color: var(--color-green); }
.negative { color: var(--color-red); }
.neutral { color: var(--color-text-muted); }

.stream-pane-empty {
  border: 2px dashed var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  color: var(--color-text-muted);
  font-size: 14px;
  cursor: default;
  background: transparent !important;
  box-shadow: none;
}
.stream-pane-empty:hover {
  box-shadow: none;
  transform: none;
  background: transparent !important;
}

/* --- Drag & Drop --- */
.stream-pane[draggable="true"] {
  cursor: grab;
}
.stream-pane[draggable="true"]:active {
  cursor: grabbing;
}
.stream-pane.dragging {
  opacity: 0.4;
  transform: scale(0.95);
  box-shadow: 0 0 0 2px var(--color-primary);
}
.stream-grid.drag-over {
  background: rgba(74, 108, 247, 0.08);
  border: 2px dashed var(--color-primary);
  border-radius: 12px;
  min-height: 80px;
  transition: background 0.2s, border 0.2s;
}
[data-theme="dark"] .stream-grid.drag-over {
  background: rgba(74, 108, 247, 0.15);
}
/* Drop insertion indicators on cards */
.stream-pane.drop-before {
  box-shadow: inset 4px 0 0 0 var(--color-primary);
}
.stream-pane.drop-after {
  box-shadow: inset -4px 0 0 0 var(--color-primary);
}

/* --- Color Picker --- */
.color-picker {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 4px 0;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition);
  outline: none;
}
.color-swatch:hover {
  transform: scale(1.15);
}
.color-swatch.selected {
  border-color: var(--color-text);
  box-shadow: 0 0 0 2px var(--color-bg);
}

/* --- Icon Picker --- */
.icon-picker {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 4px 0;
}
.icon-swatch {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 2px solid var(--color-border);
  cursor: pointer;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  transition: transform var(--transition), border-color var(--transition), background var(--transition);
}
.icon-swatch img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}
.icon-swatch:hover {
  transform: scale(1.1);
  background: rgba(74, 108, 247, 0.08);
}
.icon-swatch.selected {
  border-color: var(--color-primary);
  background: rgba(74, 108, 247, 0.12);
  box-shadow: 0 0 0 2px rgba(74, 108, 247, 0.25);
}

/* Inline icon next to titles */
.title-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
  vertical-align: middle;
  margin-right: 6px;
}
.stream-pane-icon {
  width: 20px;
  height: 20px;
  object-fit: contain;
  vertical-align: middle;
  margin-right: 4px;
}

/* --- Todo Section --- */
.todo-section {
  margin-bottom: 28px;
}
.todo-body {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.todo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .todo-header {
  background: rgba(255, 255, 255, 0.04);
  box-shadow: none;
}
.todo-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.todo-header h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.todo-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  padding: 0 6px;
}
.todo-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.todo-list:empty::after {
  content: 'No active tasks — you\'re all caught up!';
  display: block;
  padding: 20px 16px;
  color: var(--color-text-muted);
  font-size: 13px;
  text-align: center;
  background: var(--color-card);
  border: 1px dashed var(--color-border);
  border-radius: 10px;
}
.todo-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--todo-color, #94a3b8);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .todo-item {
  border-left-color: var(--todo-color, var(--color-border));
  box-shadow: none;
}
.todo-item[data-has-color="true"] {
  background: rgba(var(--todo-r, 255), var(--todo-g, 255), var(--todo-b, 255), 0.10);
  border-color: rgba(var(--todo-r), var(--todo-g), var(--todo-b), 0.25);
}
[data-theme="dark"] .todo-item[data-has-color="true"] {
  background: rgba(var(--todo-r, 255), var(--todo-g, 255), var(--todo-b, 255), 0.16);
  border-color: rgba(var(--todo-r), var(--todo-g), var(--todo-b), 0.3);
}
.todo-color-none {
  background: var(--color-card) !important;
  border: 2px dashed var(--color-border) !important;
  color: var(--color-text-muted);
  font-size: 10px;
  line-height: 1;
}
.todo-item:hover {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 1px rgba(74, 108, 247, 0.15);
}
.todo-item[data-has-color="true"]:hover {
  background: rgba(var(--todo-r, 255), var(--todo-g, 255), var(--todo-b, 255), 0.18);
}
[data-theme="dark"] .todo-item[data-has-color="true"]:hover {
  background: rgba(var(--todo-r, 255), var(--todo-g, 255), var(--todo-b, 255), 0.24);
}
[data-theme="dark"] .todo-item:not([data-has-color="true"]) {
  background: rgba(255, 255, 255, 0.04);
}
[data-theme="dark"] .todo-item:not([data-has-color="true"]):hover {
  background: rgba(255, 255, 255, 0.06);
}
.todo-item.dragging {
  opacity: 0.4;
  transform: scale(0.97);
  box-shadow: 0 0 0 2px var(--color-primary);
}
.todo-item[draggable="true"] {
  cursor: grab;
}
.todo-item[draggable="true"]:active {
  cursor: grabbing;
}
.todo-item.todo-drop-before {
  box-shadow: 0 -2px 0 0 var(--color-primary);
}
.todo-item.todo-drop-after {
  box-shadow: 0 2px 0 0 var(--color-primary);
}
.todo-checkbox {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #94a3b8;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  padding: 0;
}
.todo-checkbox:hover {
  border-color: #34d399;
  background: rgba(52, 211, 153, 0.1);
  transform: scale(1.1);
}
.todo-checkbox.checked {
  background: #34d399;
  border-color: #34d399;
}
.todo-checkbox.checked::after {
  content: '✓';
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}
.todo-title {
  flex: 1;
  font-size: 14px;
  color: var(--color-text);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.todo-item.archived .todo-title {
  text-decoration: line-through;
  opacity: 0.45;
}
.todo-item.archived {
  opacity: 0.6;
}
.todo-item.archived .todo-checkbox {
  border-color: #34d399;
  background: #34d399;
}
.todo-item.archived .todo-checkbox::after {
  content: '✓';
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}
.todo-description-preview {
  font-size: 12px;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  flex-shrink: 1;
}
.todo-stream-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
  font-weight: 500;
}
.todo-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.1s;
  flex-shrink: 0;
}
.todo-item:hover .todo-actions {
  opacity: 1;
}
.todo-footer {
  padding: 8px 0 0;
  text-align: center;
}
.btn-text {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.1s, background 0.1s;
}
.btn-text:hover {
  color: var(--color-primary);
  background: rgba(74, 108, 247, 0.08);
}
.todo-archived-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.todo-archived-list .todo-item {
  border-style: dashed;
}

/* Stream-level todos */
.stream-todos {
  margin-bottom: 28px;
}
.stream-todos-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.stream-todos-header h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}
.stream-todos-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stream-todos-list:empty::after {
  content: 'No tasks for this stream';
  display: block;
  padding: 16px 12px;
  color: var(--color-text-muted);
  font-size: 13px;
  text-align: center;
  background: var(--color-card);
  border: 1px dashed var(--color-border);
  border-radius: 10px;
}

/* --- Stream Documents --- */
.stream-documents {
  margin-bottom: 28px;
}
.stream-documents-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.stream-documents-header h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}
.stream-documents-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stream-documents-list:empty::after {
  content: 'No documents attached';
  display: block;
  padding: 16px 12px;
  color: var(--color-text-muted);
  font-size: 13px;
  text-align: center;
  background: var(--color-card);
  border: 1px dashed var(--color-border);
  border-radius: 10px;
}
.document-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .document-item {
  background: rgba(255, 255, 255, 0.04);
  box-shadow: none;
}
.document-item:hover {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 1px rgba(74, 108, 247, 0.15);
}
[data-theme="dark"] .document-item:hover {
  background: rgba(255, 255, 255, 0.06);
}
.document-icon {
  font-size: 24px;
  flex-shrink: 0;
  line-height: 1;
}
.document-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.document-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.document-desc-preview {
  font-size: 12px;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.document-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-size: 12px;
  color: var(--color-text-muted);
  flex-shrink: 0;
  white-space: nowrap;
}

/* Document view modal */
.doc-view-desc {
  font-size: 14px;
  color: var(--color-text);
  margin-bottom: 16px;
  line-height: 1.6;
}
.doc-view-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 13px;
  color: var(--color-text-muted);
  padding: 12px 16px;
  background: var(--color-surface-hover);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  margin-bottom: 16px;
}

/* File input styling */
.form-group input[type="file"] {
  width: 100%;
  padding: 9px 12px;
  font-size: 14px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-input-bg);
  color: var(--color-text);
  font-family: inherit;
}

/* Clickable todo title */
.todo-clickable {
  cursor: pointer;
}
.todo-clickable:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

/* Todo description in modal */
.todo-description-field textarea {
  min-height: 80px;
  resize: vertical;
}

/* --- Stream Detail View --- */
.back-link {
  display: inline-block;
  color: var(--color-primary);
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 16px;
}
.back-link:hover { text-decoration: underline; }

.stream-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.stream-title {
  font-size: 28px;
  font-weight: 700;
}

.stream-desc {
  color: var(--color-text-muted);
  margin-top: 4px;
  font-size: 15px;
}

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

.stream-summary {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.stream-summary .summary-item {
  min-width: 140px;
}

.summary-view-toggle {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  margin-bottom: -8px;
}

.stream-actions {
  display: flex;
  gap: 8px;
  margin-top: 24px;
}

/* --- Category Sections --- */
.category-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

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

.category-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.category-header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.category-net {
  font-weight: 700;
  font-size: 15px;
  margin-right: 8px;
}

.category-items {
  padding: 0;
}

/* --- Item Rows --- */
.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--color-border);
  gap: 12px;
  transition: background var(--transition);
}
.item-row:last-child { border-bottom: none; }
.item-row:hover { background: var(--color-surface-hover); }

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

.item-name {
  font-weight: 600;
  font-size: 15px;
}

.item-meta {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.item-financials {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.item-revenue {
  color: var(--color-green);
  font-weight: 600;
  font-size: 14px;
}

.item-cost-total {
  color: var(--color-red);
  font-weight: 600;
  font-size: 14px;
}

.item-net {
  font-weight: 700;
  font-size: 15px;
  min-width: 80px;
  text-align: right;
}

.item-amortized {
  font-size: 12px;
  color: var(--color-text-muted);
  font-weight: 400;
  white-space: nowrap;
}
.item-date-annotation {
  font-size: 12px;
  color: var(--color-text-muted);
  font-weight: 400;
  font-style: italic;
}
.item-date-annotation.inactive {
  color: var(--color-primary);
}
.item-row.item-inactive {
  opacity: 0.5;
}

.item-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}
.item-row:hover .item-actions { opacity: 1; }

/* --- Cost breakdown (expandable inside an item) --- */
.item-expand-toggle {
  background: none;
  border: none;
  color: var(--color-primary);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  margin-top: 4px;
}
.item-expand-toggle:hover { text-decoration: underline; }

.cost-breakdown {
  padding: 8px 20px 14px 36px;
  border-bottom: 1px solid var(--color-border);
}

.cost-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 13px;
  color: var(--color-text-muted);
}

.cost-row-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}
.cost-row:hover .cost-row-actions { opacity: 1; }

.cost-add-row {
  margin-top: 8px;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  line-height: 1.4;
}

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

.btn-outline {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text);
}
.btn-outline:hover { background: var(--color-surface-hover); }

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

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-xs {
  padding: 3px 8px;
  font-size: 11px;
}

.btn-full { width: 100%; }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: var(--color-text-muted);
  font-size: 14px;
  transition: all var(--transition);
}
.btn-icon:hover { background: var(--color-surface-hover); color: var(--color-text); }
.btn-icon.danger:hover { color: var(--color-danger); }

/* --- Forms --- */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  font-size: 14px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-input-bg);
  color: var(--color-text);
  transition: border-color var(--transition);
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.1);
}

.form-group textarea { resize: vertical; }

.form-row {
  display: flex;
  gap: 12px;
}
.form-row .flex-1 { flex: 1; }
.form-row .flex-2 { flex: 2; }

.optional {
  font-weight: 400;
  color: var(--color-text-muted);
}

.field-hint {
  display: block;
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 3px;
}

.error-msg {
  background: var(--color-red-bg);
  color: var(--color-red);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* --- Modals --- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: var(--color-modal-overlay);
}

.modal-content {
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  margin: 20px;
}

.modal-content.modal-wide { max-width: 600px; }
.modal-content.modal-sm { max-width: 380px; }

.modal-content h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

/* --- Toast --- */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--color-text);
  color: var(--color-bg);
  padding: 12px 20px;
  border-radius: 6px;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  animation: slideIn 200ms ease;
}

.toast.success { background: var(--color-green); color: white; }
.toast.error { background: var(--color-red); color: white; }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Loading spinner --- */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}

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

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--color-text-muted);
  gap: 12px;
}

/* --- Reports View --- */
.report-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.report-header h2 {
  font-size: 24px;
  font-weight: 700;
}

.report-filters {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  padding: 16px 20px;
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  flex-wrap: wrap;
}

.report-filter-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.report-filter-checks {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.report-filter-checks label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  cursor: pointer;
  color: var(--color-text);
}

.report-filter-checks input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

.report-section {
  margin-bottom: 32px;
}

.report-section-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--color-primary);
  display: inline-block;
}

.report-summary-cards {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.report-summary-cards .summary-item {
  flex: 1;
  min-width: 160px;
}

.report-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.report-chart-container {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--color-border);
  position: relative;
  min-height: 300px;
}

.report-stream-detail {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  margin-bottom: 16px;
  overflow: hidden;
}

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

.report-stream-detail-header h4 {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.report-stream-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.report-stream-detail-stats {
  display: flex;
  gap: 24px;
  font-size: 14px;
}

.report-stream-detail-stats span {
  font-weight: 600;
}

.report-stream-items {
  padding: 0;
}

.report-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  border-bottom: 1px solid var(--color-border);
  font-size: 14px;
}

.report-item-row:last-child {
  border-bottom: none;
}

.report-item-name {
  font-weight: 500;
}

.report-item-meta {
  font-size: 12px;
  color: var(--color-text-muted);
}

.report-item-amount {
  font-weight: 600;
  white-space: nowrap;
}

.report-item-amortized {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-left: 8px;
}

.nav-link.active {
  opacity: 1;
  font-weight: 600;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .container { padding: 12px; }

  /* ---- Header ---- */
  .app-header { padding: 0 12px; height: auto; min-height: 48px; }
  .header-inner { flex-wrap: wrap; gap: 4px; padding: 8px 0; }
  .header-logo-img { height: 32px; }
  .header-tagline-img { display: none; }
  .header-nav { gap: 8px; }
  .nav-link { font-size: 13px; padding: 4px 6px; }
  .theme-toggle { font-size: 12px; padding: 4px 8px; }
  .app-header .btn-outline { font-size: 12px; padding: 4px 10px; }

  /* ---- Summary Cards ---- */
  .summary-bar {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
  }
  .summary-item {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
    padding: 12px 14px;
  }
  .summary-label { font-size: 10px; letter-spacing: 0.5px; }
  .summary-value { font-size: 20px; }
  .summary-period-toggle { margin-bottom: 16px; }

  /* ---- View Mode Toggle ---- */
  .view-mode-bar { margin-bottom: 14px; }

  /* ---- Pipeline Sections ---- */
  .pipeline-section .section-header {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }
  .section-header-left { flex: 1; min-width: 0; }
  .section-header-left h2 { font-size: 15px; }
  .pipeline-collapsed-summary { font-size: 12px; gap: 8px; }
  .pipeline-section .section-header .btn-primary { font-size: 12px; padding: 5px 10px; }
  .pipeline-section .section-header .btn-icon { font-size: 13px; padding: 4px 6px; }

  /* ---- Stream Panes ---- */
  .stream-grid { grid-template-columns: 1fr; gap: 8px; }
  .stream-pane { padding: 12px; }
  .stream-pane-name { font-size: 15px; }
  .stream-pane-summary { flex-wrap: wrap; gap: 4px 10px; font-size: 12px; }

  /* ---- Todo Section ---- */
  .todo-section { margin-bottom: 20px; }
  .todo-header { padding: 10px 12px; }
  .todo-header h2 { font-size: 15px; }
  .todo-item { padding: 8px 10px; font-size: 13px; }
  .todo-item-text { font-size: 13px; }
  .todo-description-preview { display: none; }
  .todo-stream-tag { font-size: 10px; padding: 1px 6px; }

  /* ---- Stream Detail ---- */
  .stream-header { flex-direction: column; gap: 8px; }
  .stream-title { font-size: 20px; }
  .stream-summary .summary-item { min-width: 0; flex: 1 1 calc(50% - 4px); padding: 10px 12px; }
  .stream-summary .summary-bar { gap: 8px; }

  /* ---- Items & Costs ---- */
  .item-row { flex-wrap: wrap; gap: 6px; }
  .item-financials { flex-wrap: wrap; gap: 6px; }
  .item-actions { opacity: 1; }

  /* ---- Forms & Modals ---- */
  .form-row { flex-direction: column; gap: 0; }
  .modal-content { margin: 8px; padding: 16px; max-width: calc(100vw - 16px); }
  .modal-content.modal-wide { max-width: calc(100vw - 16px); }

  /* ---- Reports ---- */
  .report-charts { grid-template-columns: 1fr; }
  .report-stream-detail-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .report-stream-detail-stats { flex-wrap: wrap; gap: 12px; }
}

@media (max-width: 480px) {
  .container { padding: 8px; }

  /* Header goes even tighter */
  .header-inner { justify-content: space-between; }
  .header-logo-img { height: 28px; }
  .header-nav { gap: 6px; flex-wrap: wrap; }
  .nav-link { font-size: 12px; }

  /* Summary cards stack to full width */
  .summary-item { flex: 1 1 100%; }

  /* Pipeline headers stack actions below */
  .pipeline-section .section-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .section-header-actions {
    width: 100%;
    justify-content: flex-start;
  }
  .section-header-left h2 { font-size: 14px; }

  /* Stream actions go full width */
  .stream-actions { flex-direction: column; }
  .stream-actions .btn { width: 100%; }

  /* Category headers */
  .category-header { flex-wrap: wrap; gap: 6px; }
  .category-header-actions { flex-wrap: wrap; gap: 4px; }

  /* Document items */
  .document-item { padding: 10px 12px; gap: 8px; }
  .document-title { font-size: 13px; }
  .document-meta { font-size: 11px; }
}
