:root {
  --layer-01: #ffffff;
  --layer-02: #f4f4f4;
  --layer-accent: #e0e0e0;
  --text-primary: #161616;
  --text-secondary: #525252;
  --text-helper: #6f6f6f;
  --text-placeholder: #a8a8a8;
  --border-subtle: #e0e0e0;
  --border-strong: #8d8d8d;
  --interactive: #0f62fe;
  --interactive-hover: #0353e9;
  --support-success: #198038;
  --support-error: #da1e28;
  --support-warning: #f1c21b;
  --support-info: #0043ce;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
}

[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--text-primary);
  background: var(--layer-02);
  font-family: var(--sans);
  font-size: 0.875rem;
  line-height: 1.29;
}

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.shell-header {
  flex-shrink: 0;
  background: var(--layer-01);
  border-bottom: 1px solid var(--border-subtle);
}

.shell-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3rem;
  padding: 0.625rem 1rem;
  width: min(96rem, 100%);
  margin: 0 auto;
}

.shell-header-title-block {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.shell-header-brand {
  flex-shrink: 0;
  color: var(--text-primary);
  font-size: 0.875rem;
  font-weight: 600;
}

.shell-header-brand::after {
  content: "";
  display: inline-block;
  width: 1px;
  height: 1rem;
  margin-left: 0.75rem;
  background: var(--border-subtle);
  vertical-align: middle;
}

.shell-header-title {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 400;
}

.shell-header-actions {
  flex-shrink: 0;
}

.field-inline {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.field-label {
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 400;
}

select,
input {
  height: 2.5rem;
  padding: 0 2rem 0 1rem;
  border: none;
  border-bottom: 1px solid var(--border-strong);
  background: var(--layer-02);
  color: var(--text-primary);
  font: inherit;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='%23161616'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
}

select {
  min-width: 18rem;
}

input {
  padding: 0 1rem;
  background: var(--layer-01);
  border: 1px solid var(--border-strong);
  background-image: none;
}

select:focus,
input:focus {
  outline: 2px solid var(--interactive);
  outline-offset: -2px;
}

input:disabled {
  background: var(--layer-02);
  color: var(--text-placeholder);
  border-color: var(--border-subtle);
}

.shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: min(96rem, 100%);
  margin: 0 auto;
  padding: 1rem;
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(16rem, 0.85fr);
  gap: 1rem;
  align-items: stretch;
  min-height: 0;
}

.main-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
  min-height: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  flex-shrink: 0;
  background: var(--border-subtle);
  border: 1px solid var(--border-subtle);
}

.stat {
  min-height: 5.5rem;
  padding: 0.75rem 1rem;
  background: var(--layer-01);
}

.stat-pending {
  background: var(--layer-02);
}

.stat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.stat-label {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 400;
}

.stat-status {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--support-success);
}

.stat-status-pending {
  background: var(--text-placeholder);
}

.stat-value {
  margin: 0.35rem 0 0.1rem;
  font: 1.375rem/1.2 var(--mono);
  font-weight: 400;
  color: var(--text-primary);
}

.stat-value-pending {
  color: var(--text-placeholder);
}

.stat-note {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.75rem;
  line-height: 1.34;
}

