:root {
  --bg: #0f1115;
  --surface: #181b21;
  --surface-hover: #1f232b;
  --border: #2a2e38;
  --text: #e2e4e9;
  --text-muted: #8b919d;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 8px;
  --shadow: 0 4px 12px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }

.site-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(15,17,21,0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between;
}
.site-header h1 { margin: 0; font-size: 18px; }
.header-meta { display: flex; align-items: center; gap: 12px; }

.container { max-width: 1100px; margin: 0 auto; padding: 24px; }

section { margin-bottom: 32px; }
section h2 { margin: 0 0 16px; font-size: 16px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* Buttons */
.btn-small, .btn-primary, .btn-secondary, .btn-danger {
  border: none; border-radius: var(--radius);
  padding: 6px 12px; font-size: 13px; cursor: pointer; transition: background .2s;
}
.btn-small { background: var(--surface); color: var(--text); border: 1px solid var(--border); text-decoration: none; }
.btn-small:hover { background: var(--surface-hover); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
button:disabled, .btn-small:disabled, .btn-primary:disabled, .btn-secondary:disabled, .btn-danger:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.85);
}

/* Image filter sub-tabs in file browser */
.img-filter-btn { background: var(--surface); color: var(--text-muted); border: 1px solid var(--border); }
.img-filter-btn:hover { background: var(--surface-hover); color: var(--text); }
.img-filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Bag filter sub-tabs in file browser */
.bag-filter-btn { background: var(--surface); color: var(--text-muted); border: 1px solid var(--border); }
.bag-filter-btn:hover { background: var(--surface-hover); color: var(--text); }
.bag-filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Log filter sub-tabs in file browser */
.log-filter-btn { background: var(--surface); color: var(--text-muted); border: 1px solid var(--border); }
.log-filter-btn:hover { background: var(--surface-hover); color: var(--text); }
.log-filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--surface); border: 1px solid var(--border);
}
.badge::before { content: "●"; }
.badge.ok { color: var(--success); }
.badge.err { color: var(--danger); }
.badge.warn { color: var(--warning); }

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

/* ========== Tab Navigation ========== */
.tab-nav {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  flex-wrap: wrap;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
  border-radius: var(--radius);
  transition: all .2s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab-btn:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.tab-btn.active {
  color: var(--accent);
  background: rgba(59,130,246,0.1);
}

.tab-btn .tab-icon {
  font-size: 16px;
  line-height: 1;
}

.tab-pane {
  display: none;
}

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

/* 小屏幕竖屏：底部固定 tab 栏 */
@media (max-width: 768px) and (orientation: portrait) {
  .tab-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    margin: 0;
    padding: 4px 4px 8px;
    border-bottom: none;
    border-top: 1px solid var(--border);
    background: rgba(15,17,21,0.95);
    backdrop-filter: blur(8px);
    z-index: 100;
    justify-content: space-around;
    flex-wrap: nowrap;
  }

  .tab-btn {
    flex: 1;
    padding: 4px 2px;
    font-size: 10px;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    border-radius: var(--radius);
  }

  .tab-btn .tab-icon {
    font-size: 20px;
  }

  .tab-btn .tab-label {
    font-size: 10px;
  }

  .container {
    padding-bottom: 72px;
  }
}

/* 横屏（小高度）：左侧垂直 tab 栏 */
@media (orientation: landscape) and (max-height: 500px) {
  .tab-nav {
    position: fixed;
    left: 0; top: 48px; bottom: 0;
    width: 72px;
    flex-direction: column;
    border-bottom: none;
    border-right: 1px solid var(--border);
    padding: 8px 4px;
    background: rgba(15,17,21,0.95);
    backdrop-filter: blur(8px);
    z-index: 99;
    margin: 0;
    gap: 4px;
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-y: auto;
  }

  .tab-btn {
    flex-direction: column;
    padding: 6px 2px;
    font-size: 10px;
    gap: 2px;
    width: 100%;
    justify-content: center;
  }

  .tab-btn .tab-icon {
    font-size: 18px;
  }

  .tab-btn .tab-label {
    font-size: 10px;
  }

  .container {
    margin-left: 80px;
    padding-left: 16px;
    max-width: calc(100vw - 96px);
  }

  .site-header {
    padding-left: 88px;
  }
}

/* Cards */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.task-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; cursor: pointer; transition: transform .15s, border-color .15s;
}
.task-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.task-card h3 { margin: 0 0 6px; font-size: 15px; }
.task-card p { margin: 0; color: var(--text-muted); font-size: 13px; }
.task-card .card-footer { margin-top: 12px; display: flex; align-items: center; justify-content: space-between; }
.task-card .status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.task-card.active .status-dot { background: var(--success); box-shadow: 0 0 6px var(--success); }
.task-card.stopping .status-dot { background: var(--warning); }

/* Config */
.config-header { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.config-header h2 { margin: 0; }
.config-form { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 16px 0; }
@media (max-width: 640px) { .config-form { grid-template-columns: 1fr; } }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 12px; color: var(--text-muted); }
.form-group input, .form-group select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 10px; font-size: 14px;
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--accent); }
.form-group .hint { font-size: 11px; color: var(--text-muted); }
.config-actions { margin-top: 16px; }
.command-preview {
  background: var(--bg); border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 10px; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px; color: var(--text-muted); white-space: pre-wrap; word-break: break-all;
  margin-bottom: 12px; min-height: 36px;
}

