:root {
  --bg: #f6f8fa;
  --bg2: #ffffff;
  --bg3: #eaeef2;
  --border: #d0d7de;
  --fg: #24292f;
  --fg2: #57606a;
  --fg3: #6e7781;
  --blue: #0969da;
  --green: #1a7f37;
  --red: #cf222e;
  --yellow: #9a6700;
  --purple: #8250df;
  --font: 'SF Mono', 'Consolas', 'Monaco', 'Fira Code', monospace;
  --radius: 6px;
}

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

body {
  font-family: var(--font);
  font-size: 13px;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

input,
select,
textarea,
button {
  font-family: var(--font);
  font-size: 13px;
}

/* Layout */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header h1 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--blue);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.clock {
  color: var(--fg2);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
}

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--fg2);
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
}

.btn-logout:hover {
  border-color: var(--fg2);
  color: var(--fg);
}

nav.subnav {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  padding: 0 1rem;
}

nav.subnav a {
  padding: 0.5rem 1rem;
  color: var(--fg2);
  border-bottom: 2px solid transparent;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

nav.subnav a:hover {
  color: var(--fg);
  text-decoration: none;
}

nav.subnav a.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

/* Sections */
section {
  margin-bottom: 1.5rem;
}

section h2 {
  font-size: 0.8rem;
  color: var(--fg2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Quick Actions */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.quick-actions .stats {
  margin-left: auto;
  display: flex;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--fg3);
}

.quick-actions .stat-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--fg);
  cursor: pointer;
  font-size: 0.8rem;
  white-space: nowrap;
  min-height: 36px;
}

.btn:hover {
  background: var(--border);
}

.btn-primary {
  background: #1f6feb;
  border-color: #1f6feb;
  color: #fff;
}

.btn-primary:hover {
  background: #388bfd;
}

.btn-danger {
  background: #da3633;
  border-color: #da3633;
  color: #fff;
}

.btn-danger:hover {
  background: #f85149;
}

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  min-height: 28px;
}

.btn-icon {
  padding: 0.35rem;
  min-height: unset;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge.queued {
  background: #eaeef2;
  color: var(--fg2);
}

.badge.assigned {
  background: #ddf4ff;
  color: var(--blue);
}

.badge.in-progress {
  background: #fff8c5;
  color: var(--yellow);
}

.badge.done {
  background: #dafbe1;
  color: var(--green);
}

.badge.failed {
  background: #ffebe9;
  color: var(--red);
}

.badge.blocked {
  background: #fff3cd;
  color: #856404;
  animation: pulse-blocked 2s ease-in-out infinite;
}

@keyframes pulse-blocked {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.6;
  }
}

.badge.online {
  background: #dafbe1;
  color: var(--green);
}

.badge.offline {
  background: #ffebe9;
  color: var(--red);
}

/* Availability Toggle */
.availability-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-right: 1rem;
  font-size: 0.85rem;
  color: var(--fg2);
}

.availability-toggle .indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  transition: background 0.3s;
}

.availability-toggle .indicator.available {
  background: var(--green);
}

.availability-toggle .indicator.away {
  background: #f0ad4e;
}

/* Blocked task response form */
.blocked-response {
  background: #fff3cd22;
  border: 1px solid #f0ad4e44;
  border-radius: 8px;
  padding: 1rem;
  margin-top: 0.75rem;
}

.blocked-response h4 {
  margin: 0 0 0.5rem 0;
  color: #f0ad4e;
  font-size: 0.9rem;
}

.blocked-response .question-text {
  background: var(--bg2);
  padding: 0.75rem;
  border-radius: 6px;
  margin-bottom: 0.75rem;
  font-style: italic;
  color: var(--fg);
}

.blocked-response textarea {
  width: 100%;
  min-height: 80px;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
  margin-bottom: 0.5rem;
}

.blocked-response .btn-respond {
  background: #f0ad4e;
  color: #000;
  border: none;
  padding: 0.5rem 1.25rem;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

.blocked-response .btn-respond:hover {
  background: #ec971f;
}

/* Workers Grid */
.workers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.75rem;
}

.worker-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  cursor: pointer;
  transition: border-color 0.15s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.worker-card:hover {
  border-color: var(--blue);
}

.worker-card .name {
  font-weight: 600;
  color: var(--blue);
  font-size: 0.9rem;
}

