:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --ink: #17211c;
  --muted: #66726d;
  --line: #d8dfd5;
  --panel: #ffffff;
  --accent: #0f6b5f;
  --accent-dark: #0a4e46;
  --blue: #254f8f;
  --amber: #a35f00;
  --danger: #a0292d;
  --shadow: 0 18px 55px rgba(20, 38, 30, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(15, 107, 95, 0.08), transparent 36%),
    linear-gradient(315deg, rgba(37, 79, 143, 0.09), transparent 42%),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 16px;
  color: #ffffff;
  background: var(--accent);
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

button.secondary {
  border: 1px solid var(--line);
  color: var(--ink);
  background: #ffffff;
}

button.secondary:hover {
  border-color: #aeb9b3;
  background: #eef3ef;
}

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

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 107, 95, 0.14);
}

.shell {
  min-height: 100vh;
}

.login-view {
  width: min(420px, calc(100vw - 32px));
  margin: 0 auto;
  padding-top: 14vh;
}

.brand-mark {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  font-weight: 800;
  font-size: 1.3rem;
  box-shadow: var(--shadow);
}

.brand-mark.small {
  width: 38px;
  height: 38px;
  font-size: 1rem;
  box-shadow: none;
}

h1 {
  margin: 20px 0 24px;
  font-size: 2.25rem;
  line-height: 1.05;
}

.login-form {
  display: grid;
  gap: 16px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}

input {
  min-height: 44px;
  padding: 0 12px;
}

.error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 0.9rem;
}

.app-view {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 70px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(12px);
}

.identity {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.identity strong {
  display: block;
  line-height: 1.2;
}

.identity span {
  display: block;
  overflow: hidden;
  max-width: 60vw;
  color: var(--muted);
  font-size: 0.86rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.portal-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: auto;
}

.portal-nav a {
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.portal-nav a:hover,
.portal-nav [data-friday-open] {
  color: #ffffff;
  background: var(--accent);
}

.portal-content {
  width: min(1180px, calc(100vw - 36px));
  margin: 0 auto;
  padding: 42px 0;
}

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

.portal-panel {
  min-height: 170px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #ffffff;
}

.portal-panel p {
  color: var(--muted);
  line-height: 1.5;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  min-height: calc(100vh - 70px);
}

.workspace.cfo-open {
  grid-template-columns: minmax(260px, 330px) minmax(0, 1fr) minmax(320px, 420px);
}

.context-rail {
  display: grid;
  align-content: start;
  gap: 20px;
  overflow: auto;
  max-height: calc(100vh - 70px);
  padding: 22px;
  border-right: 1px solid var(--line);
  background: rgba(250, 252, 249, 0.92);
}

.context-rail section {
  display: grid;
  gap: 10px;
}

h2 {
  margin: 0;
  font-size: 0.84rem;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--muted);
}

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

.list-item {
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.list-item strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.list-item span,
.list-item p {
  display: block;
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.compact .list-item {
  padding: 8px 10px;
}

.chat-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: calc(100vh - 70px);
}

.cfo-panel {
  display: grid;
  align-content: start;
  gap: 18px;
  overflow: auto;
  max-height: calc(100vh - 70px);
  padding: 22px;
  border-left: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.cfo-panel[hidden] {
  display: none;
}

.cfo-panel section {
  display: grid;
  gap: 10px;
}

.cfo-header {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.cfo-header strong {
  display: block;
  margin-top: 4px;
  font-size: 1.9rem;
  line-height: 1;
}

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

.cfo-summary > div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f7faf7;
}

.cfo-summary span {
  display: block;
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 700;
  text-transform: uppercase;
}

.cfo-summary strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 1rem;
}

.utility-grid {
  display: grid;
  gap: 8px;
}

.maintenance-plug {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfb;
}

.maintenance-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.maintenance-head strong {
  display: block;
  margin-top: 4px;
  font-size: 1.6rem;
  line-height: 1;
}

.maintenance-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.status-pill {
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  background: #eef3ef;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: capitalize;
  white-space: nowrap;
}

.status-pill.good,
.status-pill.healthy {
  color: var(--accent-dark);
  background: #e7f4f0;
}

.status-pill.watch {
  color: #704000;
  background: #fff2d9;
}

.status-pill.risk,
.status-pill.critical_attention {
  color: var(--danger);
  background: #fdebed;
}

.utility-item {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  padding: 11px;
  background: #ffffff;
}

.utility-item.good {
  border-left-color: var(--accent);
}

.utility-item.watch {
  border-left-color: var(--amber);
}

.utility-item.risk {
  border-left-color: var(--danger);
}

.utility-item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.utility-item strong {
  font-size: 0.9rem;
}

.utility-item span {
  border-radius: 999px;
  padding: 3px 7px;
  color: var(--muted);
  background: #eef3ef;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: capitalize;
  white-space: nowrap;
}

.utility-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.messages {
  display: grid;
  align-content: start;
  gap: 14px;
  overflow: auto;
  padding: 26px;
}

.message {
  width: min(850px, 100%);
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  line-height: 1.5;
  white-space: pre-wrap;
}

.message.user {
  justify-self: end;
  border-color: rgba(15, 107, 95, 0.35);
  background: #eff8f5;
}

.message.friday {
  justify-self: start;
}

.message.meta {
  border-color: rgba(163, 95, 0, 0.25);
  color: #694000;
  background: #fff8ed;
  font-size: 0.9rem;
}

.citations {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.citation {
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.86rem;
}

.composer {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr) 110px;
  gap: 12px;
  padding: 18px 24px 24px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
}

.mode-select {
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #ffffff;
}

textarea {
  min-height: 72px;
  max-height: 180px;
  resize: vertical;
  padding: 12px;
  line-height: 1.45;
}

@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 1fr;
  }

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

  .context-rail {
    order: 2;
    max-height: none;
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .chat-panel {
    min-height: 68vh;
  }

  .cfo-panel {
    order: 3;
    max-height: none;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

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

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

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