:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-alt: #f0f3f6;
  --text: #242a32;
  --muted: #687382;
  --line: #dfe5ec;
  --line-strong: #c5d2df;
  --blue: #2f6fdb;
  --blue-soft: #eaf3ff;
  --navy: #20395c;
  --green: #2c8755;
  --pink: #e4487d;
  --amber: #a36b00;
  --danger: #c94d55;
  --shadow: 0 12px 32px rgba(34, 46, 66, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
}

[hidden] {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.side-menu {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 22px;
  background: #17283f;
  color: #fff;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-row span,
.storage-box small {
  display: block;
  color: rgba(255, 255, 255, 0.68);
  font-size: 0.82rem;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #fff;
  color: var(--navy);
  font-size: 1.8rem;
  font-weight: 800;
}

.nav-list {
  display: grid;
  align-content: start;
  gap: 8px;
}

.nav-item {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.82);
  background: transparent;
  text-align: left;
  font-weight: 800;
}

.nav-item:hover,
.nav-item.is-active {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.16);
}

.nav-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.14);
  font-size: 0.75rem;
}

.storage-box {
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.storage-copy {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 0.9rem;
}

.storage-meter {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

.storage-meter span {
  display: block;
  width: 0;
  height: 100%;
  background: #54c68b;
}

.main-shell {
  min-width: 0;
}

.top-bar {
  min-height: 76px;
  padding: 14px 22px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
}

.top-bar h1,
.top-bar p,
.detail-header h2,
.chat-header h2,
.panel-title-row h2 {
  margin: 0;
}

.top-bar h1 {
  font-size: 1.35rem;
}

.top-bar p,
.detail-header p,
.chat-header p,
.panel-title-row p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.menu-toggle,
.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.menu-toggle {
  display: grid;
  place-content: center;
  gap: 4px;
}

.menu-toggle span {
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: var(--navy);
}

.user-pill {
  padding: 8px 12px;
  display: grid;
  gap: 1px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: right;
}

.user-pill span {
  font-size: 0.9rem;
}

.user-pill strong {
  color: var(--blue);
  font-size: 0.78rem;
}

main {
  padding: 18px;
}

.page-view {
  display: none;
}

.page-view.is-active {
  display: block;
}

.documents-grid,
.chat-grid,
.jobs-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(380px, 460px);
  gap: 18px;
  align-items: start;
}

.library-panel,
.detail-panel,
.chat-docs-panel,
.chat-panel,
.job-list-panel,
.job-detail-panel,
.job-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.library-panel,
.chat-docs-panel,
.chat-panel,
.job-list-panel,
.job-detail-panel {
  min-height: calc(100vh - 112px);
}

.library-panel {
  padding: 18px;
}

.toolbar,
.panel-title-row,
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.search-box {
  min-width: 260px;
  width: min(520px, 100%);
}

.search-box label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.search-box input,
.toolbar select,
.composer textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
}

.search-box input,
.toolbar select {
  height: 40px;
  padding: 0 12px;
}

.toolbar-actions {
  display: flex;
  gap: 10px;
}

.primary-btn,
.soft-btn {
  min-height: 38px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  font-weight: 800;
  text-decoration: none;
}

.primary-btn {
  border: 1px solid var(--blue);
  color: #fff;
  background: var(--blue);
}

.soft-btn {
  border: 1px solid var(--line-strong);
  color: var(--navy);
  background: #fff;
}

.limit-strip {
  margin: 14px 0;
  padding: 10px 12px;
  border: 1px solid #e7d7ad;
  border-radius: 8px;
  color: #704a00;
  background: #fff8e9;
  font-size: 0.88rem;
  font-weight: 700;
}

.file-list {
  display: grid;
  gap: 10px;
}

.file-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  min-height: 74px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.file-row.is-selected {
  border-color: #82b7ff;
  background: var(--blue-soft);
  box-shadow: inset 4px 0 0 var(--blue);
}

.file-row.is-child {
  margin-left: 24px;
}

.file-row[hidden] {
  display: none;
}

.file-main h3 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
}

.file-main p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.file-tags,
.source-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  min-height: 22px;
  padding: 2px 8px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.chip.green {
  background: #e8f6ef;
  color: var(--green);
}

.chip.pink {
  background: #feeaf2;
  color: var(--pink);
}

.chip.amber {
  background: #fff4d9;
  color: var(--amber);
}

.row-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row-actions button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--navy);
  font-weight: 800;
}

