:root {
  --bg: #F5F5F7;
  --surface: #FFFFFF;
  --surface-2: #F2F2F7;
  --surface-hover: #ECECF1;
  --border: rgba(0, 0, 0, 0.06);
  --border-strong: rgba(0, 0, 0, 0.11);
  --text: #1D1D1F;
  --text-2: #6E6E73;
  --text-3: #86868B;
  --accent: #0071E3;
  --accent-soft: rgba(0, 113, 227, 0.10);
  --green: #30D158;
  --green-text: #15803D;
  --green-bg: #EAF7EE;
  --green-border: #BBF7D0;
  --red: #FF3B30;
  --red-bg: rgba(255, 59, 48, 0.10);
  --orange: #FF9500;
  --orange-bg: rgba(255, 149, 0, 0.12);
  --topbar-bg: rgba(245, 245, 247, 0.96);
  --tabbar-bg: rgba(255, 255, 255, 0.97);
  --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.04);
  --shadow-sheet: 0 -8px 32px rgba(0, 0, 0, 0.14);
  --radius-card: 20px;
  --radius-list: 14px;
  --radius-btn: 12px;
  --radius-pill: 999px;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Inter", "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

html[data-theme="dark"] {
  --bg: #0B0C0F;
  --surface: #1C1C1E;
  --surface-2: #2C2C2E;
  --surface-hover: #323236;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #F5F5F7;
  --text-2: #AEAEB2;
  --text-3: #8E8E93;
  --accent: #0A84FF;
  --accent-soft: rgba(10, 132, 255, 0.16);
  --green: #30D158;
  --green-text: #34D399;
  --green-bg: rgba(48, 209, 88, 0.14);
  --green-border: rgba(48, 209, 88, 0.28);
  --red: #FF453A;
  --red-bg: rgba(255, 69, 58, 0.16);
  --orange: #FF9F0A;
  --orange-bg: rgba(255, 159, 10, 0.16);
  --topbar-bg: rgba(11, 12, 15, 0.96);
  --tabbar-bg: rgba(24, 24, 27, 0.97);
  --shadow-card: 0 2px 14px rgba(0, 0, 0, 0.28);
  --shadow-sheet: 0 -10px 36px rgba(0, 0, 0, 0.55);
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, textarea, select {
  font-family: inherit;
  color: inherit;
}

.tg-hidden {
  display: none !important;
}

.tg-app-shell {
  min-height: 100vh;
  max-width: 540px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Top Bar */
.tg-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 54px;
  padding: max(8px, env(safe-area-inset-top)) 16px 8px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
}

.tg-topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.tg-topbar-brand {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tg-topbar-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tg-topbar-subtitle {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  line-height: 1.2;
}

.tg-topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tg-icon-btn {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.14s ease, background 0.14s ease;
}

.tg-icon-btn:active {
  transform: scale(0.94);
  background: var(--surface-2);
}

.tg-icon-btn.is-spinning svg {
  animation: tgSpin 0.8s linear infinite;
}

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

/* Main Content */
.tg-main {
  flex: 1;
  padding: 14px 16px calc(86px + env(safe-area-inset-bottom));
}

.tg-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tg-section-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 6px 6px 2px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Cards */
.tg-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 16px;
  box-shadow: var(--shadow-card);
}

.tg-card-accent {
  border-color: rgba(0, 113, 227, 0.24);
  background: linear-gradient(180deg, rgba(0, 113, 227, 0.05) 0%, var(--surface) 44%);
}

html[data-theme="dark"] .tg-card-accent {
  border-color: rgba(10, 132, 255, 0.30);
  background: linear-gradient(180deg, rgba(10, 132, 255, 0.10) 0%, var(--surface) 44%);
}

.tg-hero-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.tg-hero-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin: 0;
  line-height: 1.2;
}

.tg-hero-sub {
  font-size: 13px;
  color: var(--text-2);
  margin: 4px 0 0;
}

