/* Import theme system */
@import url('./themes.css');

/* CSS Custom Properties (Variables) */
:root {
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 1.875rem;

  /* Layout */
  --header-height: 3.5rem;
  --sidebar-width-expanded: 16rem;
  --sidebar-width-collapsed: 4.5rem;
  --sidebar-width: var(--sidebar-width-expanded);
  --footer-height: 5rem;
  --border-radius: 0.5rem;
  --border-radius-sm: 0.25rem;
  --border-radius-lg: 0.75rem;

  /* Transitions */
  --transition-fast: 150ms ease-in-out;
  --transition-normal: 250ms ease-in-out;
  --transition-slow: 350ms ease-in-out;

  /* Z-index */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-popover: 1060;
  --z-tooltip: 1070;
  --z-toast: 1080;
}

/* Spacing for complex object header */
.complex-object-header {
    margin-bottom: var(--spacing-lg);
}

/* Reset and Base Styles */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  line-height: 1.15;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Layout */
.app {
  display: grid;
  grid-template-rows: var(--header-height) 1fr auto;
  grid-template-columns: 1fr;
  min-height: 100vh;
}

/* Header */
.header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "left center right";
  align-items: center;
  gap: var(--spacing-md);
  padding: 0 var(--spacing-lg);
  background-color: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  box-shadow: var(--shadow-sm);
  color: var(--header-text);
  z-index: var(--z-sticky);
  position: sticky;
  top: 0;
  width: 100%;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.header-left {
  grid-area: left;
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.sidebar-toggle {
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-primary);
    border-radius: 0.375rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.sidebar-toggle:hover {
    background-color: var(--bg-accent);
}

.sidebar-toggle .material-icons {
    font-size: 1.25rem;
    transition: transform var(--transition-normal);
}

.sidebar.collapsed .sidebar-toggle .material-icons {
    transform: rotate(180deg);
}

.logo {
  width: 2rem;
  height: 2rem;
}

.app-title {
  margin: 0;
  font-size: var(--font-size-xl);
  font-weight: 600;
  color: var(--text-primary);
}

.header-center {
  grid-area: center;
  display: flex;
  justify-content: center;
  max-width: 32rem;
}

.config-selector {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.config-selector label {
  font-weight: 500;
  color: var(--text-secondary);
}

.config-select {
  min-width: 12rem;
  padding: var(--spacing-sm) var(--spacing-md);
  border: 1px solid var(--input-border);
  border-radius: var(--border-radius);
  background-color: var(--input-bg);
  color: var(--text-primary);
  font-size: var(--font-size-sm);
  transition: border-color var(--transition-fast);
}

.config-select:focus {
  outline: none;
  border-color: var(--input-focus-border);
  box-shadow: 0 0 0 3px var(--input-focus-ring);
}

.header-right {
  grid-area: right;
  display: flex;
  align-items: center;
  gap: var(--spacing-lg);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.header-actions .btn {
  height: 2.25rem;
  padding: 0 var(--spacing-md);
  border-radius: 0.375rem;
  font-size: var(--font-size-sm);
  font-weight: 500;
  transition: all var(--transition-fast);
}

.header-actions .btn-icon {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-actions .material-icons {
  font-size: 1.125rem;
}


/* Theme Toggle Styling */
.theme-toggle {
  position: relative;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle:hover {
  background-color: var(--bg-accent);
}

.theme-toggle .material-icons {
  font-size: 1.125rem;
  transition: all var(--transition-fast);
}

/* Unified Spinner System */
@keyframes modern-spin {
  0% {
    transform: rotate(0deg) scale(1);
    opacity: 1;
  }
  50% {
    transform: rotate(180deg) scale(1.1);
    opacity: 0.7;
  }
  100% {
    transform: rotate(360deg) scale(1);
    opacity: 1;
  }
}

/* Unified Spinner System */
@keyframes smooth-rotate {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Base spinner class - can be used anywhere */
.spinner {
  position: relative;
  border-radius: 50%;
  animation: smooth-rotate 1s linear infinite;
  flex-shrink: 0;
  border: 2px solid transparent;
  border-top: 2px solid var(--primary-color);
}

/* Size variants */
.spinner-sm {
  width: 16px !important;
  height: 16px !important;
}

.spinner-md {
  width: 24px !important;
  height: 24px !important;
}

.spinner-lg {
  width: 48px !important;
  height: 48px !important;
}

/* Context-specific spinner styles */
.spinner.spinner-inline {
  display: inline-block;
  vertical-align: middle;
  margin-right: var(--spacing-xs);
}

.spinner.spinner-button {
  border-top-color: currentColor;
}

/* Loading overlay specific styles */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: var(--z-modal-backdrop);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-inverse);
  padding: var(--spacing-xl);
  border-radius: var(--border-radius-lg);
  background-color: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* Dark mode: lighter text for better readability */
[data-theme="dark"] .loading-spinner {
  color: var(--text-secondary);
}

/* Auto dark mode support */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .loading-spinner {
    color: var(--text-secondary);
  }
}

.loading-spinner .spinner {
  margin-bottom: var(--spacing-md);
}

/* Legacy support - keep for backward compatibility */
@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.rotating {
  animation: rotate 1s linear infinite;
}


@media (max-width: 640px) {
  .header-actions .btn-icon-only {
    width: 2rem;
    height: 2rem;
    padding: 0;
  }

}

/* Ensure buttons restore properly when transitioning from icon-only to full size */
@media (min-width: 641px) {
  .header-actions .btn:not(.btn-icon) {
    width: auto;
    height: auto;
    padding: var(--spacing-sm) var(--spacing-md);
    white-space: nowrap;
  }

  .app-title {
    font-size: var(--font-size-lg);
  }
}



/* Main Content */
.main-content {
  /* Removed grid layout for main content as sidebar is now fixed */
  overflow: hidden;
}

/* Content Actions at top of main content - aligned with sidebar header */
.main-content > .content-actions {
  position: fixed;
  top: calc(var(--header-height) + var(--spacing-md));
  right: var(--spacing-lg);
  z-index: var(--z-fixed);
}

#yaml-preview-btn .icon {
    transition: transform 0.3s ease;
}

#yaml-preview-btn.active .icon {
    transform: rotate(180deg);
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: var(--header-height);
  bottom: var(--footer-height); /* Stops a bit below the Logs page (at the footer) */
  left: 0;
  width: var(--sidebar-width);
  background-color: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  overflow-y: auto;
  z-index: var(--z-fixed);
  transition: width var(--transition-normal), transform var(--transition-normal);
  overflow-x: hidden;
}

.sidebar.collapsed {
    width: var(--sidebar-width-collapsed);
}

.sidebar.collapsed .nav-text,
.sidebar.collapsed .nav-title,
.sidebar.collapsed .validation-indicator {
    opacity: 0;
    pointer-events: none;
    width: 0;
    margin-left: -1rem; /* Hide text better */
}

.sidebar.collapsed .app-title,
.sidebar.collapsed .sidebar-header h3,
.sidebar.collapsed .sidebar-config-selector {
    display: none;
}

.sidebar-header {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-header h3 {
  margin: 0;
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--text-primary);
}

/* Config selector in sidebar */
.sidebar-config-selector {
  padding: var(--spacing-sm);
}

.sidebar-config-selector .config-selector {
  display: flex;
  flex-direction: row;
  gap: var(--spacing-sm);
  align-items: center;
}

.sidebar-config-selector .config-select {
  flex: 1;
  min-width: auto;
  padding: var(--spacing-sm);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--border-radius);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: var(--font-size-sm);
  transition: border-color var(--transition-fast);
}

.sidebar-config-selector .config-select:focus {
  outline: none;
  border-color: var(--input-focus-border);
  box-shadow: 0 0 0 3px var(--input-focus-ring);
}

.sidebar-config-selector #new-config-btn {
  width: 2.5rem;
  height: 2.5rem;
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-config-selector #new-config-btn .icon {
  width: 1.25rem;
  height: 1.25rem;
}



