:root {
  color-scheme: light;
  --ink: #0b1a2b;
  --muted: #5f7187;
  --soft: #f1f6fb;
  --surface: #ffffff;
  --surface-subtle: #f7fbff;
  --line: #dbe9f7;
  --line-strong: #c7dbf0;
  --blue: #1e4db7;
  --blue-deep: #0b2e5a;
  --ocean: #0f5f86;
  --ocean-deep: #12485e;
  --sea-glass: #e6f5fb;
  --teal: #0f6b70;
  --amber: #b45309;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --shadow: 0 18px 48px rgba(11, 26, 43, 0.09);
  --shadow-soft: 0 10px 28px rgba(11, 26, 43, 0.06);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--soft);
  overflow: hidden;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea {
  font: inherit;
}

button {
  appearance: none;
}

img {
  display: block;
  max-width: 100%;
}

.background-grid {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(
      180deg,
      var(--surface-subtle) 0%,
      var(--soft) 52%,
      #ffffff 100%
    ),
    repeating-linear-gradient(
      90deg,
      rgba(15, 95, 134, 0.04) 0 1px,
      transparent 1px 92px
    ),
    repeating-linear-gradient(
      180deg,
      rgba(11, 46, 90, 0.035) 0 1px,
      transparent 1px 92px
    );
}

.workspace-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

.auth-view {
  min-height: 100vh;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 28px;
  padding: 32px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 16px;
  width: min(100%, 440px);
}

.auth-brand img,
.sidebar-brand img {
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.auth-brand h1 {
  margin: 2px 0 0;
  font-size: 30px;
  line-height: 1.12;
  letter-spacing: 0;
}

.auth-panel {
  width: min(100%, 440px);
  display: grid;
  gap: 18px;
  justify-items: start;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

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

.app-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  padding: 14px;
  gap: 14px;
}

.sidebar,
.main-panel,
.auth-panel {
  backdrop-filter: blur(16px);
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 18px;
  min-height: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow-soft);
}

.sidebar-brand,
.company-strip,
.employee-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.sidebar-brand strong,
.company-strip strong,
.employee-strip strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.2;
  text-transform: uppercase;
}

.navigation {
  display: grid;
  gap: 8px;
}

.nav-button,
.conversation {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.nav-button {
  min-height: 42px;
  padding: 10px 12px;
  font-weight: 700;
}

.nav-button:hover,
.nav-button.active,
.conversation:hover,
.conversation.active {
  border-color: var(--line);
  background: var(--surface-soft);
}

.nav-button.active,
.conversation.active {
  color: var(--blue-deep);
  box-shadow: inset 3px 0 0 var(--blue);
}

.sidebar-meter {
  align-self: end;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-subtle);
  color: var(--muted);
}

.sidebar-meter strong {
  color: var(--ocean-deep);
  font-size: 22px;
  line-height: 1;
}

.main-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
}

.company-mark {
  position: relative;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: linear-gradient(135deg, var(--surface) 0%, var(--sea-glass) 100%);
  color: var(--ocean-deep);
  font-weight: 800;
}

.company-mark.large {
  width: 72px;
  height: 72px;
  font-size: 22px;
}

.company-mark img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 6px;
  background: var(--surface);
}

.company-mark img[hidden] {
  display: none;
}

.primary-action,
.ghost-action,
.danger-action,
.icon-action {
  min-height: 40px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    transform 140ms ease;
}

.primary-action {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #ffffff;
  padding: 9px 16px;
}

.primary-action:hover {
  border-color: var(--blue-deep);
  background: var(--blue-deep);
}

.ghost-action,
.danger-action {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 12px;
}

.ghost-action:hover {
  border-color: var(--ocean);
  color: var(--ocean-deep);
}

.danger-action {
  color: var(--danger);
}

.danger-action:hover {
  border-color: #f5b5ae;
  background: var(--danger-soft);
}

