/* ==========================================================================
   Base Styles - Global typography, colors, and resets
   ========================================================================== */

/* CSS Reset and Box Sizing */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* CSS Custom Properties (Variables) */
:root {
  /* Color Palette */
  --color-primary: #2563eb;
  --color-primary-light: #3b82f6;
  --color-primary-dark: #1d4ed8;
  
  --color-secondary: #64748b;
  --color-secondary-light: #94a3b8;
  --color-secondary-dark: #475569;
  
  --color-success: #059669;
  --color-success-light: #dcfce7;
  --color-warning: #d97706;
  --color-error: #dc2626;
  
  --color-background: #ffffff;
  --color-surface: #f8fafc;
  --color-surface-elevated: #ffffff;
  --color-border: #e2e8f0;
  --color-border-light: #f1f5f9;
  
  /* Additional color variants */
  --color-primary-lighter: #dbeafe;
  --color-hover-light: #f0fdf4;
  
  --color-text-primary: #1e293b;
  --color-text-secondary: #64748b;
  --color-text-muted: #94a3b8;
  
  /* Typography */
  --font-family-base: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-family-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 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;
  
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.75;
  
  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  
  /* Border Radius */
  --radius-sm: 0.125rem;
  --radius-base: 0.25rem;
  --radius-md: 0.375rem;
  --radius-lg: 0.5rem;
  --radius-xl: 0.75rem;
  --radius-full: 9999px;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-base: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  
  /* Transitions */
  --transition-fast: 150ms ease-in-out;
  --transition-base: 200ms ease-in-out;
  --transition-slow: 300ms ease-in-out;
  
  /* Touch Targets */
  --touch-target-min: 44px;
}

/* Base HTML Elements */
html {
  font-family: var(--font-family-base);
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
  background-color: var(--color-background);
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  margin-bottom: var(--space-4);
}

h1 { font-size: var(--font-size-3xl); }
h2 { font-size: var(--font-size-2xl); }
h3 { font-size: var(--font-size-xl); }
h4 { font-size: var(--font-size-lg); }
h5 { font-size: var(--font-size-base); }
h6 { font-size: var(--font-size-sm); }

p {
  margin-bottom: var(--space-4);
}

/* Button Components */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  min-height: var(--touch-target-min);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background-color: #7a8a9f;
  color: white;
  border-color: #7a8a9f;
}

.btn-primary:hover:not(:disabled) {
  background-color: #6a7a8f;
  border-color: #6a7a8f;
}

.btn-secondary {
  background-color: #8e9aaa;
  color: white;
  border-color: #8e9aaa;
}

.btn-secondary:hover:not(:disabled) {
  background-color: #7e8a9a;
  border-color: #7e8a9a;
}

.btn-icon {
  padding: var(--space-2);
  min-width: var(--touch-target-min);
  background: transparent;
  border: none;
  border-radius: var(--radius-base);
  color: var(--color-text-secondary);
  font-size: var(--font-size-lg);
}

.btn-icon:hover:not(:disabled) {
  background-color: var(--color-surface);
  color: var(--color-text-primary);
}

/* Form Elements */
input,
select,
textarea {
  font-family: inherit;
  font-size: var(--font-size-base);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-background);
  color: var(--color-text-primary);
  transition: border-color var(--transition-fast);
  min-height: var(--touch-target-min);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Panel Components */
.panel {
  background-color: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Hide book manager when nav is toggled off */
#book-manager.nav-hidden {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
  position: absolute;
  z-index: -1;
}

/* Expand editor panel when nav is hidden */
#app-container.nav-hidden #editor-panel {
  grid-column: 1 / -1;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  gap: var(--space-3);
}

/* Toggle nav button */
.toggle-nav-btn {
  font-size: 1.25rem;
  padding: var(--space-2);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-base);
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.toggle-nav-btn:hover {
  background: var(--color-hover);
}

.toggle-nav-btn .icon {
  transition: transform 0.3s ease;
}

#app-container.nav-hidden .toggle-nav-btn .icon {
  transform: rotate(90deg);
}

.panel-header h2 {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  margin: 0;
}

