/*
 * Application visual system.
 *
 * The interface is tuned as a compact operator console: calm neutral surfaces,
 * sparse blue action states, dense tables, and low-noise controls.
 */

:root {
  --background: #f7f9fb;
  --surface: #ffffff;
  --surface-low: #f2f4f6;
  --surface-mid: #eceef0;
  --surface-high: #e6e8ea;
  --surface-highest: #e0e3e5;
  --text: #191c1e;
  --text-soft: #344256;
  --muted: #515f74;
  --muted-2: #737686;
  --border: #c3c6d7;
  --border-soft: #dbe1ea;
  --primary: #004ac6;
  --primary-2: #2563eb;
  --primary-soft: #eef3ff;
  --primary-border: #b4c5ff;
  --good: #067647;
  --good-bg: #d8f5e5;
  --warn: #9a5a00;
  --warn-bg: #fff0c2;
  --bad: #ba1a1a;
  --bad-bg: #ffdad6;
  --sidebar-width: 240px;
  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 8px;
  --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

button {
  letter-spacing: 0;
}

.material-symbols-outlined {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  overflow: hidden;
  font-family: "Material Symbols Outlined";
  font-size: 20px;
  font-style: normal;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  font-feature-settings: "liga";
  -webkit-font-feature-settings: "liga";
  -webkit-font-smoothing: antialiased;
  font-variation-settings: "FILL" 0, "wght" 450, "GRAD" 0, "opsz" 24;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 8px 10px;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted-2);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary-2);
  box-shadow: var(--focus-ring);
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--border-soft);
  padding: 13px 16px;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--surface-low);
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 650;
  line-height: 16px;
  text-transform: uppercase;
}

tbody tr {
  transition: background-color 120ms ease;
}

tbody tr:hover {
  background: #fbfcff;
}

td {
  color: var(--text);
}

td a:first-child {
  font-weight: 650;
}

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

.signed-in .main-shell {
  min-width: 0;
  margin-left: var(--sidebar-width);
}

.signed-out .app-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.signed-out .main-shell {
  width: min(100%, 420px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: 28px;
}

.signed-out h2 {
  margin: 0 0 18px;
  font-size: 24px;
  line-height: 32px;
}

.signed-out form {
  display: grid;
  gap: 14px;
}

.signed-out input[type="checkbox"] {
  width: auto;
  min-height: auto;
}

.signed-out input[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
  padding: 8px 14px;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface-low);
  padding: 88px 10px 16px;
}

.sidebar-brand {
  display: grid;
  gap: 2px;
  margin-bottom: 24px;
  padding: 0 10px;
}

.brand {
  color: var(--text);
  font-size: 20px;
  font-weight: 850;
  line-height: 24px;
}

.brand:hover {
  text-decoration: none;
}

.sidebar-brand span {
  color: var(--text-soft);
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 520;
  transition: background-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.nav-link:hover {
  background: var(--surface-high);
  color: var(--text);
  text-decoration: none;
}

.nav-link:active {
  transform: scale(0.985);
}

.nav-link.active {
  background: var(--primary-2);
  color: #ffffff;
  font-weight: 750;
  box-shadow: inset 2px 0 0 var(--primary);
}

.nav-link .material-symbols-outlined {
  color: currentColor;
}

.sidebar-footer {
  display: grid;
  gap: 8px;
  margin-top: auto;
  border-top: 1px solid var(--border-soft);
  padding: 14px 10px 0;
}

.sidebar-footer span {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-soft);
  font-size: 13px;
}

.sidebar-footer .material-symbols-outlined {
  color: var(--muted);
  font-size: 18px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.94);
  padding: 0 24px;
  backdrop-filter: blur(12px);
}

.topbar-left,
.topbar-actions,
.user-chip {
  display: flex;
  align-items: center;
}

.topbar-left {
  min-width: 0;
  gap: 18px;
}

.topbar-brand {
  color: var(--primary);
  font-size: 18px;
  font-weight: 850;
}

.topbar-brand:hover {
  text-decoration: none;
}

