:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-hover: #f0f2f5;
  --border: #e0e2e8;
  --text: #2e2e2e;
  --text-muted: #6b7280;
  --accent: #004ead;
  --accent-hover: #003d8a;
  --accent-light: rgba(0, 78, 173, 0.08);
  --critical: #dc2626;
  --high: #ea580c;
  --medium: #d97706;
  --low: #059669;
  --success: #16a34a;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
}

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

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

/* ---- Login screen ---- */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #f0f4fa 0%, #e8edf5 100%);
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.10);
  padding: 48px 40px 40px;
  text-align: center;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  max-width: 200px;
  max-height: 80px;
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 28px;
  letter-spacing: 0.5px;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card input[type="password"] {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
  text-align: center;
}

.login-card input[type="password"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.login-card button[type="submit"] {
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.login-card button[type="submit"]:hover {
  background: var(--accent-hover);
}

.login-error {
  color: var(--critical);
  font-size: 0.85rem;
  margin-top: 12px;
  min-height: 1.2em;
}

/* Layout */
.app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px 20px;
}

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

.header-logo {
  height: 40px;
  width: auto;
  object-fit: contain;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

header .settings {
  display: flex;
  gap: 8px;
  align-items: center;
}

header input, header select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 6px 12px;
  font-size: 0.85rem;
  cursor: pointer;
}

header input::placeholder { color: var(--text-muted); }

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
}

.tab {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  padding: 8px 18px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
}

.tab:hover { background: var(--surface); color: var(--text); }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Views */
.view { display: none; }
.view.active-view { display: block; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 1.05rem;
  margin-bottom: 12px;
  font-weight: 600;
}

.card h3 {
  font-size: 0.95rem;
  margin-bottom: 8px;
  font-weight: 500;
}

/* Intake form */
textarea {
  width: 100%;
  min-height: 140px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 12px;
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
}

textarea::placeholder { color: var(--text-muted); }
textarea:focus { outline: none; border-color: var(--accent); }

.intake-options {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.intake-options select {
  flex: 1;
  padding: 6px 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
}

.intake-preview-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.preview-tag {
  display: inline-block;
  background: var(--accent-light);
  color: var(--text);
  font-size: 0.82rem;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.preview-tag strong {
  color: var(--accent);
}

/* Editable preview task cards */
.preview-editable {
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  background: var(--surface);
}

.preview-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.preview-editable .edit-title {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.preview-editable .edit-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.preview-editable .edit-row:last-of-type {
  margin-bottom: 0;
}

.preview-editable .edit-row label {
  display: flex;
  align-items: center;
  gap: 4px;
}

.preview-editable .edit-row select,
.preview-editable .edit-row input {
  font-size: 0.82rem;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
}

.preview-editable .edit-row input[type="number"] {
  width: 60px;
}

.preview-editable .desc {
  margin-top: 10px;
  font-size: 0.83rem;
  color: var(--text-muted);
  line-height: 1.5;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.btn-discard {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}

.btn-discard:hover {
  color: var(--critical);
}

/* Image preview for intake */
.image-preview {
  position: relative;
  display: inline-block;
  margin-bottom: 10px;
}

.image-preview img {
  max-width: 100%;
  max-height: 200px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
}

.btn-remove-image {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--critical);
  color: #fff;
  border: 2px solid var(--surface);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.btn-remove-image:hover {
  background: #b91c1c;
}

/* Drag-and-drop visual feedback */
textarea.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(0, 78, 173, 0.15);
}

.assignee-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}

.assignee-option {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}

.assignee-option input[type="checkbox"] {
  accent-color: var(--accent);
}

.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s;
}

button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

button.secondary:hover { background: var(--surface-hover); }

/* Task list */
.task-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

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

.priority-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}

.priority-dot.critical { background: var(--critical); }
.priority-dot.high { background: var(--high); }
.priority-dot.medium { background: var(--medium); }
.priority-dot.low { background: var(--low); }

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

.task-info .title {
  font-weight: 500;
  font-size: 0.95rem;
}

.task-info .meta {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 2px;
}