.panel-tools {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.panel-content {
  flex: 1;
  padding: var(--space-6);
  overflow-y: auto;
}

/* Tree Components */
.tree-container {
  font-size: var(--font-size-sm);
  overflow: visible;
  position: relative;
}

.tree-item {
  display: flex;
  align-items: center;
  position: relative;
  margin: 1px 0;
  border-radius: var(--radius-base);
  cursor: pointer;
  transition: all var(--transition-fast);
  min-height: 32px;
  z-index: 1;
  overflow: visible;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.tree-item:hover {
  background-color: var(--color-hover-light);
  z-index: 2;
}

.tree-item.selected {
  background-color: var(--color-primary-lighter) !important;
  color: var(--color-text-primary) !important;
  z-index: 10;
}

/* Ensure selected state overrides hover */
.tree-item.selected:hover {
  background-color: var(--color-primary-lighter) !important;
  color: var(--color-text-primary) !important;
  z-index: 10;
}

.tree-item-content {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3) var(--space-1) var(--space-2);
  width: 100%;
  position: relative;
  z-index: inherit;
}

.tree-item .drag-handle {
  font-size: 10px;
  color: var(--color-text-muted);
  cursor: grab;
  opacity: 0;
  transition: opacity var(--transition-fast);
  width: 12px;
}

.tree-item:hover .drag-handle {
  opacity: 1;
}

.tree-item.selected .drag-handle {
  color: var(--color-text-secondary) !important;
  opacity: 1;
}

.tree-item .expand-arrow {
  font-size: 10px;
  width: 12px;
  text-align: center;
  transition: transform var(--transition-fast);
  color: var(--color-text-secondary);
}

.tree-item.expanded .expand-arrow {
  transform: rotate(90deg);
}

.tree-item.selected .expand-arrow {
  color: var(--color-text-secondary) !important;
}

.tree-item .icon {
  font-size: var(--font-size-base);
  width: 16px;
  text-align: center;
  color: var(--color-text-primary);
}

.tree-item.selected .icon {
  color: var(--color-text-primary) !important;
}

.tree-item .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
}

.tree-item.selected .name {
  color: var(--color-text-primary) !important;
}

/* Drag and Drop Styles */
.tree-item.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.tree-item.drop-target {
  background: var(--color-primary-lighter);
  border-left: 3px solid var(--color-primary);
}

.tree-item.drop-target .tree-item-content {
  background: var(--color-primary-lighter);
}

.drag-handle {
  cursor: grab;
}

.drag-handle:active {
  cursor: grabbing;
}

/* Tree Floating Actions - Old individual item styles (remove later) */
.tree-floating-actions {
  position: absolute;
  top: -4px;
  right: 4px;
  display: flex;
  gap: 2px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(2px);
  transition: all var(--transition-fast);
  z-index: 100;
  padding: 2px;
}

.tree-item.selected .tree-floating-actions {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  z-index: 101;
}

/* Global Floating Actions */
.global-floating-actions {
  position: absolute;
  display: flex;
  gap: 2px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(2px);
  transition: all var(--transition-slow);
  z-index: 100;
  padding: 2px;
  pointer-events: none;
}

.global-floating-actions.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: all;
}

.tree-floating-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: var(--radius-full);
  background-color: var(--color-surface-elevated);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 10px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--color-border);
  position: relative;
  z-index: 102;
}

.tree-floating-btn:hover {
  transform: scale(1.1);
  color: var(--color-text-primary);
}

.tree-floating-btn.btn-add {
  background-color: var(--color-success);
  color: white;
  border-color: var(--color-success);
}

.tree-floating-btn.btn-add:hover {
  background-color: var(--color-success-dark, #059669);
}

.tree-floating-btn.btn-rename {
  background-color: var(--color-warning);
  color: white;
  border-color: var(--color-warning);
}

.tree-floating-btn.btn-rename:hover {
  background-color: var(--color-warning-dark, #d97706);
}

.tree-floating-btn.btn-delete {
  background-color: var(--color-error);
  color: white;
  border-color: var(--color-error);
}

.tree-floating-btn.btn-delete:hover {
  background-color: var(--color-error-dark, #dc2626);
}

/* Tree expansion/collapse */
.tree-children {
  overflow: hidden;
  transition: max-height var(--transition-base), opacity var(--transition-base);
}

.tree-children.collapsed {
  max-height: 0;
  opacity: 0;
}

.tree-children.expanded {
  max-height: 1000px;
  opacity: 1;
}

/* Status Indicators */
.status-indicator {
  font-size: var(--font-size-xs);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  font-weight: var(--font-weight-medium);
}

.status-saved {
  background-color: var(--color-success);
  color: white;
}

.status-saving {
  background-color: var(--color-warning);
  color: white;
}

.status-error {
  background-color: var(--color-error);
  color: white;
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-sm);
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.breadcrumb-item {
  color: var(--color-text-secondary);
}

.breadcrumb-item:not(:last-child)::after {
  content: "›";
  margin-left: var(--space-2);
  color: var(--color-text-muted);
}

/* Welcome Message */
.welcome-message {
  text-align: center;
  padding: var(--space-16) var(--space-8);
  color: var(--color-text-secondary);
}

.welcome-message h3 {
  color: var(--color-text-primary);
  margin-bottom: var(--space-6);
}

.quick-actions {
  display: flex;
  justify-content: center;
  gap: var(--space-4);
  margin: var(--space-8) 0;
  flex-wrap: wrap;
}

.storage-info {
  margin-top: var(--space-8);
  padding: var(--space-6);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  text-align: left;
  max-width: 500px;
  margin-left: auto;
  margin-right: auto;
}

.storage-info h4 {
  margin-bottom: var(--space-4);
  color: var(--color-text-primary);
  text-align: center;
}

.storage-details {
  font-size: var(--font-size-sm);
}

.storage-metrics {
  display: grid;
  gap: var(--space-3);
}

.storage-metrics .metric {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border-light);
}

.storage-metrics .metric:last-child {
  border-bottom: none;
}

.storage-metrics .metric strong {
  color: var(--color-text-primary);
}

/* Form Value Group */
.value-group {
  display: flex;
  align-items: stretch;
  background-color: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color var(--transition-fast);
}

.value-group:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.value-group input {
  flex: 1;
  border: none;
  border-radius: 0;
  padding: var(--space-3) var(--space-4);
  background-color: transparent;
  min-height: var(--touch-target-min);
}

.value-group input:focus {
  outline: none;
  border: none;
  box-shadow: none;
}

.value-group .unit {
  display: flex;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  background-color: var(--color-surface);
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  border-left: 1px solid var(--color-border);
  white-space: nowrap;
}

/* Bulk Actions Menu */
.bulk-actions-menu {
  position: relative;
  display: inline-block;
}

.bulk-actions-menu .btn-icon {
  min-width: 44px;
  min-height: 44px;
  padding: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.bulk-actions-menu .btn-icon:hover {
  background: var(--color-hover);
  border-color: var(--color-primary);
}

.bulk-actions-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  z-index: 1000;
}

.bulk-actions-dropdown .dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease;
  font-size: 0.95rem;
}

.bulk-actions-dropdown .dropdown-item:first-child {
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.bulk-actions-dropdown .dropdown-item:last-child {
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.bulk-actions-dropdown .dropdown-item:hover {
  background: var(--color-hover);
}

.bulk-actions-dropdown .dropdown-item.danger {
  color: var(--color-danger);
}

.bulk-actions-dropdown .dropdown-item.danger:hover {
  background: rgba(220, 38, 38, 0.1);
}

.bulk-actions-dropdown .dropdown-item .icon {
  font-size: 1.1rem;
}

/* Selection Mode */
.selection-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
}

.selection-header .select-all-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.selection-header label {
  cursor: pointer;
  user-select: none;
  font-weight: 500;
}

.item-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  flex-shrink: 0;
  margin-right: var(--space-2);
}

#toggle-selection-mode.active {
  background: var(--color-primary);
  color: white;
}