.worker-card .wstatus {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.25rem;
  font-size: 0.8rem;
}

.worker-card .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.worker-card .dot.online {
  background: var(--green);
}

.worker-card .dot.offline {
  background: var(--red);
}

.worker-card .current-task {
  margin-top: 0.35rem;
  color: var(--fg2);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.worker-card .meta {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--fg3);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

th,
td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--fg2);
  font-weight: 500;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  position: sticky;
  top: 0;
  background: var(--bg);
}

tr {
  cursor: pointer;
  transition: background 0.1s;
}

tr:hover {
  background: var(--bg2);
}

td.title-cell {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

td.mono {
  font-size: 0.75rem;
  color: var(--fg3);
}

/* Filter Bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  align-items: center;
}

.filter-bar select,
.filter-bar input {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  min-height: 32px;
}

/* Form */
.form-section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}

.form-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
}

.form-toggle h2 {
  margin: 0;
}

.form-toggle .arrow {
  color: var(--fg2);
  transition: transform 0.2s;
}

.form-toggle .arrow.open {
  transform: rotate(180deg);
}

.form-body {
  padding: 0 1rem 1rem;
  display: none;
}

.form-body.open {
  display: block;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-group.full {
  grid-column: 1 / -1;
}

.form-group label {
  font-size: 0.75rem;
  color: var(--fg2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group input,
.form-group select,
.form-group textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  min-height: 36px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.15);
}

.form-group textarea {
  min-height: 100px;
  resize: vertical;
}

.form-group .hint {
  font-size: 0.7rem;
  color: var(--fg3);
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--fg3);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.path-cell {
  font-size: 0.75rem;
  word-break: break-all;
  max-width: 320px;
  display: inline-block;
}

.output-pre {
  margin: 0;
  padding: 1rem;
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 70vh;
  overflow: auto;
  background: var(--bg);
  border-radius: var(--radius);
}

/* Chain Step Builder */
.chain-steps {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-top: 0.5rem;
}

.chain-step {
  display: grid;
  grid-template-columns: 2rem 1fr 1fr auto;
  gap: 0.5rem;
  align-items: start;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.chain-step:last-child {
  border-bottom: none;
}

.chain-step .step-num {
  color: var(--fg3);
  font-size: 0.8rem;
  padding-top: 0.4rem;
  text-align: center;
}

.chain-step input,
.chain-step select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
}

/* Toggle */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.toggle {
  position: relative;
  width: 40px;
  height: 22px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle .slider {
  position: absolute;
  inset: 0;
  background: var(--bg3);
  border-radius: 11px;
  cursor: pointer;
  transition: 0.2s;
}

.toggle .slider::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 16px;
  height: 16px;
  background: var(--fg2);
  border-radius: 50%;
  transition: 0.2s;
}

.toggle input:checked+.slider {
  background: #1f6feb;
}

.toggle input:checked+.slider::before {
  transform: translateX(18px);
  background: #fff;
}

/* Slide-in Panel */
.panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.panel-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 520px;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  z-index: 201;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.panel.open {
  transform: translateX(0);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-header h3 {
  font-size: 0.95rem;
  color: var(--fg);
  margin-right: 1rem;
  word-break: break-word;
}

.panel-close {
  background: none;
  border: none;
  color: var(--fg2);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}

.panel-close:hover {
  color: var(--fg);
}

.panel-body {
  padding: 1rem;
  flex: 1;
  overflow-y: auto;
}

.panel-body .field {
  margin-bottom: 0.75rem;
}

.panel-body .field-label {
  font-size: 0.7rem;
  color: var(--fg3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.2rem;
}

.panel-body .field-value {
  color: var(--fg);
  word-break: break-word;
}

.panel-body .field-value.mono {
  font-size: 0.8rem;
  background: var(--bg);
  padding: 0.5rem;
  border-radius: var(--radius);
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
}

.panel-body .field-value.error {
  color: var(--red);
}

.panel-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Modal (Log Viewer) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 900px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

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

.modal-header h3 {
  font-size: 0.85rem;
}

.modal-body {
  flex: 1;
  overflow: auto;
  padding: 0;
}

.modal-body pre {
  margin: 0;
  padding: 1rem;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-all;
}

/* Chain Status */
.chain-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
}

.chain-item:hover {
  border-color: var(--fg3);
}

.chain-title {
  font-size: 0.85rem;
  color: var(--fg);
  margin-bottom: 0.35rem;
  display: flex;
  justify-content: space-between;
}

.progress-bar {
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar .fill {
  display: block;
  height: 100%;
  background: var(--green);
  transition: width 0.3s;
}

.chain-meta {
  font-size: 0.75rem;
  color: var(--fg3);
  margin-top: 0.25rem;
}

.chain-steps-detail {
  margin-top: 0.5rem;
  display: none;
}

.chain-steps-detail.open {
  display: block;
}

.chain-step-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
  font-size: 0.8rem;
}

.chain-step-row .step-idx {
  color: var(--fg3);
  width: 1.5rem;
  text-align: right;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  color: var(--fg);
  font-size: 0.85rem;
  z-index: 500;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success {
  border-color: var(--green);
}

.toast.error {
  border-color: var(--red);
}

/* Login Page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 360px;
}

.login-card h1 {
  text-align: center;
  color: var(--blue);
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.login-card .subtitle {
  text-align: center;
  color: var(--fg3);
  font-size: 0.8rem;
  margin-bottom: 1.5rem;
}

.login-card input {
  width: 100%;
  margin-bottom: 1rem;
}

.login-card .btn {
  width: 100%;
  justify-content: center;
}

.login-card .error-msg {
  color: var(--red);
  font-size: 0.8rem;
  text-align: center;
  margin-top: 0.5rem;
  min-height: 1.2em;
}

/* Settings / Projects pages */
.page-section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.page-section h3 {
  font-size: 0.85rem;
  color: var(--fg);
  margin-bottom: 0.75rem;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

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

.settings-row label {
  color: var(--fg2);
  font-size: 0.85rem;
}

/* Loading */
#loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--fg3);
}

/* Plans */
.plan-phase {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  overflow: hidden;
}

.plan-phase.active {
  border-color: var(--blue);
}

.phase-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.75rem;
  background: var(--bg3);
  cursor: pointer;
  font-size: 0.85rem;
}

.phase-header:hover {
  background: var(--border);
}

.phase-body {
  display: none;
  padding: 0.5rem 0.75rem;
}

.phase-body.open {
  display: block;
}

.markdown-view {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-size: 0.75rem;
  line-height: 1.5;
  max-height: 400px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Hamburger menu */
.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--fg);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}

@media (max-width: 768px) {
  .hamburger { display: block; }
  .subnav {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.5rem;
    z-index: 100;
    min-width: 160px;
  }
  .subnav.open { display: flex; }
  .subnav a { padding: 0.5rem 1rem; }
  .header-right { position: relative; }
}

/* Mobile Core Improvements */
@media (max-width: 768px) {
  .container {
    padding: 0.5rem;
  }

  .header {
    display: flex;
    flex-wrap: wrap;
    padding: 0.5rem 0.75rem;
    gap: 0.5rem 0;
  }

  .header h1 {
    flex: 1 1 auto;
    font-size: 1.1rem;
  }

  .header-right {
    display: contents;
  }

  .clock {
    display: none;
  }

  .btn-logout {
    margin-left: auto;
    order: 2;
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
  }

  .subnav {
    flex: 1 1 100%;
    order: 3;
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .subnav::-webkit-scrollbar {
    display: none;
  }

  .subnav a {
    padding: 0.4rem 0.6rem;
    font-size: 0.9rem;
  }

  .workers-grid {
    grid-template-columns: 1fr;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .quick-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .quick-actions .stats {
    margin-left: 0;
    flex-wrap: wrap;
  }

  .panel {
    width: 100%;
  }

  .chain-step {
    grid-template-columns: 1.5rem 1fr;
  }

  .chain-step select,
  .chain-step .btn-icon {
    grid-column: 2;
  }

  .filter-bar {
    flex-direction: column;
  }

  .filter-bar select,
  .filter-bar input {
    width: 100%;
  }
}

@media (max-width: 480px) {
  body {
    font-size: 13px;
  }

  th,
  td {
    padding: 0.4rem 0.5rem;
    font-size: 0.8rem;
  }

  .btn {
    min-height: 44px;
  }

  .form-group input,
  .form-group select,
  .form-group textarea {
    min-height: 44px;
  }

  .login-card {
    padding: 1.5rem;
  }
}

/* Chat Page */
body.chat-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.chat-wrapper {
  flex: 1;
  display: flex;
  overflow: hidden;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.chat-sidebar {
  width: 260px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  flex-shrink: 0;
}

.chat-sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.btn-new-chat {
  width: 100%;
  justify-content: center;
}

.chat-session-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.chat-session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--fg2);
  font-size: 0.85rem;
  transition: all 0.15s;
}

.chat-session-item:hover {
  background: var(--bg3);
  color: var(--fg);
}

.chat-session-item.active {
  background: var(--border);
  color: var(--fg);
  font-weight: 500;
}

.chat-session-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-session-delete {
  background: none;
  border: none;
  color: var(--fg3);
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}

.chat-session-item:hover .chat-session-delete {
  opacity: 1;
}

.chat-session-delete:hover {
  color: var(--red);
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  -webkit-overflow-scrolling: touch;
}

.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--fg3);
  text-align: center;
  gap: 0.5rem;
  padding: 2rem;
}