.task-info .desc {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

.status-badge {
  font-size: 0.75rem;
  padding: 2px 10px;
  border-radius: 12px;
  font-weight: 500;
  flex-shrink: 0;
}

.status-badge.not_started { background: #f1f3f5; color: var(--text-muted); }
.status-badge.in_progress { background: #dbeafe; color: #1d4ed8; }
.status-badge.blocked { background: #fee2e2; color: var(--critical); }
.status-badge.done { background: #dcfce7; color: var(--success); }

/* Plan task checkboxes */
.task-check {
  display: flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 4px;
}

.task-check input[type="checkbox"] {
  display: none;
}

.task-check .checkmark {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-radius: 4px;
  transition: all 0.15s;
  position: relative;
}

.task-check input:checked + .checkmark {
  background: var(--accent);
  border-color: var(--accent);
}

.task-check input:checked + .checkmark::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.task-check:hover .checkmark {
  border-color: var(--accent);
}

/* Slot checkbox (inline) */
.slot-check {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  margin-right: 4px;
  vertical-align: middle;
}

.slot-check input[type="checkbox"] {
  display: none;
}

.slot-check .checkmark-sm {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-radius: 3px;
  display: inline-block;
  transition: all 0.15s;
  position: relative;
}

.slot-check input:checked + .checkmark-sm {
  background: var(--accent);
  border-color: var(--accent);
}

.slot-check input:checked + .checkmark-sm::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 0px;
  width: 4px;
  height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.slot-check:hover .checkmark-sm {
  border-color: var(--accent);
}

/* Completed task state */
.completed-task {
  opacity: 0.45;
  text-decoration: line-through;
  transition: opacity 0.3s;
}

.completed-task .title {
  text-decoration: line-through;
}

.schedule-slot.checkable {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.schedule-day.today {
  border-color: var(--accent);
  background: var(--accent-light);
}

/* Task timeline (projected vs deadline) */
.task-timeline {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  font-size: 0.8rem;
}

.timeline-dates {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}

.timeline-label {
  font-weight: 500;
  color: var(--text-muted);
}

.timeline-date {
  color: var(--text);
}

.timeline-sep {
  color: var(--border);
  margin: 0 2px;
}

.track-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 10px;
  flex-shrink: 0;
}

.track-badge.on-track {
  background: #dcfce7;
  color: var(--success);
}

.track-badge.at-risk {
  background: #fee2e2;
  color: var(--critical);
}

.track-badge.no-deadline {
  background: var(--surface-hover);
  color: var(--text-muted);
}

.task-item.done-task {
  opacity: 0.55;
}

/* Risk items */
.risk-item {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  font-size: 0.85rem;
  border-left: 3px solid;
}

.risk-item.high {
  background: #fef2f2;
  border-left-color: var(--critical);
}

.risk-item.medium {
  background: #fffbeb;
  border-left-color: var(--medium);
}

.risk-item.low {
  background: #f0fdf4;
  border-left-color: var(--low);
}

.risk-item.blocked {
  background: #f9fafb;
  border-left-color: var(--text-muted);
  opacity: 0.75;
}

.risk-item .risk-label {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
}

/* Plan header */
.plan-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.plan-header h2 { margin: 0; }
.btn-sm {
  padding: 4px 12px;
  font-size: 0.75rem;
}

/* Summary */
.summary {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 0.9rem;
  line-height: 1.7;
  margin-bottom: 16px;
}

.plan-note {
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 10px 14px;
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text-muted);
  margin: 12px 0 16px;
}
.summary .md-heading {
  font-size: 0.95rem;
  margin: 8px 0 4px;
  color: var(--accent);
}
.summary strong {
  color: var(--text);
}

/* Section headers */
.section-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
  font-weight: 600;
}

/* Loading */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

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

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

/* Empty state */
.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 0.9rem;
}

/* Preview tasks */
.preview-list { margin-top: 16px; }

/* ===== Chat interface ===== */
.chat-card {
  padding: 0;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 200px);
  min-height: 400px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-bubble {
  max-width: 85%;
  animation: fadeIn 0.2s ease-out;
}

.chat-bubble.user {
  align-self: flex-end;
}

.chat-bubble.assistant {
  align-self: flex-start;
}

.chat-content {
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.6;
}

.chat-bubble.user .chat-content {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-bubble.assistant .chat-content {
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-bubble.assistant .chat-content code {
  background: var(--accent-light);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.85em;
}

.chat-bubble.assistant .chat-content strong {
  color: var(--accent);
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  border-radius: 0 0 var(--radius) var(--radius);
}

.chat-input-row textarea {
  min-height: 40px;
  max-height: 120px;
  resize: none;
  padding: 8px 12px;
  font-size: 0.9rem;
}

.chat-input-row button {
  flex-shrink: 0;
  align-self: flex-end;
  padding: 8px 20px;
}

.btn-clear-chat {
  background: var(--surface) !important;
  color: var(--muted) !important;
  border: 1px solid var(--border) !important;
  font-size: 0.8rem !important;
  padding: 8px 12px !important;
}
.btn-clear-chat:hover {
  color: var(--critical) !important;
  border-color: var(--critical) !important;
}

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

/* ===== Project summaries ===== */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}

.project-summary {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.project-summary.at-risk {
  border-color: var(--critical);
  border-left: 3px solid var(--critical);
}

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

.project-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.risk-badge {
  background: #fee2e2;
  color: var(--critical);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.05em;
}

.project-meta {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 4px;
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}

.progress-fill.at-risk {
  background: var(--critical);
}

/* ===== Late badge (inline on plan tasks) ===== */
.late-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: #fef2f2;
  color: var(--critical);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 6px;
  white-space: nowrap;
  vertical-align: middle;
}

.plan-task.has-warning {
  border-left: 3px solid var(--critical);
}

/* ===== At-risk task cards (replaces project summaries) ===== */
.at-risk-task {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  border-left: 3px solid;
}

.at-risk-task.high {
  background: #fef2f2;
  border-left-color: var(--critical);
}

.at-risk-task.medium {
  background: #fffbeb;
  border-left-color: var(--medium);
}

.at-risk-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.at-risk-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.at-risk-meta {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ===== Schedule preview ===== */
.schedule-preview {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.schedule-day {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.day-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 90px;
  flex-shrink: 0;
}

.day-slots {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.schedule-slot {
  background: var(--accent-light);
  color: var(--text);
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
}

.schedule-slot[title] {
  cursor: help;
}

.schedule-slot.partial {
  border: 1px dashed rgba(0, 78, 173, 0.25);
  background: transparent;
}

.slot-hours {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.slot-account {
  color: var(--accent);
  font-size: 0.75rem;
  opacity: 0.8;
}

.day-capacity {
  color: var(--text-muted);
  font-size: 0.75rem;
  flex-shrink: 0;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s;
  z-index: 100;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: var(--critical); }

/* ===== Billing badges ===== */
.badge-finalized {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--brand-green, #3bb273);
  color: #fff;
}
.badge-snapshot {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 500;
  background: var(--surface-2, #e8e8e8);
  color: var(--text-muted, #777);
}
.badge-live {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--brand-blue, #3a86ff);
  color: #fff;
}

/* ===== Billing ===== */
.billing-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filter-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 14px;
  font-size: 0.82rem;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s;
}
.filter-btn:hover { color: var(--text); border-color: var(--accent); }
.filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.date-input {
  padding: 4px 8px;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
}

.billing-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.summary-card {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.summary-card.green { border-color: #16a34a; }
.summary-card.purple { border-color: #7c3aed; }
.summary-card.teal { border-color: #0d9488; }

.summary-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}
.summary-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}
.summary-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.billing-client {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 12px;
}

.billing-client-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.billing-client-name {
  font-size: 1.05rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.currency-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.03em;
}

.billing-client-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.billing-client-total {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  background: #16a34a;
  padding: 4px 14px;
  border-radius: 6px;
  flex-shrink: 0;
}

.btn-toggle-details {
  display: block;
  width: 100%;
  background: var(--accent-light);
  border: 1px solid transparent;
  color: var(--accent);
  padding: 8px;
  margin-top: 12px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background 0.15s;
}
.btn-toggle-details:hover {
  background: rgba(0, 78, 173, 0.12);
}

.billing-details {
  margin-top: 12px;
}

.billing-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.billing-table th {
  text-align: center;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
}

.billing-table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.billing-table .center { text-align: center; }
.billing-table .amount { text-align: right; font-weight: 600; color: #16a34a; }

.billing-task-name {
  font-weight: 500;
}
.billing-task-due {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.billing-total-row td {
  border-bottom: none;
  border-top: 2px solid var(--border);
  padding-top: 12px;
}

.billing-filters select {
  padding: 5px 10px;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

@media (max-width: 640px) {
  .app { padding: 16px 12px; }

  /* ---- Center logo & user dropdown ---- */
  header {
    flex-direction: column;
    gap: 12px;
    align-items: center;
    text-align: center;
  }

  .tabs { overflow-x: auto; }
  .chat-card { height: calc(100vh - 240px); }
  .projects-grid { grid-template-columns: 1fr; }
  .schedule-day { flex-direction: column; align-items: flex-start; }

  /* ---- Cards: tighter padding ---- */
  .card { padding: 16px; }

  /* ---- Task cards: keep status badges on screen ---- */
  .task-item {
    gap: 8px;
  }
  .status-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    white-space: nowrap;
  }

  /* ---- Timeline dates: don't break mid-date ---- */
  .timeline-date {
    white-space: nowrap;
  }
  .timeline-dates {
    flex-wrap: wrap;
    gap: 4px;
  }
  .task-timeline {
    flex-wrap: wrap;
    gap: 6px;
  }

  /* ---- Billing: stack title & action buttons ---- */
  .plan-header {
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
  }
  .plan-header > div {
    justify-content: center;
  }

  /* ---- Billing: filters row ---- */
  .billing-filters {
    justify-content: center;
  }
  .billing-filters select {
    margin-left: 0 !important;
    width: 100%;
  }

  /* ---- Billing: summary cards ---- */
  .billing-summary {
    grid-template-columns: 1fr;
  }

  /* ---- Billing: client cards ---- */
  .billing-client {
    padding: 14px;
  }
  .billing-client-header {
    flex-direction: column;
    gap: 8px;
  }
  .billing-client-total {
    align-self: flex-start;
  }

  /* ---- Billing: detail table — horizontal scroll ---- */
  .billing-details {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-left: -14px;
    margin-right: -14px;
    padding: 0 14px;
  }
  .billing-table {
    min-width: 520px;
    font-size: 0.78rem;
  }
  .billing-table th,
  .billing-table td {
    padding: 8px 6px;
    white-space: nowrap;
  }
  .billing-table td:first-child {
    white-space: normal;
    min-width: 130px;
  }
}
