:root {
  color-scheme: light;
  --bg: #f3f4f1;
  --surface: #ffffff;
  --line: #c9cbc4;
  --line-strong: #aeb2aa;
  --text: #20251f;
  --muted: #62695f;
  --accent: #315d73;
  --accent-dark: #25485a;
  --danger: #9d3228;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Malgun Gothic", "Segoe UI", sans-serif;
  font-size: 14px;
}

button,
input {
  font: inherit;
}

button {
  height: 36px;
  border: 1px solid var(--accent-dark);
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

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

button:disabled {
  border-color: var(--line-strong);
  background: #d5d7d1;
  color: #777d74;
  cursor: default;
}

.shell {
  min-height: 100vh;
}

[hidden] {
  display: none !important;
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  display: grid;
  width: min(380px, 100%);
  gap: 16px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 28px rgba(32, 37, 31, 0.08);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 16px;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  color: var(--muted);
  font-size: 13px;
}

input {
  height: 36px;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
}

select {
  height: 36px;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 0 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

input:focus {
  outline: 2px solid rgba(49, 93, 115, 0.22);
  border-color: var(--accent);
}

input[readonly],
.computed-input {
  border-color: #d5d7d1;
  background: #f4f5f0;
  color: var(--muted);
  cursor: default;
}

input[readonly]:focus,
.computed-input:focus {
  outline: none;
  border-color: #d5d7d1;
}

.message {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  white-space: pre-line;
}

#app-view {
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.session-box {
  display: flex;
  align-items: center;
  gap: 12px;
}

.session-box span {
  color: var(--muted);
  font-weight: 700;
}

.session-box button {
  width: 90px;
}

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

.tabs {
  display: flex;
  gap: 6px;
  margin-top: 14px;
  border-bottom: 1px solid var(--line);
}

.tab-button {
  min-width: 104px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  background: #e7e8e2;
  color: var(--text);
}

.tab-button:hover,
.tab-button.active {
  border-color: var(--accent-dark);
  background: var(--accent);
  color: #fff;
}

.tab-page {
  display: none;
  padding-top: 14px;
  min-height: 0;
}

.tab-page.active {
  display: block;
}

.metrics article {
  display: grid;
  gap: 6px;
  min-height: 82px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metrics span,
.panel-header span {
  color: var(--muted);
  font-size: 13px;
}

.metrics strong {
  font-size: 24px;
  line-height: 1;
}

.tables {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
}

.dashboard-grid {
  align-items: start;
}

.dashboard-grid > .dashboard-charts,
.dashboard-grid > .dashboard-details {
  grid-column: 1 / -1;
}

.dashboard-charts {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
}

.dashboard-details {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
}

.dashboard-detail-table {
  height: 170px;
  max-height: 170px;
}

.dashboard-charts .panel {
  min-height: 0;
}

.chart-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  padding: 8px;
}

.chart-box {
  height: 260px;
  min-height: 260px;
  border: 1px solid var(--line);
  background: #fff;
}

.chart-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
}

.dashboard-grid .panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
}