.row-actions .danger {
  color: var(--danger);
}

.detail-panel {
  position: sticky;
  top: 94px;
  min-height: calc(100vh - 112px);
  overflow: hidden;
}

.detail-header,
.chat-docs-panel,
.chat-panel,
.job-list-panel,
.job-detail-panel {
  padding: 18px;
}

.eyebrow {
  color: var(--blue);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.tab-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.tab-btn {
  min-height: 42px;
  border: 0;
  background: #fff;
  color: var(--muted);
  font-weight: 800;
}

.tab-btn.is-active {
  color: var(--blue);
  background: var(--blue-soft);
}

.tab-panel {
  display: none;
  padding: 16px;
}

.tab-panel.is-active {
  display: block;
}

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

.preview-body {
  min-height: 430px;
  max-height: calc(100vh - 260px);
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
}

.preview-body object,
.preview-body iframe {
  width: 100%;
  min-height: 420px;
  border: 0;
}

.preview-body pre {
  white-space: pre-wrap;
  word-break: break-word;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.preview-table th,
.preview-table td {
  padding: 8px;
  border: 1px solid var(--line);
  text-align: left;
}

.access-note,
.ai-control-box {
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
  color: var(--muted);
  font-size: 0.88rem;
}

.permission-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.access-search input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

.selected-account-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0;
}

.department-access {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.department-access summary {
  min-height: 44px;
  padding: 9px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
  background: #f7f9fb;
  cursor: pointer;
  font-weight: 800;
  text-transform: uppercase;
  font-size: 0.82rem;
}

.department-checkboxes {
  display: inline-flex;
  align-items: center;
  gap: 14px;
}

.department-checkboxes label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: none;
}

.department-checkboxes input {
  width: 18px;
  height: 18px;
  accent-color: #2d7a3d;
}

.department-checkboxes label.is-partial input {
  accent-color: #9aa3ad;
}

.account-row {
  min-height: 58px;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
}

.account-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.account-profile strong,
.account-profile small {
  display: block;
}

.account-profile small {
  color: var(--muted);
}

.account-avatar {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: #6b7d2b;
  font-weight: 800;
}

.account-permission-options {
  display: flex;
  gap: 12px;
  white-space: nowrap;
}

.account-permission-options label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.account-permission-options input {
  width: 18px;
  height: 18px;
  accent-color: #2d7a3d;
}

.permission-row,
.switch-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.permission-row strong,
.switch-row strong,
.switch-row small {
  display: block;
}

.permission-select {
  min-width: 116px;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
}

.ai-control-box {
  display: grid;
  gap: 8px;
}

.switch-row small {
  color: var(--muted);
  font-size: 0.78rem;
}

.switch-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--blue);
}

.chat-grid {
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
}

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

.job-list-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
}

.job-list {
  display: grid;
  align-content: start;
  gap: 8px;
  overflow: auto;
}

.job-list-item {
  width: 100%;
  padding: 12px;
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
}

.job-list-item.is-selected {
  border-color: #82b7ff;
  background: var(--blue-soft);
  box-shadow: inset 4px 0 0 var(--blue);
}

.job-list-item span,
.job-list-item small {
  color: var(--muted);
}

.job-detail-panel {
  display: grid;
  gap: 14px;
}

.job-header {
  padding-bottom: 14px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
}

.job-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.job-header p,
.job-customer span {
  display: block;
  margin: 3px 0 0;
  color: var(--muted);
}

.job-customer {
  text-align: right;
}

.job-content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 14px;
}

.job-section {
  padding: 14px;
  box-shadow: none;
}

.job-section h2 {
  margin: 0 0 12px;
  font-size: 1rem;
}

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

.detail-pair {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbfc;
}

.detail-pair span,
.detail-pair strong {
  display: block;
}

.detail-pair span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.detail-pair strong {
  margin-top: 3px;
  font-size: 0.9rem;
}

.job-updates,
.comment-list {
  display: grid;
  gap: 10px;
  max-height: 430px;
  overflow: auto;
}

.update-row,
.comment-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.update-row span,
.comment-row span,
.update-row small {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.update-row p,
.comment-row p {
  margin: 5px 0;
}

.comment-row.is-ai {
  border-color: #b8d5ff;
  background: #f4f8ff;
}

.comment-row.is-ai .account-avatar {
  background: var(--blue);
  font-size: 0.74rem;
}

.comments-section {
  display: grid;
  gap: 12px;
}

.comment-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 10px;
}

