:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --surface: #ffffff;
  --ink: #16181b;
  --muted: #62686f;
  --line: #d9ddd8;
  --dark: #171a1f;
  --green: #087a55;
  --green-bg: #e6f5ef;
  --red: #bb2d3b;
  --red-bg: #fbeaec;
  --amber: #a65f00;
  --amber-bg: #fff2d8;
  --focus: #1665d8;
  --radius: 6px;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-variant-numeric: tabular-nums;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-width: 320px; color: var(--ink); background: var(--bg); }
button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 35%, transparent); outline-offset: 2px; }
[hidden] { display: none !important; }
.lucide { width: 18px; height: 18px; stroke-width: 2; }

.login-shell { min-height: 100dvh; width: 100%; overflow-x: hidden; display: grid; place-items: center; padding: 20px; background: #ecefeb; }
.login-panel { width: 100%; max-width: min(390px, calc(100vw - 40px)); min-width: 0; padding: 30px 26px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 12px 32px rgba(23,26,31,.08); }
.brand-mark { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 4px; background: var(--dark); color: #fff; font-size: 14px; font-weight: 800; }
.login-panel h1 { margin: 20px 0 26px; font-size: 25px; line-height: 1.25; letter-spacing: 0; }
.login-panel form { display: grid; gap: 9px; }
.login-panel label { margin-top: 7px; color: #454b51; font-size: 14px; font-weight: 600; }
.login-panel input { width: 100%; height: 46px; border: 1px solid #bbc1bc; border-radius: 5px; padding: 0 12px; color: var(--ink); background: #fff; }
.primary-button, .secondary-button, .danger-button, .resume-button, .stop-button, .save-button { min-height: 42px; border-radius: 5px; border: 1px solid transparent; padding: 0 14px; font-weight: 650; transition: background-color .18s ease, border-color .18s ease, color .18s ease; }
.primary-button { margin-top: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--dark); color: #fff; }
.primary-button:hover { background: #30343a; }
.form-error { margin: 5px 0 0; color: var(--red); font-size: 13px; }

.topbar { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 12px max(16px, env(safe-area-inset-left)); background: var(--dark); color: #fff; }
.brand-line { display: flex; align-items: center; gap: 10px; }
.brand-line strong { font-size: 18px; }
.brand-mini { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid #5a6068; border-radius: 4px; font-size: 11px; font-weight: 800; color: #dce2df; }
.sync-status { margin: 2px 0 0 44px; color: #aeb5bc; font-size: 12px; }
.user-actions { display: flex; align-items: center; gap: 9px; }
.role-badge { border: 1px solid #59616a; border-radius: 999px; padding: 5px 9px; color: #dde3e0; font-size: 12px; }
.icon-button { width: 40px; height: 40px; display: inline-grid; place-items: center; flex: 0 0 40px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); color: #34393e; transition: background-color .18s ease, border-color .18s ease; }
.topbar .icon-button { border-color: #515860; background: #25292f; color: #fff; }
.icon-button:hover { background: #e9ece8; border-color: #b3bab4; }
.topbar .icon-button:hover { background: #343940; }
.market-strip { min-height: 44px; display: flex; align-items: center; gap: 11px; padding: 7px max(16px, env(safe-area-inset-left)); border-bottom: 1px solid #2e343b; background: #20252b; color: #cbd2d7; font-size: 12px; }
.market-strip strong { color: #fff; font-size: 18px; }
.market-strip span:last-child { color: #9fa8b0; }

.summary-band { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); border-bottom: 1px solid var(--line); background: var(--surface); }
.summary-band > div { min-height: 86px; display: flex; flex-direction: column; justify-content: center; padding: 14px 22px; border-right: 1px solid var(--line); }
.summary-band > div:last-child { border-right: 0; }
.summary-band span { color: var(--muted); font-size: 13px; }
.summary-band strong { margin-top: 5px; overflow-wrap: anywhere; font-size: 24px; line-height: 1.1; }

.toolbar { display: flex; align-items: center; gap: 10px; max-width: 1440px; margin: 0 auto; padding: 18px 18px 14px; }
.search-field { height: 42px; min-width: 220px; max-width: 390px; flex: 1; display: flex; align-items: center; gap: 8px; padding: 0 11px; border: 1px solid #c7ccc8; border-radius: 5px; background: var(--surface); color: var(--muted); }
.search-field input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); }
.segmented { display: inline-flex; height: 42px; padding: 3px; border: 1px solid #c7ccc8; border-radius: 5px; background: #e8ebe7; }
.segmented button { min-width: 66px; border: 0; border-radius: 3px; padding: 0 10px; background: transparent; color: #555c62; }
.segmented button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.1); font-weight: 650; }

.remark-filter-band { max-width: 1440px; margin: -4px auto 0; padding: 0 18px 12px; display: flex; align-items: flex-start; gap: 10px; }
.remark-filter-label { flex: 0 0 auto; padding-top: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.remark-filters { min-width: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.remark-filter { min-height: 30px; display: inline-flex; align-items: center; gap: 7px; border: 1px solid #c7ccc8; border-radius: 5px; padding: 4px 8px; background: var(--surface); color: #4c5359; font-size: 12px; transition: background-color .18s ease, border-color .18s ease, color .18s ease; }
.remark-filter:hover { border-color: #9da59f; background: #eef1ed; }
.remark-filter.active { border-color: var(--dark); background: var(--dark); color: #fff; }
.remark-filter strong { min-width: 18px; padding: 1px 5px; border-radius: 999px; background: #e8ebe7; color: #4c5359; font-size: 10px; line-height: 16px; text-align: center; }
.remark-filter.active strong { background: #41464d; color: #fff; }

.accounts-area { max-width: 1440px; margin: 0 auto; padding: 0 18px 28px; }
.desktop-table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; min-width: 1320px; border-collapse: collapse; }
th, td { height: 58px; padding: 9px 14px; border-bottom: 1px solid #e7e9e6; text-align: left; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th { height: 43px; background: #ecefeb; color: #5f666c; font-size: 12px; font-weight: 700; text-transform: none; }
td { font-size: 14px; }
.number { text-align: right; }
.account-id { font-weight: 750; }
.account-cell { display: flex; align-items: center; gap: 7px; min-width: 190px; }
.expand-button { width: 30px; height: 30px; display: inline-grid; place-items: center; flex: 0 0 30px; border: 1px solid #cbd1cc; border-radius: 4px; background: #fff; color: #3d454b; }
.expand-button:hover { background: #eef1ed; }
.expand-button .lucide { width: 16px; height: 16px; }
.account-meta { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.pnl { font-weight: 750; }
.positive { color: var(--green) !important; }
.negative { color: var(--red) !important; }
.status-stack { display: flex; flex-wrap: wrap; gap: 5px; }
.status-pill { display: inline-flex; align-items: center; gap: 5px; min-height: 26px; border-radius: 999px; padding: 3px 8px; color: #555c62; background: #eef0ed; font-size: 11px; font-weight: 650; }
.status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #858c91; }
.status-pill.online { color: var(--green); background: var(--green-bg); }
.status-pill.online::before { background: var(--green); }
.status-pill.stopped { color: var(--red); background: var(--red-bg); }
.status-pill.stopped::before { background: var(--red); }
.status-pill.pending { color: var(--amber); background: var(--amber-bg); }
.status-pill.pending::before { background: var(--amber); }
.row-actions { display: flex; justify-content: flex-end; gap: 7px; }
.stop-button { color: var(--red); border-color: #e6aeb4; background: #fff; }
.stop-button:hover { background: var(--red-bg); }
.resume-button { color: var(--green); border-color: #9bcdbb; background: #fff; }
.resume-button:hover { background: var(--green-bg); }
.remark-wrap { display: flex; align-items: center; gap: 6px; }
.remark-input { width: min(220px, 100%); height: 36px; border: 1px solid transparent; border-radius: 4px; padding: 0 7px; background: transparent; }
.remark-input:hover, .remark-input:focus { border-color: #bdc3be; background: #fff; }
.save-button { min-height: 34px; padding: 0 9px; color: #fff; background: #3c444b; }
.details-row td { height: auto; padding: 0; background: #f8f9f7; }
.details-content { display: grid; grid-template-columns: minmax(230px, .8fr) minmax(0, 2.2fr); gap: 18px; padding: 15px 18px 17px 51px; }
.details-remark, .details-orders { min-width: 0; display: grid; align-content: start; gap: 8px; }
.details-remark > span, .details-orders > span { color: var(--muted); font-size: 12px; font-weight: 700; }
.pending-empty { margin: 0; color: var(--muted); font-size: 13px; }
.pending-table-wrap { overflow: auto; border: 1px solid #dce0dc; border-radius: 4px; background: #fff; }
.pending-table { min-width: 660px; }
.pending-table th, .pending-table td { height: 37px; padding: 7px 10px; font-size: 12px; }
.pending-table th { height: 34px; }
.mobile-cards { display: none; }
.empty-state { min-height: 240px; display: grid; place-items: center; align-content: center; color: var(--muted); }
.empty-state .lucide { width: 30px; height: 30px; }
.empty-state p { margin: 9px 0 0; }

dialog { width: min(calc(100% - 32px), 420px); border: 1px solid var(--line); border-radius: 7px; padding: 0; color: var(--ink); background: #fff; box-shadow: 0 24px 70px rgba(0,0,0,.24); }
dialog::backdrop { background: rgba(15,17,19,.58); }
dialog form { padding: 24px; }
.dialog-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; color: var(--red); background: var(--red-bg); }
dialog h2 { margin: 17px 0 8px; font-size: 20px; }
dialog p { margin: 0; color: var(--muted); line-height: 1.6; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 22px; }
.secondary-button { border-color: #c9ceca; background: #fff; color: #3f454a; }
.danger-button { background: var(--red); color: #fff; }
.danger-button.resume { background: var(--green); }
.toast { position: fixed; z-index: 20; right: 18px; bottom: max(18px, env(safe-area-inset-bottom)); max-width: min(390px, calc(100% - 36px)); padding: 11px 14px; border-radius: 5px; background: #24282d; color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.22); font-size: 13px; }

@media (min-width: 701px) and (max-width: 1100px) {
  .summary-band { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .summary-band > div { min-height: 72px; }
  .summary-band > div:nth-child(4n) { border-right: 0; }
  .summary-band > div:nth-child(-n+4) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 700px) {
  .topbar { min-height: 58px; padding: 8px max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left)); }
  .brand-line strong { font-size: 16px; }
  .brand-mini { width: 30px; height: 30px; }
  .sync-status { margin-left: 40px; }
  .market-strip { min-height: 34px; gap: 7px; padding: 4px 10px; }
  .market-strip strong { font-size: 16px; }
  .summary-band { grid-template-columns: 1fr 1fr; }
  .summary-band > div { min-height: 58px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
  .summary-band > div:nth-child(2n) { border-right: 0; }
  .summary-band > div:nth-child(7), .summary-band > div:nth-child(8) { border-bottom: 0; }
  .summary-band strong { margin-top: 3px; font-size: 17px; }
  .toolbar { flex-wrap: wrap; padding: 9px 10px 8px; }
  .search-field { order: 1; max-width: none; flex-basis: calc(100% - 50px); }
  .toolbar > .icon-button { order: 2; }
  .segmented { order: 3; width: 100%; }
  .segmented button { flex: 1; min-width: 0; }
  .remark-filter-band { margin-top: 0; padding: 0 10px 8px; gap: 7px; }
  .remark-filter-label { padding-top: 6px; }
  .remark-filters { flex: 1; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
  .remark-filter { flex: 0 0 auto; min-height: 29px; white-space: nowrap; }
  .accounts-area { padding: 0 10px 18px; }
  .desktop-table-wrap { display: none; }
  .mobile-cards { display: grid; gap: 7px; }
  .account-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
  .card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 9px; padding: 9px 11px 8px; border-bottom: 1px solid #e7e9e6; }
  .card-head .account-id { font-size: 15px; }
  .card-grid { display: grid; grid-template-columns: 1fr 1fr; }
  .card-metric { min-height: 51px; display: flex; flex-direction: column; justify-content: center; padding: 6px 11px; border-right: 1px solid #e7e9e6; border-bottom: 1px solid #e7e9e6; }
  .card-metric:nth-child(2n) { border-right: 0; }
  .card-metric span { color: var(--muted); font-size: 11px; }
  .card-metric strong { margin-top: 2px; overflow-wrap: anywhere; font-size: 15px; line-height: 1.2; }
  .pnl-metric strong { font-weight: 750; }
  .mobile-details { border-bottom: 1px solid #e7e9e6; }
  .mobile-details summary { min-height: 44px; display: flex; align-items: center; padding: 0 11px; color: #3f474d; font-size: 12px; font-weight: 700; cursor: pointer; }
  .mobile-details .details-content { display: grid; grid-template-columns: 1fr; gap: 10px; padding: 0 11px 11px; }
  .mobile-details .remark-input { width: 100%; border-color: #c8cdc9; }
  .mobile-details .save-button { min-width: 58px; white-space: nowrap; }
  .card-actions { display: flex; justify-content: flex-end; gap: 7px; padding: 7px 11px; }
  .card-actions button { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