/* System monitor */
.system-monitor { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.sys-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px;
}
.sys-card .sys-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.sys-card .sys-value { font-size: 18px; font-weight: 600; }
.sys-card .sys-bar { width: 100%; height: 6px; background: var(--bg); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.sys-card .sys-bar > div { height: 100%; border-radius: 999px; transition: width .3s; }
.sys-card .sys-detail { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* Instances */
.instances-list { display: flex; flex-direction: column; gap: 10px; }
.instance-row {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; display: grid; grid-template-columns: 1fr auto auto;
  align-items: center; gap: 16px;
}
@media (max-width: 640px) { .instance-row { grid-template-columns: 1fr; gap: 8px; } }
.instance-info { min-width: 0; }
.instance-info .id { font-family: monospace; font-size: 12px; color: var(--accent); }
.instance-info .cmd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px; color: var(--text-muted); margin-top: 4px;
  white-space: pre-wrap; word-break: break-all;
}
.instance-meta { display: flex; align-items: center; gap: 12px; }
.status-badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 8px;
  border-radius: 999px; background: var(--bg); border: 1px solid var(--border);
}
.status-badge.running { color: var(--success); border-color: rgba(34,197,94,0.3); }
.status-badge.pending { color: var(--warning); border-color: rgba(245,158,11,0.3); }
.status-badge.stopping { color: var(--warning); border-color: rgba(245,158,11,0.3); }
.status-badge.failed { color: var(--danger); border-color: rgba(239,68,68,0.3); }
.status-badge.completed { color: var(--accent); border-color: rgba(59,130,246,0.3); }
.status-badge.stopped { color: var(--text-muted); }

.progress-bar {
  width: 120px; height: 6px; background: var(--bg); border-radius: 999px; overflow: hidden;
}
.progress-bar > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }

.instance-actions { display: flex; gap: 8px; }

.result-block { margin-top: 10px; padding: 8px 10px; background: var(--bg); border-radius: var(--radius); border: 1px solid var(--border); }
.result-label { font-size: 11px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.result-pre { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 12px; color: var(--text); white-space: pre-wrap; word-break: break-all; }
.file-links { display: flex; flex-wrap: wrap; gap: 6px; }
.file-link { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); color: var(--accent); font-size: 12px; text-decoration: none; }
.file-link:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.file-link:hover .file-remark { color: rgba(255,255,255,0.8); }
.file-title { font-weight: 500; }
.file-remark { color: var(--text-muted); font-size: 11px; }

.interrupt-block { border-color: var(--warning); background: rgba(245,158,11,0.05); }
.interrupt-block .result-label { color: var(--warning); }

/* Modal */
.modal {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center;
  z-index: 300; padding: 24px;
}
.modal-content {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 520px; max-height: 70vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.modal-body { padding: 8px; overflow-y: auto; }
.file-list { display: flex; flex-direction: column; gap: 2px; }
.file-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: var(--radius); cursor: pointer;
  font-size: 13px;
}
.file-item:hover { background: var(--surface-hover); }
.file-item .fname { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.file-item .fmeta { color: var(--text-muted); font-size: 11px; }

/* File preview */
.preview-img { max-width: 100%; max-height: calc(90vh - 60px); object-fit: contain; border-radius: var(--radius); }
.preview-video { max-width: 100%; max-height: calc(90vh - 60px); border-radius: var(--radius); }
.preview-btn { background: var(--accent); color: #fff; border: none; padding: 2px 8px; border-radius: var(--radius); font-size: 12px; cursor: pointer; margin-right: 4px; }
.preview-btn:hover { opacity: 0.85; }
.spinner { width: 28px; height: 28px; border: 3px solid rgba(255,255,255,0.15); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* App market */
.app-upload-area {
  background: var(--surface); border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 24px; text-align: center; margin-bottom: 16px; transition: border-color .2s, background .2s;
  cursor: pointer;
}
.app-upload-area.dragover { border-color: var(--accent); background: rgba(59,130,246,0.05); }
.app-upload-area p { margin: 0; color: var(--text-muted); font-size: 13px; }
.app-upload-area .upload-link { color: var(--accent); text-decoration: underline; cursor: pointer; }
.apps-list { display: flex; flex-direction: column; gap: 8px; }
.app-row {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; display: grid; grid-template-columns: 1fr auto auto;
  align-items: center; gap: 12px;
}
@media (max-width: 640px) { .app-row { grid-template-columns: 1fr; gap: 8px; } }
.app-row .app-name { font-weight: 500; font-size: 14px; }
.app-row .app-meta { font-size: 11px; color: var(--text-muted); }
.app-row .app-version { display: inline-block; padding: 1px 6px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); font-size: 11px; margin-left: 6px; }

/* Collapsible result blocks */
.result-block { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.result-block.collapsed .result-body { display: none; }
.result-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--bg); cursor: pointer; user-select: none;
}
.result-header:hover { background: var(--surface-hover); }
.result-header .collapse-icon {
  font-size: 11px; color: var(--text-muted); transition: transform .2s;
}
.result-block.collapsed .result-header .collapse-icon {
  transform: rotate(-90deg);
}
.result-body {
  padding: 10px 12px; background: var(--bg); border-top: 1px solid var(--border);
}
.result-body .result-pre { margin: 0; }

/* History */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-row {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px;
}
.history-row .history-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.history-row .history-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.history-row .history-files .file-link.missing { color: var(--text-muted); text-decoration: line-through; pointer-events: none; }

/* Log panel */
.log-panel {
  position: fixed; bottom: 0; left: 0; right: 0; max-height: 40vh;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 200;
}
.log-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--bg);
}
#log-content {
  flex: 1; overflow-y: auto; margin: 0; padding: 12px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px; line-height: 1.6; color: var(--text-muted); white-space: pre-wrap;
}

