:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #eef3f3;
  --text: #1f2933;
  --muted: #64707d;
  --border: #d7dee5;
  --accent: #117a7a;
  --accent-strong: #0d5f5f;
  --warn: #b45309;
  --danger: #b42318;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: grid;
  column-gap: 12px;
  grid-template-columns: 252px minmax(0, 1fr);
  row-gap: 10px;
  padding: 10px 18px;
}

.brand-heading {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: center;
  min-height: 56px;
  min-width: 0;
  text-align: center;
}

.brand-logo {
  border-radius: 50%;
  flex: 0 0 56px;
  height: 56px;
  object-fit: cover;
  width: 56px;
}

.header-toolbar {
  align-items: center;
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  justify-content: flex-end;
  min-width: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 700;
  white-space: nowrap;
}

.brand-heading h1 {
  font-size: 40px;
  line-height: 1.05;
  text-align: center;
}

h2 {
  font-size: 16px;
}

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

button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  min-height: 34px;
  padding: 7px 12px;
}

button:hover {
  border-color: var(--accent);
}

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

.tab-list button {
  position: relative;
}

.tab-list button.loading {
  cursor: progress;
}

.tab-list button.loading::after {
  animation: tab-loading-spin 0.8s linear infinite;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  content: "";
  height: 13px;
  margin-top: -6.5px;
  opacity: 0.9;
  position: absolute;
  right: 11px;
  top: 50%;
  width: 13px;
}

@keyframes tab-loading-spin {
  to {
    transform: rotate(360deg);
  }
}

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

input {
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  margin-left: 6px;
  padding: 6px 8px;
  width: 88px;
}

.header-actions,
.calc-controls,
.panel-actions,
.panel-title {
  align-items: center;
  display: flex;
  gap: 10px;
}

.header-actions {
  flex: 0 0 auto;
  flex-wrap: nowrap;
  gap: 8px;
  justify-content: flex-end;
  min-width: 0;
}

.header-actions button {
  min-height: 32px;
  padding: 6px 10px;
}

.auto-refresh-control {
  align-items: center;
  display: inline-flex;
  gap: 6px;
}

.auto-refresh-control input {
  margin-left: 0;
  padding-left: 6px;
  padding-right: 6px;
  width: 54px;
}

#autoRefreshStatus {
  min-width: 0;
  white-space: nowrap;
}

.layout {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  padding: 12px 18px 18px;
}

.workspace {
  display: grid;
  gap: 12px;
  grid-template-columns: 252px minmax(0, 1fr);
  min-width: 0;
}

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

.side-panel {
  padding: 14px;
}

.data-panel {
  position: relative;
}

.data-panel-header {
  align-items: center;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  min-height: 66px;
  padding: 10px 14px;
}

