:root {
  --bg: #0b1120;
  --bg-elevated: #111827;
  --bg-panel: #162033;
  --border: #24324a;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #38bdf8;
  --primary-hover: #0ea5e9;
  --emerald: #34d399;
  --amber: #fbbf24;
  --rose: #fb7185;
  --violet: #a78bfa;
  --radius: 12px;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  height: 100%;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.5px;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

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

/* Workspace Layout */
.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 248px;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px 12px;
  overflow-y: auto;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  transition: all 0.15s ease;
}

.nav-item:hover {
  background: rgba(56, 189, 248, 0.08);
  color: var(--text);
}

.nav-item.active {
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.35);
  color: #fff;
  font-weight: 600;
}

.nav-icon {
  width: 18px;
  text-align: center;
}

.nav-count {
  margin-left: auto;
  font-size: 11px;
  font-family: var(--font-mono);
  background: var(--bg-panel);
  padding: 1px 7px;
  border-radius: 99px;
  color: var(--primary);
}

.sidebar-selection {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.section-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 8px;
}

.selection-actions {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.selected-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  max-height: 180px;
  overflow-y: auto;
}

.sel-pill {
  font-size: 11px;
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: #e0f2fe;
  padding: 2px 8px;
  border-radius: 99px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.sel-pill button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0;
  font-size: 12px;
}

/* Main Content */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* Cards & Grids */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.card-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 28px;
  font-weight: 700;
  font-family: var(--font-mono);
  margin-top: 4px;
}

.text-emerald { color: var(--emerald); }
.text-sky { color: var(--primary); }
.text-amber { color: var(--amber); }
.text-violet { color: var(--violet); }
.text-rose { color: var(--rose); }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 16px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Device Cards */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}

.device-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  transition: border-color 0.15s ease, transform 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.device-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.35);
}

.device-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

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

.device-alias {
  font-weight: 700;
  font-size: 15px;
}

.device-sub {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.device-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  font-size: 12px;
  background: var(--bg-panel);
  padding: 10px;
  border-radius: 8px;
}

.meta-item {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  color: var(--text-muted);
}

.meta-item strong {
  color: var(--text);
  font-family: var(--font-mono);
  font-weight: 500;
}

.device-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.device-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: auto;
}

/* Screen Wall */
.wall-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.wall-controls-left, .wall-controls-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.wall-text-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.wall-text-bar .input {
  max-width: 420px;
}

.screen-wall-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.phone-stage {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.phone-stage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}

.phone-screen-wrap {
  position: relative;
  background: #020617;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #1e293b;
  cursor: crosshair;
  user-select: none;
  aspect-ratio: 9 / 19;
  display: flex;
  align-items: center;
  justify-content: center;
}

.phone-screen-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.phone-stage-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

/* Buttons, Inputs, Pills */
.btn, .btn-xs {
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-panel);
  transition: all 0.15s ease;
}

.btn {
  padding: 8px 14px;
  font-size: 13px;
}

.btn-xs {
  padding: 4px 10px;
  font-size: 12px;
}

.btn:hover, .btn-xs:hover {
  border-color: var(--primary);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #082f49;
}

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

.btn-secondary {
  background: var(--bg-panel);
}

.btn-danger {
  background: rgba(251, 113, 133, 0.15);
  border-color: rgba(251, 113, 133, 0.45);
  color: #fecdd3;
}

.btn-ghost {
  background: transparent;
  border-style: dashed;
  color: var(--primary);
}

.input, .input-sm, .textarea {
  width: 100%;
  background: #0b1324;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 11px;
  font-size: 13px;
  outline: none;
}

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

.input-sm {
  padding: 6px 9px;
  font-size: 12px;
  width: auto;
}

.textarea {
  font-family: var(--font-mono);
  resize: vertical;
}

.pill, .tag {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 99px;
  font-family: var(--font-mono);
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-muted);
}

.pill-ok {
  background: rgba(52, 211, 153, 0.14);
  border-color: rgba(52, 211, 153, 0.35);
  color: var(--emerald);
}

.pill-warn {
  background: rgba(251, 191, 36, 0.14);
  border-color: rgba(251, 191, 36, 0.35);
  color: var(--amber);
}

.pill-err {
  background: rgba(251, 113, 133, 0.14);
  border-color: rgba(251, 113, 133, 0.35);
  color: var(--rose);
}

.pill-info {
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.35);
  color: var(--primary);
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.form-row label {
  font-size: 12px;
  color: var(--text-muted);
}

.form-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.form-inline .input {
  flex: 1;
  min-width: 140px;
}

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

.sub-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.sub-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 8px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.checkbox-label, .switch-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

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

/* Tables & Outputs */
.table-wrap {
  overflow-x: auto;
}

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

th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

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

.batch-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}

