:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f9fbfc;
  --line: #d9e1e8;
  --line-soft: #edf1f5;
  --text: #111827;
  --muted: #5f6f82;
  --brand: #0f766e;
  --brand-2: #115e59;
  --brand-soft: #e5f4f2;
  --soft: #eef8f6;
  --danger: #a7352a;
  --shadow: 0 20px 50px rgba(20, 32, 45, .16);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

.layout {
  display: grid;
  grid-template-columns: 318px minmax(360px, 1fr) minmax(380px, 40vw);
  height: 100vh;
  height: 100dvh;
  gap: 0;
  background: var(--bg);
  overflow: hidden;
}

.layout.admin-layout {
  grid-template-columns: 340px minmax(0, 1fr);
}

.rail,
.chat-pane,
.reader-pane {
  background: var(--panel);
  min-height: 0;
  overflow: hidden;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
  overflow: auto;
}

.brand {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 12px;
  align-items: center;
}

.mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--brand);
  color: white;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.1;
}

h2 {
  font-size: 14px;
  margin-bottom: 12px;
}

p,
span,
.status {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.box,
.profile-card,
.sidebar-card,
.action-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel);
}

.profile-card {
  padding: 12px;
}

.sidebar-card,
.action-card {
  border-color: var(--line-soft);
}

.action-card {
  display: grid;
  gap: 12px;
}

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

.action-button {
  display: grid;
  align-content: center;
  gap: 4px;
  min-height: 70px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  text-align: left;
}

.action-button:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.action-button.primary {
  border-color: transparent;
  background: var(--brand);
  color: white;
}

.action-button.primary:hover {
  background: var(--brand-2);
}

.action-button span {
  color: inherit;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
}

.action-button small {
  color: currentColor;
  font-size: 11px;
  font-weight: 700;
  opacity: .72;
  line-height: 1.25;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
}

button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--brand);
  color: white;
  cursor: pointer;
  font-weight: 800;
}

button:hover {
  background: var(--brand-2);
}

button:disabled {
  opacity: .65;
  cursor: wait;
}

button.ghost {
  background: #eef3f6;
  color: var(--text);
  padding: 8px 11px;
}

button.ghost:hover {
  background: #dfe8ee;
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.user-row strong {
  font-size: 14px;
}

.small-list {
  display: grid;
  gap: 8px;
  max-height: 190px;
  overflow: auto;
}

.small-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #ffffff;
  cursor: pointer;
}

.small-item:hover {
  border-color: var(--brand);
}

.small-item strong,
.small-item span {
  display: block;
}

.small-item strong {
  font-size: 13px;
}

.small-item span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.status {
  min-height: 20px;
  margin-top: 10px;
}

.notice {
  border: 1px solid #f1d28a;
  border-radius: 8px;
  background: #fff8e8;
  color: #6f5512;
  padding: 10px;
  font-size: 13px;
  line-height: 1.45;
  margin-bottom: 12px;
}

.check-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.check-row input {
  width: auto;
}

.metric-stack {
  display: grid;
  gap: 7px;
}

.metric-stack span,
.metric-stack strong {
  font-size: 13px;
}

.workspace-pane {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #f7f9fb;
}

.workspace-scroll {
  display: grid;
  align-content: start;
  gap: 16px;
  min-height: 0;
  overflow: auto;
  padding: 20px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: white;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
}

.metrics-grid.compact {
  grid-template-columns: repeat(5, minmax(110px, 1fr));
  margin-bottom: 12px;
}

.metric {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 13px;
  background: #fbfcfd;
}

.metric strong,
.metric span {
  display: block;
}

.metric strong {
  color: var(--text);
  font-size: 22px;
  line-height: 1.1;
}

.metric span {
  margin-top: 5px;
}

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

.data-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.data-item strong,
.data-item span {
  display: block;
}

.data-item strong {
  color: var(--text);
  font-size: 13px;
  margin-bottom: 4px;
}

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

.chat-pane {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  border-right: 1px solid var(--line);
}

.topbar,
.reader-header {
  border-bottom: 1px solid var(--line);
  padding: 18px 22px;
  background: #ffffff;
}

.topbar strong {
  display: block;
  margin-bottom: 3px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: auto;
  padding: 24px;
  background: #f8fafb;
}

.msg {
  max-width: 780px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 13px 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.msg.user {
  align-self: flex-end;
  background: var(--soft);
  border-color: #c9e4df;
}

.msg.assistant {
  align-self: flex-start;
  background: white;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 16px 18px;
  background: #ffffff;
}

.composer textarea {
  min-height: 48px;
  max-height: 92px;
  resize: none;
}

.reader-pane {
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-width: 0;
}

.sources {
  display: grid;
  gap: 10px;
  max-height: 230px;
  overflow: auto;
  border-bottom: 1px solid var(--line);
  padding: 14px;
  background: #fbfcfd;
}

.source {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
  cursor: pointer;
}

.source:hover {
  border-color: var(--brand);
}

.source strong,
.source span {
  display: block;
}

.source strong {
  font-size: 13px;
  margin-bottom: 4px;
}

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

.empty {
  color: var(--muted);
  font-size: 13px;
}

iframe {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  background: #f8fafc;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 22px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .46);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 16px;
  width: min(520px, 100%);
  max-height: min(760px, calc(100vh - 44px));
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: 8px;
  background: #ffffff;
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal-dialog.wide {
  width: min(760px, 100%);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 14px;
}

.modal-header h2 {
  margin-bottom: 4px;
  font-size: 18px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 8px;
  background: #eef3f6;
  color: var(--text);
  line-height: 1;
}

.icon-button:hover {
  background: #dfe8ee;
}

.modal-form {
  display: grid;
  gap: 12px;
}

.form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 14px;
}

.form-span {
  grid-column: 1 / -1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 2px;
}

body.modal-open {
  overflow: hidden;
}

@media (max-width: 1040px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) minmax(240px, 38vh);
  }

  .layout.admin-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .rail {
    max-height: 34vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .metrics-grid,
  .metrics-grid.compact {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  iframe {
    min-height: 0;
  }
}

@media (max-width: 680px) {
  .layout {
    grid-template-rows: auto minmax(0, 1fr) minmax(220px, 34vh);
  }

  .rail {
    padding: 16px;
  }

  .brand {
    grid-template-columns: 42px 1fr;
  }

  .mark {
    width: 42px;
    height: 42px;
  }

  .action-grid,
  .form-grid,
  .composer {
    grid-template-columns: 1fr;
  }

  .modal {
    align-items: end;
    padding: 12px;
  }

  .modal-dialog,
  .modal-dialog.wide {
    width: 100%;
    max-height: calc(100vh - 24px);
  }

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

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

.login-body {
  display: grid;
  place-items: center;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  overflow: auto;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(21, 39, 55, .08);
}

.login-brand {
  margin-bottom: 22px;
}

.login-form {
  display: grid;
  gap: 4px;
}

.login-error {
  margin-top: 14px;
  border: 1px solid #f0b8b2;
  border-radius: 8px;
  background: #fff3f1;
  color: var(--danger);
  padding: 10px;
  font-size: 13px;
}
