:root {
  --bg: #f0efe9;
  --panel: #ffffff;
  --ink: #163126;
  --muted: #65756d;
  --brand: #1f7a56;
  --brand-2: #2f5f49;
  --danger: #b13d2d;
  --ring: #b8d5c7;
  --line: #dce4df;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: "SF Pro Text", "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 10% 10%, #d9e6d6 0%, transparent 40%),
    radial-gradient(circle at 90% 90%, #f7d8bc 0%, transparent 35%), var(--bg);
  min-height: 100%;
  width: 100%;
  overflow-x: hidden;
}

.bg-shape {
  position: fixed;
  border-radius: 50%;
  filter: blur(60px);
  z-index: 0;
  pointer-events: none;
}

.bg-shape-1 {
  width: 360px;
  height: 360px;
  left: -120px;
  top: -100px;
  background: #b3dbc6;
}

.bg-shape-2 {
  width: 420px;
  height: 420px;
  right: -180px;
  bottom: -180px;
  background: #f5c8a3;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1480px;
  margin: 20px auto;
  padding: max(0px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
}

.panel {
  background: color-mix(in srgb, var(--panel) 92%, #f8f7f2 8%);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 8px 24px rgba(26, 50, 39, 0.08);
}

.auth-panel {
  max-width: 420px;
  margin: 72px auto;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 8px;
}

.muted {
  color: var(--muted);
  margin: 0;
}

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  border: 1px solid #ccd7d0;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--ring);
  border-color: var(--brand);
}

button {
  border: 0;
  border-radius: 10px;
  padding: 9px 12px;
  background: linear-gradient(135deg, #2e4a5e, #1d3248);
  color: #fff;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.danger {
  background: linear-gradient(135deg, #c24a36, var(--danger));
}

.btn-secondary {
  background: #eff5f1;
  color: #214736;
  border: 1px solid #c9d8ce;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 12px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.topbar-actions button {
  min-height: 40px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

@media (min-width: 1200px) {
  .kpi-grid {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }
}

.kpi-card {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
}

.kpi-title {
  font-size: 12px;
  color: var(--muted);
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.tab-btn {
  background: #eff5f1;
  color: #214736;
  border: 1px solid #c9d8ce;
}

.tab-btn.active {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
}

.tab-panel {
  margin-bottom: 10px;
}

.chats-layout {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 12px;
}

.chat-directory {
  min-height: 72vh;
  border-top: 3px solid #7eab96;
}

.chat-workspace {
  min-height: 72vh;
}

.list-header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.list-scroll {
  max-height: 74vh;
  overflow: auto;
  display: grid;
  gap: 8px;
}

.chat-row {
  border: 1px solid #d7e0da;
  border-left: 4px solid transparent;
  border-radius: 12px;
  background: #fff;
  padding: 10px;
  cursor: pointer;
}

.chat-row.new-client {
  border-left: 4px solid #2a7c4f;
  background: linear-gradient(90deg, #f3fbf6 0%, #ffffff 44%);
}

.chat-row.active {
  border-color: var(--brand);
  box-shadow: inset 0 0 0 1px var(--brand);
}

.chat-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.chat-row-top > div:first-child {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-row-top-right {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.chat-row-archive-btn {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: transparent;
  color: transparent;
  border: 1px solid transparent;
  padding: 0;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

/* Show red when hovering the entire row or when the row is active */
.chat-row:hover .chat-row-archive-btn,
.chat-row.active .chat-row-archive-btn {
  opacity: 1;
  background: #fce8e6;
  color: #c02a1a;
  border-color: #e5b0aa;
}

/* Deeper red on direct button hover */
.chat-row-archive-btn:hover {
  transform: none;
  background: #f8d0cc;
  color: #a51e10;
  border-color: #d6908a;
  opacity: 1 !important;
}

/* Mobile: always visible, always red, larger tap target */
@media (hover: none) {
  .chat-row-archive-btn {
    opacity: 1;
    width: 32px;
    height: 32px;
    font-size: 14px;
    background: #fce8e6;
    color: #c02a1a;
    border-color: #e5b0aa;
  }
}

.chat-row-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.chat-priority-select {
  min-width: 148px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid #c9d8ce;
  background: #f7fbf9;
  color: #214736;
  font-size: 12px;
}

.priority-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 11px;
  font-weight: 700;
  margin-right: 6px;
}

.priority-tone-5 {
  background: #8a1028;
  border-color: #6e0d20;
  color: #fff;
}

.priority-tone-4 {
  background: #a51f39;
  border-color: #861b2f;
  color: #fff;
}

.priority-tone-3 {
  background: #c4512e;
  border-color: #a34426;
  color: #fff;
}

.priority-tone-2 {
  background: #d18c24;
  border-color: #ae751d;
  color: #fff;
}

.priority-tone-1 {
  background: #8fa838;
  border-color: #788c2f;
  color: #1f3311;
}

.priority-tone-0 {
  background: #3c9a64;
  border-color: #2f7f52;
  color: #fff;
}

.chat-row.priority-row-5 {
  border-left-color: #8a1028;
}

.chat-row.priority-row-4 {
  border-left-color: #a51f39;
}

.chat-row.priority-row-3 {
  border-left-color: #c4512e;
}

.chat-row.priority-row-2 {
  border-left-color: #d18c24;
}

.chat-row.priority-row-1 {
  border-left-color: #8fa838;
}

.chat-row.priority-row-0 {
  border-left-color: #3c9a64;
}

.chat-priority-select.priority-tone-5 {
  background: #fff3f5;
  border-color: #d8a4b0;
  color: #6e0d20;
}

.chat-priority-select.priority-tone-4 {
  background: #fff4f6;
  border-color: #dfb0ba;
  color: #861b2f;
}

.chat-priority-select.priority-tone-3 {
  background: #fff7f1;
  border-color: #e3c1ac;
  color: #8f3d24;
}

.chat-priority-select.priority-tone-2 {
  background: #fffaef;
  border-color: #e7d2a4;
  color: #8a5c18;
}

.chat-priority-select.priority-tone-1 {
  background: #f6faee;
  border-color: #d2dfb1;
  color: #556a1f;
}

.chat-priority-select.priority-tone-0 {
  background: #eef8f2;
  border-color: #b5d8c4;
  color: #2f7f52;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
}

.badge-neutral {
  background: #edf1ee;
  color: #425249;
}

.badge-success {
  background: #dcf4e8;
  color: #15603d;
}

.badge-warn {
  background: #fff3cd;
  color: #7f5d00;
}

.badge-planned {
  background: #ffe4bf;
  color: #9a4b00;
}

.badge-danger {
  background: #f8d7da;
  color: #8e1f2d;
}

.verified-client-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  background: #d9ebff;
  color: #0d4ea6;
  border: 1px solid #b8d4fb;
  font-size: 11px;
  font-weight: 700;
  vertical-align: middle;
}

.new-lead-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  background: #e8f7ef;
  color: #0f6a3f;
  border: 1px solid #bfe3cf;
  font-size: 11px;
  font-weight: 700;
  vertical-align: middle;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.workspace-section {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
  box-shadow: 0 2px 12px rgba(20, 40, 30, 0.06);
}

/* Client card column — warm tint */
.workspace-section-main {
  max-height: 76vh;
  overflow: auto;
  background: #fdfbf8;
  border-color: #dddbd5;
  border-top: 3px solid #c9a05c;
}

/* Chat column — cool tint */
.workspace-section-chat {
  min-height: 76vh;
  background: #f5f8fc;
  border-color: #c8d5e3;
  border-top: 3px solid #4e8dc0;
  display: flex;
  flex-direction: column;
}

/* Chat messages fill available space */
.workspace-section-chat .chat-messages {
  flex-grow: 1;
  max-height: none;
}

/* Send form area at bottom of chat — visually separate */
.workspace-section-chat .send-form {
  border-top: 1px solid #c8d5e3;
  background: #edf3fa;
  border-radius: 0 0 10px 10px;
  margin: 8px -10px -10px;
  padding: 10px;
  flex-shrink: 0;
}

/* Section labels for workspace columns */
.section-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 3px 9px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.section-tag-warm {
  background: #f5e9d6;
  color: #8b6733;
  border: 1px solid #e2cfa3;
}

.section-tag-cool {
  background: #deeaf5;
  color: #3a6080;
  border: 1px solid #b8d0e8;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.summary-item {
  border: 1px dashed #d9e2db;
  border-radius: 10px;
  padding: 8px;
  background: #fdfefd;
}

.workflow-track {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
  overflow: visible;
  padding-bottom: 2px;
}

.workflow-step {
  border: 1px solid #d7e0da;
  border-radius: 10px;
  padding: 6px 7px;
  background: #fff;
  color: var(--ink);
  display: grid;
  gap: 3px;
  text-align: left;
  min-width: 0;
  width: 100%;
}

.workflow-step[data-stage-select] {
  cursor: pointer;
}

.workflow-step[data-stage-select]:hover {
  border-color: #9cb9aa;
}

.workflow-step .dot {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid #cad8cf;
}

.workflow-step .label {
  font-size: 11px;
  line-height: 1.2;
}

.workflow-step.done {
  border-color: #98ccb3;
  background: #ecf8f1;
}

.workflow-step.done .dot {
  background: #2b8b60;
  color: #fff;
  border-color: #2b8b60;
}

.workflow-step.current {
  border-color: #de9f5a;
  background: #fff3e4;
}

.workflow-step.current .dot {
  background: #d17100;
  color: #fff;
  border-color: #d17100;
}

.workflow-step.todo .dot {
  background: #f5f7f6;
  color: #63756a;
}

.workflow-caption {
  margin-top: 8px;
}

.workflow-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

.workflow-editor {
  border: 1px dashed #d7e0da;
  border-radius: 10px;
  padding: 8px;
  background: #fcfefd;
  margin-bottom: 10px;
  display: grid;
  gap: 8px;
}

.workflow-editor-list {
  display: grid;
  gap: 6px;
}

.workflow-editor-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: center;
  border: 1px solid #e0e7e2;
  border-radius: 10px;
  padding: 7px;
  background: #fff;
}

.workflow-editor-number {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid #cad8cf;
  font-size: 12px;
  font-weight: 700;
  color: #4f6558;
}

.workflow-editor-label {
  font-size: 13px;
}

.workflow-editor-actions {
  display: flex;
  gap: 6px;
}

.workflow-editor-actions .btn-secondary {
  padding: 6px 9px;
  font-size: 12px;
}

.workflow-editor-restore {
  display: grid;
  gap: 6px;
}

.workflow-restore-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.map-card {
  border: 1px solid #dbe5de;
  border-radius: 12px;
  background: #fbfefd;
  padding: 10px;
  display: grid;
  gap: 10px;
}

.map-frame {
  width: 100%;
  min-height: 240px;
  border: 1px solid #d7e0da;
  border-radius: 10px;
}

.map-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  border: 1px solid #c8d8ce;
  background: #eff5f1;
  color: #214736;
  padding: 8px 10px;
  text-decoration: none;
  font-size: 13px;
}

.docs-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.doc-card {
  border: 1px solid #d7e0da;
  border-radius: 12px;
  background: #fff;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.doc-card h5 {
  margin: 0;
}

.doc-file-input {
  width: 100%;
  padding: 8px;
  border: 1px dashed #d3a86d;
  border-radius: 10px;
  background: #fff8ee;
  color: #5b4a32;
}

.doc-file-input::file-selector-button {
  margin-right: 10px;
  border: 1px solid #d28d3a;
  border-radius: 8px;
  padding: 7px 12px;
  background: linear-gradient(180deg, #f6b457 0%, #e89931 100%);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.sticky-save-bar {
  position: sticky;
  bottom: 0;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #dfe7e1;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, #fff 36%);
  z-index: 2;
}

.form-grid {
  display: grid;
  gap: 10px;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.timeline {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.timeline li {
  border-left: 3px solid #d6e2db;
  padding-left: 8px;
  font-size: 13px;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #c8d5e3;
  margin-bottom: 4px;
}

.chat-messages {
  display: grid;
  gap: 8px;
  max-height: min(62vh, 560px);
  overflow: auto;
  margin-top: 8px;
  padding-right: 4px;
}

.msg {
  border: 1px solid #d9e1db;
  border-radius: 12px;
  padding: 10px;
  background: #fff;
}

/* Incoming message — client */
.msg-in {
  border-left: 4px solid #7e9f8e;
  background: #fff;
}

/* Outgoing message — manager */
.msg-out {
  border-left: 4px solid #1f7a56;
  background: #eef7f2;
}

.msg-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 12px;
  color: #5c6b63;
}

.msg-text {
  white-space: pre-wrap;
}

.send-form {
  margin-top: 8px;
  display: grid;
  gap: 8px;
}

.deal-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.deal-col {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
  min-height: 220px;
  display: grid;
  align-content: start;
  gap: 8px;
}

.deal-col h4 {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.deal-col-title {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
}

.deal-col-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid #d5e0d9;
  background: #f6faf8;
  font-size: 12px;
}

.deal-col-work {
  border-top: 3px solid #d2b15f;
}

.deal-col-planned {
  border-top: 3px solid #df8a2d;
}

.deal-col-done {
  border-top: 3px solid #5fa379;
}

.deal-list {
  display: grid;
  gap: 8px;
}

.deal-card {
  border: 1px solid #d7e0da;
  border-radius: 10px;
  padding: 8px;
  background: #fdfefd;
}

.deal-actions {
  margin-top: 8px;
  display: grid;
  gap: 6px;
}

.archive-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.archive-card {
  border: 1px solid #ead6d1;
  border-radius: 12px;
  padding: 10px;
  background: #fff8f6;
}

.hidden {
  display: none !important;
}

.error {
  color: var(--danger);
  margin-top: 6px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(92vw, 460px);
  padding: 10px 14px;
  border-radius: 12px;
  color: #fff;
  z-index: 9999;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.24);
}

.toast-ok {
  background: #1f3a2d;
}

.toast-error {
  background: #8f2d20;
}

/* Engineer brief card */
.engineer-card {
  border: 2px solid #1f7a56;
  border-radius: 14px;
  background: linear-gradient(135deg, #e8f7ef 0%, #f5fdf8 100%);
  padding: 14px;
  margin-bottom: 14px;
  display: grid;
  gap: 10px;
}

.engineer-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #1a5e3f;
}

.engineer-card-header .eng-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: #1f7a56;
  color: #fff;
  font-size: 14px;
}

.engineer-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.engineer-meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.engineer-meta-label {
  font-size: 11px;
  color: #4a7060;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.engineer-meta-value {
  font-size: 14px;
  font-weight: 600;
  color: #163126;
  word-break: break-word;
}

.engineer-meta-value a {
  color: #1f7a56;
  text-decoration: none;
}

.engineer-meta-value a:hover {
  text-decoration: underline;
}

.engineer-brief-text {
  background: #fff;
  border: 1px solid #b3d9c4;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: #163126;
}

.engineer-brief-empty {
  color: #76968a;
  font-style: italic;
  font-size: 13px;
}

/* Form section headers */
.form-section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #4f6558;
  margin: 16px 0 4px;
  padding: 6px 8px;
  border-left: 3px solid var(--brand);
  border-bottom: 1px solid #dce4df;
  background: linear-gradient(90deg, #f3faf6 0%, transparent 60%);
  border-radius: 0 6px 0 0;
}

/* Archive modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 30, 20, 0.55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-box {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  width: min(460px, 100%);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  display: grid;
  gap: 12px;
}

.modal-box h3 {
  margin: 0;
}

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

/* Service type select in form */
.service-type-select {
  width: 100%;
}

@media (max-width: 980px) {
  .engineer-meta-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1200px) {
  .chats-layout {
    grid-template-columns: 320px minmax(0, 1fr);
  }

  .workspace-grid {
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  }
}

@media (max-width: 980px) {
  .bg-shape {
    opacity: 0.3;
    filter: blur(72px);
  }

  .app-shell {
    margin: 10px auto;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }

  .panel {
    border-radius: 14px;
    padding: 11px;
  }

  .topbar {
    position: sticky;
    top: calc(6px + env(safe-area-inset-top));
    z-index: 20;
  }

  .topbar {
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: stretch;
    display: grid;
    grid-template-columns: 1fr;
  }

  .topbar-actions button {
    width: 100%;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tabs {
    flex-wrap: wrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
    padding-bottom: 2px;
  }

  .tab-btn {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .chats-layout {
    grid-template-columns: 1fr;
  }

  .chat-directory {
    min-height: auto;
  }

  .chat-workspace {
    min-height: auto;
  }

  .list-scroll {
    max-height: min(42dvh, 440px);
  }

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

  .workspace-section-chat {
    order: 1;
  }

  .workspace-section-main {
    order: 2;
  }

  .workspace-section-main,
  .workspace-section-chat {
    max-height: none;
    min-height: auto;
    overflow: visible;
  }

  /* All buttons: min 44px tap target on touch screens */
  button {
    min-height: 44px;
    font-size: 15px;
  }

  .btn-secondary {
    min-height: 44px;
  }

  .chat-row {
    padding: 12px;
  }

  .chat-row-top {
    align-items: center;
  }

  .chat-row-top-right {
    align-items: center;
    gap: 8px;
  }

  input, select, textarea {
    font-size: 16px; /* prevents iOS zoom on focus */
    min-height: 44px;
    padding: 10px 14px;
  }

  textarea {
    min-height: 80px;
  }

  .chat-priority-select {
    min-width: 0;
    width: 100%;
    margin-top: 6px;
    min-height: 44px;
  }

  .modal-actions {
    flex-direction: column-reverse;
    gap: 10px;
  }

  .modal-actions button {
    width: 100%;
    min-height: 48px;
    font-size: 16px;
  }

  .modal-box {
    padding: 16px;
    border-radius: 20px;
  }

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

  .workflow-track {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workflow-editor-row {
    grid-template-columns: 28px 1fr;
  }

  .workflow-editor-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .deal-board {
    grid-template-columns: 1fr;
  }

  .archive-list {
    grid-template-columns: 1fr;
  }

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

  .workspace-section-chat .chat-messages {
    flex-grow: 0;
    max-height: min(46dvh, 460px);
  }

  .map-frame {
    min-height: 210px;
  }

  .sticky-save-bar {
    bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .sticky-save-bar button {
    width: 100%;
    min-height: 42px;
  }
}

@media (max-width: 640px) {
  .bg-shape {
    display: none;
  }

  .auth-panel {
    margin: 18px auto;
  }

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

  .workflow-track {
    grid-template-columns: 1fr;
  }

  .workflow-step {
    padding: 8px;
  }

  .list-header {
    flex-direction: column;
    align-items: stretch;
  }

  .list-header input {
    width: 100%;
  }

  .workspace-section-chat .chat-messages {
    max-height: min(50dvh, 500px);
  }
}
