:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --panel: #ffffff;
  --ink: #1d2833;
  --muted: #637083;
  --line: #d9e0e7;
  --blue: #2563eb;
  --blue-dark: #1e4fbf;
  --green: #11845b;
  --red: #b42318;
  --amber: #a16207;
  --shadow: 0 12px 30px rgba(25, 40, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", Arial, sans-serif;
  letter-spacing: 0;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 24px 28px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.app-header h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

.app-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.status-pill,
.signal-chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

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

.control-panel,
.chart-area,
.table-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel {
  align-self: start;
  padding: 18px;
  position: sticky;
  top: 12px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  padding: 8px 10px;
}

select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  padding: 8px 10px;
}

input:focus,
select:focus {
  border-color: var(--blue);
  outline: 3px solid rgba(37, 99, 235, 0.14);
}

details {
  margin: 6px 0 14px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}

summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--ink);
}

.param-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.switch-row {
  margin-bottom: 14px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 8px;
}

.switch input {
  width: 18px;
  min-height: 18px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

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

.primary-button {
  background: var(--blue);
  color: #fff;
}

.primary-button:hover:not(:disabled) {
  background: var(--blue-dark);
}

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

.compact-button {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 13px;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.secondary-link {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.workspace {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.message {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  padding: 10px 12px;
  font-size: 14px;
}

.message.error {
  border-color: rgba(180, 35, 24, 0.28);
  background: #fff4f2;
  color: var(--red);
}

.message.success {
  border-color: rgba(17, 132, 91, 0.25);
  background: #f0fff8;
  color: var(--green);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
}

.metric-card {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  box-shadow: var(--shadow);
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-value {
  margin-top: 10px;
  font-size: 24px;
  font-weight: 800;
  line-height: 1.1;
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.neutral {
  color: var(--ink);
}

.chart-area {
  padding: 14px;
}

.chart-toolbar,
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
}

canvas {
  width: 100%;
  height: 430px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.table-section {
  padding: 14px;
}

.table-header span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
  font-size: 13px;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2),
th:last-child,
td:last-child {
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
}

td:last-child {
  white-space: normal;
  min-width: 180px;
}

footer {
  padding: 0 28px 24px;
  color: var(--muted);
  font-size: 12px;
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #f5f7f9;
}

.auth-shell {
  width: min(440px, calc(100vw - 32px));
}

.auth-panel {
  display: grid;
  gap: 16px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-panel h1 {
  margin: 0;
  font-size: 26px;
}

.auth-panel p {
  margin: -8px 0 0;
  color: var(--muted);
}

.auth-panel form,
.stack-form {
  display: grid;
  gap: 14px;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px 28px 26px;
}

.admin-table {
  min-width: 1120px;
}

.table-input {
  min-width: 120px;
}

.action-cell {
  display: flex;
  gap: 8px;
}

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

  .admin-layout {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
  }

  .metrics-grid {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }
}

@media (max-width: 680px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
    padding: 18px 16px 14px;
  }

  .layout {
    padding: 14px 16px 22px;
  }

  .field-row,
  .param-grid,
  .button-row,
  .metrics-grid {
    grid-template-columns: 1fr;
  }

  canvas {
    height: 320px;
  }

  footer {
    padding: 0 16px 20px;
  }
}