/* Category Picker Modal */
.category-picker-modal {
  max-width: 600px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.category-picker-breadcrumbs {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2);
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-3);
  overflow-x: auto;
  flex-wrap: wrap;
}

.breadcrumb-item {
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  transition: background 0.2s ease;
  white-space: nowrap;
}

.breadcrumb-item:hover {
  background: var(--color-hover);
}

.breadcrumb-separator {
  color: var(--color-text-tertiary);
}

.category-picker-list {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  min-height: 200px;
  max-height: 400px;
}

.category-picker-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-2);
  cursor: pointer;
  transition: all 0.2s ease;
}

.category-picker-item:hover {
  background: var(--color-surface);
  border-color: var(--color-primary);
  transform: translateX(4px);
}

.category-picker-item .category-icon {
  font-size: 1.2rem;
}

.category-picker-item .category-name {
  flex: 1;
  font-weight: 500;
}

.category-picker-item .category-badge {
  background: var(--color-surface);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
}

.empty-picker {
  text-align: center;
  color: var(--color-text-secondary);
  padding: var(--space-8);
}

/* Data Items */
.data-items {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.data-item {
  background-color: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  cursor: pointer;
  position: relative;
}

.data-item:hover {
  border-color: var(--color-secondary);
  box-shadow: var(--shadow-sm);
}

.data-item.selected {
  border-color: var(--color-primary);
  background-color: var(--color-primary-light, rgba(37, 99, 235, 0.05));
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.data-item.selected .unit {
  color: var(--color-text-secondary);
  background-color: var(--color-surface);
}

.data-item:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.data-item-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  position: relative;
}

/* Drag Handle */
.drag-handle {
  cursor: grab;
  color: var(--color-text-tertiary);
  font-size: 20px;
  padding: var(--space-2) var(--space-3);
  margin-left: calc(-1 * var(--space-2));
  margin-right: calc(-1 * var(--space-1));
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  opacity: 0.5;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  touch-action: none;
  border-radius: var(--radius-base);
}

.drag-handle:hover {
  opacity: 1;
  color: var(--color-primary);
  background-color: rgba(37, 99, 235, 0.1);
}

.drag-handle:active {
  cursor: grabbing;
  transform: scale(1.1);
}

.data-item[draggable="true"] .drag-handle {
  cursor: grabbing;
  opacity: 1;
  color: var(--color-primary);
}

.data-item.dragging {
  opacity: 0.4 !important;
  cursor: grabbing;
  transform: scale(0.98);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.data-item.drag-over {
  border-color: var(--color-primary) !important;
  border-style: dashed !important;
  background-color: var(--color-primary-light, rgba(37, 99, 235, 0.1)) !important;
  transform: translateY(-2px) scale(1.02) !important;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3) !important;
}

.data-item .item-name {
  flex: 1;
  min-width: 120px;
  border: none;
  background: transparent;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-base);
  transition: background-color var(--transition-fast);
  cursor: inherit;
  color: var(--color-text-primary);
}

.data-item .item-name:focus {
  background-color: var(--color-surface);
  box-shadow: none;
  border: none;
  cursor: text;
  color: var(--color-text-primary);
}

