/*
 * Copyright (C) 2025 Jema Technology
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

/* JemaOS Gallery - Main Styles */
/* Based on JemaOS Material Design 3 */

/* CSS Variables - JemaOS Color Scheme */
:root {
  /* Primary Colors */
  --primary-color: #6569d0;
  --primary-variant: #6569d0;
  --primary-rgb: 101, 105, 208;
  --on-primary: #ffffff;
  
  /* Surface Colors */
  --surface-color: #202124;
  --surface-variant: #2d2e30;
  --on-surface: #e8eaed;
  --on-surface-variant: #9aa0a6;
  
  /* Background Colors */
  --background-color: #1f1f1f;
  --background-variant: #2d2e30;
  
  /* Secondary Colors */
  --secondary-color: #5f6368;
  --accent-color: #6569d0;
  
  /* Error Colors */
  --error-color: #ea4335;
  --warning-color: #fbbc04;
  --success-color: #34a853;
  
  /* Border Colors */
  --border-color: #3c4043;
  --divider-color: #3c4043;
  
  /* Typography */
  --font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-size-xs: 0.75rem;    /* 12px */
  --font-size-sm: 0.875rem;   /* 14px */
  --font-size-base: 1rem;     /* 16px */
  --font-size-lg: 1.125rem;   /* 18px */
  --font-size-xl: 1.25rem;    /* 20px */
  --font-size-2xl: 1.5rem;    /* 24px */
  --font-size-3xl: 1.875rem;  /* 30px */
  
  /* Font Weights */
  --font-weight-light: 300;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-bold: 700;
  
  /* Spacing */
  --space-xs: 0.25rem;   /* 4px */
  --space-sm: 0.5rem;    /* 8px */
  --space-md: 1rem;      /* 16px */
  --space-lg: 1.5rem;    /* 24px */
  --space-xl: 2rem;      /* 32px */
  --space-2xl: 3rem;     /* 48px */
  
  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
  
  /* Transitions */
  --transition-fast: 0.15s ease-in-out;
  --transition-normal: 0.3s ease-in-out;
  --transition-slow: 0.5s ease-in-out;
  
  /* Z-index */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal: 2100;
  --z-popover: 2110;
  --z-tooltip: 2120;
  --z-toast: 2130;
}

@media (prefers-color-scheme: light) {
  :root {
    /* Surface Colors */
    --surface-color: #ffffff;
    --surface-variant: #f1f3f4;
    --on-surface: #202124;
    --on-surface-variant: #5f6368;
    
    /* Background Colors */
    --background-color: #ffffff;
    --background-variant: #f8f9fa;
    
    /* Border Colors */
    --border-color: #dadce0;
    --divider-color: #dadce0;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(60, 64, 67, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(60, 64, 67, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(60, 64, 67, 0.3);
    --shadow-xl: 0 20px 25px -5px rgba(60, 64, 67, 0.3);
  }
}

/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: 1.5;
  color: var(--on-surface);
  background-color: var(--background-color);
  overflow: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Utility Classes */
.hidden {
  display: 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;
}

/* Loading Screen */
.loading-screen {
  display: none !important; /* Permanently hidden as per request */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--background-color);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
}

.loading-spinner {
  display: none !important; /* Permanently hidden as per request */
  width: 48px;
  height: 48px;
  border: 4px solid var(--surface-variant);
  border-top: 4px solid var(--primary-color);
  border-radius: var(--radius-full);
  animation: spin 1s linear infinite;
  margin-bottom: var(--space-md);
}

