:root { --bg: #0f0f0f; --card: #1a1a1a; --border: #2a2a2a; --text: #e0e0e0; --dim: #888; --accent: #4f9cf7; --green: #4caf50; --yellow: #ffc107; --red: #f44336; --orange: #ff9800; --purple: #ab47bc; }
* { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; overflow: hidden; }
body { font-family: -apple-system, system-ui, sans-serif; background: var(--bg); color: var(--text); height: 100%; overflow: hidden; position: fixed; width: 100%; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }

#login { display: flex; align-items: center; justify-content: center; height: 100%; }
#login form { background: var(--card); padding: 32px; border-radius: 12px; width: 300px; }
#login input { width: 100%; padding: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 16px; margin-bottom: 12px; }
#login button { width: 100%; padding: 12px; background: var(--accent); border: none; border-radius: 8px; color: #fff; font-size: 16px; cursor: pointer; }

.nav { display: flex; gap: 8px; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--border); z-index: 10; overflow-x: auto; flex-shrink: 0; }
.nav button { padding: 10px 16px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 14px; cursor: pointer; white-space: nowrap; flex-shrink: 0; min-height: 44px; }
.nav button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.view { display: none; }
.view.active { display: block; overflow-y: auto; }

#app { height: 100%; display: flex; flex-direction: column; }
#app > .view { flex: 1; min-height: 0; }