.tg-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.tg-stat-grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tg-stat-box {
  background: var(--surface-2);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tg-stat-val {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.tg-spec-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.tg-spec-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 11px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tg-spec-item.is-full {
  grid-column: 1 / -1;
}

.tg-spec-k {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
}

.tg-spec-v {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tg-stat-lbl {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
}

/* Status Pills */
.tg-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  border: 1px solid transparent;
}

.tg-pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
  flex-shrink: 0;
}

.tg-pill-dot.is-pulse {
  animation: tgPulse 1.8s ease-in-out infinite;
}

@keyframes tgPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.82); }
}

.tg-pill-green {
  background: var(--green-bg);
  color: var(--green-text);
  border-color: var(--green-border);
}

.tg-pill-blue {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(0, 113, 227, 0.18);
}

.tg-pill-red {
  background: var(--red-bg);
  color: var(--red);
  border-color: rgba(255, 59, 48, 0.22);
}

.tg-pill-orange {
  background: var(--orange-bg);
  color: var(--orange);
  border-color: rgba(255, 149, 0, 0.24);
}

.tg-pill-gray {
  background: var(--surface-2);
  color: var(--text-2);
  border-color: var(--border);
}

/* Inset Grouped Lists */
.tg-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-list);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.tg-row {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}

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

.tg-row-static {
  cursor: default;
}

.tg-row:not(.tg-row-static):not(:disabled):active {
  background: var(--surface-2);
}

.tg-row:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.tg-row-main {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  flex: 1;
}

.tg-row-ico {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tg-row-ico.is-green {
  background: var(--green-bg);
  color: var(--green-text);
}

.tg-row-ico.is-red {
  background: var(--red-bg);
  color: var(--red);
}

.tg-row-ico.is-gray {
  background: var(--surface-2);
  color: var(--text-2);
}

.tg-row-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.tg-row-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tg-row-sub {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tg-row-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  color: var(--text-3);
  font-size: 13px;
}

.tg-chevron {
  width: 16px;
  height: 16px;
  color: var(--text-3);
  opacity: 0.7;
}

/* Buttons */
.tg-btn {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: var(--radius-btn);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.14s ease, opacity 0.14s ease, background 0.14s ease;
  text-decoration: none;
}

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

.tg-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  transform: none;
  filter: saturate(0.55);
}

.tg-btn-full {
  width: 100%;
}

.tg-btn-primary {
  background: var(--accent);
  color: #FFFFFF;
}

.tg-btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-strong);
}

.tg-btn-green {
  background: var(--green-bg);
  color: var(--green-text);
  border-color: var(--green-border);
}

.tg-btn-start {
  background: #248A3D;
  color: #FFFFFF;
  border-color: #1F7A35;
}

html[data-theme="dark"] .tg-btn-start {
  background: #30D158;
  color: #051B0B;
  border-color: #30D158;
}

.tg-btn-amber {
  background: #B25000;
  color: #FFFFFF;
  border-color: #9A4500;
}

html[data-theme="dark"] .tg-btn-amber {
  background: #FF9F0A;
  color: #1C1200;
  border-color: #FF9F0A;
}

.tg-btn-stop {
  background: #D70015;
  color: #FFFFFF;
  border-color: #C20012;
}

html[data-theme="dark"] .tg-btn-stop {
  background: #FF453A;
  color: #FFFFFF;
  border-color: #FF453A;
}

.tg-btn-neutral {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

html[data-theme="dark"] .tg-btn-neutral {
  background: #2C2C2E;
  color: #F5F5F7;
  border-color: rgba(255, 255, 255, 0.16);
}

.tg-btn-spinner {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  display: inline-block;
  animation: tgSpin 0.65s linear infinite;
  flex-shrink: 0;
}

.tg-btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border-color: rgba(255, 59, 48, 0.22);
}

.tg-btn-danger-solid {
  background: var(--red);
  color: #FFFFFF;
}

.tg-btn-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.tg-btn-row-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* Device Card */
.tg-device-card {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tg-device-card:active {
  transform: scale(0.985);
}

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

.tg-device-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.015em;
}

.tg-device-meta {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}

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

.tg-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* Segmented Control */
.tg-segmented {
  display: flex;
  background: var(--surface-2);
  border-radius: 11px;
  padding: 3px;
  gap: 3px;
}

