/* CSS Variables for Themes */
:root {
  /* Default Blue Theme */
  --brand: #0170ff;
  --grid: #e5e7eb;
  --stripe: #f8fafc;
  --text: #111827;
  --text-secondary: #6b7280;
  --border: #d1d5db;
  --shadow: rgba(0, 0, 0, 0.1);
  --shadow-light: rgba(0, 0, 0, 0.05);
}

/* Theme Variations */
[data-theme="blue"] {
  --brand: #0170ff;
  --grid: #e5e7eb;
  --stripe: #f0f7ff;
}

[data-theme="green"] {
  --brand: #059669;
  --grid: #d1fae5;
  --stripe: #f0fdf4;
}

[data-theme="red"] {
  --brand: #dc2626;
  --grid: #fecaca;
  --stripe: #fef2f2;
}

[data-theme="yellow"] {
  --brand: #d97706;
  --grid: #fef3c7;
  --stripe: #fffbeb;
}

[data-theme="pink"] {
  --brand: #ec4899;
  --grid: #fce7f3;
  --stripe: #fdf2f8;
}

/* Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, 'Noto Sans Arabic', sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  color: var(--text);
  direction: rtl;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

/* Toolbar */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  padding: 16px 24px;
  margin-bottom: 24px;
  box-shadow: 0 8px 32px var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
  display: flex;
  gap: 12px;
  align-items: center;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: white;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.toolbar-btn:hover {
  background: #f9fafb;
  border-color: var(--brand);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--shadow-light);
}

.toolbar-btn .btn-icon {
  font-size: 16px;
}

.settings-btn {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}

.settings-btn:hover {
  background: var(--brand);
  opacity: 0.9;
}

/* Settings Panel */
.settings-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  border-radius: 20px;
  box-shadow: 0 20px 60px var(--shadow);
  border: 1px solid var(--border);
  z-index: 1000;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.settings-panel.hidden {
  display: none;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.settings-header h3 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

.close-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 8px;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.close-btn:hover {
  background: #f3f4f6;
  color: var(--text);
}

.settings-content {
  padding: 24px;
}

.setting-group {
  margin-bottom: 24px;
}

.setting-group label {
  display: block;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  font-size: 14px;
}

.setting-value {
  color: var(--text-secondary);
  font-size: 14px;
  padding: 8px 0;
}

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 8px 0;
}

.radio-option input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
}

.radio-option span {
  font-size: 14px;
  color: var(--text);
}

.theme-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.theme-btn {
  padding: 8px 16px;
  border: 2px solid var(--border);
  border-radius: 20px;
  background: white;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s ease;
  min-width: 60px;
}

.theme-btn.active {
  border-color: var(--brand);
  background: var(--brand);
  color: white;
}

.theme-btn:hover:not(.active) {
  border-color: var(--brand);
  transform: translateY(-1px);
}

.reset-btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s ease;
}

.reset-btn:hover {
  background: #f3f4f6;
  border-color: var(--brand);
}