.icon-action {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--blue-deep);
  font-size: 22px;
  line-height: 1;
}

.icon-action:hover {
  border-color: var(--blue);
  background: var(--surface-soft);
}

button:disabled,
input:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.panel-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
}

.conversation-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-right: 1px solid var(--line);
  background: rgba(247, 251, 255, 0.72);
}

.section-heading,
.document-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.section-heading h2,
.document-toolbar h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
  letter-spacing: 0;
}

.document-toolbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.conversation-list {
  min-height: 0;
  overflow: auto;
  padding: 10px;
}

.conversation {
  display: grid;
  gap: 2px;
  min-height: 58px;
  padding: 10px;
}

.conversation strong,
.conversation span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation span {
  color: var(--muted);
  font-size: 12px;
}

.chat-panel,
.documents-panel {
  min-height: 0;
  display: grid;
}

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

.messages,
.documents {
  min-height: 0;
  overflow: auto;
  padding: 24px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  width: min(76%, 720px);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.message span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.message p {
  margin: 0;
  white-space: pre-wrap;
}

.message.assistant {
  align-self: flex-start;
  border-color: #bfd4f1;
  background: var(--surface-soft);
}

.message.user {
  align-self: flex-end;
  border-color: #b8d8d5;
  background: #eef8f8;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

textarea {
  min-height: 46px;
  max-height: 160px;
  resize: vertical;
  padding: 10px 12px;
}

input {
  min-height: 40px;
  padding: 8px 10px;
}

textarea:focus,
input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(30, 77, 183, 0.12);
}

.documents-panel {
  grid-template-rows: auto auto minmax(0, 1fr);
}

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

.upload-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.2fr) auto;
  gap: 12px;
  align-items: end;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-subtle);
}

.upload-row label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.documents {
  display: grid;
  align-content: start;
  gap: 12px;
}

.document-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 92px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.document-card h3 {
  margin: 8px 0 3px;
  font-size: 16px;
  line-height: 1.25;
  letter-spacing: 0;
}

.document-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

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

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--status-border, #b8d8d5);
  border-radius: 999px;
  background: var(--status-bg, #eef6f9);
  color: var(--ocean-deep);
  font-size: 12px;
  font-weight: 800;
  text-transform: capitalize;
}

.status.ready {
  --status-border: #b8d8d5;
  --status-bg: #eef8f8;
  color: var(--teal);
}

.status.processing {
  --status-border: #bfd4f1;
  --status-bg: #eef3ff;
  color: var(--blue-deep);
}

.status.failed {
  --status-border: #f5b5ae;
  --status-bg: #fff1f0;
  color: var(--danger);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.54);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 5;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  box-shadow: var(--shadow);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .app-view {
    min-height: 100vh;
    grid-template-columns: 1fr;
  }

  .sidebar {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    align-items: center;
  }

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

  .sidebar-meter {
    display: none;
  }

  .main-panel {
    min-height: 72vh;
  }
}

@media (max-width: 720px) {
  .auth-view {
    padding: 18px;
  }

  .auth-brand h1 {
    font-size: 24px;
  }

  .app-view {
    padding: 8px;
    gap: 8px;
  }

  .sidebar {
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .employee-strip {
    width: 100%;
    justify-content: space-between;
  }

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

  .conversation-panel {
    max-height: 190px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .conversation-list {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(190px, 1fr);
    overflow-x: auto;
  }

  .messages,
  .documents {
    padding: 14px;
  }

  .message {
    width: 100%;
  }

  .composer,
  .upload-row,
  .document-toolbar {
    grid-template-columns: 1fr;
  }

  .document-toolbar {
    align-items: stretch;
  }

  .section-heading,
  .document-toolbar {
    padding: 14px;
  }

  .upload-row {
    padding: 14px;
  }

  .search-box {
    width: 100%;
  }

  .document-card {
    align-items: stretch;
    flex-direction: column;
  }

  .document-actions {
    justify-content: flex-start;
  }
}