.filters { display: flex; gap: 6px; padding: 10px 16px; overflow-x: auto; flex-wrap: nowrap; }
.filters button { padding: 10px 14px; background: var(--card); border: 1px solid var(--border); border-radius: 16px; color: var(--dim); font-size: 13px; cursor: pointer; white-space: nowrap; flex-shrink: 0; min-height: 44px; }
.filters button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.job-list { padding: 0 12px 12px; }
.job-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 6px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.job-card:active { background: #222; }
.job-card.has-unread { border-left: 3px solid var(--red); }
.job-card.is-blocked { border-left: 3px solid var(--orange); }
.job-card.is-stale { border-left: 3px solid var(--yellow); }
.job-card .info { flex: 1; min-width: 0; }
.job-card .info h3 { font-size: 14px; font-weight: 600; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-card .info .meta { font-size: 12px; color: var(--dim); }
.job-card .info .desc { font-size: 12px; color: var(--dim); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badges { display: flex; gap: 4px; flex-shrink: 0; flex-direction: column; align-items: flex-end; }
.badge { font-size: 10px; padding: 3px 8px; border-radius: 6px; font-weight: 600; white-space: nowrap; }
.badge.lead { background: #ffc10720; color: var(--yellow); }
.badge.active { background: #4caf5020; color: var(--green); }
.badge.completed { background: #4f9cf720; color: var(--accent); }
.badge.lost { background: #f4433620; color: var(--red); }
.unread-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); flex-shrink: 0; }
.running-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); flex-shrink: 0; animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes thinking { 0% { opacity: 0.3; } 50% { opacity: 1; } 100% { opacity: 0.3; } }
.msg.thinking { animation: thinking 1.5s infinite; color: var(--dim); font-style: italic; }
.pin { font-size: 10px; padding: 3px 8px; border-radius: 6px; font-weight: 600; white-space: nowrap; }
.pin.new { background: #66666630; color: #999; }
.pin.in-progress { background: #4f9cf720; color: var(--accent); }
.pin.blocked { background: #ff980020; color: var(--orange); }
.pin.review { background: #ab47bc20; color: var(--purple); }
.pin.done { background: #4caf5020; color: var(--green); }

#chat-view { display: none; flex-direction: column; height: 100%; }
#chat-view.active { display: flex; }
.chat-header { padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--border); }
.chat-header-top { display: flex; align-items: center; gap: 10px; }
.chat-header .back { background: none; border: none; color: var(--accent); font-size: 24px; cursor: pointer; padding: 0 4px; }
.chat-header .title { flex: 1; min-width: 0; }
.chat-header .title h2 { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header .title .sub { font-size: 11px; color: var(--dim); }
.chat-actions { display: flex; gap: 6px; padding-top: 8px; overflow-x: auto; }
.chat-actions button, .chat-actions select { padding: 8px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 12px; cursor: pointer; white-space: nowrap; font-family: inherit; min-height: 38px; }
.chat-actions select { appearance: none; padding-right: 6px; font-size: 16px; }

/* Taskboard */
.taskboard { border-top: 1px solid var(--border); background: var(--card); max-height: min(200px, 30vh); overflow-y: auto; }
.taskboard-header { display: flex; justify-content: space-between; align-items: center; padding: 8px 16px; cursor: pointer; }
.taskboard-header h3 { font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.5px; }
.taskboard-body { padding: 0 16px 8px; }

/* Task cards */
.task-card { padding: 12px 16px; border-bottom: 1px solid var(--border); border-left: 3px solid transparent; }
.task-card[data-pri="3"] { border-left-color: var(--red); }
.task-card[data-pri="2"] { border-left-color: var(--orange); }
.task-card[data-pri="1"] { border-left-color: #64b5f6; }
.task-card-top { display: flex; align-items: flex-start; gap: 10px; }
.task-card-top input[type=checkbox] { accent-color: var(--green); width: 24px; height: 24px; min-width: 24px; margin-top: 2px; padding: 10px; }
.task-card-top .task-text { flex: 1; font-size: 14px; line-height: 1.4; word-wrap: break-word; }
.task-card-top .task-text.done { text-decoration: line-through; color: var(--dim); }
.task-card-top .task-del { background: none; border: none; color: var(--red); cursor: pointer; font-size: 18px; min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; opacity: 0.6; }
.task-card-top .task-del:hover { opacity: 1; }
.task-card-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; padding-left: 34px; font-size: 12px; }
.task-job-name { color: var(--dim); font-size: 11px; }

/* Task input */
.task-input-row { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.task-input-field { padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 16px; font-family: inherit; }

/* Legacy task-item compat */
.task-item { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; }
.task-add select { padding: 6px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 14px; }
.task-add button { padding: 6px 14px; background: var(--accent); border: none; border-radius: 6px; color: #fff; cursor: pointer; font-size: 14px; white-space: nowrap; }
.task-add input[type=date] { width: 120px; flex: none; }
.task-add button { padding: 6px 10px; background: var(--accent); border: none; border-radius: 6px; color: #fff; font-size: 12px; cursor: pointer; }

/* Task item: priority as left border */
.task-item[data-pri="3"] { border-left: 3px solid var(--red); }
.task-item[data-pri="2"] { border-left: 3px solid var(--orange); }
.task-item[data-pri="1"] { border-left: 3px solid #64b5f6; }
.task-meta { display: contents; }

@media (max-width: 600px) {
  /* Global task input form: stack vertically */
  #tasks-view .task-input-row { flex-direction: column; align-items: stretch !important; }
  #tasks-view .task-input-row > * { width: 100%; max-width: 100% !important; min-height: 44px; font-size: 16px !important; }
  /* Task items: wrap for two-line layout */
  .task-item { flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--border); min-height: 48px; align-items: flex-start; }
  .task-item input[type=checkbox] { width: 24px; height: 24px; min-width: 24px; margin-top: 2px; }
  .task-item .task-text { white-space: normal; overflow: visible; text-overflow: unset; flex: 1; min-width: 0; }
  .task-item .task-del { min-width: 44px; min-height: 44px; font-size: 18px; opacity: 0.7; display: flex; align-items: center; justify-content: center; }
  .task-item .task-meta { width: 100%; padding-left: 32px; font-size: 12px; display: flex; gap: 8px; align-items: center; color: var(--dim); margin-top: 2px; }
  .task-item .task-pri { font-size: 11px; }
}

/* Files panel */
.file-browser { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: var(--bg); z-index: 200; display: flex; flex-direction: column; }
.fb-header { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--border); }
.fb-header button { background: none; border: none; color: var(--text); cursor: pointer; font-size: 18px; }
.fb-breadcrumb { font-size: 13px; color: var(--dim); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fb-breadcrumb span { cursor: pointer; color: var(--accent); }
.fb-body { flex: 1; display: flex; overflow: hidden; }
.fb-tree { width: 260px; min-width: 200px; border-right: 1px solid var(--border); overflow-y: auto; padding: 8px 0; background: var(--card); }
.fb-tree-item { display: flex; align-items: center; gap: 6px; padding: 6px 12px; cursor: pointer; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fb-tree-item:hover { background: var(--border); }
.fb-tree-item.active { background: var(--accent); color: #fff; }
.fb-tree-item.dir { font-weight: 600; }
.fb-viewer { flex: 1; overflow: auto; padding: 0; }
.fb-viewer-content { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px; line-height: 1.6; padding: 16px; white-space: pre-wrap; word-break: break-all; color: var(--text); min-height: 100%; }
.fb-viewer-empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--dim); font-size: 14px; }
.fb-viewer-actions { display: flex; gap: 8px; padding: 8px 16px; background: var(--card); border-top: 1px solid var(--border); font-size: 12px; align-items: center; }
.fb-viewer-actions .fb-meta { color: var(--dim); flex: 1; }
.fb-line-num { display: inline-block; width: 40px; text-align: right; padding-right: 12px; color: var(--dim); user-select: none; }
@media (max-width: 600px) { .fb-tree { width: 100%; } .fb-body { flex-direction: column; } .fb-viewer { border-top: 1px solid var(--border); } }

.chat-messages { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; position: relative; }
.drop-zone { position: absolute; inset: 0; background: rgba(79,156,247,0.15); border: 2px dashed var(--accent); display: flex; align-items: center; justify-content: center; font-size: 18px; color: var(--accent); z-index: 100; pointer-events: none; display: none; }
.drop-zone.visible { display: flex; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 12px; font-size: 14px; line-height: 1.45; word-wrap: break-word; overflow-wrap: break-word; }
.msg.user { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.user.client-fwd { background: #2d5a2d; border: 1px solid #3a7a3a; }
.msg.assistant { background: var(--card); border: 1px solid var(--border); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.system { background: #2a2a2a; color: var(--dim); align-self: center; font-size: 12px; text-align: center; }
.msg.assistant p { margin-bottom: 6px; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant code { background: #0a0a0a; padding: 1px 5px; border-radius: 3px; font-size: 12px; font-family: monospace; }
.msg.assistant pre { background: #0a0a0a; padding: 10px; border-radius: 6px; overflow-x: auto; margin: 6px 0; }
.msg.assistant pre code { background: transparent; padding: 0; }
.msg.assistant a { color: var(--accent); }
.reply-block { background: #1b3a1b; border: 1px solid #2d5a2d; border-radius: 8px; padding: 10px 12px; margin-top: 8px; font-size: 13px; line-height: 1.45; position: relative; white-space: pre-wrap; }
.reply-block, .action-block { animation: fadeIn 0.2s ease-in; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.reply-block::before { content: '📋 Reply for client'; display: block; font-size: 10px; font-weight: 600; color: var(--green); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; user-select: none; -webkit-user-select: none; }
.reply-block .copy-btn { position: absolute; top: 8px; right: 8px; background: var(--green); border: none; border-radius: 4px; color: #fff; font-size: 10px; padding: 3px 8px; cursor: pointer; }
.action-block { background: #2a1f3a; border: 1px solid #4a3560; border-radius: 8px; padding: 10px 12px; margin-top: 8px; font-size: 13px; line-height: 1.45; position: relative; white-space: pre-wrap; }
.action-block::before { content: '⚡ Action needed'; display: block; font-size: 10px; font-weight: 600; color: var(--purple); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.action-block .task-btn { position: absolute; top: 8px; right: 8px; background: var(--purple); border: none; border-radius: 4px; color: #fff; font-size: 12px; padding: 6px 12px; cursor: pointer; }
.chat-input { padding: 12px 16px; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); background: var(--card); border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.chat-input textarea { flex: 1; padding: 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 16px; resize: none; min-height: 44px; max-height: 120px; font-family: inherit; line-height: 1.4; min-width: 100px; }
.chat-input button { padding: 10px 16px; border: none; border-radius: 8px; color: #fff; font-size: 15px; cursor: pointer; white-space: nowrap; height: 44px; }
.chat-input button:disabled { opacity: 0.5; cursor: not-allowed; }
#attachments { display: flex; flex-wrap: wrap; gap: 4px; width: 100%; }
#attachments:empty { display: none; }
.attach-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--border); border-radius: 4px; padding: 2px 8px; font-size: 12px; color: var(--text); }
.attach-chip button { background: none; border: none; color: var(--red); cursor: pointer; font-size: 14px; padding: 0 2px; height: auto; }
#chat-send { background: var(--accent); }
#chat-pause { background: var(--orange); display: none; }
#chat-stop { background: var(--red); display: none; }

.form-view { padding: 16px; }
.form-view h2 { font-size: 18px; margin-bottom: 16px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--dim); margin-bottom: 4px; }
.field input, .field textarea { width: 100%; padding: 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 15px; font-family: inherit; }
.field textarea { min-height: 80px; resize: vertical; }
.form-view button.submit { width: 100%; padding: 12px; background: var(--accent); border: none; border-radius: 8px; color: #fff; font-size: 16px; cursor: pointer; margin-top: 8px; }

.loading { color: var(--dim); font-style: italic; padding: 20px; text-align: center; }
.empty { color: var(--dim); text-align: center; padding: 40px 20px; font-size: 14px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--card); border: 1px solid var(--border); color: var(--text); padding: 10px 18px; border-radius: 8px; font-size: 14px; z-index: 1000; opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none; max-width: 90%; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.success { border-color: var(--green); color: var(--green); }
#toast.error { border-color: var(--red); color: var(--red); }
#toast.info { border-color: var(--accent); color: var(--accent); }
body.light { --bg: #f5f5f5; --card: #ffffff; --border: #e0e0e0; --text: #1a1a1a; --dim: #666; }
body.light .msg.assistant pre, body.light .msg.assistant code { background: #e8e8e8; }
body.light .job-card:active { background: #eee; }
body.light .reply-block { background: #d4edda; border-color: #a3d9a5; color: #1a1a1a; }
body.light .action-block { background: #e8d5f5; border-color: #c9a5e0; color: #1a1a1a; }
body.light .msg.user { background: #3b82f6; }
body.light .msg.user.client-fwd { background: #d4edda; color: #1a1a1a; border-color: #a3d9a5; }
body.light .msg.system { background: #e8e8e8; color: #1a1a1a; }
.quick-replies { display: flex; gap: 6px; overflow-x: auto; padding: 4px 16px; }
.quick-replies span { background: var(--border); border-radius: 16px; padding: 6px 12px; font-size: 12px; color: var(--dim); cursor: pointer; white-space: nowrap; flex-shrink: 0; }

/* Mobile touch fixes */
input, textarea, select { font-size: 16px; }
.quick-replies span { padding: 10px 16px; font-size: 14px; min-height: 44px; display: inline-flex; align-items: center; }
.quick-replies { -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.quick-replies::-webkit-scrollbar { display: none; }
.task-item { padding: 10px 0; }
.task-item input[type=checkbox] { width: 24px; height: 24px; min-width: 24px; }
.task-item .task-del { font-size: 18px; padding: 8px; min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; opacity: 0.7; }
#toast { bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
.nav { scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
@media (max-width: 600px) {
  .fb-tree { max-height: 40vh; }
  .fb-viewer { min-height: 40vh; }
}

/* Manager filter tabs */
.mgr-filters { display: flex; gap: 6px; padding: 0 16px 10px; overflow-x: auto; scrollbar-width: none; }
.mgr-filters::-webkit-scrollbar { display: none; }
.mgr-filters button { padding: 8px 14px; background: var(--card); border: 1px solid var(--border); border-radius: 16px; color: var(--dim); font-size: 13px; cursor: pointer; white-space: nowrap; flex-shrink: 0; min-height: 40px; }
.mgr-filters button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.mgr-filters .count { font-size: 11px; opacity: 0.7; margin-left: 4px; }

/* Manager date section headers */
.mgr-section { padding: 10px 14px 4px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--dim); }
.mgr-section.overdue { color: var(--red); }
.mgr-section.today { color: var(--accent); }

/* Manager task card variants */
.mgr-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; margin: 0 12px 8px; overflow: hidden; }
.mgr-card.overdue { border-color: var(--red); box-shadow: inset 3px 0 0 var(--red); }
.mgr-card.today { border-color: var(--accent); }
.mgr-card.dead { opacity: 0.45; }
.task-pri { font-size: 11px; white-space: nowrap; border-radius: 4px; padding: 2px 6px; }
.task-pri.p3 { background: #f4433630; color: var(--red); }
.task-pri.p2 { background: #ff980030; color: var(--orange); }
.task-pri.p1 { background: #2196f330; color: #64b5f6; }
.task-due { font-size: 11px; color: var(--orange); white-space: nowrap; }
.task-due.overdue { color: var(--red); font-weight: bold; }
.file-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--border); border-radius: 6px; padding: 3px 10px; font-size: 12px; cursor: pointer; margin: 2px 4px 2px 0; white-space: nowrap; }
.file-chip:hover { background: var(--accent); color: #fff; }
.task-add { display: flex; gap: 6px; padding: 6px 0; flex-wrap: wrap; }
.task-add input { flex: 1; min-width: 100px; padding: 6px 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 16px; font-family: inherit; }

/* Work toggle (show work) */
.work-toggle { margin-bottom: 8px; border-radius: 6px; background: #151515; border: 1px solid var(--border); font-size: 12px; }
.work-toggle summary { padding: 4px 10px; cursor: pointer; color: var(--dim); list-style: none; font-style: italic; }
.work-toggle summary::-webkit-details-marker { display: none; }
.work-toggle summary::before { content: '▶ '; font-size: 9px; }
.work-toggle[open] summary::before { content: '▼ '; }
.work-content { padding: 6px 10px; border-top: 1px solid var(--border); max-height: 400px; overflow-y: auto; color: var(--dim); font-size: 12px; white-space: pre-wrap; word-break: break-word; }