.result-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.result-card pre {
  margin: 8px 0 0;
  padding: 8px;
  background: #060a14;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  overflow-x: auto;
  max-height: 200px;
  white-space: pre-wrap;
  word-break: break-word;
}

.shot-thumb {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 8px;
  background: #020617;
  margin-top: 8px;
}

/* Logcat Console */
.logcat-console {
  height: calc(100vh - 230px);
  overflow-y: auto;
  background: #050914;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.log-line {
  display: grid;
  grid-template-columns: 112px 126px 26px 120px 1fr;
  gap: 8px;
  padding: 2px 4px;
  border-bottom: 1px solid rgba(36, 50, 74, 0.35);
}

.log-V { color: #94a3b8; }
.log-D { color: #38bdf8; }
.log-I { color: #34d399; }
.log-W { color: #fbbf24; }
.log-E, .log-F { color: #fb7185; font-weight: 600; }

/* Doctor & History */
.doctor-list, .history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.doctor-item, .history-item {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.code-hint {
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  background: #060a14;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--primary);
}

/* Status & Empty */
.status-box {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.3);
  font-size: 12px;
}

.empty-hint {
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: 12px;
  grid-column: 1 / -1;
}

.hidden {
  display: none !important;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.75);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  width: min(460px, 92vw);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  z-index: 1;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}

.qr-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.qr-svg-box {
  width: 230px;
  height: 230px;
  background: #fff;
  padding: 10px;
  border-radius: 12px;
  display: grid;
  place-items: center;
}

.qr-svg-box svg {
  width: 100%;
  height: 100%;
}

.qr-status {
  text-align: center;
  font-weight: 600;
  color: var(--primary);
  font-size: 13px;
}

.qr-steps {
  width: 100%;
  background: var(--bg-panel);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal-footer {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* Toasts */
.toast-stack {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  background: var(--bg-panel);
  border: 1px solid var(--primary);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  max-width: 360px;
}

.toast-err {
  border-color: var(--rose);
}

/* ==================== V3.2 Tactical Command Cockpit, Kanban & Viral Studio ==================== */
.nav-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  padding: 10px 10px 4px;
}

.nav-group-title:first-child {
  padding-top: 2px;
}

.cockpit-hero {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.14), rgba(99, 102, 241, 0.12) 55%, rgba(16, 185, 129, 0.08));
  border: 1px solid rgba(56, 189, 248, 0.32);
  border-radius: 16px;
  padding: 18px 20px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.cockpit-hero-title {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.cockpit-hero-sub {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 4px;
}

.funnel-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(155px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
  overflow-x: auto;
}

.funnel-step {
  position: relative;
  background: linear-gradient(180deg, rgba(22, 32, 51, 0.95), rgba(17, 24, 39, 0.95));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 15px;
  transition: border-color 0.2s ease, transform 0.15s ease;
}

.funnel-step:hover {
  border-color: rgba(56, 189, 248, 0.5);
  transform: translateY(-1px);
}

.funnel-step-num {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--primary);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.funnel-step-title {
  font-size: 13px;
  font-weight: 600;
  margin-top: 2px;
  color: #e2e8f0;
}

.funnel-step-val {
  font-size: 28px;
  font-weight: 800;
  font-family: var(--font-mono);
  margin: 6px 0 4px;
  color: #fff;
}

.funnel-step-sub {
  font-size: 11.5px;
  color: var(--text-muted);
}

.station-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.station-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
}

.station-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  height: 3px;
  background: var(--primary);
}

.station-card.station-wecom::before {
  background: linear-gradient(90deg, #8b5cf6, #ec4899);
}

.station-card.station-scout::before {
  background: linear-gradient(90deg, #0ea5e9, #38bdf8);
}

.station-card.station-kos::before {
  background: linear-gradient(90deg, #10b981, #34d399);
}

.quota-bar-wrap {
  background: #0b1120;
  border: 1px solid var(--border);
  border-radius: 99px;
  height: 8px;
  overflow: hidden;
}

.quota-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #0ea5e9, #34d399);
  transition: width 0.3s ease;
}

/* Kanban CRM Board */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(245px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
  align-items: start;
}

.kanban-col {
  background: rgba(17, 24, 39, 0.85);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  min-height: 440px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.kanban-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 13px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.kanban-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 620px;
  overflow-y: auto;
}

.kanban-card {
  background: var(--bg-panel);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 11px;
  padding: 11px;
  font-size: 12.5px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kanban-card:hover {
  border-color: rgba(56, 189, 248, 0.45);
}

.campaign-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}

.campaign-pill {
  padding: 7px 14px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s ease;
}

.campaign-pill.active {
  background: rgba(56, 189, 248, 0.16);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.dual-qr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  width: 100%;
}

.qr-panel-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

@media (max-width: 860px) {
  .sidebar {
    width: 190px;
  }
  .inline-grid-3 {
    grid-template-columns: 1fr;
  }
  .funnel-strip {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }
}