.stat-detail {
  display: none;
}

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--border-subtle);
  background: var(--layer-01);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.panel-header h2 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.btn-primary {
  min-height: 2.5rem;
  padding: 0.625rem 1rem;
  color: #fff;
  background: var(--interactive);
  font-size: 0.875rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.btn-primary:hover:not(:disabled) {
  background: var(--interactive-hover);
}

.btn-primary:disabled {
  background: var(--layer-accent);
  color: var(--text-placeholder);
  cursor: not-allowed;
}

.chat-thread {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem;
  background: var(--layer-02);
}

.chat-empty {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 0;
  padding: 1rem;
  color: var(--text-secondary);
  text-align: center;
}

.chat-empty strong {
  color: var(--text-primary);
  font-size: 0.875rem;
  font-weight: 600;
}

.chat-empty span {
  max-width: 24rem;
  font-size: 0.75rem;
  line-height: 1.5;
}

.chat-message {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  width: min(90%, 42rem);
}

.chat-message.user {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-message.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-meta {
  display: none;
}

.chat-role {
  color: var(--text-helper);
  font-size: 0.75rem;
  font-weight: 400;
}

.chat-message.user .chat-role {
  text-align: right;
}

.chat-bubble {
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-subtle);
  background: var(--layer-01);
  font-size: 0.875rem;
  line-height: 1.43;
}

.chat-message.user .chat-bubble {
  border-color: var(--interactive);
  color: #fff;
  background: var(--interactive);
}

.chat-message.assistant .chat-bubble {
  border-left: 3px solid var(--interactive);
}

.chat-message.error .chat-bubble {
  border-left-color: var(--support-error);
  color: #750e13;
  background: #fff1f1;
}

.chat-bubble p {
  margin: 0 0 0.5rem;
}

.chat-bubble p:last-of-type {
  margin-bottom: 0;
}

.chat-bubble h1,
.chat-bubble h2,
.chat-bubble h3 {
  margin: 0.75rem 0 0.35rem;
  line-height: 1.25;
  font-weight: 600;
}

.chat-bubble h1 { font-size: 1rem; }
.chat-bubble h2 { font-size: 0.95rem; }
.chat-bubble h3 { font-size: 0.9rem; }

.chat-bubble h3.md-section {
  margin: 0.85rem 0 0.35rem;
  color: var(--text-primary, #161616);
  font-size: 0.875rem;
}

.chat-bubble h1:first-child,
.chat-bubble h2:first-child,
.chat-bubble h3:first-child {
  margin-top: 0;
}

.chat-bubble ul,
.chat-bubble ol {
  margin: 0 0 0.65rem 1.15rem;
  padding: 0;
}

.chat-bubble li {
  margin: 0 0 0.35rem;
}

.chat-bubble li:last-child {
  margin-bottom: 0;
}

.chat-bubble strong {
  font-weight: 600;
}

.chat-bubble code {
  padding: 0.08rem 0.25rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8em;
  background: #f4f4f4;
}

.chat-bubble hr {
  border: 0;
  border-top: 1px solid var(--border-subtle);
  margin: 0.75rem 0;
}

.md-table-wrap {
  overflow-x: auto;
  margin: 0.5rem 0 0.75rem;
  border: 1px solid var(--border-subtle);
  background: #fafbfc;
}

.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  line-height: 1.45;
}

.md-table th,
.md-table td {
  padding: 0.45rem 0.55rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border-subtle);
}

.md-table th {
  background: #eef2f5;
  font-weight: 600;
}

.md-table tr:last-child td {
  border-bottom: 0;
}

.chat-bubble small {
  display: block;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.75rem;
  line-height: 1.34;
}

.chat-message.user .chat-bubble small {
  border-top-color: rgba(255, 255, 255, 0.25);
  color: #d0e2ff;
}

.chat-bubble.loading {
  color: var(--text-secondary);
  font-style: italic;
}

.chat-form {
  display: flex;
  gap: 0;
  flex-shrink: 0;
  border-top: 1px solid var(--border-subtle);
  background: var(--layer-01);
}

.chat-form input {
  flex: 1;
  min-width: 0;
  border: 0;
  border-right: 1px solid var(--border-subtle);
}

.chat-form .btn-primary {
  flex-shrink: 0;
  min-width: 5rem;
}

.charts-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
  min-height: 0;
}

.charts-placeholder {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  min-height: 0;
  padding: 1rem;
  border: 1px dashed var(--border-strong);
  background: var(--layer-01);
  color: var(--text-secondary);
  text-align: center;
}

.charts-placeholder strong {
  color: var(--text-primary);
  font-size: 0.875rem;
  font-weight: 600;
}

.charts-placeholder span {
  font-size: 0.75rem;
  line-height: 1.43;
}

.chart-card {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-subtle);
  background: var(--layer-01);
}

.chart-card header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

.chart-card h3 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
}

.chart-meta {
  color: var(--text-helper);
  font-size: 0.75rem;
}

.chart-body {
  flex: 1;
  min-height: 5rem;
  position: relative;
}

.chart-body canvas {
  width: 100% !important;
  height: 100% !important;
}

.empty {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.footer-note {
  flex-shrink: 0;
  margin: 0;
  padding: 0.5rem 1rem 0.75rem;
  width: min(96rem, 100%);
  margin-inline: auto;
  color: var(--text-helper);
  font-size: 0.75rem;
  text-align: center;
}

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

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

  .app {
    height: auto;
    min-height: 100%;
    overflow: visible;
  }

  .shell {
    flex: none;
    min-height: auto;
  }

  .workspace {
    grid-template-columns: 1fr;
    flex: none;
    min-height: auto;
  }

  .main-column {
    min-height: auto;
  }

  .chat-panel {
    min-height: 24rem;
  }

  .chat-thread {
    min-height: 14rem;
    max-height: 24rem;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .shell-header-inner {
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem 1rem;
  }

  .shell-header-title-block {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }

  .shell-header-brand::after {
    display: none;
  }

  .shell-header-actions select {
    width: 100%;
    min-width: 0;
  }

  .charts-column {
    min-height: auto;
  }

  .chart-card {
    flex: none;
  }

  .chart-body {
    height: 8rem;
  }
}

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

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

  .panel-header .btn-primary {
    width: 100%;
  }
}