.dashboard-table {
  height: 240px;
  max-height: 240px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.profile-bar {
  display: flex;
  align-items: end;
  gap: 8px;
  margin-bottom: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.profile-bar label {
  width: min(360px, 42vw);
}

.profile-bar button {
  width: auto;
  min-width: 84px;
  padding: 0 12px;
}

.bar-status {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.strategy-layout {
  display: grid;
  grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
  gap: 12px;
  height: calc(100vh - 185px);
  min-height: 0;
  overflow: hidden;
}

.left-pane,
.right-pane {
  display: grid;
  align-content: start;
  gap: 10px;
  min-width: 0;
}

.right-pane {
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.right-grid {
  display: grid;
  grid-template-columns: minmax(230px, 0.62fr) minmax(0, 1.38fr);
  gap: 10px;
  height: 100%;
  min-height: 0;
}

.strategy-layout .panel,
.right-grid .panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
}

.calculation-panel .readonly-form.single {
  gap: 6px;
  padding: 8px;
}

.calculation-panel .readonly-field {
  min-height: 40px;
  padding: 6px 8px;
}

.order-split-panel {
  min-width: 0;
}

.order-control-row {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(110px, 140px) minmax(220px, 360px);
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: #fafbf8;
}

.order-control-row label,
.order-inline-form label {
  display: grid;
  gap: 4px;
}

.order-control-row span,
.order-inline-form span {
  color: var(--muted);
  font-size: 12px;
}

.order-inline-form {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) auto;
  align-items: end;
  gap: 6px;
}

.order-inline-form button {
  min-width: 62px;
  padding: 0 10px;
}

.split-order-tables {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  padding: 8px;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.order-panel-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
}

.order-panel-tab {
  height: 30px;
  min-width: 78px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 5px 5px 0 0;
  background: #e7e8e2;
  color: var(--text);
  font-size: 13px;
}

.order-panel-tab:hover,
.order-panel-tab.active {
  border-color: var(--accent-dark);
  background: var(--accent);
  color: #fff;
}

.order-panel-page {
  display: none;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.order-panel-page.active {
  display: flex;
  flex-direction: column;
}

.order-result-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: #fafbf8;
}

.order-result-summary div {
  display: grid;
  gap: 4px;
  min-height: 42px;
  padding: 6px 8px;
  border: 1px solid #e1e3dc;
  border-radius: 6px;
  background: #fff;
}

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

.order-result-summary strong {
  font-size: 13px;
}

.order-result-table {
  flex: 1;
  max-height: none;
  min-height: 0;
}

.split-table-box {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border: 1px solid #e1e3dc;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}

.split-table-box h3 {
  margin: 0;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #f4f5f0;
  font-size: 13px;
  letter-spacing: 0;
}

.split-table-box .small-table {
  max-height: none;
  min-height: 0;
  flex: 1;
}

.inner-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border-bottom: 1px solid var(--line);
}

.inner-tab {
  height: 32px;
  min-width: 78px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 5px 5px 0 0;
  background: #e7e8e2;
  color: var(--text);
  font-size: 13px;
}

.inner-tab:hover,
.inner-tab.active {
  border-color: var(--accent-dark);
  background: var(--accent);
  color: #fff;
}

.inner-panel {
  display: none;
}

.inner-panel.active {
  display: block;
  max-height: calc(100vh - 245px);
  overflow: auto;
}

.compact-panel {
  border-radius: 0 8px 8px 8px;
}

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

.side-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.side-panel .panel-header button {
  width: 84px;
  height: 30px;
  font-size: 12px;
}

.work-panel {
  min-height: calc(100vh - 190px);
}

.profile-list {
  display: grid;
  gap: 4px;
  padding: 8px;
}

.profile-item {
  display: grid;
  gap: 2px;
  width: 100%;
  height: auto;
  min-height: 52px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.profile-item:hover,
.profile-item.active {
  border-color: var(--accent);
  background: #edf3f5;
  color: var(--text);
}

.profile-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.detail-grid {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

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

.readonly-form.single {
  grid-template-columns: 1fr;
  padding: 12px;
  gap: 8px;
}

.readonly-field {
  display: grid;
  gap: 4px;
  min-height: 48px;
  padding: 8px;
  border: 1px solid #e1e3dc;
  border-radius: 6px;
  background: #fafbf8;
}

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

.readonly-field strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subheader {
  border-top: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.header-actions {
  display: flex;
  gap: 6px;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 280px);
  min-height: 0;
}

.table-wrap.tall {
  max-height: calc(100vh - 390px);
}

.strategy-table {
  max-height: 220px;
  min-height: 0;
  flex: 0 1 auto;
}

.small-table {
  max-height: 320px;
}

.order-split-panel .small-table,
.right-pane > .panel:last-child .small-table {
  max-height: none;
  flex: 1;
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

th,
td {
  height: 34px;
  padding: 0 10px;
  border-bottom: 1px solid #e5e6e0;
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  background: #e7e8e2;
  color: #1e251f;
  font-weight: 700;
}

tbody tr:hover {
  background: #f7f8f4;
}

tbody tr.action-row {
  cursor: pointer;
}

tbody tr.action-row:hover {
  background: #e7f0f4;
}

tbody tr.selected-data-row {
  background: #d8e9f4;
  outline: 2px solid #2b7fbf;
  outline-offset: -2px;
}

.empty {
  color: var(--muted);
  text-align: center;
}

.api-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
  padding: 14px;
}

.api-layout > div {
  display: grid;
  align-content: start;
  gap: 12px;
}

.json-result {
  min-height: 220px;
  max-height: 360px;
  margin: 8px 14px 0;
  overflow: auto;
  border: 1px solid #e1e3dc;
  border-radius: 6px;
  padding: 10px;
  background: #fbfcfa;
  color: var(--text);
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre;
}

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

.api-layout .settings-form {
  padding: 0;
}

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

.settings-form.one-col {
  grid-template-columns: 1fr;
  padding: 12px;
}

.embedded-settings-form {
  padding: 0;
}

.padded-actions {
  padding: 0 12px 12px;
}

.padded-message {
  padding: 0 12px 12px;
}

.api-result-box {
  border-top: 1px solid var(--line);
}

.checkbox-grid {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
  padding: 12px;
  border: 1px solid #e1e3dc;
  border-radius: 6px;
  background: #fafbf8;
}

.checkbox-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.checkbox-grid input {
  width: 16px;
  height: 16px;
}

.form-actions {
  display: flex;
  grid-column: 1 / -1;
  gap: 8px;
}

.form-actions button {
  min-width: 120px;
}

.muted-message {
  grid-column: 1 / -1;
  color: var(--muted);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(25, 31, 34, 0.32);
}

.modal-overlay[hidden] {
  display: none;
}

.modal-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.18);
}

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

.modal-header h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0;
}

.modal-header button {
  width: 32px;
  min-width: 32px;
  height: 30px;
  padding: 0;
}

.modal-field {
  display: grid;
  gap: 6px;
  padding: 14px;
}

.modal-field span {
  color: var(--muted);
  font-size: 13px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 14px 14px;
}

.modal-actions button {
  min-width: 88px;
}

#profile-create-message {
  min-height: 18px;
  margin: -4px 14px 12px;
}

@media (max-width: 920px) {
  #app-view {
    padding: 12px;
  }

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

  .metrics,
  .tables,
  .workspace,
  .strategy-layout,
  .right-grid,
  .api-layout,
  .settings-form,
  .settings-form.two-col,
  .settings-form.one-col,
  .readonly-form,
  .checkbox-grid {
    grid-template-columns: 1fr;
  }

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

  .profile-bar label,
  .profile-bar button {
    width: 100%;
  }

  .tabs {
    overflow-x: auto;
  }

  .table-wrap {
    max-height: none;
  }
}