/* Selected row states */
.data-item.selected .item-name {
  color: var(--color-text-primary);
  background-color: rgba(255, 255, 255, 0.3);
}

.data-item.selected .item-name:focus {
  background-color: var(--color-surface);
  color: var(--color-text-primary);
}

.data-item .value-group {
  display: flex;
  align-items: stretch;
  min-width: 160px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-base);
  overflow: hidden;
  transition: border-color var(--transition-fast);
  position: relative;
}

.data-item .value-group:focus-within {
  border-color: var(--color-primary);
}

.data-item .item-unit-selector {
  border: none;
  background: var(--color-surface);
  padding: var(--space-2) var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  border-left: 1px solid var(--color-border);
  cursor: pointer;
  min-width: 70px;
}

.data-item .item-unit-selector:focus {
  outline: none;
  background: var(--color-background);
}

.data-item .item-value {
  flex: 1;
  border: none;
  background: transparent;
  padding: var(--space-2) var(--space-3);
  text-align: right;
  cursor: inherit;
  color: var(--color-text-primary);
}

.data-item .item-value:focus {
  outline: none;
  box-shadow: none;
  cursor: text;
  color: var(--color-text-primary);
}

/* Selected row value states */
.data-item.selected .item-value {
  color: var(--color-text-primary);
}

.data-item.selected .item-value:focus {
  color: var(--color-text-primary);
}

.data-item.selected .value-group {
  background-color: rgba(255, 255, 255, 0.3);
}

.data-item.selected .value-group:focus-within {
  background-color: var(--color-background);
}

.data-item .unit {
  padding: var(--space-2) var(--space-3);
  background-color: var(--color-surface);
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  border-left: 1px solid var(--color-border);
  white-space: nowrap;
}

/* Floating Action Buttons */
.floating-actions {
  position: absolute;
  top: -8px;
  right: 8px;
  display: flex;
  gap: var(--space-1);
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: all var(--transition-fast);
  z-index: 10;
}

.data-item.selected .floating-actions {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.floating-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: var(--radius-full);
  background-color: var(--color-surface-elevated);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: var(--font-size-sm);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--color-border);
}

.floating-btn:hover {
  transform: scale(1.1);
  color: var(--color-text-primary);
}

.floating-btn.btn-clone {
  background-color: var(--color-success);
  color: white;
  border-color: var(--color-success);
}

.floating-btn.btn-clone:hover {
  background-color: var(--color-success-dark, #059669);
}

.floating-btn.btn-delete {
  background-color: var(--color-error);
  color: white;
  border-color: var(--color-error);
}

.floating-btn.btn-delete:hover {
  background-color: var(--color-error-dark, #dc2626);
}

/* Chart Components */
.chart-visualization {
  margin-bottom: var(--space-2);
  position: relative;
}

.chart-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  gap: var(--space-2);
}

.zoom-indicator {
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  font-weight: 500;
}

.zoom-indicator span {
  color: var(--color-primary);
  font-weight: 600;
}

.btn-sm {
  padding: 4px 12px;
  font-size: 0.85rem;
}

.chart-container,
.line-chart-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 400px;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  padding: var(--space-4);
  overflow: hidden;
}

.chart-visualization:not(:has(.chart-controls)) .line-chart-container {
  border-radius: var(--radius-lg);
}

.chart-container svg {
  max-width: 100%;
  height: auto;
  display: block;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  touch-action: pan-x pan-y pinch-zoom;
}

.chart-empty-state {
  text-align: center;
  padding: var(--space-16) var(--space-8);
  color: var(--color-text-secondary);
}

.chart-empty-state .empty-icon {
  font-size: 4rem;
  margin-bottom: var(--space-4);
}

.chart-empty-state h3 {
  color: var(--color-text-primary);
  margin-bottom: var(--space-2);
}

/* Chart Editor Layout */
.chart-editor {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.chart-title-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
}

.chart-type-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  font-weight: 500;
}

.chart-title-row h2 {
  margin: 0;
}

.unit-system-display {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 0 0 auto;
}

.btn-icon {
  background: none;
  border: none;
  padding: var(--space-2);
  cursor: pointer;
  font-size: var(--font-size-lg);
  border-radius: var(--radius-sm);
  transition: background-color var(--transition-fast);
  min-width: var(--touch-target-min);
  min-height: var(--touch-target-min);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background-color: var(--color-surface);
}

.unit-selector {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background-color: var(--color-surface);
  font-size: var(--font-size-sm);
  transition: all var(--transition-fast);
}

.unit-selector:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  background-color: var(--color-surface);
}

.unit-selector:not(:disabled) {
  border-color: var(--color-primary);
  background-color: var(--color-background);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.unit-label {
  padding: 0 var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  font-weight: 600;
}

.data-editor {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-2);
}

.data-editor h3 {
  margin: 0 0 var(--space-1) 0;
  color: var(--color-text-primary);
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
}

.data-summary {
  margin-top: var(--space-6);
  padding: var(--space-4);
  background-color: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  text-align: center;
}

.total-display {
  font-size: var(--font-size-lg);
  color: var(--color-text-primary);
}

