:root {
  --bg: #f4f6f7;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #6b7785;
  --line: #dce3ea;
  --accent: #c62828;
  --accent-dark: #8f1d1d;
  --accent-border: #d5a16c;
  --gain: #c62828;
  --loss: #16834a;
  --soft: #fff1e8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #3a1717 0%, #8f1d1d 52%, #f4f6f7 52%);
}

.login-panel {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 18px 60px rgba(16, 32, 39, .18);
}

.brand {
  color: var(--accent);
  font-weight: 800;
  font-size: 20px;
  margin-bottom: 14px;
}

.brand.small {
  margin: 0 0 6px;
  color: #ffd8b3;
  font-size: 16px;
}

.login-panel h1,
.app-header h1 {
  margin: 0;
  letter-spacing: 0;
}

.login-panel p,
.app-header p {
  color: var(--muted);
  margin: 6px 0 16px;
}

label {
  display: block;
  margin-bottom: 12px;
  color: #334155;
  font-weight: 700;
}

input,
select {
  width: 100%;
  margin-top: 8px;
  border: 1px solid #cfd8e3;
  border-radius: 6px;
  padding: 10px 11px;
  font-size: 15px;
  background: #fff;
}

button {
  border: 1px solid var(--accent-border);
  background: var(--soft);
  color: var(--accent-dark);
  border-radius: 6px;
  padding: 8px 12px;
  font-weight: 800;
  cursor: pointer;
  min-height: 36px;
}

.upload-btn {
  border: 1px solid var(--accent-border);
  background: var(--soft);
  color: var(--accent-dark);
  border-radius: 6px;
  padding: 0 12px;
  font-weight: 800;
  cursor: pointer;
  font-size: 13px;
  height: 36px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  margin: 0;
}

.upload-btn input {
  display: none;
}

.login-panel button {
  width: 100%;
  margin-top: 4px;
  background: var(--accent);
  color: #fff;
}

button.ghost {
  background: transparent;
  color: #fff1e8;
  border-color: rgba(255, 255, 255, .35);
}

.form-error {
  min-height: 20px;
  margin-top: 12px;
  color: var(--accent);
  font-size: 14px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 16px 24px;
  background: #3a1717;
  color: #fff;
}

.long-edition {
  --accent: #d98900;
  --accent-dark: #a45d00;
  --accent-border: #d9a23b;
  --soft: #fff4d8;
}

.long-edition .app-header {
  background: #b56b08;
}

.long-edition .edition-badge {
  border-color: rgba(255, 243, 208, .72);
  color: #fff3d0;
}

.long-edition button.ghost {
  color: #fff3d0;
  border-color: rgba(255, 243, 208, .5);
}

.app-header h1 {
  font-size: 24px;
}

.edition-badge {
  display: inline-block;
  vertical-align: middle;
  padding: 2px 6px;
  border: 1px solid rgba(255, 216, 179, .65);
  border-radius: 4px;
  color: #ffd8b3;
  font-size: 12px;
  font-weight: 700;
}

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

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

.header-actions > button,
.header-tools > button,
.header-tools > .upload-btn {
  height: 36px;
  min-height: 36px;
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-size: 13px;
}

main {
  padding: 16px 24px 96px;
}

.today-board {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
}

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

.board-head span,
.section-title span {
  color: var(--muted);
  font-size: 13px;
}

.board-head h2,
.section-title h2 {
  margin: 2px 0 0;
  font-size: 18px;
}

.board-head strong {
  color: var(--accent-dark);
  font-size: 14px;
}

.stock-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 10px;
  padding: 12px;
}

.stock-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
  cursor: pointer;
}

.stock-card:hover,
.stock-card:focus {
  border-color: #d5a16c;
  box-shadow: 0 4px 16px rgba(143, 29, 29, .12);
  outline: none;
}

.top1-card {
  background: #fff9f2;
  border-color: #d5a16c;
}

.stock-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.stock-top h3 {
  margin: 0 0 2px;
  font-size: 19px;
}

.stock-top span,
.quote small,
.levels span {
  color: var(--muted);
  font-size: 12px;
}

.quote {
  text-align: right;
  min-width: 86px;
}

.quote strong {
  display: block;
  color: var(--accent);
  font-size: 21px;
}

.quote strong.pos {
  color: var(--gain);
}

.quote strong.neg {
  color: var(--loss);
}

.logic {
  margin: 0 0 10px;
  color: #334155;
  line-height: 1.45;
  font-size: 13px;
}

.levels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(86px, 1fr));
  gap: 6px 10px;
}

.levels div {
  border-top: 1px solid var(--line);
  padding-top: 7px;
}

.levels strong {
  display: block;
  margin-top: 2px;
  font-size: 13px;
}

.tags {
  margin-top: 8px;
}

.tag {
  display: inline-block;
  margin: 0 4px 4px 0;
  padding: 3px 6px;
  border-radius: 4px;
  background: var(--soft);
  color: #9a3412;
  font-size: 12px;
  font-weight: 700;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric {
  padding: 12px 14px;
}

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

.metric strong {
  font-size: 22px;
}

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

.top1-dashboard {
  border-bottom: 1px solid var(--line);
}

.top1-dashboard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px 8px;
}

.top1-dashboard-head h2 {
  margin: 0;
  font-size: 18px;
}

.top1-dashboard-head p,
.top1-dashboard-head > span {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.top1-dashboard-head > span {
  margin: 0;
  color: var(--accent-dark);
  font-weight: 800;
}

.top1-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 0 14px 12px;
}

.top1-summary > div {
  min-width: 0;
  padding: 8px 12px;
  border-left: 1px solid var(--line);
}

.top1-summary > div:first-child {
  border-left: 0;
  padding-left: 0;
}

