/* Patches for tomwebapp.html tab switching */

/* Ensure hidden class works with high specificity */
.hidden {
  display: none !important;
}

/* 
   Ensure tab content layout is correct when shown.
   These tabs require flex layout to display their children correctly.
   Moving this from hardcoded JS to CSS.
*/
#tab-library:not(.hidden),
#tab-settings:not(.hidden) {
  display: flex !important;
  flex-direction: column;
  height: 100%;
}

/* Ensure default display for other tabs if they don't have specific display rules */
.tab-content:not(.hidden) {
  /* No default display forced, let other CSS rules decide (usually block) */
}

/* Fix for potential pointer-events issues if they were disabled */
.tab-link {
  pointer-events: auto;
}

.tab-link.permission-locked {
  position: relative;
}

.tab-link.permission-locked::before {
  content: "🔒";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  opacity: 0.85;
  pointer-events: none;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 50%;
}

.tomwebapp-inline-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px;
  color: var(--text-secondary);
  width: 100%;
}

.tomwebapp-inline-spinner {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: rgba(255, 255, 255, 0.8);
  animation: tomwebapp-inline-spin 0.8s linear infinite;
}

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

#tab-tools .tool-card.permission-locked {
  position: relative;
}

#tab-tools .tool-card.permission-locked::after {
  content: "🔒";
  position: absolute;
  top: 10px;
  right: 10px;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  pointer-events: none;
  opacity: 0.9;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 50%;
}

#tab-tools .tool-card.tom-tool-loading {
  position: relative;
  overflow: hidden;
}

#tab-tools .tool-card.tom-tool-loading::before {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg,
      rgba(249, 216, 73, 0.95) 0%,
      rgba(249, 216, 73, 0.95) var(--tom-tool-progress, 0%),
      rgba(255, 255, 255, 0.14) var(--tom-tool-progress, 0%),
      rgba(255, 255, 255, 0.14) 100%);
  pointer-events: none;
  z-index: 1002;
}

html.tom-tools-nav-loading .tab-link {
  pointer-events: none !important;
}

#tab-tools.tom-tools-loading-lock .tool-card,
#tab-tools.tom-tools-loading-lock button,
#tab-tools.tom-tools-loading-lock a {
  pointer-events: none !important;
}

[data-lock-indicator="true"] {
  position: relative;
}

[data-lock-indicator="true"]::before {
  content: "🔒";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  pointer-events: none;
  opacity: 0.9;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 50%;
}

.permission-locked:not([data-lock-indicator="true"]):not(.tab-link):not(.tool-card):not(.game-card):not(.settings-pane)::before {
  content: "🔒";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  pointer-events: none;
  opacity: 0.9;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 50%;
}

html.tomai-agent-ui-locked [data-tom-agent-ui="input"],
html.tomai-agent-ui-locked [data-tom-agent-ui="collapsed-icon"] {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.settings-content.pane-apimart-active {
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

.settings-content.pane-apimart-active #pane-apimart {
  height: 100% !important;
}

.settings-content.pane-apimart-active #pane-apimart .settings-group {
  height: 100% !important;
  margin: 0 !important;
}

.settings-content.pane-apimart-active #pane-apimart .settings-header {
  display: none !important;
}

.settings-content.pane-apimart-active #pane-apimart #apimart-settings-frame {
  min-height: 100% !important;
}

.settings-content.pane-apimart-active #pane-apimart,
.settings-content.pane-apimart-active #pane-apimart .settings-group,
.settings-content.pane-apimart-active #pane-apimart #apimart-settings-frame,
.settings-content.pane-apimart-active #pane-apimart .api-config-content {
  background: transparent !important;
}

.settings-content.pane-apimart-active #pane-apimart .apimart-model-box,
.settings-content.pane-apimart-active #pane-apimart .model-tags-scrollbox,
.settings-content.pane-apimart-active #pane-apimart .model-tag,
.settings-content.pane-apimart-active #pane-apimart .floating-badge {
  background: transparent !important;
}

.tab-content-container.settings-active:has(.settings-content.pane-apimart-active) {
  padding-top: 0 !important;
}

#tab-agent .agent-controls {
  justify-content: space-between;
  gap: 50px;
  overflow-x: hidden;
}

#tab-agent .agent-controls-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
}

#tab-agent .agent-controls .api-quick-controls {
  flex: 0 0 auto;
  margin-left: 0 !important;
}

#notification-bar .notification-close-btn {
  background: #c2410c !important;
  border: none !important;
  color: #fff !important;
  opacity: 1 !important;
  width: 32px !important;
  height: 32px !important;
}

#notification-bar .notification-close-btn:hover {
  background: #ea580c !important;
}

#notification-bar .notification-close-btn .notification-close-icon {
  width: 20px !important;
  height: 20px !important;
  display: block !important;
}

.tomwebapp-global-loading-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.35s ease;
  z-index: 100000;
}

.tomwebapp-global-loading-icon {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease;
  z-index: 100001;
  pointer-events: none;
}

.tomwebapp-show-global-loading .tomwebapp-global-loading-mask {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.tomwebapp-show-global-loading .tomwebapp-global-loading-icon {
  opacity: 1;
  visibility: visible;
}

.tomwebapp-global-loading-spinner {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.22);
  border-top-color: var(--accent-color, #06b6d4);
  animation: tomwebapp-spin 0.9s linear infinite;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
}

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

#btn-send-message.loading .loading-icon-wrapper img:not(.send-thinking-icon),
#btn-send-message.waiting .loading-icon-wrapper img:not(.send-thinking-icon),
.action-btn-large.loading .loading-icon-wrapper img,
.action-btn-large.waiting .loading-icon-wrapper img {
  animation: tomwebapp-spin 0.9s linear infinite !important;
}

@keyframes tomwebapp-thinking-breathe {
  0% {
    transform: scale(1);
    opacity: 0.92;
  }
  50% {
    transform: scale(1.3);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 0.92;
  }
}

#btn-send-message.loading .loading-icon-wrapper img.send-thinking-icon,
#btn-send-message.waiting .loading-icon-wrapper img.send-thinking-icon {
  animation: tomwebapp-thinking-breathe 1.2s ease-in-out infinite !important;
  transform-origin: center;
}

#tom-top-loading-progress {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--tab-nav-height);
  height: 5px;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

#tom-top-loading-progress.visible {
  opacity: 1;
}

#tom-top-loading-progress .tom-top-loading-progress-bar {
  width: 0%;
  height: 100%;
  background: #f9d849;
  box-shadow: 0 0 12px rgba(249, 216, 73, 0.55);
  transition: width 0.12s linear;
}

#tom-top-loading-progress.indeterminate .tom-top-loading-progress-bar {
  width: 0%;
  animation: none;
  transform: none;
}