.topbar-divider {
  width: 1px;
  height: 26px;
  background: var(--border);
}

.topbar-context {
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
}

.topbar-actions {
  gap: 10px;
}

.user-chip {
  max-width: min(42vw, 340px);
  gap: 8px;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: var(--surface-low);
  color: var(--text-soft);
  padding: 5px 10px 5px 6px;
  font-size: 13px;
}

.user-chip span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip .material-symbols-outlined {
  color: var(--primary);
}

.page {
  width: min(100%, 1440px);
  margin: 0 auto;
  padding: 34px 32px 56px;
}

.page.narrow {
  width: min(100%, 940px);
}

.page-header,
.panel-header,
.suggestion-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.page-header {
  margin-bottom: 24px;
}

.page-header h1,
.panel h2,
.suggestion h2,
.briefing-item h2 {
  margin: 0;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 780;
  line-height: 32px;
}

.panel h2,
.suggestion h2,
.briefing-item h2 {
  font-size: 18px;
  font-weight: 760;
  line-height: 26px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.subtle,
.table-subtitle {
  color: var(--muted);
}

.table-subtitle {
  max-width: 560px;
  margin: 5px 0 0;
  font-size: 13px;
  line-height: 19px;
}

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

.actions form {
  margin: 0;
}

.vertical-actions {
  align-items: stretch;
  flex-direction: column;
}

.button,
.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  line-height: 18px;
  padding: 8px 13px;
  text-decoration: none;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
  white-space: nowrap;
}

.button:hover,
.link-button:hover {
  border-color: var(--muted-2);
  background: var(--surface-high);
  text-decoration: none;
}

.button:active,
.link-button:active {
  transform: scale(0.975);
}

.button-primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.button-primary:hover {
  border-color: var(--primary);
  background: var(--primary-2);
  color: #ffffff;
}

.button-small {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--primary);
  padding: 0;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-soft);
  padding: 0;
}

.icon-button:hover {
  border-color: var(--border);
  background: var(--surface-high);
}

.text-link {
  color: var(--primary);
  font-size: 13px;
  font-weight: 750;
}

.flash {
  width: min(calc(100% - 64px), 1440px);
  margin: 16px auto 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 10px 14px;
}

.flash-notice {
  border-color: #9ddfc1;
  background: #ecfff4;
  color: #075e3b;
}

.flash-alert,
.form-errors,
.panel-alert {
  border-color: #f2aaa5;
  background: #fff3f1;
  color: #7f1111;
}

.form-errors {
  border: 1px solid #f2aaa5;
  border-radius: var(--radius);
  padding: 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.metric,
.panel,
.suggestion,
.briefing-item,
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.metric {
  min-height: 104px;
  padding: 18px 20px;
  transition: border-color 120ms ease, background-color 120ms ease;
}

.metric:hover {
  border-color: var(--primary-border);
  background: #fbfdff;
}

.metric span {
  display: block;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 10px;
  color: var(--text);
  font-size: 32px;
  font-weight: 820;
  line-height: 36px;
}

.split-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  margin-bottom: 24px;
}

.panel {
  padding: 18px 20px;
  margin-bottom: 24px;
}

.panel-header {
  margin-bottom: 14px;
}

.panel > .panel-header:first-child {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-soft);
}

.panel > .panel-header:first-child + .list,
.panel > .panel-header:first-child + .table-wrap,
.panel > .panel-header:first-child + .markdown-box,
.panel > .panel-header:first-child + .json-box {
  margin-top: 0;
}

.table-wrap {
  overflow-x: auto;
}

.table-wrap table {
  min-width: 720px;
}

.table-wrap-flat {
  border: 0;
  border-radius: 0;
}

.table-wrap-flat table {
  min-width: 640px;
}

.list {
  display: grid;
  margin-top: 12px;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
  padding: 12px 2px;
  transition: background-color 120ms ease;
}

.list-row:first-child {
  padding-top: 0;
}

.list-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.list-row:hover {
  background: #fbfcff;
  text-decoration: none;
}

.list-row span {
  min-width: 0;
}

.list-row strong {
  display: block;
  overflow-wrap: anywhere;
}

