/**
 * SimpleGallery WebOS - WebOSToolkit Component Stylesheet (`window.sys.ui`)
 * Modern, responsive, glassmorphic UI components for WebOS applications.
 */

/* ==========================================================================
   1. CSS Variables & Base Component Tokens
   ========================================================================== */
:root {
  --webos-ui-font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --webos-ui-radius-sm: 6px;
  --webos-ui-radius-md: 10px;
  --webos-ui-radius-lg: 16px;
  --webos-ui-radius-full: 9999px;

  --webos-ui-bg-glass: rgba(30, 41, 59, 0.82);
  --webos-ui-bg-card: rgba(15, 23, 42, 0.65);
  --webos-ui-bg-hover: rgba(255, 255, 255, 0.08);
  --webos-ui-bg-active: rgba(99, 102, 241, 0.2);

  --webos-ui-border: rgba(255, 255, 255, 0.12);
  --webos-ui-border-focus: rgba(99, 102, 241, 0.6);

  --webos-ui-primary: #6366f1;
  --webos-ui-primary-hover: #4f46e5;
  --webos-ui-primary-text: #ffffff;

  --webos-ui-success: #10b981;
  --webos-ui-warning: #f59e0b;
  --webos-ui-danger: #ef4444;
  --webos-ui-info: #3b82f6;

  --webos-ui-text-main: #f8fafc;
  --webos-ui-text-muted: #94a3b8;
  --webos-ui-shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
  --webos-ui-shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
  --webos-ui-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Theme Overrides if data-theme is light */
[data-theme="light-minimal"] {
  --webos-ui-bg-glass: rgba(255, 255, 255, 0.9);
  --webos-ui-bg-card: rgba(241, 245, 249, 0.9);
  --webos-ui-bg-hover: rgba(0, 0, 0, 0.05);
  --webos-ui-border: rgba(0, 0, 0, 0.1);
  --webos-ui-text-main: #0f172a;
  --webos-ui-text-muted: #64748b;
}

/* ==========================================================================
   2. Toast Notifications Container & Items
   ========================================================================== */
.webos-toast-container {
  position: fixed;
  top: 48px;
  right: 16px;
  z-index: 999999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 380px;
  width: calc(100vw - 32px);
  pointer-events: none;
}

.webos-toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--webos-ui-radius-md);
  background: var(--webos-ui-bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--webos-ui-border);
  box-shadow: var(--webos-ui-shadow-lg);
  color: var(--webos-ui-text-main);
  font-family: var(--webos-ui-font-family);
  font-size: 0.9rem;
  line-height: 1.4;
  animation: webosToastSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.webos-toast-exit {
  opacity: 0;
  transform: translateX(100%);
}