.nav-menu {
  list-style: none;
  margin: 0;
  padding: var(--spacing-sm) 0;
}

.nav-item {
  margin: 0;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-sm) var(--spacing-md);
  margin: 0 var(--spacing-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--font-size-sm);
  font-weight: 500;
  border-radius: var(--border-radius);
  transition: all var(--transition-fast);
  position: relative;
  white-space: nowrap;
}

.nav-link:hover {
  background-color: var(--sidebar-item-hover);
  color: var(--text-primary);
}

.nav-link.active {
  background-color: var(--primary-color);
  color: var(--button-text-primary);
  font-weight: 600;
}

.nav-link.active .icon {
    color: var(--button-text-primary);
}

.nav-link.active::before {
    content: '';
    position: absolute;
    left: calc(-1 * var(--spacing-sm));
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 1.5rem;
    background: var(--primary-color);
    border-radius: 0 2px 2px 0;
}

.nav-link .icon {
  width: 1.25rem;
  height: 1.25rem;
  color: var(--text-muted);
  transition: color var(--transition-fast);
}

.nav-link:hover .icon {
    color: var(--text-primary);
}

.nav-text {
    transition: opacity var(--transition-fast), width var(--transition-fast), margin-left var(--transition-normal);
}

.validation-indicator {
  margin-left: auto;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.validation-indicator.valid {
  background-color: var(--success-color);
  opacity: 1;
}

.validation-indicator.invalid {
  background-color: var(--error-color);
  opacity: 1;
}

.validation-indicator.warning {
  background-color: var(--warning-color);
  opacity: 1;
}

/* Content Area */
.content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--bg-primary);
  margin-left: var(--sidebar-width); /* Make space for the fixed sidebar */
  transition: margin-left var(--transition-normal);
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-lg);
  border-bottom: 1px solid var(--border-color);
  background-color: var(--card-bg);
}

