:root {
  --workspace-panel-shadow: 0 8px 24px rgba(35, 50, 45, 0.06);
}

body {
  font-family: Inter, "Segoe UI Variable", "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

.app-shell {
  grid-template-columns: 300px minmax(0, 1fr);
  transition: grid-template-columns 0.2s ease;
}

.app-shell.sidebar-collapsed { grid-template-columns: 68px minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 20px;
  gap: 12px;
  transition: width 0.2s ease, padding 0.2s ease, box-shadow 0.2s ease;
}

.sidebar-header { display: grid; gap: 10px; }
.sidebar-header .brand { min-width: 0; margin-bottom: 0; }
.brand-copy { min-width: 0; }
.brand-copy h1, .brand-copy p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-expanded-content { display: grid; gap: 12px; }
.sidebar-actions { grid-template-columns: 1fr; }
.order-select { text-overflow: ellipsis; }

.sidebar-toggle {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.sidebar-toggle:hover { border-color: var(--teal); background: var(--surface-soft); }
#sidebarToggleIcon { font-size: 1.35rem; line-height: 1; }

.sidebar-collapsed .sidebar { padding: 14px 12px; overflow-x: hidden; }
.sidebar-collapsed .sidebar-header .brand { justify-content: center; }
.sidebar-collapsed .brand-copy,
.sidebar-collapsed .sidebar-expanded-content,
.sidebar-collapsed #sidebarToggleLabel { display: none; }
.sidebar-collapsed .brand-mark { width: 42px; height: 42px; flex: 0 0 42px; }
.sidebar-collapsed .sidebar-toggle { width: 42px; min-height: 38px; margin-inline: auto; }
.sidebar-collapsed .stage-nav { gap: 7px; }
.sidebar-collapsed .stage-button {
  min-height: 42px;
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  gap: 0;
  padding: 5px;
}
.sidebar-collapsed .stage-button > span:not(.stage-number) { display: none; }
.sidebar-collapsed .stage-number { width: 28px; height: 28px; }

.field-label, .eyebrow { letter-spacing: 0; }
.field-label {
  margin-top: 4px;
  color: #526064;
  font-size: 0.76rem;
  font-weight: 700;
}

.control, .text-input, .text-area {
  min-height: 42px;
  border-color: #cfd7d2;
  padding: 10px 12px;
  line-height: 1.35;
}

.control:focus, .text-input:focus, .text-area:focus {
  outline: 3px solid rgba(23, 107, 99, 0.13);
  border-color: var(--teal);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 13px;
  font-size: 0.9rem;
  font-weight: 650;
  line-height: 1.2;
}

.button.compact {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 0.82rem;
}

.selected-order-summary {
  display: none;
  gap: 3px;
  min-height: 54px;
  border: 1px solid #b7d2c7;
  border-radius: 7px;
  background: #edf6f1;
  padding: 10px 12px;
}

.selected-order-summary strong { overflow-wrap: anywhere; font-size: 0.9rem; }
.selected-order-summary span, .selected-order-summary small { color: var(--muted); font-size: 0.76rem; }
.order-list {
  display: grid;
  flex: 0 0 auto;
  gap: 6px;
  max-height: 230px;
  overflow-y: auto;
  padding-right: 3px;
}

.order-list-item {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  padding: 9px 10px;
  text-align: left;
  cursor: pointer;
}

.order-list-item:hover, .order-list-item.active { border-color: var(--teal); background: var(--surface-soft); }
.order-list-item > span:first-child { min-width: 0; display: grid; gap: 2px; }
.order-list-item strong, .order-list-item small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-list-item strong { font-size: 0.83rem; }
.order-list-item small { color: var(--muted); font-size: 0.72rem; }
.order-list-status, .sla-pill {
  border-radius: 999px;
  background: #eef1ee;
  color: var(--muted);
  padding: 3px 7px;
  font-size: 0.68rem;
  font-weight: 750;
  white-space: nowrap;
}

.order-list-status.overdue, .sla-pill.overdue { background: #fde8e6; color: var(--red); }
.order-list-status.due-soon, .sla-pill.due-soon { background: #fff0d8; color: #8a4d0f; }
.sla-pill.on-track, .sla-pill.complete { background: #e5f3e9; color: var(--green); }
.sla-pill.cancelled, .status-pill.cancelled { background: #ecefed; color: #5f696b; }
.stage-button.cancelled-state { border-color: #c7cfcb; background: #f3f5f3; color: #657071; }
.stage-button.cancelled-state .stage-number { background: #788383; color: white; }
.stage-nav { margin-top: 2px; }
.stage-button { min-height: 60px; padding: 9px 10px; }
.stage-name { font-size: 0.84rem; font-weight: 700; line-height: 1.3; }
.stage-state { font-size: 0.72rem; }
.main-panel { padding: 22px 26px 36px; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  margin: -22px -26px 20px;
  padding: 16px 26px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 248, 244, 0.97);
  backdrop-filter: blur(10px);
}

.topbar-heading { min-width: 0; }
.topbar h2 { font-size: 1.45rem; line-height: 1.2; }
.topbar .subtle { max-width: 620px; margin: 5px 0 0; font-size: 0.86rem; }
.topbar-actions {
  order: -1;
  width: 100%;
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-start;
  gap: 7px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 3px;
  scrollbar-width: thin;
}
.topbar-actions > * { flex: 0 0 auto; }
.topbar-actions > .button.secondary { min-height: 38px; padding: 8px 11px; background: transparent; }
.topbar-actions > .button.secondary.active { background: white; box-shadow: 0 2px 8px rgba(35, 50, 45, 0.06); }
.system-clock { min-height: 38px; padding: 8px 10px; font-size: 0.8rem; }
.account-control { min-height: 38px; font-weight: 600; }
.nav-badge {
  min-width: 19px;
  height: 19px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: var(--red);
  color: white;
  padding: 0 5px;
  font-size: 0.67rem;
  font-weight: 800;
}

.panel { border-radius: 8px; box-shadow: var(--workspace-panel-shadow); }
.panel-header h3 { font-size: 1.05rem; line-height: 1.3; }
.form-field { gap: 7px; }
.form-field > span, .chat-composer label span {
  color: #4f5d61;
  font-size: 0.82rem;
  font-weight: 650;
  text-transform: none;
}

.order-header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.order-header-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 8px; color: var(--muted); font-size: 0.78rem; }
.order-header-meta strong { color: var(--ink); font-weight: 650; }
.save-bar {
  position: sticky;
  bottom: 12px;
  z-index: 8;
  margin-top: 16px;
  border: 1px solid #bfd0c8;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 24px rgba(35, 50, 45, 0.12);
}
.advance-box .button { min-width: 180px; }

.kanban-board { display: grid; grid-template-columns: repeat(4, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 4px; }
.kanban-column { min-width: 220px; min-height: 240px; border-top: 3px solid #8c989a; background: #f4f6f3; padding: 10px; }
.kanban-column.bad { border-color: var(--red); background: #fff5f4; }
.kanban-column.warn { border-color: var(--amber); background: #fff9ee; }
.kanban-column.due { border-color: var(--blue); background: #f3f7fc; }
.kanban-column.good { border-color: var(--green); background: #f2f8f4; }
.kanban-column > header { display: flex; justify-content: space-between; gap: 10px; margin: 0 0 10px; font-size: 0.82rem; font-weight: 750; }
.kanban-column > header strong { min-width: 22px; height: 22px; display: grid; place-items: center; border-radius: 999px; background: rgba(255, 255, 255, 0.8); color: var(--muted); font-size: 0.7rem; }
.kanban-cards { display: grid; gap: 8px; }
.kanban-card {
  display: grid;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  padding: 11px;
  text-align: left;
  cursor: pointer;
}
.kanban-card:hover { border-color: var(--teal); box-shadow: 0 5px 16px rgba(35, 50, 45, 0.08); }
.kanban-card-top, .kanban-meta { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.kanban-card-top strong { min-width: 0; overflow-wrap: anywhere; font-size: 0.84rem; }
.kanban-stage { color: var(--teal-dark); font-size: 0.76rem; font-weight: 700; }
.kanban-blocker { color: #4e5c5f; font-size: 0.76rem; line-height: 1.35; }
.kanban-meta small { color: var(--muted); font-size: 0.7rem; }
.kanban-empty, .chat-empty-note, .sidebar-empty { margin: 8px 2px; color: var(--muted); font-size: 0.8rem; }

.chat-view { display: grid; grid-template-columns: 270px minmax(430px, 1fr) 290px; gap: 12px; height: calc(100vh - 118px); min-height: 620px; }
.chat-view > .panel { min-height: 0; padding: 14px; box-shadow: none; }
.chat-conversation-panel, .chat-thread-panel, .chat-context-panel { display: flex; flex-direction: column; gap: 12px; }
.compact-header { margin-bottom: 0; }
.chat-conversation-list, .chat-notifications { display: grid; align-content: start; gap: 5px; min-height: 0; overflow-y: auto; }
.chat-conversation {
  display: grid;
  gap: 4px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  padding: 10px;
  text-align: left;
  cursor: pointer;
}
.chat-conversation:hover, .chat-conversation.active { border-color: var(--line); background: #f1f5f1; }
.chat-conversation.active { border-color: #a9cbc0; background: #eaf4ef; }
.conversation-top { display: flex; justify-content: space-between; gap: 8px; }
.conversation-top strong, .chat-conversation > span, .chat-conversation small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-top strong { font-size: 0.82rem; }
.conversation-top em { min-width: 19px; height: 19px; display: grid; place-items: center; border-radius: 999px; background: var(--teal); color: white; padding: 0 5px; font-size: 0.65rem; font-style: normal; }
.chat-conversation > span, .chat-conversation small { color: var(--muted); font-size: 0.72rem; }

.chat-thread-header { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.chat-thread-header h3, .chat-thread-header p { margin-top: 0; }
.chat-thread-header .subtle { margin-bottom: 0; font-size: 0.78rem; }
.chat-thread-tools { width: min(100%, 360px); display: grid; grid-template-columns: minmax(150px, 1fr) 120px; gap: 7px; }
.chat-thread-tools .text-input { min-height: 36px; padding: 7px 9px; font-size: 0.78rem; }
.chat-thread-panel .chat-messages { flex: 1; max-height: none; min-height: 0; }
.chat-messages { gap: 4px; padding: 6px 8px 8px 2px; align-content: start; }
.chat-message { grid-template-columns: 34px minmax(0, 1fr); gap: 8px; align-items: start; border: 0; background: transparent; padding: 3px 0; }
.chat-message.grouped { grid-template-columns: 34px minmax(0, 1fr); padding-top: 0; }
.chat-message.grouped::before { content: ""; }
.chat-avatar { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: #dfe9e4; color: var(--teal-dark); font-size: 0.68rem; font-weight: 800; }
.chat-bubble { width: fit-content; max-width: min(680px, 88%); display: grid; gap: 6px; border-radius: 7px; background: #f0f3f0; padding: 9px 11px; }
.chat-message.mine .chat-bubble { justify-self: end; background: #dfeee8; }
.chat-message.mine .chat-avatar { background: var(--teal); color: white; }
.chat-message-meta { gap: 6px; }
.chat-message-meta strong { font-size: 0.78rem; }
.chat-message-meta span, .chat-message-meta time { font-size: 0.68rem; }
.chat-bubble > p { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; font-size: 0.86rem; }
.chat-date-separator { display: flex; align-items: center; gap: 10px; margin: 10px 0; color: var(--muted); font-size: 0.7rem; }
.chat-date-separator::before, .chat-date-separator::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.chat-reply-quote { display: grid; gap: 2px; width: 100%; border: 0; border-left: 3px solid #79a69b; background: rgba(255, 255, 255, 0.55); color: var(--ink); padding: 5px 7px; text-align: left; cursor: pointer; }
.chat-reply-quote strong, .chat-reply-quote span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.7rem; }
.chat-message-footer { display: flex; justify-content: flex-end; gap: 10px; align-items: center; color: var(--muted); font-size: 0.66rem; }
.chat-message-footer span { display: flex; gap: 7px; }
.chat-message-footer button { border: 0; background: transparent; color: var(--teal-dark); padding: 0; font-size: 0.66rem; cursor: pointer; }
.chat-files { display: flex; flex-wrap: wrap; gap: 5px; }
.chat-file { display: flex; gap: 8px; align-items: center; min-width: 150px; max-width: 100%; border: 1px solid #cbd8d2; border-radius: 6px; background: white; color: var(--ink); padding: 7px 9px; text-decoration: none; }
.chat-file strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.72rem; }
.chat-file span { color: var(--muted); font-size: 0.66rem; white-space: nowrap; }

.chat-composer { gap: 8px; padding-top: 10px; }
.chat-composer .text-area { min-height: 68px; max-height: 150px; }
.chat-composer-actions { grid-template-columns: minmax(140px, 1fr) auto minmax(90px, auto) auto; gap: 7px; align-items: center; }
.file-button { cursor: pointer; }
.attachment-summary { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 0.72rem; }
.chat-reply-preview { display: flex; justify-content: space-between; gap: 12px; align-items: center; border-left: 3px solid var(--teal); background: #eef5ef; padding: 8px 10px; font-size: 0.76rem; }
.chat-reply-preview button { border: 0; background: transparent; color: var(--teal-dark); cursor: pointer; }

.chat-context-panel { overflow-y: auto; }
.chat-context-header h3 { overflow-wrap: anywhere; margin: 0 0 8px; font-size: 0.96rem; }
.chat-context-list { display: grid; gap: 8px; margin: 14px 0; }
.chat-context-list div { display: grid; gap: 2px; padding-bottom: 7px; border-bottom: 1px solid var(--line); }
.chat-context-list dt { color: var(--muted); font-size: 0.68rem; font-weight: 700; text-transform: uppercase; }
.chat-context-list dd { margin: 0; overflow-wrap: anywhere; font-size: 0.78rem; }
.chat-context-tasks h4 { margin: 0 0 7px; font-size: 0.82rem; }
.chat-context-tasks { display: grid; gap: 5px; }
.chat-context-tasks button, .chat-notification { display: grid; gap: 2px; width: 100%; border: 1px solid var(--line); border-radius: 6px; background: #fafbf8; color: var(--ink); padding: 8px; text-align: left; cursor: pointer; }
.chat-context-tasks strong, .chat-notification strong { font-size: 0.75rem; }
.chat-context-tasks span, .chat-notification span, .chat-notification small { color: var(--muted); font-size: 0.68rem; }
.chat-notification.unread { border-color: #d1ad72; background: #fff8eb; }
.chat-notification-section { display: grid; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }

.order-chat-drawer { position: fixed; z-index: 60; top: 0; right: 0; width: min(430px, 100vw); height: 100vh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 12px; border-left: 1px solid var(--line); background: white; padding: 18px; box-shadow: -14px 0 36px rgba(35, 50, 45, 0.16); }
.drawer-header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.drawer-header h3, .drawer-header p { margin-top: 0; }
.icon-button { width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; background: white; color: var(--ink); cursor: pointer; font-weight: 700; }
.compact-messages { max-height: none; min-height: 0; }
.drawer-composer { display: grid; gap: 8px; }
.modal-backdrop { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; background: rgba(20, 29, 28, 0.48); padding: 20px; }
.modal-panel { width: min(100%, 480px); border-radius: 8px; background: white; padding: 24px; box-shadow: 0 24px 70px rgba(20, 29, 28, 0.24); }
.modal-panel h3 { margin: 0; }
.modal-panel > .form-field { display: grid; gap: 7px; margin-top: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
.hidden { display: none !important; }

@media (max-width: 1280px) {
  .chat-view { grid-template-columns: 240px minmax(400px, 1fr); }
  .chat-context-panel { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(300px, 1fr) minmax(300px, 1fr); height: 250px; }
}

@media (max-width: 1080px) {
  .app-shell:not(.sidebar-collapsed) { grid-template-columns: 270px minmax(0, 1fr); }
  .kanban-board { grid-template-columns: repeat(4, 240px); }
}

@media (max-width: 900px) {
  .app-shell,
  .app-shell.sidebar-collapsed,
  .app-shell:not(.sidebar-collapsed) { grid-template-columns: 64px minmax(0, 1fr); }
  .sidebar { z-index: 50; padding: 14px 10px; }
  .app-shell:not(.sidebar-collapsed) .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, calc(100vw - 24px));
    height: 100vh;
    max-height: none;
    overflow-y: auto;
    padding: 18px;
    border-right: 1px solid var(--line);
    background: #fbfcf8;
    box-shadow: 18px 0 44px rgba(24, 43, 39, 0.2);
  }
  .topbar { margin: -22px -26px 20px; }
  .chat-view { height: auto; min-height: 0; grid-template-columns: 1fr; }
  .chat-conversation-panel { max-height: 330px; }
  .chat-thread-panel { min-height: 650px !important; }
  .chat-context-panel { grid-column: auto; grid-template-columns: 1fr; height: auto; max-height: 480px; }
}

@media (max-width: 620px) {
  .main-panel { padding: 16px; }
  .sidebar-collapsed .sidebar { padding: 12px 9px; }
  .app-shell:not(.sidebar-collapsed) .sidebar { padding: 16px; }
  .topbar { margin: -16px -16px 18px; padding: 14px 16px; }
  .topbar-actions { width: 100%; }
  .chat-thread-header, .order-header-actions { flex-direction: column; align-items: stretch; }
  .chat-thread-tools { width: 100%; grid-template-columns: 1fr; }
  .chat-composer-actions { grid-template-columns: 1fr 1fr; }
  .attachment-summary { grid-column: 1 / -1; }
  .modal-actions { display: grid; }
  .advance-box .button { min-width: 0; }
}
