:root {
  color: #0f172a;
  background: #eef2f7;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  height: 100%;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell[hidden],
.login-shell[hidden] {
  display: none;
}

.login-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px;
  background: #eef2f7;
}

.login-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(100%, 380px);
  padding: 22px;
  background: #ffffff;
  border: 1px solid #d8dee8;
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.12);
}

.login-brand {
  margin-bottom: 6px;
}

.login-panel .error-banner {
  margin: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: 304px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  background: #ffffff;
  border-right: 1px solid #d8dee8;
  overflow-y: auto;
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid #e2e8f0;
}

.brand svg {
  color: #0f766e;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand span {
  display: block;
  margin-top: 2px;
  color: #64748b;
  font-size: 12px;
}

.control-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tab-section {
  gap: 14px;
}

.sidebar-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 3px;
  background: #e2e8f0;
  border-radius: 8px;
}

.sidebar-tabs button {
  min-height: 34px;
  color: #475569;
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
}

.sidebar-tabs button.active {
  color: #0f172a;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.signal-criteria {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.signal-root-option {
  min-height: 34px;
  padding: 8px 10px;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}

.criterion-subtree {
  margin-left: 12px;
  padding-left: 12px;
  border-left: 2px solid #cbd5e1;
}

.criterion-option {
  min-height: 32px;
  padding: 6px 10px;
  flex-wrap: wrap;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}

.criterion-option.unavailable {
  color: #64748b;
  background: #f1f5f9;
}

.todo-tag {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 2px 6px;
  color: #713f12;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}

.section-title {
  color: #475569;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field span,
.checkbox-field span {
  color: #334155;
  font-size: 12px;
  font-weight: 600;
}

.field select,
.field input {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  color: #0f172a;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  outline: none;
}

.field select:focus,
.field input:focus {
  border-color: #0f766e;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.signal-timeframes {
  grid-template-columns: repeat(4, 1fr);
}

.segmented button,
.toggle-action,
.primary-action {
  min-height: 36px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #f8fafc;
  color: #0f172a;
}

.segmented button {
  padding: 0 8px;
  font-size: 12px;
  font-weight: 700;
}

.segmented button.active {
  border-color: #0f766e;
  background: #ccfbf1;
  color: #115e59;
}

.field-hint {
  color: #64748b;
  font-size: 11px;
  line-height: 1.35;
}

.primary-action,
.toggle-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  font-weight: 700;
}

.primary-action {
  color: #ffffff;
  background: #0f766e;
  border-color: #0f766e;
}

.primary-action:hover {
  background: #115e59;
}

.icon-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  color: #475569;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}

.icon-action:hover {
  color: #0f172a;
  background: #e2e8f0;
}

.toggle-action.enabled {
  color: #064e3b;
  background: #dcfce7;
  border-color: #86efac;
}

.checkbox-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.checkbox-field input {
  width: 16px;
  height: 16px;
  accent-color: #0f766e;
}

.checkbox-field:has(input:disabled) span {
  color: #64748b;
}

.workspace {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #eef2f7;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: #ffffff;
  border-bottom: 1px solid #d8dee8;
}

.workspace-tabs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 18px 0;
  background: #ffffff;
}

.workspace-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 14px;
  color: #475569;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px 6px 0 0;
  font-size: 13px;
  font-weight: 800;
}

.workspace-tabs button.active {
  color: #0f172a;
  background: #eef2f7;
  border-bottom-color: #eef2f7;
}

.workspace-tabs button:disabled {
  cursor: not-allowed;
  opacity: 1;
}

.workspace-panel {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  min-height: 0;
}

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

.market-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.market-title span {
  color: #64748b;
  font-size: 13px;
  white-space: nowrap;
}

.market-title strong {
  color: #0f172a;
  font-size: 20px;
  letter-spacing: 0;
  white-space: nowrap;
}

.status-strip {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  color: #475569;
  font-size: 12px;
  white-space: nowrap;
}

.loading-pill {
  padding: 4px 8px;
  color: #713f12;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 999px;
  font-weight: 700;
}

.drawing-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 10px 18px;
  background: #f8fafc;
  border-bottom: 1px solid #d8dee8;
  overflow-x: auto;
}

.drawing-toolbar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  color: #334155;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}

.drawing-toolbar button:hover:not(:disabled),
.drawing-toolbar button.active {
  color: #0f766e;
  border-color: #0f766e;
  background: #ccfbf1;
}

.rotate-icon {
  transform: rotate(90deg);
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  margin: 0 3px;
  background: #cbd5e1;
}

.error-banner {
  margin: 12px 18px 0;
  padding: 10px 12px;
  color: #7f1d1d;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  font-size: 13px;
}

.chart-frame {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  margin: 12px 18px;
  background: #ffffff;
  border: 1px solid #d8dee8;
  border-radius: 8px;
  overflow: hidden;
}

.chart-host {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

.signal-popover {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 30;
  width: min(240px, calc(100% - 24px));
  padding: 12px;
  color: #0f172a;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
}

.signal-popover[hidden] {
  display: none;
}

.signal-popover-close {
  position: absolute;
  top: 7px;
  right: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: #64748b;
  background: transparent;
  border: 0;
  border-radius: 4px;
}

.signal-popover-close:hover {
  color: #0f172a;
  background: #e2e8f0;
}

.signal-popover-close svg {
  width: 16px;
  height: 16px;
}

.signal-popover-title {
  padding-right: 26px;
  font-size: 13px;
  font-weight: 700;
}

.signal-popover-meta {
  margin-top: 5px;
  color: #475569;
  font-size: 12px;
}

.signal-popover-stage {
  margin-top: 8px;
  color: #334155;
  font-size: 12px;
}

.signal-popover-flags {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 10px;
}

.signal-popover-flag {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  color: #334155;
  font-size: 11px;
  font-weight: 600;
}

.signal-popover-flag-state {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.signal-popover-flag-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.signal-popover-flag-icon.is-true {
  background: #16a34a;
}

.signal-popover-flag-icon.is-false {
  background: #dc2626;
}

.signal-popover-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 11px;
  color: #334155;
  font-size: 12px;
  font-weight: 600;
}

.signal-popover-check input {
  margin: 0;
}

.signal-popover-inline-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #475569;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.signal-popover-inline-check input {
  margin: 0;
}

.signal-popover-inline-check:has(input:disabled) {
  color: #94a3b8;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #64748b;
  background: rgba(248, 250, 252, 0.72);
  font-size: 14px;
  pointer-events: none;
}

.empty-state[hidden] {
  display: none;
}

.chart-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px 14px;
  color: #64748b;
  font-size: 12px;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .sidebar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-right: none;
    border-bottom: 1px solid #d8dee8;
    max-height: 40vh;
    max-height: 40dvh;
  }

  .brand {
    grid-column: 1 / -1;
  }

  .workspace {
    min-height: 0;
  }
}

@media (max-width: 640px) {
  .sidebar {
    grid-template-columns: 1fr;
    padding: 14px;
  }

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

  .market-title {
    flex-wrap: wrap;
  }

  .chart-footer {
    flex-direction: column;
  }

  .chart-frame {
    margin: 10px 12px;
  }
}