.content-header h2 {
  margin: 0;
  font-size: var(--font-size-2xl);
  font-weight: 600;
  color: var(--text-primary);
}

.content-actions {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.section-content {
  flex: 1;
  padding: 0 var(--spacing-lg) var(--spacing-lg) var(--spacing-lg);
  overflow-y: auto;
}


/* YAML Preview */
.yaml-preview {
  position: fixed;
  top: var(--header-height);
  right: 0;
  bottom: var(--footer-height);
  width: 50%;
  background-color: var(--bg-primary);
  border-left: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-fixed);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition-normal);
}

.yaml-preview.active {
    transform: translateX(0);
}

.content.yaml-preview-active {
    width: calc(100% - 50%);
}

.yaml-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-lg);
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
}

.yaml-preview-header h3 {
  margin: 0;
  font-size: var(--font-size-lg);
  font-weight: 600;
}

.yaml-content {
  flex: 1;
  margin: 0;
  padding: var(--spacing-lg);
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  line-height: 1.5;
  background-color: var(--bg-primary);
  overflow: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Footer */
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-sm) var(--spacing-lg);
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  z-index: calc(var(--z-fixed) + 1);
  position: sticky;
  bottom: 0;
  width: 100%;
}

.footer-left,
.footer-center,
.footer-right {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.command-panel {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}



.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  font-size: var(--font-size-base);
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

.checkmark {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--input-border);
  border-radius: var(--border-radius-sm);
  background-color: var(--bg-primary);
  transition: all var(--transition-fast);
  position: relative;
}

.checkbox-label input[type="checkbox"]:checked + .checkmark {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
}

.checkbox-label input[type="checkbox"]:checked + .checkmark::after {
  content: '';
  position: absolute;
  left: 6px;
  top: 3px;
  width: 5px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.version-info {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}



/* Utility Classes */
.hidden {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}\n
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: var(--z-modal-backdrop);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}


/* Password Input Group */
.password-input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.password-input-group .form-input {
    padding-right: 2.5rem;
    flex-grow: 1;
}

.password-input-group .password-toggle {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    color: var(--text-muted);
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.password-input-group .password-toggle:hover {
    color: var(--text-primary);
}

.password-input-group .password-toggle .icon {
    width: 1.25rem;
    height: 1.25rem;
    fill: currentColor;
}