@keyframes webosToastSlideIn {
  from {
    opacity: 0;
    transform: translateX(50px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

.webos-toast-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
  line-height: 1;
}

.webos-toast-message {
  flex: 1;
  word-break: break-word;
}

.webos-toast-close {
  background: none;
  border: none;
  color: var(--webos-ui-text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  font-size: 1.1rem;
  line-height: 1;
  transition: var(--webos-ui-transition);
}
.webos-toast-close:hover {
  color: var(--webos-ui-text-main);
  background: var(--webos-ui-bg-hover);
}

.webos-toast-success { border-left: 4px solid var(--webos-ui-success); }
.webos-toast-error   { border-left: 4px solid var(--webos-ui-danger); }
.webos-toast-warning { border-left: 4px solid var(--webos-ui-warning); }
.webos-toast-info    { border-left: 4px solid var(--webos-ui-info); }

/* ==========================================================================
   3. Modal & Async Dialog Backdrop & Windows
   ========================================================================== */
.webos-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 999900;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: webosFadeIn 0.2s ease;
}

@keyframes webosFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.webos-modal-card {
  background: var(--webos-ui-bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--webos-ui-border);
  border-radius: var(--webos-ui-radius-lg);
  box-shadow: var(--webos-ui-shadow-lg);
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--webos-ui-text-main);
  font-family: var(--webos-ui-font-family);
  animation: webosModalPop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.webos-modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--webos-ui-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.webos-modal-title {
  font-weight: 700;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.webos-modal-close {
  background: none;
  border: none;
  color: var(--webos-ui-text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: var(--webos-ui-radius-sm);
  padding: 4px 8px;
  transition: var(--webos-ui-transition);
}
.webos-modal-close:hover {
  background: var(--webos-ui-bg-hover);
  color: var(--webos-ui-text-main);
}

.webos-modal-body {
  padding: 20px;
  overflow-y: auto;
  font-size: 0.95rem;
  line-height: 1.5;
  flex: 1;
}

.webos-modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--webos-ui-border);
  background: rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.webos-btn {
  padding: 8px 16px;
  border-radius: var(--webos-ui-radius-md);
  border: 1px solid var(--webos-ui-border);
  background: var(--webos-ui-bg-hover);
  color: var(--webos-ui-text-main);
  font-family: var(--webos-ui-font-family);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: var(--webos-ui-transition);
  user-select: none;
}
.webos-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.25);
}
.webos-btn:active {
  transform: scale(0.97);
}

.webos-btn-primary {
  background: var(--webos-ui-primary);
  border-color: var(--webos-ui-primary);
  color: #ffffff;
}
.webos-btn-primary:hover {
  background: var(--webos-ui-primary-hover);
  border-color: var(--webos-ui-primary-hover);
}

.webos-btn-danger {
  background: var(--webos-ui-danger);
  border-color: var(--webos-ui-danger);
  color: #ffffff;
}
.webos-btn-danger:hover {
  background: #dc2626;
  border-color: #dc2626;
}

/* ==========================================================================
   4. Segmented Control & Tabs
   ========================================================================== */
.webos-segmented {
  display: inline-flex;
  padding: 4px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--webos-ui-border);
  border-radius: var(--webos-ui-radius-md);
  gap: 4px;
  user-select: none;
}

.webos-segmented-btn {
  background: transparent;
  border: none;
  padding: 6px 14px;
  border-radius: var(--webos-ui-radius-sm);
  color: var(--webos-ui-text-muted);
  font-family: var(--webos-ui-font-family);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--webos-ui-transition);
}
.webos-segmented-btn:hover {
  color: var(--webos-ui-text-main);
  background: var(--webos-ui-bg-hover);
}
.webos-segmented-btn.active {
  background: var(--webos-ui-primary);
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Tabs */
.webos-tabs-nav {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--webos-ui-border);
  padding-bottom: 8px;
  margin-bottom: 16px;
}
.webos-tabs-nav.vertical {
  flex-direction: column;
  border-bottom: none;
  border-right: 1px solid var(--webos-ui-border);
  padding-bottom: 0;
  padding-right: 12px;
  margin-bottom: 0;
  margin-right: 16px;
}

.webos-tab-item {
  padding: 8px 16px;
  border-radius: var(--webos-ui-radius-md);
  background: transparent;
  border: none;
  color: var(--webos-ui-text-muted);
  font-family: var(--webos-ui-font-family);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: var(--webos-ui-transition);
}
.webos-tab-item:hover {
  color: var(--webos-ui-text-main);
  background: var(--webos-ui-bg-hover);
}
.webos-tab-item.active {
  background: var(--webos-ui-bg-active);
  color: #818cf8;
}

/* ==========================================================================
   5. Form Controls (Switch, Slider, SearchInput)
   ========================================================================== */
/* Switch */
.webos-switch-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  font-family: var(--webos-ui-font-family);
  font-size: 0.9rem;
  color: var(--webos-ui-text-main);
}
.webos-switch-track {
  width: 42px;
  height: 24px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--webos-ui-radius-full);
  position: relative;
  transition: var(--webos-ui-transition);
  border: 1px solid var(--webos-ui-border);
}
.webos-switch-thumb {
  width: 18px;
  height: 18px;
  background: #ffffff;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.webos-switch-input {
  display: none;
}
.webos-switch-input:checked + .webos-switch-track {
  background: var(--webos-ui-primary);
  border-color: var(--webos-ui-primary);
}
.webos-switch-input:checked + .webos-switch-track .webos-switch-thumb {
  transform: translateX(18px);
}