.btn-delete-item {
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
  color: var(--color-error);
  padding: var(--space-2);
  min-width: var(--touch-target-min);
}

.btn-delete-item:hover {
  background-color: var(--color-error);
  color: white;
}

/* Header Components */
#app-header {
  background-color: var(--color-surface-elevated);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.header-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Fixed Status Indicator */
#status-indicator {
  position: fixed;
  bottom: var(--space-4);
  right: var(--space-4);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  z-index: 100;
  pointer-events: auto;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-md);
}

#status-indicator:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* User Menu Dropdown */
.user-menu {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 200px;
  background-color: var(--color-surface-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  padding: var(--space-2);
  margin-top: var(--space-1);
}

.dropdown-menu.hidden {
  display: none;
}

.dropdown-item {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-base);
  transition: background-color var(--transition-fast);
}

.dropdown-item:hover {
  background-color: var(--color-surface);
}

.dropdown-divider {
  height: 1px;
  background-color: var(--color-border);
  margin: var(--space-2) 0;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: var(--font-size-sm);
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

.checkmark {
  height: 16px;
  width: 16px;
  background-color: var(--color-background);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-base);
  position: relative;
  transition: all var(--transition-fast);
}

.checkbox-label:hover input ~ .checkmark {
  border-color: var(--color-primary);
}

.checkbox-label input:checked ~ .checkmark {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
}

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.checkbox-label input:checked ~ .checkmark:after {
  display: block;
}

.help-text {
  display: block;
  margin-top: var(--space-1);
  margin-left: 24px;
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
}

.dropdown-btn {
  background: none;
  border: none;
  padding: var(--space-2) 0;
  cursor: pointer;
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  width: 100%;
  text-align: left;
  border-radius: var(--radius-base);
  transition: color var(--transition-fast);
}

.dropdown-btn:hover {
  color: var(--color-primary);
}

/* Utility Classes */
.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;
}

/* Mobile/Desktop Visibility */
.mobile-only {
  display: none;
}

.desktop-only {
  display: block;
}

@media (max-width: 899px) {
  .mobile-only {
    display: block;
  }
  
  .desktop-only {
    display: none;
  }
}

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.hidden { display: none !important; }
.invisible { visibility: hidden; }

/* Touch Device Optimizations */
.touch .btn-icon:hover {
  background-color: transparent;
}

.touch .tree-item:hover {
  background-color: transparent;
}

/* Breadcrumbs Navigation */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background-color: #e8f5e8;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin: 0 0 var(--space-2) 0;
  font-size: var(--font-size-sm);
  flex-wrap: wrap;
}

.breadcrumb-item {
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.breadcrumb-item.active {
  color: var(--color-text-primary);
  font-weight: var(--font-weight-medium);
}

/* Item Context Menu */
.item-context-menu {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  overflow: hidden;
  animation: menuSlideIn 0.15s ease-out;
}

@keyframes menuSlideIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition: background-color var(--transition-fast);
  border-bottom: 1px solid var(--color-border);
}

.context-menu-item:last-child {
  border-bottom: none;
}

.context-menu-item:hover {
  background-color: var(--color-primary-light, rgba(37, 99, 235, 0.1));
}

.context-menu-item:active {
  background-color: var(--color-primary-light, rgba(37, 99, 235, 0.2));
}

.context-menu-item .icon {
  font-size: 20px;
  width: 24px;
  text-align: center;
}

.context-menu-item span:last-child {
  flex: 1;
  color: var(--color-text-primary);
  font-size: var(--font-size-base);
}

.breadcrumb-link {
  color: var(--color-primary);
  cursor: pointer;
  transition: color var(--transition-fast);
}

.breadcrumb-link:hover {
  color: var(--color-primary-dark);
  text-decoration: underline;
}

.breadcrumb-sep {
  color: var(--color-text-muted);
  user-select: none;
}

/* Category Data Items */
.data-category {
  background: linear-gradient(135deg, var(--color-surface) 0%, var(--color-background) 100%);
  border-color: var(--color-secondary);
}

.data-category:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
}

.data-category .category-icon {
  font-size: var(--font-size-lg);
  margin-right: var(--space-2);
}

.data-category .calculated-value {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  padding: var(--space-2) var(--space-3);
  text-align: right;
  min-width: 60px;
}

.data-category .category-badge {
  padding: var(--space-1) var(--space-2);
  background-color: var(--color-primary);
  color: white;
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  margin-left: var(--space-2);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.data-category .category-nav-link {
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease;
}

.data-category .category-nav-link:hover {
  background-color: var(--color-primary-dark);
  transform: translateX(2px);
}

.data-category .category-nav-link:active {
  transform: translateX(4px);
}

/* ==========================================================================
   Modal Dialogs
   ========================================================================== */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  padding: var(--space-5);
  animation: slideUp 0.3s ease;
}

.modal-dialog {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow: auto;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: var(--space-2);
  margin: calc(var(--space-2) * -1);
  border-radius: var(--radius-md);
  transition: background-color 0.2s, color 0.2s;
  min-width: 40px;
  min-height: 40px;
}

