:root {
  color-scheme: dark;
  --bg-main: #070d0a;
  --bg-card: rgba(17, 27, 21, 0.9);
  --bg-card-hover: rgba(24, 38, 30, 0.95);
  --bg-input: #0a130e;
  --border-color: rgba(52, 211, 153, 0.18);
  --border-focus: #10b981;
  --text-main: #f0fdf4;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent-emerald: #10b981;
  --accent-mint: #34d399;
  --accent-glow: rgba(16, 185, 129, 0.25);
  --accent-gold: #f59e0b;
  --accent-red: #ef4444;
  --accent-blue: #3b82f6;
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', Consolas, 'Courier New', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Strictly 1 Screen: Zero Body Scroll */
html, body {
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  background-image: 
    radial-gradient(at 0% 0%, rgba(16, 185, 129, 0.09) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(5, 150, 105, 0.07) 0px, transparent 50%),
    radial-gradient(at 50% 30%, rgba(6, 78, 59, 0.05) 0px, transparent 60%);
  color: var(--text-main);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  width: 100%;
  max-width: 1800px;
  height: 100vh;
  max-height: 100vh;
  margin: 0 auto;
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #10b981, #065f46);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 12px var(--accent-glow);
  color: #fff;
  font-size: 16px;
  flex-shrink: 0;
}

h1 {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(to right, #ffffff, #a7f3d0);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.15;
}

header p.muted {
  font-size: 10.5px;
  line-height: 1.1;
  margin-top: 1px;
  color: var(--text-muted);
}

h2 {
  font-size: 13.5px;
  font-weight: 700;
  color: #e6fcf5;
  display: flex;
  align-items: center;
  gap: 6px;
}

h2::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 12px;
  background: #10b981;
  border-radius: 2px;
  box-shadow: 0 0 6px #10b981;
}

h3 {
  font-size: 12.5px;
  font-weight: 600;
  color: #a7f3d0;
}

.muted {
  color: var(--text-muted);
  font-size: 11px;
}

.mono {
  font-family: var(--font-mono);
  font-size: 11.5px;
}

/* Header Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.connection-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 9999px;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #a7f3d0;
  font-size: 11px;
  font-weight: 600;
}

.connection-badge::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0% { transform: scale(0.95); opacity: 0.8; box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1.15); opacity: 1; box-shadow: 0 0 0 4px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); opacity: 0.8; box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(30, 48, 38, 0.6);
  color: #d1fae5;
  border: 1px solid rgba(74, 115, 87, 0.5);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.link:hover {
  background: rgba(40, 68, 52, 0.9);
  border-color: var(--accent-emerald);
  color: #ffffff;
  transform: translateY(-1px);
}

/* Tabs Nav */
.tabs-nav {
  display: flex;
  gap: 6px;
  margin-bottom: 4px;
  flex-shrink: 0;
}

.tabs {
  display: flex;
  gap: 3px;
  background: rgba(14, 24, 18, 0.7);
  padding: 2px 4px;
  border-radius: 8px;
  border: 1px solid rgba(52, 211, 153, 0.15);
  width: fit-content;
  backdrop-filter: blur(10px);
}

.tabs button {
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  background: transparent;
  color: #94a3b8;
}

.tabs button.active {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  border-color: rgba(52, 211, 153, 0.5);
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.35);
}

.tabs button:not(.active):hover {
  background: rgba(255, 255, 255, 0.05);
  color: #e2e8f0;
}

/* Main Content Area */
main.main-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Layout Views */
.screen-view {
  display: none;
  flex-direction: column;
  gap: 4px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  animation: fadeIn 0.15s ease-in-out;
}