/* Canvas Container */
.canvas-container {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

.timetable-canvas {
  background: white;
  border-radius: 20px;
  box-shadow: 0 20px 60px var(--shadow);
  overflow: hidden;
  width: 100%;
  max-width: 1200px;
  min-height: 800px;
  position: relative;
}

/* Header */
.timetable-header {
  background: var(--brand);
  color: white;
  padding: 32px 40px 24px;
  position: relative;
  overflow: hidden;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 2;
}

.header-titles h1 {
  font-size: 36px;
  font-weight: 800;
  margin-bottom: 8px;
  line-height: 1.2;
}

.header-titles h2 {
  font-size: 20px;
  font-weight: 600;
  opacity: 0.9;
}

.header-logo img {
  width: 80px;
  height: 80px;
  filter: brightness(0) invert(1);
}

.header-watermark {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  opacity: 0.1;
  z-index: 1;
  pointer-events: none;
}

.watermark-row {
  position: absolute;
  font-size: 12px;
  font-weight: 300;
  letter-spacing: 2px;
  white-space: nowrap;
  color: white;
}

.watermark-row:first-child {
  top: 20px;
  left: -100px;
  animation: watermark-scroll 30s linear infinite;
}

.watermark-row:last-child {
  top: 40px;
  left: -200px;
  animation: watermark-scroll 25s linear infinite reverse;
}

@keyframes watermark-scroll {
  0% { transform: translateX(0); }
  100% { transform: translateX(1000px); }
}

/* Student Info */
.student-info {
  padding: 24px 40px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.info-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.info-row:last-child {
  margin-bottom: 0;
}

.info-label {
  font-weight: 700;
  color: var(--text);
  font-size: 16px;
  min-width: 60px;
}

.info-value {
  font-size: 16px;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  background: white;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  min-width: 200px;
}

.info-value:focus {
  outline: none;
  border-color: var(--brand);
  background: white;
  box-shadow: 0 0 0 3px rgba(1, 112, 255, 0.1);
}

/* Timetable Grid */
.timetable-grid {
  padding: 24px 40px;
  min-height: 400px;
}

.grid-container {
  display: grid;
  gap: 1px;
  background: var(--grid);
  border: 1px solid var(--grid);
  border-radius: 12px;
  overflow: hidden;
}

.grid-header {
  display: grid;
  background: var(--brand);
  color: white;
}

.grid-header-cell {
  padding: 16px 12px;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
  border-right: 1px solid rgba(255, 255, 255, 0.2);
}

.grid-header-cell:last-child {
  border-right: none;
}

.grid-row {
  display: grid;
  background: white;
}

.grid-row:nth-child(even) {
  background: var(--stripe);
}

.grid-cell {
  padding: 8px;
  border-right: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
  min-height: 60px;
  display: flex;
  align-items: center;
  overflow: hidden;
}

.grid-cell:last-child {
  border-right: none;
}

.grid-cell:last-child {
  border-bottom: none;
}

.time-cell {
  background: #f8fafc;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 14px;
  justify-content: center;
  text-align: center;
  overflow: hidden;
  position: relative;
}

.cell-textarea {
  width: 100%;
  min-height: 40px;
  border: none;
  background: transparent;
  resize: none;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  line-height: 1.4;
  padding: 8px;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.cell-textarea:focus {
  outline: none;
  background: white;
  border: 2px dashed var(--brand);
  box-shadow: 0 0 0 3px rgba(1, 112, 255, 0.1);
}

/* Compact Mode */
.compact .grid-cell {
  min-height: 40px;
  padding: 8px;
}

.compact .time-cell {
  min-height: 40px;
}

.compact .cell-textarea {
  min-height: 24px;
  padding: 4px 6px;
}

/* Mobile Grid Optimization */
@media (max-width: 768px) {
  .grid-container {
    border-radius: 8px;
    gap: 1px;
  }
  
  .grid-header-cell {
    padding: 12px 8px;
    font-size: 14px;
  }
  
  .grid-cell {
    padding: 6px;
    min-height: 50px;
  }
  
  .cell-textarea {
    font-size: 13px;
    padding: 6px;
  }
}

@media (max-width: 480px) {
  .grid-container {
    border-radius: 6px;
  }
  
  .grid-header-cell {
    padding: 8px 6px;
    font-size: 12px;
  }
  
  .grid-cell {
    padding: 4px;
    min-height: 45px;
  }
  
  .cell-textarea {
    font-size: 12px;
    padding: 4px;
  }
}

.compact .time-picker {
  font-size: 12px;
}

.compact .time-select {
  padding: 2px 4px;
  font-size: 11px;
  min-width: 35px;
}

.compact .hour-select {
  min-width: 30px;
}

.compact .minute-select {
  min-width: 40px;
}

.compact .meridiem-select {
  min-width: 45px;
}

/* Daily View Controls */
.daily-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  padding: 16px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 12px var(--shadow-light);
}

.daily-controls button {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s ease;
}

.daily-controls button:hover {
  background: #f3f4f6;
  border-color: var(--brand);
}

.daily-controls .current-day {
  font-weight: 600;
  color: var(--brand);
  font-size: 16px;
  min-width: 120px;
  text-align: center;
}

/* Footer */
.timetable-footer {
  padding: 20px 40px;
  background: #f8fafc;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}

/* Responsive Design */
@media (max-width: 768px) {
  .container {
    padding: 12px;
  }
  
  .toolbar {
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    border-radius: 12px;
  }
  
  .toolbar-left,
  .toolbar-center,
  .toolbar-right {
    justify-content: center;
    flex-wrap: wrap;
  }
  
  .toolbar-btn {
    padding: 8px 12px;
    font-size: 12px;
    min-width: 80px;
  }
  
  .toolbar-btn .btn-icon {
    font-size: 14px;
  }
  
  .timetable-canvas {
    transform: scale(0.9);
    transform-origin: top center;
    margin: -20px 0;
    border-radius: 16px;
  }
  
  .timetable-header {
    padding: 20px 20px 16px;
  }
  
  .header-titles h1 {
    font-size: 24px;
  }
  
  .header-titles h2 {
    font-size: 14px;
  }
  
  .header-logo img {
    width: 50px;
    height: 50px;
  }
  
  .student-info,
  .timetable-grid {
    padding: 16px 20px;
  }
  
  .timetable-footer {
    padding: 12px 20px;
    font-size: 12px;
  }
  
  .settings-panel {
    width: 95%;
    max-height: 85vh;
    border-radius: 16px;
  }
  
  .settings-content {
    padding: 20px;
  }
  
  .setting-group {
    margin-bottom: 20px;
  }
  
  .theme-options {
    gap: 6px;
  }
  
  .theme-btn {
    padding: 6px 12px;
    font-size: 12px;
    min-width: 50px;
  }
  
  .radio-group {
    gap: 8px;
  }
  
  .radio-option {
    font-size: 13px;
  }
  
  .radio-option input[type="radio"] {
    width: 16px;
    height: 16px;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 8px;
  }
  
  .toolbar {
    padding: 12px;
    gap: 8px;
  }
  
  .toolbar-btn {
    padding: 6px 8px;
    font-size: 11px;
    min-width: 70px;
  }
  
  .timetable-canvas {
    transform: scale(0.8);
    margin: -30px 0;
  }
  
  .timetable-header {
    padding: 16px 16px 12px;
  }
  
  .header-titles h1 {
    font-size: 20px;
  }
  
  .header-titles h2 {
    font-size: 12px;
  }
  
  .header-logo img {
    width: 40px;
    height: 40px;
  }
  
  .student-info,
  .timetable-grid {
    padding: 12px 16px;
  }
  
  .info-row {
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }
  
  .info-value {
    min-width: 150px;
    font-size: 14px;
  }
  
  .settings-panel {
    width: 98%;
    max-height: 80vh;
  }
  
  .settings-header {
    padding: 20px 20px 12px;
  }
  
  .settings-header h3 {
    font-size: 18px;
  }
  
  .settings-content {
    padding: 16px;
  }
}

@media (max-width: 360px) {
  .timetable-canvas {
    transform: scale(0.7);
    margin: -40px 0;
  }
  
  .toolbar-btn {
    padding: 4px 6px;
    font-size: 10px;
    min-width: 60px;
  }
  
  .header-titles h1 {
    font-size: 18px;
  }
  
  .header-titles h2 {
    font-size: 11px;
  }
  
  .header-logo img {
    width: 35px;
    height: 35px;
  }
}

/* Canvas Size Support */
.timetable-canvas {
  max-width: 1200px;
}



/* Time Input Styling */
.time-input-container {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 4px;
  box-sizing: border-box;
}

.time-cell {
  min-width: 120px;
  max-width: 120px;
}

.time-input {
  width: 60px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  font-size: 14px;
  text-align: center;
  font-family: monospace;
  border: none;
  outline: none;
  transition: all 0.2s ease;
}

.time-input:focus {
  border: 2px solid var(--brand);
  box-shadow: 0 0 0 3px rgba(1, 112, 255, 0.1);
}

.meridiem-btn {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 50px;
  white-space: nowrap;
}

.meridiem-btn:hover {
  background: #f3f4f6;
  border-color: var(--brand);
}

.meridiem-btn:active {
  transform: scale(0.95);
}



/* Text Settings CSS Variables */
:root {
  --text-align: right;
  --font-size: 14px;
  --font-weight: normal;
}

/* Apply text settings to textareas */
.cell-textarea {
  text-align: var(--text-align);
  font-size: var(--font-size);
  font-weight: var(--font-weight);
}

/* Mobile Time Input Optimization */
@media (max-width: 768px) {
  .time-input-container {
    gap: 4px;
    padding: 3px;
  }
  
  .time-input {
    width: 50px;
    padding: 4px 6px;
    font-size: 12px;
  }
  
  .meridiem-btn {
    padding: 4px 6px;
    font-size: 11px;
    min-width: 45px;
  }
}

@media (max-width: 480px) {
  .time-input-container {
    gap: 3px;
    padding: 2px;
  }
  
  .time-input {
    width: 45px;
    padding: 3px 4px;
    font-size: 11px;
  }
  
  .meridiem-btn {
    padding: 3px 4px;
    font-size: 10px;
    min-width: 40px;
  }
}

/* Utility Classes */
.hidden {
  display: none !important;
}

/* Focus States for Accessibility */
.toolbar-btn:focus,
.settings-btn:focus,
.close-btn:focus,
.theme-btn:focus,
.reset-btn:focus {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* Mobile Touch Optimization */
@media (max-width: 768px) {
  .toolbar-btn,
  .settings-btn,
  .close-btn,
  .theme-btn,
  .reset-btn {
    min-height: 44px; /* iOS touch target minimum */
    touch-action: manipulation;
  }
  
  .time-select {
    min-height: 36px; /* Touch-friendly select height */
  }
  
  .cell-textarea {
    min-height: 36px; /* Touch-friendly textarea height */
  }
  
  /* Improve touch scrolling */
  .settings-panel {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  
  /* Better touch feedback */
  .toolbar-btn:active,
  .settings-btn:active,
  .theme-btn:active {
    transform: scale(0.95);
  }
  
  /* Mobile-specific improvements */
  .timetable-canvas {
    touch-action: pan-x pan-y;
  }
  
  .grid-container {
    touch-action: pan-x pan-y;
  }
  
  /* Prevent text selection on mobile */
  .toolbar-btn,
  .theme-btn,
  .reset-btn {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
  }
  
  /* Mobile-friendly spacing */
  .container {
    padding: 8px;
  }
  
  /* Better mobile navigation */
  .daily-controls {
    padding: 12px;
    gap: 12px;
  }
  
  .daily-controls button {
    padding: 10px 16px;
    font-size: 14px;
    min-height: 44px;
  }
  
  .current-day {
    font-size: 16px;
    min-width: 100px;
  }
}

/* Smooth Transitions */
* {
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