.btn-close:hover {
  background-color: var(--color-surface);
  color: var(--color-text-primary);
}

.modal-body {
  padding: var(--space-5);
}

.modal-body label {
  display: block;
  font-weight: var(--font-weight-medium);
  margin-bottom: var(--space-2);
  margin-top: var(--space-4);
  color: var(--color-text-primary);
}

.modal-body label:first-child {
  margin-top: 0;
}

.modal-body .form-input {
  width: 100%;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 44px; /* Touch-friendly */
}

.modal-body .form-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-lighter);
}

.modal-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
}

.modal-footer .btn {
  min-width: 100px;
  min-height: 44px; /* Touch-friendly */
}

/* Comment Popout */
.comment-popout {
  position: fixed;
  width: 400px;
  max-width: calc(100vw - 32px); /* Responsive on mobile */
  max-height: calc(100vh - 100px);
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  animation: slideIn 0.2s ease-out;
}

/* Mobile optimization */
@media (max-width: 768px) {
  .comment-popout {
    width: calc(100vw - 32px);
    max-height: 80vh;
  }
  
  .comment-textarea {
    min-height: 150px;
    font-size: 16px; /* Prevent zoom on iOS */
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.comment-popout-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  border-radius: 8px 8px 0 0;
}

.comment-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--color-text-primary);
}

.btn-close-popout {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 0;
  width: 44px; /* Touch-friendly */
  height: 44px; /* Touch-friendly */
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.btn-close-popout:hover {
  background: var(--color-hover);
  color: var(--color-text-primary);
}

.comment-popout-body {
  padding: var(--space-4);
  flex: 1;
}

.comment-textarea {
  width: 100%;
  min-height: 120px;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 1rem; /* Larger for mobile */
  resize: vertical;
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  transition: border-color 0.2s ease;
}

.comment-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-lighter);
}

.comment-popout-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}

.comment-popout-footer .btn {
  padding: var(--space-3) var(--space-4);
  font-size: 0.9rem;
  min-height: 44px; /* Touch-friendly */
  min-width: 80px;
}

/* Comment button indicator */
.btn-comment.has-comment {
  background: var(--color-primary-lighter);
  color: var(--color-primary);
  font-weight: bold;
}

/* URLs Section */
.urls-section {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

.urls-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-2);
}

.urls-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--color-text-primary);
}

.btn-add-url {
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  transition: all 0.2s ease;
}

.btn-add-url:hover {
  background: var(--color-primary-dark);
  transform: scale(1.1);
}

.urls-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-height: 200px;
  overflow-y: auto;
}

.url-item {
  display: grid;
  grid-template-columns: 1fr 2fr auto;
  gap: var(--space-2);
  align-items: center;
}

.url-title,
.url-link {
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 0.9rem;
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
}

.url-title:focus,
.url-link:focus {
  outline: none;
  border-color: var(--color-primary);
}

.btn-remove-url {
  background: none;
  border: none;
  color: var(--color-text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: var(--space-1);
  line-height: 1;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.btn-remove-url:hover {
  background: #fee;
  color: #c00;
}

/* Entry Details Modal */
.entry-details-modal .modal-content {
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
}

.entry-details-content .modal-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4);
}

.entry-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.entry-field-group {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-3);
}

.entry-label {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--color-text-primary);
}

.entry-name,
.entry-value,
.entry-unit,
.entry-date,
.entry-comment {
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 1rem;
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  transition: border-color 0.2s ease;
}

.entry-name:focus,
.entry-value:focus,
.entry-unit:focus,
.entry-date:focus,
.entry-comment:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-lighter);
}

.entry-comment {
  resize: vertical;
  min-height: 80px;
  font-family: inherit;
}

.entry-details-modal .urls-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-2);
}

.entry-details-modal .urls-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.btn-comment.has-comment:hover {
  background: var(--color-primary);
  color: white;
}

/* Time Series Table - Mobile Optimized with Sticky Date Column */
.timeseries-table-wrapper {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 600px;
  position: relative;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.timeseries-table {
  width: auto; /* Let table be as wide as needed */
  min-width: 100%; /* But at least full width */
  border-collapse: collapse;
  font-size: 0.8rem;
  position: relative;
}

.timeseries-table th,
.timeseries-table td {
  padding: var(--space-1);
  border: 1px solid var(--color-border);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.timeseries-table th {
  background: #f8f9fa;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 2;
}

/* Sticky date column */
.timeseries-table .sticky-date {
  position: sticky;
  left: 0;
  background: white;
  z-index: 3;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.1);
  min-width: 252px;
  max-width: 252px;
}

.timeseries-table thead .sticky-date {
  background: #f8f9fa;
  z-index: 4;
}

.date-cell-content {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.date-cell-content .row-checkbox,
.select-all-checkbox {
  width: 20px;
  height: 20px;
  cursor: pointer;
  flex-shrink: 0;
}

.date-cell-content .date-input {
  flex: 1;
  min-width: 0;
  width: 100% !important; /* Override 75% rule for date inputs in flex container */
}

.date-cell-content .btn-icon {
  flex-shrink: 0;
  min-height: 32px;
  min-width: 32px;
}

.metric-column {
  min-width: 150px;
}

.metric-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
}

.metric-header .metric-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

.metric-display {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  cursor: pointer;
  padding: var(--space-1);
  border-radius: 4px;
  transition: background 0.2s ease;
}

.metric-display:hover {
  background: var(--color-hover);
}

.metric-name-display {
  font-weight: 600;
  font-size: 0.85rem;
}

.metric-unit-display {
  font-size: 0.7rem;
  font-style: italic;
  color: var(--color-text-secondary);
}

.metric-edit {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  flex: 1;
}

.metric-unit-input {
  font-size: 0.8rem;
  font-style: italic;
  color: var(--color-text-secondary);
}

.value-cell {
  min-width: 120px;
  cursor: pointer;
}

.value-cell-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
}