.chat-empty-icon {
  font-size: 2.5rem;
  opacity: 0.5;
}

.chat-empty-text {
  font-size: 1rem;
  font-weight: 500;
  color: var(--fg2);
}

.chat-empty-hint {
  font-size: 0.85rem;
  color: var(--fg3);
  max-width: 360px;
  line-height: 1.4;
}

.chat-bubble {
  max-width: 85%;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius);
  word-break: break-word;
  line-height: 1.5;
}

.chat-bubble.user {
  align-self: flex-end;
  background: #1f6feb;
  color: #fff;
  border-bottom-right-radius: 2px;
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}

.chat-bubble.user .chat-bubble-content {
  color: #fff;
}

.chat-bubble.animate-in {
  animation: chatFadeIn 0.2s ease-out;
}

@keyframes chatFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-bubble-content {
  font-size: 0.9rem;
  white-space: pre-wrap;
  font-family: var(--font);
}

.chat-bubble-time {
  font-size: 0.7rem;
  opacity: 0.6;
  margin-top: 0.4rem;
}

.chat-bubble.user .chat-bubble-time {
  text-align: right;
}

.chat-task-cards {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.chat-task-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.chat-task-card:hover {
  border-color: var(--blue);
}

.chat-task-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--fg);
  margin-bottom: 0.35rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-task-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-task-worker {
  font-size: 0.75rem;
  color: var(--fg3);
}