/* Search Input */
.webos-search-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 100%;
}
.webos-search-icon {
  position: absolute;
  left: 12px;
  color: var(--webos-ui-text-muted);
  font-size: 0.9rem;
  pointer-events: none;
}
.webos-search-input {
  width: 100%;
  padding: 8px 32px 8px 34px;
  border-radius: var(--webos-ui-radius-md);
  border: 1px solid var(--webos-ui-border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--webos-ui-text-main);
  font-family: var(--webos-ui-font-family);
  font-size: 0.88rem;
  outline: none;
  transition: var(--webos-ui-transition);
}
.webos-search-input:focus {
  border-color: var(--webos-ui-border-focus);
  background: rgba(0, 0, 0, 0.4);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}
.webos-search-clear {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--webos-ui-text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}
.webos-search-clear:hover {
  color: var(--webos-ui-text-main);
}

/* Slider */
.webos-slider-wrapper {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  font-family: var(--webos-ui-font-family);
}
.webos-slider-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-main, var(--webos-ui-text-main, #f8fafc));
}
.webos-slider-group {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  font-family: var(--webos-ui-font-family);
}
.webos-slider-input {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  border-radius: 4px;
  background: var(--border-color, rgba(148, 163, 184, 0.4));
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
  outline: none;
  cursor: pointer;
}
.webos-slider-input::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 4px;
  background: var(--border-color, rgba(148, 163, 184, 0.4));
}
.webos-slider-input::-moz-range-track {
  height: 8px;
  border-radius: 4px;
  background: var(--border-color, rgba(148, 163, 184, 0.4));
}
.webos-slider-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--accent-primary, var(--webos-ui-primary, #6366f1));
  border: 2px solid #ffffff;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.4);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.webos-slider-input::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-primary, var(--webos-ui-primary, #6366f1));
  border: 2px solid #ffffff;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.4);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.webos-slider-input::-webkit-slider-thumb:hover,
.webos-slider-input::-moz-range-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 3px 8px rgba(99, 102, 241, 0.6);
}
.webos-slider-value {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-primary, var(--webos-ui-primary, #6366f1));
  min-width: 45px;
  text-align: center;
  padding: 2px 8px;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: 6px;
}

/* ==========================================================================
   6. Data Tables & TreeViews
   ========================================================================== */
.webos-table-wrapper {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--webos-ui-border);
  border-radius: var(--webos-ui-radius-md);
  background: rgba(0, 0, 0, 0.2);
}
.webos-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--webos-ui-font-family);
  font-size: 0.88rem;
  color: var(--webos-ui-text-main);
  text-align: left;
}
.webos-table th {
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.3);
  font-weight: 700;
  color: var(--webos-ui-text-muted);
  border-bottom: 1px solid var(--webos-ui-border);
  user-select: none;
  cursor: pointer;
}
.webos-table th:hover {
  color: var(--webos-ui-text-main);
}
.webos-table td {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.webos-table tbody tr {
  transition: var(--webos-ui-transition);
}
.webos-table tbody tr:hover {
  background: var(--webos-ui-bg-hover);
}
.webos-table tbody tr.selected {
  background: var(--webos-ui-bg-active);
}

/* ==========================================================================
   7. Feedback Elements (EmptyState, Spinner, Tooltip)
   ========================================================================== */
.webos-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--webos-ui-text-muted);
  font-family: var(--webos-ui-font-family);
}
.webos-empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.8;
}
.webos-empty-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--webos-ui-text-main);
  margin-bottom: 6px;
}
.webos-empty-desc {
  font-size: 0.9rem;
  max-width: 360px;
  margin-bottom: 16px;
}

