:root {
  --bg: #0b1020;
  --surface: #121a2e;
  --surface-2: #19233d;
  --border: #253256;
  --text: #eef2ff;
  --muted: #93a3c7;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, 0.14);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.14);
  --cyan: #06b6d4;
  --cyan-soft: rgba(6, 182, 212, 0.14);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.82rem;
}

.text-right {
  text-align: right;
}

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.brand-badge {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--cyan);
  background: var(--cyan-soft);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 1.45rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 0.85rem;
  color: var(--muted);
}

input, select, textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
  outline: none;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}

.error-box {
  background: var(--red-soft);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fecaca;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.85rem;
  margin-bottom: 12px;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  background: var(--surface-2);
  transition: transform 0.08s ease, background 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-accent {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-danger {
  background: var(--red-soft);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.btn-sm {
  padding: 7px 11px;
  font-size: 0.82rem;
}

.btn-full {
  width: 100%;
}

.btn-link {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.78rem;
  text-decoration: underline;
  cursor: pointer;
  margin-left: auto;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* App Shell */
.app-shell {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: 84px;
}

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

.app-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
}

.app-subtitle {
  font-size: 0.76rem;
  color: var(--muted);
  margin-top: 2px;
}

.dot-status {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}

.dot-status.live {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.dot-status.demo {
  background: var(--amber);
}

/* Sticky Summary */
.summary-sticky {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(11, 16, 32, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px 12px;
}

.summary-row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.kpi-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.kpi-val {
  font-size: 1.05rem;
  font-weight: 700;
}

.scenarios-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.scenario-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 8px;
  text-align: center;
}

.scenario-box.ok {
  border-color: rgba(34, 197, 94, 0.45);
  background: linear-gradient(180deg, rgba(34, 197, 94, 0.08), var(--surface));
}

.scenario-box.warn {
  border-color: rgba(245, 158, 11, 0.5);
  background: linear-gradient(180deg, rgba(245, 158, 11, 0.1), var(--surface));
}

.scenario-box.danger {
  border-color: rgba(239, 68, 68, 0.6);
  background: linear-gradient(180deg, rgba(239, 68, 68, 0.14), var(--surface));
}

.sc-label {
  font-size: 0.69rem;
  color: var(--muted);
  margin-bottom: 3px;
}

.sc-val {
  font-size: 0.92rem;
  font-weight: 800;
  white-space: nowrap;
}

.sc-sub {
  font-size: 0.67rem;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.summary-breakdown {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.chip {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
}

.chip-green {
  background: var(--green-soft);
  color: #86efac;
}

.chip-cyan {
  background: var(--cyan-soft);
  color: #67e8f9;
}

.chip-red {
  background: var(--red-soft);
  color: #fca5a5;
}

/* Content */
.content {
  padding: 14px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}

.section-header h2 {
  margin: 0 0 3px;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  font-size: 0.74rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
}

.filter-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 10px;
}

.filter-bar select {
  width: auto;
  min-width: 120px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.check-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  cursor: pointer;
}

.check-pill input {
  width: auto;
  margin: 0;
}

.compact-select {
  width: auto;
  padding: 6px 10px;
  font-size: 0.8rem;
  margin-left: auto;
}

/* Cards */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.player-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.player-card.selected-sell {
  border-color: var(--green);
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.1), var(--surface));
}

.player-card.selected-clause {
  border-color: var(--cyan);
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.1), var(--surface));
}

.player-card.selected-buy {
  border-color: var(--primary);
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.12), var(--surface));
}

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

.pc-identity {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.pos-pill {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 3px 7px;
  border-radius: 7px;
  flex-shrink: 0;
}

.pos-1 { background: rgba(245, 158, 11, 0.22); color: #fcd34d; }
.pos-2 { background: rgba(59, 130, 246, 0.22); color: #93c5fd; }
.pos-3 { background: rgba(34, 197, 94, 0.22); color: #86efac; }
.pos-4 { background: rgba(239, 68, 68, 0.22); color: #fca5a5; }
.pos-0 { background: var(--surface-2); color: var(--muted); }

.pc-name {
  font-weight: 700;
  font-size: 0.96rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pc-meta {
  font-size: 0.76rem;
  color: var(--muted);
  margin-top: 2px;
}

.pc-value-col {
  text-align: right;
  flex-shrink: 0;
}

.pc-value {
  font-weight: 800;
  font-size: 0.96rem;
}

.delta-up { color: var(--green); font-size: 0.74rem; font-weight: 600; }
.delta-down { color: var(--red); font-size: 0.74rem; font-weight: 600; }

.pc-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.tag {
  font-size: 0.72rem;
  padding: 3px 7px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
}

.tag-refund {
  background: var(--cyan-soft);
  color: #67e8f9;
  font-weight: 600;
}

.tag-offer {
  background: var(--amber-soft);
  color: #fcd34d;
  font-weight: 600;
}

.tag-shield {
  background: var(--red-soft);
  color: #fca5a5;
}

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

.pc-controls {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mode-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mode-pill {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.mode-pill.active {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.2);
  color: #fff;
}

/* Panels */
.panel-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.panel-box-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 10px;
}

.inline-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.inline-form input[type="number"] {
  max-width: 135px;
}

.inline-form .btn {
  flex-shrink: 0;
}

.mini-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.buy-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}

.buy-row-info {
  flex: 1;
  min-width: 0;
}

.buy-row-name {
  font-weight: 700;
  font-size: 0.88rem;
}

.buy-row-sub {
  font-size: 0.73rem;
  color: var(--muted);
}

.buy-row input {
  width: 120px;
  padding: 6px 8px;
  font-size: 0.85rem;
  text-align: right;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 12px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 8px;
  border-radius: 9px;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--primary);
  color: #fff;
}

.empty-card {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 22px 16px;
  text-align: center;
}

.empty-card h3 {
  margin: 0 0 6px;
}

.help-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 0.83rem;
}

.help-box summary {
  cursor: pointer;
  font-weight: 600;
  color: #93c5fd;
}

.help-box ol {
  padding-left: 18px;
  margin: 8px 0;
  line-height: 1.5;
}

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

.span-2 {
  grid-column: span 2;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 78px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: #1e293b;
  color: #fff;
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  max-width: 92vw;
  text-align: center;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 720px;
  background: rgba(18, 26, 46, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 40;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

.nav-btn .nav-icon {
  font-size: 1.15rem;
}

.nav-btn.active {
  color: #60a5fa;
}

@media (max-width: 440px) {
  .sc-val {
    font-size: 0.82rem;
  }
  .inline-form {
    flex-wrap: wrap;
  }
  .inline-form input[type="number"] {
    max-width: none;
    flex: 1;
  }
}