.loading-screen p {
  display: none !important; /* Permanently hidden as per request */
  color: var(--on-surface-variant);
  font-size: var(--font-size-sm);
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* App Layout */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Header removed */
/* Filter Bar removed */

/* Main Content */
.main-content {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Drop Zone */
.drop-zone {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(var(--primary-rgb), 0.1);
  border: 2px dashed var(--primary-color);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
}

.drop-message {
  text-align: center;
  color: var(--primary-color);
}

.drop-message .material-icons {
  font-size: 48px;
  margin-bottom: var(--space-md);
}

.drop-message p {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-medium);
}

/* File Grid */
.file-grid {
  display: none; /* Hidden by default as per request */
  flex: 1;
  padding: var(--space-md);
  overflow-y: auto;
  overflow-x: hidden;
}

.file-grid::-webkit-scrollbar {
  width: 8px;
}

.file-grid::-webkit-scrollbar-track {
  background: var(--surface-color);
}

.file-grid::-webkit-scrollbar-thumb {
  background: var(--surface-variant);
  border-radius: var(--radius-full);
}

.file-grid::-webkit-scrollbar-thumb:hover {
  background: var(--on-surface-variant);
}

/* Empty State / Landing Page */
.empty-state {
  display: none; /* Hidden by default as per request */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--on-surface-variant);
  padding: var(--space-xl);
  background-color: var(--background-color);
  position: relative;
}

.landing-top-bar {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: var(--space-md);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  color: var(--on-surface-variant);
  cursor: pointer;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--transition-fast);
  pointer-events: auto;
}

.icon-btn:hover {
  background-color: var(--surface-variant);
  color: var(--on-surface);
}

.landing-header {
  margin-bottom: var(--space-2xl);
}

.landing-header h2 {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-normal);
  color: var(--on-surface);
  margin-bottom: var(--space-md);
}

.landing-header p {
  font-size: var(--font-size-base);
  color: var(--on-surface-variant);
  line-height: 1.6;
}

.landing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-lg);
  width: 100%;
  max-width: 1200px;
}

.landing-card {
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  cursor: pointer;
  height: 100%;
}

.landing-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-color);
}

.card-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-lg);
}

.card-icon .material-icons {
  font-size: 24px;
}

.image-icon {
  background-color: rgba(var(--primary-rgb), 0.1);
  color: var(--primary-color);
}

.pdf-icon {
  background-color: rgba(52, 168, 83, 0.1);
  color: var(--success-color);
}

.video-icon {
  background-color: rgba(234, 67, 53, 0.1);
  color: var(--error-color);
}

.audio-icon {
  background-color: rgba(161, 66, 244, 0.15);
  color: #000000;
}

.landing-card h3 {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-medium);
  color: var(--on-surface);
  margin-bottom: var(--space-sm);
}

.landing-card p {
  font-size: var(--font-size-sm);
  color: var(--on-surface-variant);
  margin-bottom: var(--space-lg);
  flex: 1;
}

.card-link {
  background: none;
  border: none;
  color: var(--primary-color);
  font-weight: var(--font-weight-medium);
  font-size: var(--font-size-sm);
  padding: 0;
  cursor: pointer;
  text-align: left;
}

.card-link:hover {
  text-decoration: underline;
}

/* Selection Toolbar removed */

/* Side Panels */
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  height: 100vh;
  background-color: var(--surface-color);
  border-left: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform var(--transition-normal);
  z-index: var(--z-modal);
  display: flex;
  flex-direction: column;
}

.side-panel.open {
  transform: translateX(0);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  border-bottom: 1px solid var(--border-color);
}

.panel-header h3 {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-medium);
  color: var(--on-surface);
  margin: 0;
}

.close-panel {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--on-surface-variant);
  cursor: pointer;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--transition-fast);
}

.close-panel:hover {
  background-color: var(--surface-variant);
  color: var(--on-surface);
}

.panel-content {
  flex: 1;
  padding: var(--space-md);
  overflow-y: auto;
}

/* Options */
.option-group {
  margin-bottom: var(--space-lg);
}

.option-group:last-child {
  margin-bottom: 0;
}

.option-group label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--on-surface);
  margin-bottom: var(--space-sm);
}

.select-input {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  background-color: var(--background-variant);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--on-surface);
  font-size: var(--font-size-sm);
  transition: border-color var(--transition-fast);
}

