*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #1c1c1e;
  --bg-card: #2c2c2e;
  --bg-card2: #3a3a3c;
  --bg-input: #1c1c1e;
  --text: #ffffff;
  --text-secondary: rgba(255,255,255,0.55);
  --text-muted: rgba(255,255,255,0.3);
  --border: rgba(255,255,255,0.08);
  --accent: #3b82f6;
  --accent-dim: rgba(59,130,246,0.15);
  --green: #34d399;
  --green-dim: rgba(52,211,153,0.15);
  --red: #f87171;
  --red-dim: rgba(248,113,113,0.15);
  --amber: #fbbf24;
  --amber-dim: rgba(251,191,36,0.15);
  --purple: #a78bfa;
  --purple-dim: rgba(167,139,250,0.15);
  --teal: #2dd4bf;
  --teal-dim: rgba(45,212,191,0.15);
  --tab-h: 60px;
  --header-h: 52px;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Header ── */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.header-icon {
  font-size: 20px;
}

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge--online {
  background: var(--green-dim);
  color: var(--green);
}

.badge--offline {
  background: rgba(255,255,255,0.07);
  color: var(--text-secondary);
}

/* ── Tab bar ── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tab-h);
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s;
}

.tab-btn span {
  font-family: inherit;
}

.tab-btn--active {
  color: var(--accent);
}

/* ── Content ── */
.content {
  position: fixed;
  top: var(--header-h);
  bottom: var(--tab-h);
  left: 0;
  right: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-panel {
  display: none;
  padding: 16px 16px 24px;
}

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

/* ── Section label ── */
.section-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin: 20px 0 8px;
}

.section-label:first-child {
  margin-top: 4px;
}

/* ── Metrics grid ── */
.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px;
}

.metric-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.metric-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.metric-value--sm {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.metric-bar {
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  margin-top: 10px;
  overflow: hidden;
}

.metric-bar__fill {
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  width: 0%;
  transition: width 0.4s ease;
}

.metric-bar__fill--warn { background: var(--amber); }
.metric-bar__fill--crit { background: var(--red); }

/* ── Card list (SMART, containers) ── */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.list-item:last-child {
  border-bottom: none;
}

.list-item__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot--green { background: var(--green); }
.dot--amber { background: var(--amber); }
.dot--red   { background: var(--red); }
.dot--gray  { background: var(--text-muted); }

.list-item__main {
  flex: 1;
  min-width: 0;
}

.list-item__title {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-item__sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.list-item__badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  flex-shrink: 0;
}

.badge--green { background: var(--green-dim); color: var(--green); }
.badge--amber { background: var(--amber-dim); color: var(--amber); }
.badge--red   { background: var(--red-dim);   color: var(--red); }
.badge--gray  { background: rgba(255,255,255,0.07); color: var(--text-secondary); }

/* ── Skeleton ── */
.skeleton-row {
  height: 52px;
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card2) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-bottom: 1px solid var(--border);
}

.skeleton-row:last-child { border-bottom: none; }

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Refresh button ── */
.refresh-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.refresh-btn:active {
  background: var(--bg-card);
  color: var(--text);
}

/* ── Command list ── */
.cmd-list {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
}

.cmd-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
  text-align: left;
}

.cmd-item:last-child {
  border-bottom: none;
}

.cmd-item:active {
  background: var(--bg-card2);
}

.cmd-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cmd-icon--blue   { background: var(--accent-dim);  color: var(--accent); }
.cmd-icon--purple { background: var(--purple-dim);  color: var(--purple); }
.cmd-icon--amber  { background: var(--amber-dim);   color: var(--amber); }
.cmd-icon--red    { background: var(--red-dim);     color: var(--red); }
.cmd-icon--green  { background: var(--green-dim);   color: var(--green); }
.cmd-icon--teal   { background: var(--teal-dim);    color: var(--teal); }

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

.cmd-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.cmd-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.cmd-arrow {
  color: var(--text-muted);
  flex-shrink: 0;
}

.cmd-result {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--bg-card);
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
}

/* ── Downloads ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Media list */
.media-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
}

.media-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.media-item:last-child { border-bottom: none; }
.media-item:active { background: var(--bg-card2); }

.media-item--selected {
  background: var(--accent-dim);
}

.media-thumb {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--bg-card2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  overflow: hidden;
}

.media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

.media-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.media-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.media-check {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
  transition: all 0.15s;
}

.media-item--selected .media-check {
  background: var(--accent);
  border-color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Folder picker */
.folder-picker {
  margin-top: 12px;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
}

.folder-picker__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.folder-picker__path {
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--text-secondary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.folder-list {
  max-height: 200px;
  overflow-y: auto;
}

.folder-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
  transition: background 0.12s;
}

.folder-row:last-child { border-bottom: none; }
.folder-row:active { background: var(--bg-card2); }
.folder-row svg { color: var(--amber); flex-shrink: 0; }

.folder-picker__actions {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}

.folder-input {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.folder-input:focus {
  border-color: var(--accent);
}

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

/* Action buttons */
.action-btn {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s;
}

.action-btn:active { opacity: 0.75; }

.action-btn--primary {
  width: 100%;
  margin: 12px 14px;
  width: calc(100% - 28px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  padding: 13px;
  border-radius: var(--radius);
}

.action-btn--ghost {
  background: var(--bg-card2);
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Icon button */
.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

/* Download progress */
.dl-progress {
  margin-top: 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
}

.dl-progress__name {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-bar {
  height: 6px;
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s ease;
}

.dl-progress__pct {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
  text-align: right;
}