.active-table-heading {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.active-table-meta {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  line-height: 1.4;
}

.active-table-meta-main {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.active-table-meta-note {
  color: var(--muted);
  font-size: 13px;
}

.active-table-meta-chip {
  background: #e8f4f4;
  border: 1px solid #b7dcdc;
  border-radius: 999px;
  color: var(--accent-strong);
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 5px 8px;
  white-space: nowrap;
}

.side-panel > h2 {
  font-size: 20px;
  line-height: 1.2;
  margin-top: 4px;
  text-align: center;
}

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

.side-controls {
  border-top: 1px solid var(--border);
  display: grid;
  gap: 0;
  margin-top: 14px;
  padding-top: 12px;
}

.side-control-group {
  display: none;
  gap: 6px;
  padding: 0 0 12px;
}

.side-control-group:has(.side-control-row:not([hidden])) {
  display: grid;
}

.side-control-group + .side-control-group:has(.side-control-row:not([hidden])) {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.side-control-group-title {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 12px;
  font-weight: 700;
  gap: 8px;
  line-height: 1.2;
}

.side-control-group-title::before {
  background: var(--accent);
  border-radius: 999px;
  content: "";
  flex: 0 0 auto;
  height: 18px;
  width: 4px;
}

.side-control-row {
  align-items: center;
  column-gap: 6px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px 34px;
  min-height: 32px;
}

.side-control-text {
  font-weight: 600;
  line-height: 1.2;
  min-width: 0;
  white-space: nowrap;
}

.side-control-row input {
  grid-column: 2;
  justify-self: end;
  margin: 0;
  min-height: 32px;
  width: 64px;
}

.side-control-row[hidden] {
  display: none;
}

.side-control-row:has(input[type="checkbox"]) {
  border-radius: 6px;
}

.side-control-row:has(input[type="checkbox"]:hover) {
  background: #f5f8fa;
}

.unit-input {
  display: contents;
}

.unit-input span {
  font-size: 12px;
  grid-column: 3;
  white-space: nowrap;
}

.lof-trade-filter input {
  text-align: right;
  width: 64px;
}

.lof-code-filter input {
  grid-column: 1;
  justify-self: stretch;
  width: 100%;
}

.lof-code-filter {
  align-items: stretch;
  gap: 6px;
  grid-template-columns: minmax(0, 1fr);
}

.lof-code-filter .side-control-text {
  height: 1px;
  overflow: hidden;
  position: absolute;
  width: 1px;
}

.filter-reset-row {
  grid-template-columns: minmax(0, 1fr);
  margin-top: 6px;
}

.filter-reset-row button {
  grid-column: 1;
  justify-self: center;
  min-height: 32px;
  padding: 0 14px;
  width: min(150px, 100%);
}

.side-control-row input[type="checkbox"] {
  appearance: none;
  background:
    radial-gradient(circle at 10px 50%, #fff 0 7px, transparent 7.5px),
    #d7e1ea;
  border-color: #c6d2dc;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(100, 112, 125, 0.08);
  cursor: pointer;
  grid-column: 2;
  height: 22px;
  justify-self: center;
  min-height: 22px;
  padding: 0;
  transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  width: 40px;
}

.side-control-row input[type="checkbox"]:checked {
  background:
    radial-gradient(circle at 30px 50%, #fff 0 7px, transparent 7.5px),
    var(--accent);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(13, 95, 95, 0.12);
}

.side-control-row input[type="checkbox"]:focus-visible {
  outline: 2px solid rgba(17, 122, 122, 0.28);
  outline-offset: 2px;
}

.panel-title {
  border-bottom: 1px solid var(--border);
  justify-content: space-between;
  padding: 12px 14px;
}

.panel-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.table-wrap {
  cursor: default;
  max-height: 430px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #8fbebb #f4f7f7;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  user-select: text;
  -webkit-user-select: text;
}

.table-wrap::-webkit-scrollbar {
  height: 14px;
  width: 14px;
}

.table-wrap::-webkit-scrollbar-track {
  background: #f4f7f7;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: #8fbebb;
  border: 3px solid #f4f7f7;
  border-radius: 999px;
}

.table-wrap::-webkit-scrollbar-corner {
  background: #f4f7f7;
}

.table-scrollbar-row {
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 8px 10px 10px;
}

.table-scrollbar-row[hidden] {
  display: none;
}

.table-scrollbar-range {
  appearance: none;
  background: transparent;
  cursor: pointer;
  display: block;
  height: 18px;
  margin: 0;
  min-height: 18px;
  padding: 0;
  width: 100%;
}

.table-scrollbar-range::-webkit-slider-runnable-track {
  background: #f4f7f7;
  border: 1px solid #d6e2e1;
  border-radius: 999px;
  height: 12px;
}

.table-scrollbar-range::-webkit-slider-thumb {
  appearance: none;
  background: #8fbebb;
  border: 2px solid #f4f7f7;
  border-radius: 999px;
  height: 18px;
  margin-top: -4px;
  width: 56px;
}

.table-scrollbar-range:focus-visible {
  outline: 2px solid rgba(17, 122, 122, 0.28);
  outline-offset: 3px;
}

.table-scrollbar-range::-moz-range-track {
  background: #f4f7f7;
  border: 1px solid #d6e2e1;
  border-radius: 999px;
  height: 12px;
}

.table-scrollbar-range::-moz-range-thumb {
  background: #8fbebb;
  border: 2px solid #f4f7f7;
  border-radius: 999px;
  height: 16px;
  width: 56px;
}

.data-panel-status {
  align-items: center;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(31, 41, 51, 0.08);
  display: grid;
  gap: 8px;
  justify-items: center;
  left: 50%;
  min-width: min(320px, calc(100% - 40px));
  padding: 22px 26px;
  pointer-events: none;
  position: absolute;
  text-align: center;
  top: 38%;
  transform: translate(-50%, -50%);
  z-index: 6;
}

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

.data-panel-status strong {
  color: var(--text);
  font-size: 16px;
  line-height: 1.3;
}

.data-panel-status-detail {
  line-height: 1.4;
}

.data-panel-status-spinner {
  animation: tab-loading-spin 0.8s linear infinite;
  border: 3px solid rgba(17, 122, 122, 0.18);
  border-right-color: var(--accent);
  border-radius: 50%;
  height: 28px;
  width: 28px;
}

.data-panel-status[data-state="error"] .data-panel-status-spinner {
  animation: none;
  border-color: var(--danger);
}

.data-panel .table-wrap {
  height: clamp(580px, calc(100vh - 236px), 1130px);
  max-height: clamp(580px, calc(100vh - 236px), 1130px);
}

.layout:has(.log-panel:not([hidden])) .data-panel .table-wrap {
  height: clamp(460px, calc(100vh - 516px), 700px);
  max-height: clamp(460px, calc(100vh - 516px), 700px);
}

table {
  border-collapse: collapse;
  font-size: 13px;
  min-width: 100%;
  table-layout: fixed;
  width: max-content;
}

th,
td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  cursor: text;
  overflow: hidden;
  padding: 8px 10px;
  text-align: left;
  text-overflow: ellipsis;
  user-select: text;
  -webkit-user-select: text;
  white-space: nowrap;
}

th:last-child,
td:last-child {
  border-right: 0;
}

th {
  background: var(--surface-muted);
  overflow: visible;
  position: sticky;
  text-align: center;
  top: 0;
  z-index: 3;
}

#dataTable td {
  text-align: center;
}

tbody tr:nth-child(even) td {
  background: #f7f9fc;
}

tbody tr:nth-child(odd) td {
  background: #fff;
}

.table-empty-cell {
  background: #fff;
  color: var(--muted);
  font-weight: 600;
  height: 56px;
  padding: 0;
  position: relative;
}

#dataTable .table-empty-cell,
#calcTable .table-empty-cell {
  text-align: center;
}

.table-empty-message {
  align-items: center;
  bottom: 0;
  display: flex;
  justify-content: center;
  left: 0;
  line-height: 1.4;
  pointer-events: none;
  position: absolute;
  top: 0;
}

table[data-selectable-rows="true"] tbody tr[data-row-key] {
  cursor: pointer;
}

table[data-selectable-rows="true"] tbody tr[data-row-key] td {
  cursor: text;
}

table[data-selectable-rows="true"] tbody tr[data-row-key]:hover td {
  background: #e8f3f3;
}

.sticky-column {
  box-shadow: inset -1px 0 var(--border);
  position: sticky;
  z-index: 2;
}

th.sticky-column {
  z-index: 4;
}

.sticky-column-last {
  box-shadow:
    inset -1px 0 var(--border),
    8px 0 10px -10px rgba(31, 41, 51, 0.45);
}

.header-label {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable:hover,
th.sorted {
  background: #dfeaea;
  color: var(--accent-strong);
}

tr[data-status="skipped"] td,
tr[data-status="stale"] td {
  color: var(--muted);
}

tr[data-status="stale"] td {
  background: #fff8e6;
}

tbody tr td.market-up {
  color: #d00000;
  font-weight: 600;
}

tbody tr td.market-down {
  color: #008000;
  font-weight: 600;
}

tbody tr td.hit {
  color: var(--danger);
  font-weight: 700;
}

.estimate-source-mark {
  align-items: center;
  border-radius: 50%;
  color: #fff;
  display: inline-flex;
  font-size: 10px;
  font-weight: 700;
  height: 15px;
  justify-content: center;
  line-height: 1;
  margin-left: 5px;
  vertical-align: 1px;
  width: 15px;
}

.estimate-warning-mark {
  background: #facc15;
  color: #713f12;
}

.estimate-warning-mark::before {
  content: "!";
}

.estimate-nav-strike {
  color: var(--muted);
  text-decoration-color: var(--muted);
  text-decoration-line: line-through;
  text-decoration-skip-ink: none;
  text-decoration-thickness: 2px;
}

.fast-tooltip {
  background: #111827;
  border-radius: 6px;
  box-shadow: 0 10px 24px rgba(31, 41, 51, 0.22);
  color: #fff;
  font-size: 12px;
  line-height: 1.45;
  max-width: min(520px, calc(100vw - 16px));
  padding: 8px 10px;
  pointer-events: none;
  position: fixed;
  white-space: normal;
  z-index: 1000;
}

.fast-tooltip[hidden] {
  display: none;
}

tbody tr td.apply-status-paused {
  background: #ffe1e1;
  color: var(--danger);
  font-weight: 700;
}

table[data-selectable-rows="true"] tbody tr.row-selected[data-row-key] td,
table[data-selectable-rows="true"] tbody tr.row-selected[data-row-key] td.apply-status-paused,
table[data-selectable-rows="true"] tbody tr.row-selected[data-row-key][data-status="stale"] td {
  background: #d7eeee;
}

.table-link {
  color: #005bd3;
  font-weight: 600;
  text-decoration: none;
}

.table-link:hover {
  color: #003f9e;
  text-decoration: underline;
}

.calc-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px;
}

.summary-line {
  color: var(--muted);
  font-size: 13px;
  padding: 0 14px 12px;
  white-space: pre-line;
}

.calc-results {
  max-height: 360px;
}

.log-panel pre {
  color: #25303b;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  margin: 0;
  max-height: 260px;
  overflow: auto;
  padding: 14px;
  white-space: pre-wrap;
}

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

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

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

  .brand-heading h1 {
    font-size: 34px;
  }

  .brand-logo {
    flex-basis: 48px;
    height: 48px;
    width: 48px;
  }

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

  .workspace {
    display: block;
  }

  .data-panel {
    margin-top: 16px;
  }
}