.comment-input-shell {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  align-items: stretch;
}

.comment-form textarea {
  width: 100%;
  min-height: 58px;
  max-height: 150px;
  padding: 10px 12px 10px 4px;
  border: 0;
  background: transparent;
  outline: 0;
  resize: vertical;
}

.chat-docs-panel {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 14px;
}

.selected-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
}

.document-picker {
  display: grid;
  gap: 8px;
  overflow: auto;
  max-height: calc(100vh - 250px);
}

.pick-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.pick-row.is-disabled {
  opacity: 0.58;
}

.pick-row input {
  margin-top: 4px;
}

.pick-row strong,
.pick-row span {
  display: block;
}

.pick-row span {
  color: var(--muted);
  font-size: 0.82rem;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
}

.status-pill {
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--green);
  background: #e8f6ef;
  font-weight: 800;
  font-size: 0.8rem;
}

.message-list {
  min-height: 480px;
  max-height: calc(100vh - 260px);
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.message {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.message.user {
  grid-template-columns: minmax(0, 1fr) 36px;
}

.message.user .avatar {
  grid-column: 2;
}

.message.user .bubble {
  grid-column: 1;
  grid-row: 1;
  justify-self: end;
  background: #eaf3ff;
}

.avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  font-size: 0.76rem;
  font-weight: 800;
}

.bubble {
  max-width: 820px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  line-height: 1.45;
  white-space: pre-wrap;
}

.source-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.composer {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
}

.composer textarea {
  min-height: 58px;
  max-height: 150px;
  padding: 10px 12px;
  resize: vertical;
}

.attach-shell,
.mention-shell {
  position: relative;
}

.icon-action-btn {
  width: 38px;
  height: 38px;
  margin: 9px 4px;
  border: 0;
  border-radius: 7px;
  background: #f4f7fb;
  color: var(--navy);
  font-size: 1.4rem;
  font-weight: 800;
}

.attach-popover,
.mention-popover {
  position: absolute;
  z-index: 30;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.attach-popover {
  left: 0;
  bottom: calc(100% + 10px);
  width: min(420px, calc(100vw - 48px));
  max-height: 460px;
  padding: 12px;
  overflow: auto;
}

.popover-title {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

.mention-shell {
  min-width: 0;
  display: grid;
}

.mention-shell textarea {
  width: 100%;
}

.mention-popover {
  left: 0;
  bottom: calc(100% + 8px);
  width: min(360px, 100%);
  overflow: hidden;
}

.mention-option {
  width: 100%;
  padding: 10px 12px;
  display: grid;
  gap: 2px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  text-align: left;
}

.mention-option:last-child {
  border-bottom: 0;
}

.mention-option:hover,
.mention-option.is-active {
  background: var(--blue-soft);
}

.mention-option strong,
.mention-option span {
  display: block;
}

.mention-option span {
  color: var(--muted);
  font-size: 0.78rem;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 20, 31, 0.42);
}

.modal-card {
  width: min(520px, 100%);
  padding: 18px;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.modal-header,
.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.modal-header h2 {
  margin: 0;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 16px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: #1f2f46;
  box-shadow: var(--shadow);
  font-weight: 800;
}

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

body.menu-collapsed .brand-row div:not(.brand-mark),
body.menu-collapsed .nav-item span:last-child,
body.menu-collapsed .storage-box {
  display: none;
}

body.menu-collapsed .side-menu {
  padding: 18px 12px;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-menu {
    position: fixed;
    z-index: 20;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 160ms ease;
  }

  body.menu-open .side-menu {
    transform: translateX(0);
  }

  body.menu-collapsed .app-shell {
    grid-template-columns: 1fr;
  }

  .documents-grid,
  .chat-grid,
  .jobs-grid,
  .job-content-grid {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
  }
}

@media (max-width: 700px) {
  main,
  .top-bar {
    padding: 12px;
  }

  .top-bar {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .user-pill {
    grid-column: 1 / -1;
    text-align: left;
  }

  .toolbar,
  .toolbar-actions,
  .panel-title-row,
  .chat-header,
  .composer,
  .job-header,
  .comment-form {
    display: grid;
    grid-template-columns: 1fr;
  }

  .comment-input-shell {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .file-row,
  .job-details {
    grid-template-columns: 1fr;
  }

  .row-actions,
  .account-row,
  .department-access summary {
    flex-wrap: wrap;
  }

  .job-customer {
    text-align: left;
  }
}