/* Spinner */
.webos-spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  border-top-color: var(--webos-ui-primary);
  animation: webosSpin 0.8s linear infinite;
}
@keyframes webosSpin {
  to { transform: rotate(360deg); }
}

/* Tooltip */
.webos-tooltip {
  position: absolute;
  z-index: 999999;
  padding: 6px 10px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--webos-ui-border);
  border-radius: var(--webos-ui-radius-sm);
  color: #ffffff;
  font-family: var(--webos-ui-font-family);
  font-size: 0.78rem;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--webos-ui-shadow-md);
  animation: webosFadeIn 0.15s ease;
}

/* ==========================================================================
   8. Cards, Gauges & Info Grids (.webos-card, .webos-gauge-card, .webos-chip)
   ========================================================================== */
.webos-card {
  background: var(--card-bg, var(--bg-card, var(--webos-ui-bg-card)));
  border: 1px solid var(--border-color, var(--webos-ui-border));
  border-radius: var(--webos-ui-radius-lg);
  padding: 18px 22px;
  margin-bottom: 16px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text-main, var(--webos-ui-text-main));
}
.webos-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.webos-card-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-main, var(--webos-ui-text-main));
}

.webos-gauges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.webos-gauge-card {
  background: var(--card-bg, var(--bg-card, rgba(255, 255, 255, 0.04)));
  border: 1px solid var(--border-color, var(--webos-ui-border));
  border-radius: var(--webos-ui-radius-md);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.webos-gauge-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.webos-gauge-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main, var(--webos-ui-text-main));
}
.webos-gauge-val {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--accent-primary, var(--webos-ui-primary));
}

.webos-progress-bar {
  width: 100%;
  height: 8px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: var(--webos-ui-radius-full);
  overflow: hidden;
}
.webos-progress-fill {
  height: 100%;
  background: var(--accent-primary, var(--webos-ui-primary));
  border-radius: var(--webos-ui-radius-full);
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.webos-progress-fill.warning { background: var(--webos-ui-warning, #f59e0b); }
.webos-progress-fill.danger  { background: var(--webos-ui-danger, #ef4444); }

.webos-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}
.webos-info-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--card-bg, var(--bg-card, rgba(255, 255, 255, 0.04)));
  border-radius: var(--webos-ui-radius-md);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.06));
}
.webos-info-label {
  font-size: 0.825rem;
  color: var(--text-muted, var(--webos-ui-text-muted));
  font-weight: 500;
}
.webos-info-val {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main, var(--webos-ui-text-main));
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.webos-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--webos-ui-radius-full);
  background: var(--card-bg, var(--bg-card, rgba(255, 255, 255, 0.06)));
  border: 1px solid var(--border-color, var(--webos-ui-border));
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main, var(--webos-ui-text-main));
}
.webos-chip.enabled {
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.35);
  color: #22c55e;
}
.webos-chip.disabled {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #f87171;
  opacity: 0.7;
}

/* Real-Time Telemetry Charts Grid & Cards */
.webos-charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  width: 100%;
  margin-bottom: 16px;
}

.webos-chart-card {
  background: var(--card-bg, var(--bg-card, rgba(255, 255, 255, 0.03)));
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
  border-radius: var(--webos-ui-radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  overflow: hidden;
}

.webos-chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.webos-chart-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted, var(--webos-ui-text-muted));
  display: flex;
  align-items: center;
  gap: 6px;
}

.webos-chart-val {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-main, var(--webos-ui-text-main));
  font-variant-numeric: tabular-nums;
}

.webos-canvas-wrapper {
  width: 100%;
  height: 80px;
  border-radius: var(--webos-ui-radius-sm);
  background: rgba(0, 0, 0, 0.12);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.04));
  overflow: hidden;
  position: relative;
}

.webos-chart-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.webos-chart-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted, var(--webos-ui-text-muted));
}
  opacity: 0.5;
}
