:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --border: #475569;
  --pos: #4ade80;
  --neg: #f87171;
  --accent: #38bdf8;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  min-height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: calc(64px + var(--safe-bottom));
}

.mobile-header {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 14px 16px 10px;
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.mobile-header-main {
  flex: 1;
  min-width: 0;
}

.mobile-app-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.mobile-build-id {
  margin: 4px 0 0;
  font-size: 0.72rem;
  color: var(--accent);
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.mobile-updated {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.mobile-mode {
  margin: 4px 0 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: #34d399;
}

.setup-cloud-auto {
  margin-bottom: 12px;
}

.setup-lan-block {
  margin-bottom: 8px;
}

.setup-check {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 12px !important;
}

.setup-check input {
  width: auto;
  margin: 0;
}

.btn-icon {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-power {
  border: none;
  background: transparent;
  padding: 0;
  width: 44px;
  height: 44px;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 50%;
  line-height: 0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn-power img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  object-fit: cover;
}

.btn-power:active {
  transform: scale(0.92);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.btn-power-setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.btn-power-setup img {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.45);
  transition: transform 0.12s ease;
}

.btn-power-setup:active img {
  transform: scale(0.92);
}

.mobile-main {
  flex: 1;
  padding: 12px 12px 8px;
}

.mobile-view {
  display: none;
}

.mobile-view.active {
  display: block;
}

.card-grid {
  display: grid;
  gap: 10px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}

.metric-card .label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 4px;
}

.metric-card .value {
  font-size: 1.15rem;
  font-weight: 700;
}

.metric-card.positive .value {
  color: var(--pos);
}

.metric-card.negative .value {
  color: var(--neg);
}

.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: inherit;
  font: inherit;
}

.account-card:active {
  background: var(--surface2);
}

.account-card h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.account-card-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.88rem;
  margin-top: 4px;
}

.account-card-row .k {
  color: var(--muted);
}

.pos {
  color: var(--pos);
}

.neg {
  color: var(--neg);
}

.detail-back {
  margin-bottom: 10px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.95rem;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: #0f172a;
  font-weight: 600;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.holding-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
}

.holding-row h3 {
  margin: 0 0 2px;
  font-size: 0.98rem;
}

.holding-row .sub {
  margin: 0 0 8px;
  font-size: 0.82rem;
  color: var(--muted);
}

.holdings-account-title {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.holdings-count {
  margin: 0 0 12px;
  font-size: 0.8rem;
  color: var(--muted);
}

.holdings-sort-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 0 10px;
  margin-bottom: 2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.holdings-sort-bar::-webkit-scrollbar {
  display: none;
}

.holdings-sort-chip {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.holdings-sort-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.holdings-summary-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 10px;
  margin-bottom: 12px;
}

.holdings-summary-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.holdings-summary-item .k {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.holdings-summary-item .v {
  font-size: 0.82rem;
  font-weight: 600;
  overflow-wrap: anywhere;
  line-height: 1.3;
}

.holdings-table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.holdings-table-row {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.holdings-table-row:last-child {
  border-bottom: none;
}

.holdings-row-top,
.holdings-row-bottom {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 0.78rem;
  color: var(--muted);
}

.holdings-row-main {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin: 6px 0;
}

.holdings-symbol {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.25;
}

.holdings-company {
  margin-top: 2px;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.holdings-pl-amt {
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.holdings-gain-pct {
  font-weight: 600;
  white-space: nowrap;
}

.holdings-meta {
  overflow-wrap: anywhere;
}

.holdings-ltp {
  text-align: right;
  white-space: nowrap;
}

.holding-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  font-size: 0.84rem;
}

.holding-grid .k {
  color: var(--muted);
}

.watch-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
}

.watch-row h3 {
  margin: 0 0 2px;
  font-size: 0.98rem;
}

.watch-row .sub {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.log-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.log-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 0.86rem;
  line-height: 1.45;
}

.log-list .time {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 4px;
}

.mobile-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 20;
}

.mobile-nav-item {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 4px;
  font-size: 0.72rem;
  cursor: pointer;
}

.mobile-nav-item.active {
  color: var(--accent);
  font-weight: 600;
}

.mobile-toast {
  position: fixed;
  left: 50%;
  bottom: calc(72px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #334155;
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 30;
  max-width: 90vw;
  text-align: center;
}

.mobile-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.setup-screen {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.96);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.setup-screen[hidden] {
  display: none !important;
}

.setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  width: min(420px, 100%);
}

.setup-card h1 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.setup-lead {
  margin: 0 0 8px;
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.45;
}

.setup-lead--cloud {
  padding: 8px 10px;
  border-radius: 8px;
  background: #ecfdf5;
  border: 1px solid #6ee7b7;
  color: #065f46;
}

.setup-lead--wifi {
  color: var(--muted);
  font-size: 0.82rem;
}

.setup-hint {
  margin: 0 0 16px;
  font-size: 0.84rem;
  color: var(--accent);
  line-height: 1.45;
}

.setup-error {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(248, 113, 113, 0.15);
  border: 1px solid var(--neg);
  color: #fecaca;
  font-size: 0.84rem;
  line-height: 1.45;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: wait;
}

.setup-card label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.82rem;
  color: var(--muted);
}

.input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 32px 16px;
  font-size: 0.92rem;
}

.btn-shutdown {
  display: none;
}

.btn-icon-shutdown {
  display: none;
}

body.app-shutdown .mobile-header,
body.app-shutdown .mobile-main,
body.app-shutdown .mobile-nav,
body.app-shutdown .mobile-toast,
body.app-shutdown .setup-screen {
  display: none !important;
}

.shutdown-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}

.shutdown-screen[hidden] {
  display: none !important;
}

.shutdown-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px 20px;
  text-align: center;
}

.shutdown-card h1 {
  margin: 0 0 10px;
  font-size: 1.2rem;
}

.shutdown-lead {
  margin: 0 0 12px;
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.45;
}

.shutdown-hint {
  margin: 0 0 18px;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
}

.shutdown-card .btn-primary {
  width: 100%;
}