.chat-typing .chat-bubble-content {
  display: flex;
  align-items: center;
  min-height: 1.2em;
}

.dot-pulse {
  display: inline-flex;
  gap: 4px;
}

.dot-pulse::before,
.dot-pulse::after,
.dot-pulse {
  content: '';
}

.dot-pulse,
.dot-pulse::before,
.dot-pulse::after {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fg3);
  animation: dotPulse 1.2s infinite ease-in-out;
}

.dot-pulse::before {
  content: '';
  animation-delay: -0.32s;
  position: relative;
  left: -10px;
}

.dot-pulse::after {
  content: '';
  animation-delay: 0.32s;
  position: relative;
  left: 4px;
}

@keyframes dotPulse {

  0%,
  80%,
  100% {
    opacity: 0.3;
  }

  40% {
    opacity: 1;
  }
}

.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg2);
}

.chat-input-bar textarea {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.9rem;
  resize: none;
  overflow-y: auto;
  max-height: 120px;
  line-height: 1.5;
  min-height: 44px;
}

.chat-input-bar textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.15);
}

.chat-send {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  flex-shrink: 0;
}

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

@media (max-width: 768px) {
  .chat-wrapper {
    flex-direction: column;
  }

  .chat-sidebar {
    width: 100%;
    height: 120px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .chat-container {
    max-width: 100%;
  }

  .chat-bubble {
    max-width: 90%;
  }

  .chat-input-bar {
    padding: 0.6rem 0.5rem;
    padding-bottom: calc(0.6rem + env(safe-area-inset-bottom));
  }

  .chat-input-bar textarea {
    font-size: 16px;
    /* prevents iOS zoom */
  }
}

/* Utilities & Modals */
.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

.modal-content {
  background: var(--bg2);
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--fg);
  margin: 0;
  font-family: var(--font);
}

#view-modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
  background: var(--bg2);
}