.list-row small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: var(--surface-low);
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 800;
  line-height: 16px;
  padding: 2px 9px;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-good {
  border-color: #a6e8c5;
  background: var(--good-bg);
  color: var(--good);
}

.badge-warn {
  border-color: #f1d684;
  background: var(--warn-bg);
  color: var(--warn);
}

.badge-bad {
  border-color: #f0aaa5;
  background: var(--bad-bg);
  color: var(--bad);
}

.badge-muted {
  color: var(--text-soft);
}

.form-stack {
  display: grid;
  gap: 16px;
}

.compact-form {
  gap: 12px;
}

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

.field-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  text-transform: none;
}

.check-row input,
td input[type="checkbox"] {
  width: auto;
  min-height: auto;
}

.small-input {
  max-width: 96px;
}

.markdown-box,
.json-box {
  max-height: 460px;
  overflow: auto;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: #fbfcff;
  color: var(--text-soft);
  padding: 14px;
  white-space: pre-wrap;
}

.json-box,
.markdown-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 18px;
}

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

.suggestion {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.suggestion-head {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-soft);
}

.topic-line {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
}

.filter-bar {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 0.8fr 0.8fr auto;
  gap: 12px;
  align-items: end;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: 14px;
  margin-bottom: 20px;
}

.table-actions {
  min-width: 230px;
}

.table-actions form {
  display: inline-block;
  margin: 0 4px 5px 0;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.score-grid div {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: #fbfcff;
  padding: 12px;
}

.score-grid span,
.detail-list dt {
  display: block;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.score-grid strong {
  display: block;
  margin-top: 6px;
  color: var(--text);
  font-size: 20px;
  font-weight: 780;
}

.copy-block h3 {
  margin: 18px 0 5px;
  color: var(--text-soft);
  font-size: 12px;
  text-transform: uppercase;
}

.copy-block p {
  max-width: 900px;
  margin: 0;
  color: var(--text);
}

.detail-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.detail-list div {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 12px;
}

.detail-list dd {
  margin: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

.briefing-list {
  display: grid;
  gap: 16px;
}

.briefing-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  gap: 18px;
  padding: 18px 20px;
}

.briefing-item p {
  margin: 10px 0 0;
}

.why {
  border-left: 3px solid var(--primary);
  color: var(--muted);
  padding-left: 12px;
}

.feedback-box {
  display: grid;
  align-content: start;
  gap: 10px;
}

.field_with_errors input,
.field_with_errors select,
.field_with_errors textarea {
  border-color: var(--bad);
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #cfd6e3;
}

::-webkit-scrollbar-thumb:hover {
  background: #b7c0cf;
}

@media (max-width: 1100px) {
  .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .score-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .signed-in .main-shell {
    margin-left: 0;
  }

  .sidebar {
    position: static;
    width: auto;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 16px;
  }

  .sidebar-brand {
    margin-bottom: 14px;
    padding: 0;
  }

  .nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    overflow-x: auto;
  }

  .nav-link {
    min-width: 116px;
    justify-content: center;
    padding: 10px 8px;
  }

  .sidebar-footer {
    display: none;
  }

  .topbar {
    height: auto;
    min-height: 60px;
    padding: 12px 16px;
  }

  .topbar-divider,
  .topbar-context {
    display: none;
  }

  .page {
    padding: 24px 16px 40px;
  }

  .page-header,
  .panel-header,
  .suggestion-head {
    display: grid;
  }

  .metric-grid,
  .split-grid,
  .suggestion-grid,
  .field-grid,
  .field-grid.two,
  .filter-bar,
  .score-grid,
  .briefing-item {
    grid-template-columns: 1fr;
  }

  .user-chip {
    max-width: 190px;
  }
}

@media (max-width: 560px) {
  th,
  td {
    padding: 11px 12px;
  }

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

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .user-chip {
    max-width: calc(100vw - 96px);
  }

  .nav {
    grid-template-columns: repeat(5, 126px);
  }

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

  .actions .button,
  .actions form,
  .actions form .button {
    width: 100%;
  }
}