.tg-seg-btn {
  flex: 1;
  min-height: 34px;
  padding: 6px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.tg-seg-btn.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.10);
}

/* Horizontal Filter Chips */
.tg-chips-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.tg-chips-scroll::-webkit-scrollbar {
  display: none;
}

.tg-filter-chip {
  flex-shrink: 0;
  min-height: 34px;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.tg-filter-chip.is-active {
  background: var(--accent);
  color: #FFFFFF;
  border-color: var(--accent);
}

/* iOS Switch */
.tg-switch {
  position: relative;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}

.tg-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.tg-switch-track {
  position: absolute;
  inset: 0;
  background: rgba(120, 120, 128, 0.28);
  border-radius: 999px;
  transition: background 0.2s ease;
  cursor: pointer;
}

.tg-switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 999px;
  background: #FFFFFF;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.18);
  transition: transform 0.2s cubic-bezier(0.32, 0.72, 0, 1);
}

.tg-switch input:checked + .tg-switch-track {
  background: var(--green);
}

.tg-switch input:checked + .tg-switch-track::after {
  transform: translateX(20px);
}

/* Inputs & Textareas */
.tg-input, .tg-textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 13px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.tg-input:focus, .tg-textarea:focus {
  border-color: var(--accent);
  background: var(--surface);
}

.tg-textarea {
  min-height: 104px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}

/* Code / Credentials / Logs */
.tg-mono-box {
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.5;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.tg-logs-box {
  max-height: 260px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.48;
  background: #111216;
  color: #E5E7EB;
  border-radius: 14px;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* AI Chat (iMessage Style — pinned bottom composer) */
.tg-support-ai-shell {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 156px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  min-height: calc(100dvh - 156px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  gap: 12px;
}

.tg-chat-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1 1 auto;
  min-height: 160px;
}

.tg-chat-dock {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 8px;
}

.tg-bubble {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.48;
  white-space: pre-wrap;
  word-break: break-word;
}

.tg-bubble-user {
  align-self: flex-end;
  background: var(--accent);
  color: #FFFFFF;
  border-bottom-right-radius: 6px;
}

.tg-bubble-ai {
  align-self: flex-start;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}

.tg-chat-composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.tg-chat-composer .tg-input {
  flex: 1;
  min-height: 44px;
}

.tg-ai-quota-bar {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  gap: 6px;
}

.tg-ai-quota-bar.is-low {
  border-color: rgba(255, 149, 0, 0.4);
  color: #B45309;
  background: rgba(255, 149, 0, 0.08);
}

html[data-theme="dark"] .tg-ai-quota-bar.is-low {
  color: #FBBF24;
  background: rgba(251, 191, 36, 0.12);
}

.tg-ai-quota-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.tg-ai-quota-bar.is-low .tg-ai-quota-dot {
  background: #F59E0B;
}

.tg-ai-disclaimer {
  font-size: 11px;
  line-height: 1.35;
  color: var(--text-3);
  text-align: center;
  padding: 2px 6px 0;
}

/* Progress Bar */
.tg-progress {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.tg-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.35s ease;
}

/* Reader Typography */
.tg-reader-title {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.25;
  margin: 0 0 8px;
}

.tg-reader-p {
  font-size: 15px;
  line-height: 1.62;
  color: var(--text);
  margin: 0 0 12px;
}

/* Bottom Tab Bar */
.tg-tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 540px;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  background: var(--tabbar-bg);
  border-top: 1px solid var(--border);
  padding: 6px 4px max(8px, env(safe-area-inset-bottom));
}

.tg-tab-btn {
  border: none;
  background: transparent;
  color: var(--text-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 46px;
  padding: 2px 2px;
  cursor: pointer;
  transition: color 0.14s ease, transform 0.12s ease;
}

.tg-tab-btn:active {
  transform: scale(0.94);
}

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

.tg-tab-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tg-tab-lbl {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* iOS Bottom Sheet / Action Sheet */
.tg-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.tg-sheet-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.tg-sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 104%);
  width: 100%;
  max-width: 540px;
  max-height: 84vh;
  overflow-y: auto;
  z-index: 70;
  background: var(--surface);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-sheet);
  padding: 10px 18px max(20px, env(safe-area-inset-bottom));
  transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1);
}