.value-display {
  padding: var(--space-1);
  min-height: 32px;
  display: flex;
  align-items: center;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s ease;
  user-select: none;
}

.value-display:hover {
  background: var(--color-hover);
}

.time-indicator,
.comment-indicator {
  font-size: 0.75rem;
  flex-shrink: 0;
  cursor: help;
}

.time-indicator {
  color: var(--color-primary);
}

.comment-indicator {
  color: var(--color-info);
}

.timeseries-table input[type="text"],
.timeseries-table input[type="number"],
.timeseries-table input[type="date"] {
  width: 75%;
  padding: var(--space-1);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 0.85rem;
  min-height: 32px;
}

.timeseries-table .btn-icon {
  min-width: 44px;
  min-height: 44px;
  padding: var(--space-2);
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s ease;
}

.timeseries-table .btn-icon:hover {
  background: var(--color-hover);
}

.timeseries-table .delete-metric,
.timeseries-table .delete-entry {
  color: var(--color-danger);
}

.timeseries-table .add-entry-below {
  color: var(--color-primary);
}

/* Suppressed row styling */
.suppressed-row {
  background-color: rgba(231, 76, 60, 0.05);
  opacity: 0.6;
}

.suppressed-row:hover {
  opacity: 0.8;
}

.suppressed-badge {
  font-size: 0.9rem;
  margin-left: 4px;
  opacity: 0.7;
}

.btn-warning {
  background-color: #f39c12;
  color: white;
}

.btn-warning:hover {
  background-color: #e67e22;
}

/* Responsive table on mobile */
@media (max-width: 768px) {
  .timeseries-table {
    font-size: 0.85rem;
  }
  
  .timeseries-table th,
  .timeseries-table td {
    padding: var(--space-1);
  }
  
  .timeseries-table input {
    font-size: 16px; /* Prevent zoom on iOS */
  }
  
  /* Reduce checkbox size on tablet/mobile */
  .date-cell-content .row-checkbox,
  .select-all-checkbox {
    width: 10px;
    height: 10px;
  }
  
  .metric-header .metric-checkbox {
    width: 9px;
    height: 9px;
  }
}

/* Line Chart Legend */
.legend-item {
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.legend-item:hover {
  opacity: 0.8;
}

.legend-item rect,
.legend-item text {
  pointer-events: none;
}

/* ==========================================================================
   Note Editor
   ========================================================================== */

.note-editor-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.note-toolbar {
  display: flex;
  gap: var(--space-3);
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
}

.note-toolbar-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.note-mode-toggle {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  overflow: hidden;
  backdrop-filter: blur(10px);
}

.mode-btn {
  padding: var(--space-2) var(--space-4);
  border: none;
  background: transparent;
  color: var(--color-text-primary);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border-right: 1px solid rgba(0, 0, 0, 0.1);
}

.mode-btn:first-child {
  border-top-left-radius: 6px;
  border-bottom-left-radius: 6px;
}

.mode-btn:last-child {
  border-right: none;
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
}

.mode-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

.mode-btn.active {
  background: rgba(0, 0, 0, 0.5);
  color: white;
  font-weight: 600;
}

.note-content-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.note-content-wrapper.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  background: white;
  max-height: 100vh;
}