.select-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.2);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--surface-variant);
  border-radius: var(--radius-full);
  transition: background-color var(--transition-fast);
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: var(--on-surface-variant);
  border-radius: var(--radius-full);
  transition: transform var(--transition-fast);
}

input:checked + .slider {
  background-color: var(--primary-color);
}

input:checked + .slider:before {
  transform: translateX(20px);
  background-color: var(--on-primary);
}

/* Button Styles */
.primary-btn {
  background-color: var(--primary-color);
  color: var(--on-primary);
  border: none;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  transition: background-color var(--transition-fast);
  pointer-events: auto;
}

.primary-btn:hover {
  background-color: var(--primary-variant);
}

/* Grid and Size Options */
.grid-size-options,
.order-options {
  display: flex;
  gap: var(--space-xs);
}

.size-btn,
.order-btn {
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border-color);
  background-color: var(--background-variant);
  color: var(--on-surface);
  cursor: pointer;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  transition: all var(--transition-fast);
}

.size-btn:hover,
.order-btn:hover {
  background-color: var(--surface-variant);
}

.size-btn.active,
.order-btn.active {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
  color: var(--on-primary);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: var(--space-md);
  right: var(--space-md);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.toast {
  background-color: var(--surface-color);
  color: var(--on-surface);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  min-width: 300px;
  animation: slideInUp 0.3s ease-out;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.toast.success {
  border-left: 4px solid var(--success-color);
}

.toast.error {
  border-left: 4px solid var(--error-color);
}

.toast.warning {
  border-left: 4px solid var(--warning-color);
}

@keyframes slideInUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  backdrop-filter: blur(4px);
  opacity: 1;
  transition: opacity var(--transition-normal);
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  display: none !important;
}

.modal-content {
  background-color: var(--surface-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 90%;
  max-width: 400px;
  border: 1px solid var(--border-color);
  transform: scale(1);
  transition: transform var(--transition-normal);
}

.modal-overlay.hidden .modal-content {
  transform: scale(0.95);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-medium);
  color: var(--on-surface);
  margin: 0;
}

.modal-body {
  padding: var(--space-lg);
}

.info-row {
  display: flex;
  margin-bottom: var(--space-sm);
  font-size: var(--font-size-sm);
}

.info-row:last-child {
  margin-bottom: 0;
}

.info-label {
  width: 100px;
  color: var(--on-surface-variant);
  font-weight: var(--font-weight-medium);
  flex-shrink: 0;
}

.info-value {
  color: var(--on-surface);
  word-break: break-word;
}

.modal-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

/* Window Controls Overlay Support */
@media (display-mode: window-controls-overlay) {
  .landing-top-bar {
    padding-left: env(titlebar-area-x, 0);
    padding-right: calc(100vw - (env(titlebar-area-x, 0) + env(titlebar-area-width, 100vw)));
    -webkit-app-region: drag;
    app-region: drag;
  }

  .landing-top-bar button {
    -webkit-app-region: no-drag;
    app-region: no-drag;
  }
  
  /* Ensure side panel starts below the window controls */
  .side-panel {
    top: env(titlebar-area-height, 0);
    height: calc(100vh - env(titlebar-area-height, 0));
  }
}

/* Responsive Design */
@media (max-width: 768px) {
  .app-header {
    padding: 0 var(--space-sm);
    height: 56px;
  }
  
  .header-center {
    margin: 0 var(--space-sm);
  }
  
  .filter-bar {
    padding: var(--space-xs) var(--space-sm);
    flex-direction: column;
    gap: var(--space-sm);
    align-items: stretch;
  }
  
  .filter-group {
    justify-content: center;
  }
  
  .view-controls {
    justify-content: center;
  }
  
  .side-panel {
    width: 100vw;
  }
  
  .selection-toolbar {
    left: var(--space-sm);
    right: var(--space-sm);
    transform: none;
  }
}