.tg-sheet.is-open {
  transform: translate(-50%, 0);
}

.tg-sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--border-strong);
  margin: 0 auto 14px;
}

.tg-sheet-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}

.tg-sheet-desc {
  font-size: 13.5px;
  color: var(--text-2);
  margin: 0 0 14px;
}

/* Toast (Bottom Snackbar above Tab Bar) */
.tg-toast-root {
  position: fixed;
  top: auto;
  bottom: calc(74px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  width: calc(100% - 32px);
  max-width: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.tg-toast {
  max-width: 100%;
  background: rgba(29, 29, 31, 0.96);
  color: #FFFFFF;
  border-radius: 14px;
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.08);
  animation: tgToastUp 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

html[data-theme="dark"] .tg-toast {
  background: rgba(44, 44, 46, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.tg-toast.is-error {
  background: rgba(185, 28, 28, 0.95);
  color: #FFFFFF;
  border-color: rgba(255, 255, 255, 0.16);
}

html[data-theme="dark"] .tg-toast.is-error {
  background: rgba(153, 27, 27, 0.96);
  border-color: rgba(255, 69, 58, 0.42);
}

.tg-toast.is-success {
  background: rgba(21, 128, 61, 0.95);
  color: #FFFFFF;
  border-color: rgba(255, 255, 255, 0.16);
}

html[data-theme="dark"] .tg-toast.is-success {
  background: rgba(20, 83, 45, 0.96);
  border-color: rgba(48, 209, 88, 0.42);
}

@keyframes tgToastUp {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Initial Boot Splash */
.tg-splash {
  min-height: 58vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
}

.tg-splash-logo {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.tg-splash-bar {
  width: 96px;
  height: 3px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  position: relative;
}

.tg-splash-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 45%;
  border-radius: 999px;
  background: var(--accent);
  animation: tgSplashSlide 1.05s ease-in-out infinite;
}

@keyframes tgSplashSlide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(240%); }
}

.tg-error-card {
  border-color: rgba(255, 59, 48, 0.24);
}

/* Shimmer Skeleton (kept minimal for inline loaders) */
.tg-skel-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tg-skel {
  border-radius: 10px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-hover) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: tgShimmer 1.3s infinite linear;
}

.tg-skel-sm { height: 14px; width: 38%; }
.tg-skel-md { height: 18px; width: 72%; }
.tg-skel-lg { height: 28px; width: 58%; }

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

.tg-empty {
  text-align: center;
  padding: 26px 14px;
  color: var(--text-2);
}

.tg-empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 6px;
}

.tg-empty-sub {
  font-size: 13.5px;
  margin: 0 0 14px;
}

.tg-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

.tg-ul {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--text-2);
  font-size: 13.5px;
}

.tg-ul li {
  margin-bottom: 5px;
}