.top1-summary span,
.top1-summary strong,
.top1-summary small {
  display: block;
}

.top1-summary span,
.top1-summary small {
  color: var(--muted);
  font-size: 12px;
}

.top1-summary strong {
  margin: 3px 0;
  font-size: 24px;
  line-height: 1.1;
}

.long-edition .bottom-nav {
  grid-template-columns: repeat(2, 1fr);
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

.top1-table {
  min-width: 720px;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: #41505d;
  background: #f8fafb;
  white-space: nowrap;
}

td.note {
  min-width: 220px;
  line-height: 1.4;
}

.pos {
  color: var(--gain);
  font-weight: 800;
}

.neg {
  color: var(--loss);
  font-weight: 800;
}

.empty {
  padding: 20px;
  color: var(--muted);
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover {
  background: #fff9f2;
}

.chart-panel {
  margin-bottom: 12px;
}

.tv-chart {
  width: 100%;
  height: 390px;
  padding: 4px;
  position: relative;
}

.tv-chart a[href*="tradingview" i],
.tv-chart [title*="tradingview" i],
.tv-chart [aria-label*="tradingview" i] {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.small-chart {
  height: 260px;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  background: #ffffff;
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(15, 23, 42, .08);
  z-index: 20;
}

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

.modal-panel {
  width: min(620px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 20px 70px rgba(15, 23, 42, .24);
}

.wide-modal {
  width: min(1120px, 100%);
}

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

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

.title-actions button {
  padding: 5px 8px;
  font-size: 12px;
}

.modal-head {
  margin-bottom: 12px;
}

.modal-head h2 {
  margin: 0;
  font-size: 20px;
}

.icon-btn {
  padding: 6px 10px;
  background: transparent;
}

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

.result-line {
  min-height: 22px;
  margin: 8px 0;
  color: var(--accent-dark);
  font-weight: 700;
  line-height: 1.4;
}

.result-line.error {
  color: var(--loss);
}

.customer-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
  margin-bottom: 8px;
}

.customer-toolbar input {
  margin-top: 0;
}

.customer-table {
  min-width: 1040px;
}

.customer-table td {
  white-space: nowrap;
}

.customer-table .customer-info,
.log-table .device-cell {
  white-space: normal;
  min-width: 180px;
}

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

.row-actions button {
  padding: 5px 8px;
  font-size: 12px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 8px 0 0;
}

.pager button,
.pager select {
  height: 32px;
  min-height: 32px;
  padding: 4px 8px;
  font-size: 12px;
}

.pager select {
  width: auto;
  margin: 0;
  border: 1px solid #cfd8e3;
  border-radius: 6px;
}

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

.status-pill {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  background: #edf7ed;
  color: #166534;
  font-weight: 800;
}

.status-pill.expired,
.status-pill.disabled {
  background: #fff1e8;
  color: var(--accent-dark);
}

.log-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.log-table {
  min-width: 760px;
}

.nav-item {
  border: 0;
  border-radius: 0;
  background: #ffffff;
  color: #475569;
  padding: 18px 8px;
  min-height: 60px;
  font-size: 15px;
}

.nav-item.active {
  color: #fff;
  background: var(--accent);
}

@media (max-width: 760px) {
  .app-header,
  .board-head,
  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions,
  .header-tools {
    width: 100%;
    justify-content: flex-start;
  }

  #appView .app-header {
    padding-right: 92px;
  }

  #logoutBtn {
    position: fixed;
    top: max(8px, env(safe-area-inset-top));
    right: 10px;
    z-index: 40;
    min-width: 66px;
    background: #3a1717;
  }

  .long-edition #logoutBtn {
    background: #b56b08;
  }

  main {
    padding: 12px 12px 92px;
  }

  .stock-grid {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 8px;
  }

  .stock-card {
    padding: 9px 10px;
    border-radius: 6px;
  }

  .stock-top {
    gap: 8px;
    margin-bottom: 5px;
  }

  .stock-top h3 {
    font-size: 16px;
    margin-bottom: 0;
  }

  .stock-top span,
  .quote small,
  .levels span {
    font-size: 11px;
  }

  .quote {
    min-width: 68px;
  }

  .quote strong {
    font-size: 17px;
  }

  .logic {
    margin-bottom: 6px;
    font-size: 12px;
    line-height: 1.32;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .levels {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px 8px;
  }

  .levels div {
    padding-top: 5px;
  }

  .levels strong {
    font-size: 12px;
    margin-top: 1px;
  }

  .tags {
    margin-top: 5px;
  }

  .tag {
    padding: 2px 5px;
    margin-bottom: 2px;
    font-size: 11px;
  }

  .top1-table {
    min-width: 520px;
  }

  .top1-table th,
  .top1-table td {
    padding: 5px 6px;
    font-size: 11px;
    line-height: 1.25;
  }

  .top1-table td strong {
    font-size: 12px;
  }

  .metrics,
  .form-grid,
  .customer-toolbar {
    grid-template-columns: 1fr;
  }

  .top1-summary {
    padding: 0 8px 10px;
  }

  .top1-summary > div {
    padding: 6px 4px;
    text-align: center;
  }

  .top1-summary strong {
    margin: 2px 0;
    font-size: 19px;
  }

  .top1-summary span,
  .top1-summary small {
    font-size: 10px;
    white-space: nowrap;
  }

  .top1-dashboard-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
    padding: 10px 10px 7px;
  }

  .top1-dashboard-head h2 {
    font-size: 16px;
  }

  .top1-dashboard-head p {
    margin-top: 3px;
    line-height: 1.35;
  }

  .top1-dashboard-head > span {
    margin-top: 1px;
  }

  .pager {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}