.screen-view.active {
  display: flex;
  flex: 1;
  min-height: 0;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Screen 1: Control Split */
.control-split {
  display: grid;
  grid-template-columns: minmax(400px, 1.4fr) minmax(380px, 1fr);
  gap: 6px;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.positions-split {
  display: grid;
  grid-template-columns: minmax(450px, 1.15fr) minmax(360px, 0.85fr);
  gap: 6px;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 10px;
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  transition: border-color 0.2s ease;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.card:hover {
  border-color: rgba(52, 211, 153, 0.35);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.count-badge {
  font-size: 11px;
  font-weight: 600;
  color: #a7f3d0;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.25);
  padding: 2px 8px;
  border-radius: 9999px;
  white-space: nowrap;
}

/* Bot Card (Left) */
.bot-card {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.account-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 4px;
  flex-shrink: 0;
}

.account-toolbar select {
  flex: 1;
  min-width: 130px;
  padding: 3px 6px;
  font-size: 11px;
  height: 25px;
}

.account-toolbar button {
  padding: 3px 7px;
  font-size: 11px;
  height: 25px;
}

/* Notice Bar */
.notice {
  min-height: 0;
  color: #fbbf24;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 5px;
  background: rgba(45, 34, 18, 0.6);
  border: 1px solid rgba(245, 158, 11, 0.3);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}
.notice:empty { display: none; }

/* Table Container (Internal scrolling ONLY) */
.bot-card .table-container {
  flex: 1;
  min-height: 0;
  max-height: none !important;
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid rgba(52, 211, 153, 0.15);
  border-radius: 6px;
}

.table-container {
  overflow-x: auto;
  overflow-y: auto;
  border: 1px solid rgba(52, 211, 153, 0.15);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  text-align: left;
}

.bot-list-table {
  table-layout: fixed;
  width: 100%;
}
.bot-list-table th:first-child,
.bot-list-table td:first-child {
  width: 140px;
  white-space: nowrap;
}
.bot-list-table th:last-child,
.bot-list-table td:last-child {
  width: auto;
}
.status-col {
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  max-width: 0 !important;
}
.status-flex {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}
.status-detail-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 11px;
  color: #94a3b8;
  flex: 1;
  min-width: 0;
}

th {
  background: #0d1a13;
  color: #a7f3d0;
  font-weight: 600;
  padding: 5px 8px;
  border-bottom: 1px solid rgba(52, 211, 153, 0.2);
  position: sticky;
  top: 0;
  z-index: 10;
}

td {
  padding: 5px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: middle;
}

tr:hover td {
  background: rgba(52, 211, 153, 0.05);
}

tr.is-selected td {
  background: rgba(56, 189, 248, 0.16) !important;
  border-bottom: 1px solid rgba(56, 189, 248, 0.4) !important;
}

tr.is-selected .bot-name {
  color: #38bdf8 !important;
  font-weight: 700;
  text-shadow: 0 0 8px rgba(56, 189, 248, 0.4);
}

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 9999px;
  font-size: 10px;
  font-weight: 600;
}

.badge-connected { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.badge-training { background: rgba(56, 189, 248, 0.15); color: #38bdf8; animation: pulse 2s infinite; }
.badge-idle { background: rgba(74, 222, 128, 0.15); color: #4ade80; }
.badge-moving { background: rgba(96, 165, 250, 0.15); color: #60a5fa; }
.badge-connecting, .badge-joining { background: rgba(251, 191, 36, 0.15); color: #fbbf24; }
.badge-error { background: rgba(248, 113, 113, 0.15); color: #f87171; }
.badge-disconnected { background: rgba(148, 163, 184, 0.1); color: #94a3b8; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Task Card (Right) */
.task-card {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.task-body-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 6px;
  overflow: hidden;
}

.task-col-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
}

.task-col-right {
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

/* Inventory Widget in Monitor */
.inv-box {
  background: rgba(10, 19, 14, 0.7);
  border: 1px solid rgba(52, 211, 153, 0.15);
  border-radius: 6px;
  padding: 4px 6px;
  margin-bottom: 0;
  flex-shrink: 0;
}

.inv-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  max-height: 48px;
  overflow-y: auto;
  margin-top: 3px;
}

.inv-slot {
  background: #112219;
  border: 1px solid #234331;
  border-radius: 4px;
  padding: 2px 5px;
  font-size: 10.5px;
  font-family: var(--font-mono);
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.inv-count {
  background: var(--accent-emerald);
  color: #fff;
  border-radius: 3px;
  padding: 1px 3px;
  font-size: 9.5px;
  font-weight: 700;
}

.chest-box {
  background: rgba(10, 19, 14, 0.5);
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid rgba(52, 211, 153, 0.12);
  flex-shrink: 0;
}

/* Keypad Controls */
.manual-keypad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px;
  background: rgba(10, 19, 14, 0.7);
  border: 1px solid rgba(52, 211, 153, 0.15);
  border-radius: 6px;
  margin-bottom: 0;
  flex-shrink: 0;
}

.key-btn {
  width: 28px;
  height: 26px;
  background: #15261d;
  border: 1px solid #284c37;
  border-radius: 4px;
  color: #e2ede5;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  touch-action: none;
}
.key-btn:active, .key-btn.active {
  background: var(--accent-emerald);
  color: #fff;
}
.key-btn-wide {
  width: 58px;
  font-size: 10px;
}

/* Logs Container Wrap & #logs (Internal scrolling ONLY) */
.logs-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#logs {
  flex: 1;
  min-height: 50px;
  height: 100%;
  max-height: none !important;
  overflow-y: auto;
  background: #080f0b;
  border: 1px solid rgba(52, 211, 153, 0.15);
  border-radius: 6px;
  padding: 4px 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

.log-line { padding: 1px 0; }
.log-line.log-auth { color: #fde047; }
.log-line.log-server { color: #c084fc; }
.log-line.log-claim { color: #4ade80; }
.log-line.log-error { color: #f87171; }
.log-line.log-info { color: #cbd5e1; }

/* Policy Card */
.policy-card {
  flex-shrink: 0;
  margin-top: 0;
  padding: 4px 10px;
}

.policy-form-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.policy-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
}

.policy-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #a7f3d0;
  padding: 2px 8px;
  border-radius: 5px;
  font-size: 11px;
}

/* Inputs & Form Elements */
input, select, textarea {
  background: var(--bg-input);
  color: #f0fdf4;
  border: 1px solid rgba(74, 115, 87, 0.6);
  border-radius: 6px;
  padding: 5px 8px;
  font-family: var(--font-sans);
  font-size: 11.5px;
  transition: all 0.2s ease;
  outline: none;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent-emerald);
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.25);
}

input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: #10b981;
  cursor: pointer;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 6px;
}

.field label {
  font-size: 10.5px;
  font-weight: 600;
  color: #a7f3d0;
  letter-spacing: 0.02em;
}

.row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.row.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.row.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.row.grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 6px; }

/* Buttons */
button {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  border: 1px solid rgba(52, 211, 153, 0.4);
  border-radius: 6px;
  padding: 4px 10px;
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.25);
  white-space: nowrap;
}

button:hover {
  background: linear-gradient(135deg, #34d399, #10b981);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
}

button:active {
  transform: translateY(0);
}

button.secondary {
  background: rgba(30, 48, 38, 0.6);
  color: #d1fae5;
  border: 1px solid rgba(74, 115, 87, 0.5);
  box-shadow: none;
}

button.secondary:hover {
  background: rgba(40, 68, 52, 0.9);
  border-color: var(--accent-emerald);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.2);
}

button.danger {
  background: rgba(76, 29, 29, 0.6);
  color: #fecdd3;
  border: 1px solid rgba(225, 29, 72, 0.4);
  box-shadow: none;
}

button.danger:hover {
  background: rgba(159, 18, 57, 0.85);
  border-color: #f43f5e;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(225, 29, 72, 0.3);
}

button.action-btn-sm {
  padding: 3px 6px;
  font-size: 10.5px;
  border-radius: 5px;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* Map Screen */
.map-card {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.map-canvas-wrap {
  position: relative;
  border: 1px solid rgba(52, 211, 153, 0.2);
  border-radius: 6px;
  background: #09120d;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

canvas#map {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: crosshair;
}

.config-card {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
}

/* Server & Raw JSON Screens */
#screen-server, #screen-accounts, #screen-raw-json {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

/* Modal Dialogs */
.log-dialog {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 16px;
}

.log-dialog[hidden] {
  display: none !important;
}

.log-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 14px;
  width: 100%;
  max-width: 820px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

#modalLogsContainer {
  flex: 1;
  min-height: 200px;
  max-height: 60vh;
  overflow-y: auto;
  background: #080f0b;
  border: 1px solid rgba(52, 211, 153, 0.15);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
  color: #cbd5e1;
}

/* Custom Sleek Scrollbars (Never outer scroll, smooth internal scroll) */
*::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

*::-webkit-scrollbar-track {
  background: rgba(10, 19, 14, 0.5);
  border-radius: 3px;
}

*::-webkit-scrollbar-thumb {
  background: rgba(52, 211, 153, 0.28);
  border-radius: 3px;
}

*::-webkit-scrollbar-thumb:hover {
  background: rgba(52, 211, 153, 0.55);
}

/* Toast */
#toast-container {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 9999;
}

.toast {
  background: #14281e;
  border: 1px solid var(--accent-emerald);
  color: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  font-size: 11.5px;
  display: flex;
  align-items: center;
  gap: 6px;
  animation: slideIn 0.2s ease;
}

.toast.toast-error { background: #3b1414; border-color: #ef4444; color: #fecaca; }
.toast.toast-success { background: #0e2e1d; border-color: #10b981; color: #d1fae5; }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1024px) {
  .control-split, .positions-split {
    grid-template-columns: 1fr;
  }
}

/* Screen Tasks (Task Queue Screen) */
#screen-tasks {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.tasks-card {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tasks-card .table-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;
}

.badge-task-queued {
  background: rgba(251, 191, 36, 0.18);
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, 0.3);
}

.badge-task-running {
  background: rgba(56, 189, 248, 0.18);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.35);
  animation: pulse 1.5s infinite;
}

.badge-task-done {
  background: rgba(16, 185, 129, 0.18);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-task-error {
  background: rgba(239, 68, 68, 0.18);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-task-canceled {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.task-action-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(52, 211, 153, 0.2);
  color: #e2e8f0;
  font-size: 11px;
}

/* Activity Logs Styling */
.logs-wrap {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: rgba(10, 18, 14, 0.85);
  border: 1px solid rgba(52, 211, 153, 0.2);
  border-radius: 6px;
  padding: 6px 8px;
}

#logs {
  flex: 1;
  min-height: 0;
  max-height: 230px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.log-line {
  padding: 2px 6px;
  border-radius: 3px;
  word-break: break-word;
  white-space: pre-wrap;
}

.log-info {
  color: #e2e8f0;
}

.log-auth {
  color: #a7f3d0;
  background: rgba(16, 185, 129, 0.08);
}

.log-claim {
  color: #fde047;
  background: rgba(234, 179, 8, 0.1);
}

.log-server {
  color: #93c5fd;
  border-left: 2px solid #3b82f6;
  padding-left: 5px;
}

.log-warning {
  color: #fbbf24;
  background: rgba(245, 158, 11, 0.14);
  border-left: 3px solid #f59e0b;
  padding-left: 5px;
  font-weight: 600;
}

.log-error {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.16);
  border-left: 3px solid #ef4444;
  padding-left: 5px;
  font-weight: 600;
}


.chest-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}

/* Settings Sub-Tabs */
.settings-subtabs {
  display: flex;
  gap: 8px;
}
.settings-subtab-btn {
  background: rgba(15, 23, 42, 0.6);
  color: #94a3b8;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 6px 14px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.settings-subtab-btn:hover {
  background: rgba(30, 41, 59, 0.85);
  color: #f8fafc;
}
.settings-subtab-btn.active {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border-color: #10b981;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.25);
}
.settings-panel {
  display: block;
}

/* ============================================================
   MOBILE / PHONE RESPONSIVE UI (Desktop > 768px giu nguyen 100%)
   ============================================================ */
.mobile-pane-switcher {
  display: none;
}

.mobile-back-btn {
  display: none !important;
}

@media (max-width: 768px) {
  html, body {
    height: auto !important;
    min-height: 100dvh;
    max-height: none !important;
    overflow-x: hidden;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .wrap {
    height: auto !important;
    min-height: 100dvh;
    max-height: none !important;
    padding: 8px 8px calc(18px + env(safe-area-inset-bottom, 0px)) 8px;
    overflow: visible !important;
  }

  /* Header gon dep 2 hang tren phone */
  header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 8px;
    padding-bottom: 8px;
  }

  .brand-group {
    justify-content: space-between;
  }

  h1 {
    font-size: 16px;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
    gap: 6px;
  }

  .connection-badge {
    flex: 1;
    justify-content: center;
    padding: 5px 8px;
    font-size: 11px;
  }

  .header-actions .link,
  .header-actions button {
    min-height: 32px;
    padding: 4px 10px !important;
    font-size: 11.5px;
  }

  /* Tab dieu huong vuot ngang muot */
  .tabs-nav {
    margin-bottom: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs-nav::-webkit-scrollbar {
    display: none;
  }

  .tabs {
    width: max-content;
    min-width: 100%;
    padding: 3px;
    gap: 4px;
  }

  .tabs button {
    min-height: 36px;
    padding: 6px 12px;
    font-size: 12px;
    white-space: nowrap;
  }

  /* Main & Screen views cho phep cuon tu nhien */
  main.main-content,
  .screen-view,
  .screen-view.active,
  #screen-tasks,
  #screen-server,
  #screen-accounts,
  #screen-raw-json {
    height: auto !important;
    min-height: 0;
    overflow: visible !important;
    padding-right: 0;
  }

  /* Thanh chuyen doi nhanh Danh sach <-> Chi tiet tren phone */
  .mobile-pane-switcher {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 8px;
    position: sticky;
    top: 0;
    z-index: 30;
    background: rgba(7, 13, 10, 0.92);
    backdrop-filter: blur(10px);
    padding: 4px 0;
  }

  .mobile-pane-btn {
    min-height: 38px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 700;
    border-radius: 8px;
    background: rgba(17, 27, 21, 0.95);
    border: 1px solid rgba(52, 211, 153, 0.25);
    color: #94a3b8;
    box-shadow: none;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-pane-btn.active {
    background: linear-gradient(135deg, #10b981, #059669);
    border-color: rgba(52, 211, 153, 0.6);
    color: #ffffff;
    box-shadow: 0 3px 10px rgba(16, 185, 129, 0.35);
  }

  .mobile-back-btn {
    display: inline-flex !important;
    min-height: 30px;
    padding: 3px 9px !important;
    font-size: 11.5px !important;
  }

  .control-split,
  .positions-split {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: visible !important;
  }

  /* An/hien dung pane dang chon tren mobile */
  #screen-control[data-mobile-pane="list"] .bot-detail-card,
  #screen-bicanh[data-mobile-pane="list"] .bot-detail-card {
    display: none;
  }

  #screen-control[data-mobile-pane="detail"] .bot-card,
  #screen-bicanh[data-mobile-pane="detail"] .bot-card {
    display: none;
  }

  .card,
  .bot-card,
  .task-card,
  .map-card,
  .config-card {
    height: auto !important;
    overflow: visible !important;
    padding: 10px;
  }

  .bot-card .table-container {
    overflow: visible !important;
    border: none;
    background: transparent;
  }

  /* Thanh Healer Pool gon dep tren phone */
  #healerPoolBar {
    padding: 8px !important;
    gap: 6px !important;
    font-size: 11px !important;
  }
  #healerQueueInfo {
    margin-left: 0 !important;
    width: 100%;
  }

  /* Toolbar hang loat de bam tren phone */
  .account-toolbar {
    gap: 6px !important;
    margin-bottom: 8px !important;
  }
  .account-toolbar button {
    min-height: 34px;
    height: auto !important;
    padding: 5px 10px !important;
    font-size: 11.5px !important;
    flex: 1 1 auto;
  }
  .account-toolbar > div {
    width: 100%;
    margin-left: 0 !important;
  }
  .account-toolbar select {
    min-height: 34px;
    height: 34px !important;
    font-size: 12px !important;
  }

  /* Chuyen bang danh sach Bot sang Card UI tren phone (khong bao gio bi cat chu!) */
  #screen-control .bot-list-table,
  #screen-bicanh .bot-list-table {
    display: block;
    table-layout: auto;
  }

  #screen-control .bot-list-table thead,
  #screen-bicanh .bot-list-table thead {
    display: none;
  }

  #screen-control .bot-list-table tbody,
  #screen-bicanh .bot-list-table tbody {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  #screen-control .bot-list-table tbody tr,
  #screen-bicanh .bot-list-table tbody tr {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px;
    background: rgba(10, 19, 14, 0.85);
    border: 1px solid rgba(52, 211, 153, 0.22);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  }

  #screen-control .bot-list-table tbody tr.is-selected,
  #screen-bicanh .bot-list-table tbody tr.is-selected {
    background: rgba(56, 189, 248, 0.14);
    border-color: rgba(56, 189, 248, 0.6);
  }

  #screen-control .bot-list-table tbody tr td,
  #screen-bicanh .bot-list-table tbody tr td {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
    width: 100% !important;
    max-width: none !important;
    padding: 0 !important;
    border: none !important;
    white-space: normal !important;
    overflow: visible !important;
    background: transparent !important;
  }

  #screen-control .bot-list-table .bot-name,
  #screen-bicanh .bot-list-table .bot-name {
    font-size: 14px !important;
  }

  #screen-control .bot-list-table .bot-checkbox,
  #screen-bicanh .bot-list-table .bot-checkbox {
    width: 18px;
    height: 18px;
  }

  .status-flex {
    flex-wrap: wrap;
    white-space: normal;
  }

  .status-detail-text {
    font-size: 11.5px;
  }

  /* Khung Chi tiet Bot tren phone */
  .detail-ribbon {
    gap: 6px !important;
  }

  .inv-box {
    padding: 8px !important;
  }

  .inv-grid {
    max-height: 120px;
    gap: 4px;
  }

  .inv-slot {
    padding: 4px 6px;
    font-size: 11px;
  }

  #realmInfoBadge {
    padding: 9px 10px !important;
    font-size: 12px !important;
  }

  #btnToggleTargetRealm,
  #btnToggleTargetRealmAlt {
    min-height: 28px !important;
    height: auto !important;
    padding: 3px 8px !important;
    font-size: 11px !important;
  }

  #targetRealmBox {
    padding: 8px !important;
  }

  #targetRealmBox > div {
    flex-direction: column;
    align-items: stretch !important;
    gap: 6px !important;
  }

  #targetRealmSelect,
  #targetStageSelect {
    width: 100% !important;
    height: 36px !important;
    font-size: 13px !important;
  }

  #btnSaveTargetRealm,
  #btnClearTargetRealm,
  #btnCloseTargetRealm {
    min-height: 34px !important;
    height: 34px !important;
    font-size: 12px !important;
    margin-left: 0 !important;
  }

  /* Hop thoai & Log thoai mai doc tren phone */
  .chat-logs-container {
    min-height: 280px !important;
    padding: 8px !important;
  }

  .chat-logs-container > div:first-child {
    flex-wrap: wrap;
    gap: 6px;
  }

  #logs {
    min-height: 190px !important;
    max-height: 42vh !important;
    font-size: 11px !important;
    line-height: 1.45 !important;
  }

  .chat-row {
    gap: 6px !important;
    margin-top: 8px !important;
  }

  #chat,
  #biCanhChat {
    height: 38px !important;
    font-size: 16px !important; /* Ngan iOS Safari tu phong to khi focus */
    padding: 6px 10px !important;
  }

  #send,
  #biCanhSend {
    height: 38px !important;
    padding: 0 16px !important;
    font-size: 13px !important;
  }

  /* Luoi nut thao tac bot 2 cot de bam bang ngon tay */
  .bot-action-toolbar {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px !important;
    padding: 8px !important;
  }

  .bot-action-toolbar button {
    min-height: 38px;
    padding: 6px 8px !important;
    font-size: 12px !important;
    margin-left: 0 !important;
    white-space: normal;
    line-height: 1.2;
  }

  /* Form grids thu ve 1 cot */
  .row.grid-2,
  .row.grid-3,
  .row.grid-4 {
    grid-template-columns: 1fr !important;
  }

  /* Modal full man hinh gon tren phone */
  .log-dialog {
    padding: 8px;
  }

  .log-panel {
    max-height: 92dvh;
    padding: 10px;
  }

  #modalLogsContainer {
    max-height: 68dvh;
    font-size: 11px;
  }

  /* Toast can giua duoi man hinh */
  #toast-container {
    left: 10px;
    right: 10px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .toast {
    width: 100%;
    font-size: 12.5px;
    padding: 10px 12px;
  }

  .policy-card {
    padding: 8px 10px;
    margin-top: 6px;
  }
}

@media (max-width: 400px) {
  .bot-action-toolbar {
    grid-template-columns: 1fr 1fr;
  }
  .bot-action-toolbar button {
    font-size: 11px !important;
  }
}


