:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-strong: #eef3f7;
  --text: #17202a;
  --muted: #667281;
  --line: #d8e0e8;
  --accent: #1677ff;
  --accent-strong: #0e5fd8;
  --good: #0f8a5f;
  --warn: #c77800;
  --danger: #d43f3a;
  --ink: #111827;
  --radius: 8px;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

.app-shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #18202b;
  color: #ffffff;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: #16a085;
  color: #ffffff;
  font-weight: 800;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.section-head h3,
.section-head p,
.settings-panel h3,
.export-panel h3,
.export-panel p,
.simulator-panel h3,
.result-panel h3 {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
}

.brand p {
  margin-top: 4px;
  color: #aeb8c4;
  font-size: 13px;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: #c6d0dc;
  text-align: left;
  padding: 0 14px;
  cursor: pointer;
}

.nav-tab.active,
.nav-tab:hover {
  background: #263241;
  color: #ffffff;
}

.side-status {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #b8c3cf;
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
}

.status-dot.off {
  background: #ef4444;
}

.workspace {
  padding: 28px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 26px;
}

.eyebrow {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.topbar h2 {
  font-size: 26px;
  letter-spacing: 0;
}

.top-actions {
  display: flex;
  gap: 10px;
}

.auth-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(190px, 260px) minmax(190px, 260px) auto;
  gap: 12px;
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 22px;
}

.auth-panel h3,
.auth-panel p {
  margin: 0;
}

.auth-panel h3 {
  font-size: 16px;
}

.auth-panel p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.compact-field {
  display: grid;
  gap: 6px;
}

.compact-field span {
  color: #39485a;
  font-size: 13px;
}

.compact-field input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 10px;
}

.primary-button,
.ghost-button {
  min-height: 38px;
  border-radius: var(--radius);
  padding: 0 14px;
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
}

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

.primary-button:hover {
  background: var(--accent-strong);
}

.ghost-button {
  background: #ffffff;
  color: var(--ink);
  border-color: var(--line);
}

.ghost-button:hover {
  border-color: #b8c5d2;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  margin-bottom: 14px;
}

.section-head.spaced {
  margin-top: 28px;
}

.section-head h3,
.settings-panel h3,
.export-panel h3,
.simulator-panel h3,
.result-panel h3 {
  font-size: 18px;
}

.section-head p,
.export-panel p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

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

.symbol-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 12px;
}

.symbol-main {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}

.symbol-main strong {
  display: block;
  font-size: 17px;
}

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

.pill {
  border-radius: 999px;
  background: #e9f8f2;
  color: var(--good);
  padding: 4px 8px;
  font-size: 12px;
}

.pill.off {
  background: #f1f3f5;
  color: var(--muted);
}

.card-actions {
  display: flex;
  gap: 8px;
}

.small-button {
  min-height: 32px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #ffffff;
  padding: 0 10px;
  cursor: pointer;
}

.small-button.danger {
  color: var(--danger);
}

.rules-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.rules-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

.rules-table th,
.rules-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.rules-table th {
  background: var(--panel-strong);
  color: #405064;
  font-size: 13px;
}

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

.rules-table input,
.rules-table select,
.field input,
.field select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 10px;
  background: #ffffff;
  color: var(--text);
}

.rules-table input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
}

.add-row {
  margin-top: 12px;
}

.settings-layout,
.preview-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.settings-panel,
.export-panel,
.simulator-panel,
.result-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 16px;
}

.field span,
.toggle-line span {
  color: #39485a;
  font-size: 14px;
}

.toggle-line {
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.export-panel textarea {
  margin-top: 12px;
  width: 100%;
  min-height: 260px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #101820;
  color: #d6e5f3;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.full {
  width: 100%;
  margin-top: 18px;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.metric-row div {
  background: #f4f8fb;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.metric-row span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.metric-row strong {
  font-size: 24px;
}

.message-box {
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffaf0;
  padding: 14px;
  line-height: 1.8;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  min-width: 220px;
  max-width: calc(100vw - 48px);
  background: #111827;
  color: #ffffff;
  border-radius: var(--radius);
  padding: 12px 14px;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.45);
  z-index: 20;
}

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

.modal {
  width: min(460px, 100%);
  background: #ffffff;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 18px;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.22);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head h3 {
  margin: 0;
  font-size: 18px;
}

.icon-button {
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 14px;
    gap: 14px;
  }

  .nav-tabs {
    grid-template-columns: repeat(3, 1fr);
  }

  .nav-tab {
    text-align: center;
  }

  .side-status {
    display: none;
  }

  .workspace {
    padding: 18px;
  }

  .topbar,
  .section-head,
  .auth-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .auth-panel {
    display: flex;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions button,
  .section-head button {
    flex: 1;
  }

  .symbol-grid,
  .settings-layout,
  .preview-layout,
  .metric-row {
    grid-template-columns: 1fr;
  }
}