/* Account Checker (Mini App Tools) */
.tg-ac-kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.tg-ac-kpi {
  padding: 11px 12px;
  border-radius: 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.tg-ac-kpi-label {
  font-size: 11px;
  color: var(--text-2);
  font-weight: 500;
}

.tg-ac-kpi-val {
  font-size: 17px;
  font-weight: 700;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.015em;
}

.tg-ac-health-bar {
  font-size: 15px;
  letter-spacing: 1px;
  line-height: 1.3;
  margin: 6px 0;
  word-break: break-all;
}

.tg-ac-prog {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.tg-ac-prog-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tg-ac-prog-top {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.tg-ac-prog-track {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.tg-ac-prog-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

.tg-ac-prog-fill.is-warn { background: var(--orange); }
.tg-ac-prog-fill.is-ok { background: var(--green); }

.tg-ac-chip-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.tg-ac-vid {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.tg-ac-vid:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.tg-ac-vid-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tg-ac-vid-meta {
  font-size: 11.5px;
  color: var(--text-2);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.tg-ac-vid-thumb {
  width: 56px;
  min-width: 56px;
  max-width: 56px;
  height: 78px;
  border-radius: 9px;
  object-fit: cover;
  background: var(--surface-2);
  border: 1px solid var(--border);
  flex-shrink: 0;
  display: block;
}

.tg-ac-vid-thumb-ph {
  width: 56px;
  min-width: 56px;
  max-width: 56px;
  height: 78px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tg-ac-hist-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.tg-ac-hist-item:last-child { border-bottom: none; padding-bottom: 2px; }
.tg-ac-hist-item:first-child { padding-top: 2px; }
.tg-ac-hist-main { min-width: 0; flex: 1; }
.tg-ac-hist-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tg-ac-hist-handle { font-weight: 600; font-size: 14px; color: var(--text); }
.tg-ac-hist-meta { font-size: 11.5px; color: var(--text-2); margin-top: 3px; font-variant-numeric: tabular-nums; }
.tg-ac-hist-acts { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.tg-ac-tags-box {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  max-height: 92px;
  overflow-y: auto;
  word-break: break-word;
}

/* ==================== PASS 7: SCHEDULER GRID & DB GROUPS ==================== */
.tg-select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  appearance: auto;
}

.tg-select:focus {
  border-color: var(--accent);
  background: var(--surface);
}

.tg-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tg-field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}

.tg-field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tg-sch-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}

.tg-sch-table {
  border-collapse: separate;
  border-spacing: 3px;
  min-width: 620px;
  width: 100%;
  padding: 6px;
}

.tg-sch-corner {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--surface-2);
  min-width: 38px;
}

.tg-sch-hr-btn {
  width: 100%;
  min-width: 21px;
  height: 22px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  padding: 0;
}

.tg-sch-hr-btn.is-active {
  background: rgba(0, 122, 255, 0.14);
  color: var(--accent);
}

.tg-sch-day-th {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface-2);
  padding-right: 4px;
}

.tg-sch-day-btn {
  width: 36px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.tg-sch-day-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFFFFF;
}

.tg-sch-cell {
  width: 100%;
  min-width: 21px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  position: relative;
  padding: 0;
  transition: transform 0.08s ease, background 0.12s ease, border-color 0.12s ease;
}

.tg-sch-cell:active {
  transform: scale(0.92);
}

.tg-sch-cell.is-other {
  background: rgba(52, 199, 89, 0.24);
  border-color: rgba(52, 199, 89, 0.45);
}

.tg-sch-cell.is-current {
  background: var(--accent);
  border-color: var(--accent);
}

.tg-sch-cell.is-restart::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: #FF9F0A;
}

.tg-sch-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--text-2);
}

.tg-sch-leg-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.tg-sch-leg-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}

.tg-sch-leg-dot.is-current { background: var(--accent); }
.tg-sch-leg-dot.is-other { background: rgba(52, 199, 89, 0.5); }
.tg-sch-leg-dot.is-restart { background: #FF9F0A; border-radius: 999px; }

.tg-days-pills {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
}

.tg-day-pill {
  min-height: 34px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.tg-day-pill.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFFFFF;
}

.tg-times-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tg-time-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(0, 122, 255, 0.12);
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tg-time-chip-rm {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

.tg-time-add-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tg-time-add-row .tg-input {
  flex: 1;
  min-height: 40px;
  padding: 8px 10px;
}

.tg-check-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
}

.tg-check-card input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.tg-check-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tg-check-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.tg-check-hint {
  font-size: 11.5px;
  color: var(--text-2);
  line-height: 1.35;
}

.tg-dbg-scroll {
  max-height: 46vh;
  overflow-y: auto;
  margin-bottom: 12px;
}

.tg-dbg-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.tg-dbg-item:last-child {
  border-bottom: 0;
}

.tg-dbg-pick {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: transparent;
  border: 0;
  padding: 0;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}

.tg-dbg-name {
  font-size: 14.5px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tg-dbg-pick.is-active .tg-dbg-name {
  color: var(--accent);
  font-weight: 600;
}

.tg-dbg-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.tg-dbg-inline-form {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.tg-dbg-inline-form .tg-input {
  flex: 1;
  min-height: 40px;
  padding: 8px 11px;
  font-size: 14px;
}

.tg-dbg-inline-form .tg-btn {
  min-height: 40px;
  padding: 8px 13px;
  flex-shrink: 0;
}