.fullscreen-controls {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  z-index: 10000;
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.btn-exit-fullscreen {
  padding: var(--space-2) var(--space-4);
  background: rgba(220, 53, 69, 0.5);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: all 0.2s ease;
  backdrop-filter: blur(10px);
}

.btn-exit-fullscreen:hover {
  background: rgba(220, 53, 69, 0.7);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.note-textarea {
  width: 100%;
  height: 100%;
  padding: var(--space-4);
  border: none;
  resize: none;
  font-family: 'Courier New', monospace;
  font-size: 1rem;
  line-height: 1.6;
  background: white;
  color: var(--color-text-primary);
}

.note-textarea:focus {
  outline: none;
}

.note-preview {
  width: 100%;
  height: 100%;
  padding: var(--space-4);
  overflow-y: auto;
  background: white;
}

/* Markdown Body Styles */
.markdown-body {
  line-height: 1.6;
  color: var(--color-text-primary);
}

.markdown-body h1 {
  font-size: 2em;
  margin-top: 0;
  margin-bottom: var(--space-4);
  border-bottom: 2px solid var(--color-border);
  padding-bottom: var(--space-2);
}

.markdown-body h2 {
  font-size: 1.5em;
  margin-top: var(--space-5);
  margin-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
  padding-bottom: var(--space-2);
}

.markdown-body h3 {
  font-size: 1.25em;
  margin-top: var(--space-4);
  margin-bottom: var(--space-2);
}

.markdown-body p {
  margin-top: 0;
  margin-bottom: var(--space-3);
}

.markdown-body ul,
.markdown-body ol {
  margin-bottom: var(--space-3);
  padding-left: var(--space-5);
}

.markdown-body li {
  margin-bottom: var(--space-1);
}

.markdown-body code {
  background: var(--color-bg-secondary);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

.markdown-body pre {
  background: var(--color-bg-secondary);
  padding: var(--space-3);
  border-radius: 4px;
  overflow-x: auto;
  margin-bottom: var(--space-3);
}

.markdown-body pre code {
  background: none;
  padding: 0;
}

.markdown-body blockquote {
  margin: var(--space-3) 0;
  padding-left: var(--space-4);
  border-left: 4px solid var(--color-border);
  color: var(--color-text-secondary);
}

.markdown-body a {
  color: var(--color-primary);
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
}

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: var(--space-3);
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--color-border);
  padding: var(--space-2);
  text-align: left;
}

.markdown-body th {
  background: var(--color-bg-secondary);
  font-weight: 600;
}

/* ==========================================================================
   History Modal Styles
   ========================================================================== */

.history-modal {
  width: 600px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.history-modal .modal-body {
  overflow-y: auto;
  flex: 1;
}

.backup-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.backup-item {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: var(--space-3);
  background: var(--color-surface);
  cursor: pointer;
  transition: all 0.2s ease;
}

.backup-item:hover {
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.backup-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-2);
}

.backup-date {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--color-text-primary);
}

.backup-size {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
}

.backup-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

.backup-preview {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
}

.backup-preview-text {
  width: 100%;
  min-height: 200px;
  max-height: 400px;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-family: var(--font-family-mono);
  font-size: 0.85rem;
  background: white;
  resize: vertical;
}

.backup-preview-json {
  width: 100%;
  max-height: 400px;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-family: var(--font-family-mono);
  font-size: 0.75rem;
  background: #f8f9fa;
  overflow: auto;
  white-space: pre;
  color: #333;
}

.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--color-text-secondary);
}

.empty-state p {
  font-size: 1.1rem;
  margin-bottom: var(--space-2);
}

.empty-state small {
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.btn-rollback {
  padding: var(--space-2) var(--space-3);
  font-size: 0.9rem;
}

.markdown-body hr {
  border: none;
  border-top: 2px solid var(--color-border);
  margin: var(--space-5) 0;
}

/* ==========================================================================
   Loading Spinner
   ========================================================================== */

.loading-spinner-container {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-16);
  min-height: 200px;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spinner-rotate 0.8s linear infinite;
}

@keyframes spinner-rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* ==========================================================================
   Chart Search
   ========================================================================== */

.chart-search-dialog {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  background: var(--color-surface-elevated);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-4);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

#chart-search-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-size: 1.25rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  outline: none;
  font-family: var(--font-family-base);
}

#chart-search-input:focus {
  border-color: var(--color-primary);
}

.chart-search-close {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--color-text-secondary);
  padding: var(--space-2);
  line-height: 1;
}

.chart-search-close:hover {
  color: var(--color-text-primary);
}

.chart-search-results {
  max-height: 400px;
  overflow-y: auto;
}

.search-results-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-background);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
}

.search-result-item:hover {
  background: var(--color-primary-lighter);
  border-color: var(--color-primary);
  transform: translateX(4px);
}

.search-result-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.search-result-content {
  flex: 1;
  min-width: 0;
}

.search-result-name {
  font-size: 1.125rem;
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
  margin-bottom: var(--space-1);
}

.search-result-path {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-no-results {
  text-align: center;
  padding: var(--space-8);
  color: var(--color-text-secondary);
  font-size: 1.125rem;
}

/* Chart shrinking animation */
.chart-visualization {
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.chart-visualization.chart-shrunk {
  position: fixed;
  top: 120px;
  right: 20px;
  width: 25vw;
  min-width: 200px;
  max-width: 400px;
  height: auto;
  z-index: 90;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.chart-visualization.chart-shrunk .chart-container {
  height: 25vw;
  min-height: 200px;
  max-height: 400px;
}

/* Context Menu */
.chart-context-menu {
  position: fixed;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: var(--space-1);
  z-index: 1000;
  min-width: 180px;
}

.chart-context-menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  transition: background-color 0.15s;
}

.chart-context-menu-item:hover {
  background-color: var(--color-surface);
}

.chart-context-menu-item.danger:hover {
  background-color: #fee;
  color: #c00;
}

.chart-context-menu-separator {
  height: 1px;
  background-color: var(--color-border);
  margin: var(--space-1) 0;
}

/* Chart segment selection highlight */
.chart-segment-selected {
  stroke: #4a90e2 !important;
  stroke-width: 3px !important;
}