/* Reset & base */
* { margin:0; padding:0; box-sizing:border-box; }
html,body { 
    height:100%; 
    font-family: 'Vazirmatn', 'Segoe UI', Tahoma, Verdana, sans-serif; /* CHANGED: Better Font */
    background: linear-gradient(135deg,#f5f7fa 0%,#c3cfe2 100%); 
    color:#333; 
    direction: rtl; 
}
.container-wrapper {
  max-width: 1400px !important; /* CHANGED: Constrained width for large screens */
  width: 98% !important;
  margin: 20px auto;
  background: #ffffff;
  border-radius: 20px;
  padding: 25px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.12);
  position: relative;
  z-index: 1;
}

/* Inputs */
input[type="text"], textarea, select, input[type="date"], input[type="time"]{ 
    width:100%;
    min-height:50px; /* CHANGED: better touch target */
    padding:10px; 
    border-radius:8px; 
    border:1px solid #e6edf6; 
    font-family:inherit; 
    background-color: white; 
    transition: border 0.2s;
}
input:focus, textarea:focus, select:focus {
    border-color: #4299e1;
    outline: none;
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
}

textarea {
    resize: vertical;
    overflow-y: auto;
    min-height: 100px;
    line-height: 1.6;
}

/* Cards */
.card { background:#fff; border-radius:12px; padding:16px; box-shadow:0 8px 25px rgba(0,0,0,0.06); border:1px solid #eef2f7; }
.section-title { display:flex; justify-content:space-between; align-items:center; font-weight:700; border-bottom:1px solid #eef2f7; padding-bottom:10px; margin-bottom:12px; }
.drag-handle { cursor:move; color:#cbd5e0; }

/* Buttons & helpers */
.btn { background: linear-gradient(135deg,#4299e1 0%,#3182ce 100%); color:#fff; padding:8px 12px; border-radius:8px; border:none; cursor:pointer; transition: all 0.2s; font-weight: 500; }
.btn:hover { opacity: 0.9; transform: translateY(-1px); }
.btn.small{ padding:6px 10px; font-size:13px; }
.text-link{ background:none; border:none; color:#2563eb; cursor:pointer; font-weight:600; transition: color 0.2s; }
.text-link:hover { color: #1d4ed8; }
.text-muted{ background:none; border:none; color:#6b7280; }
.text-sm { font-size: 0.875rem; }

/* Emoji */
.emoji-button{ display:flex; flex-direction:column; align-items:center; justify-content:center; padding:12px; border-radius:10px; background:#fff; border:1px solid #e6edf6; min-width:88px; cursor:pointer; transition: all 0.2s; }
.emoji-button:hover { transform: translateY(-2px); }
.emoji-button.selected{ box-shadow:0 8px 20px rgba(66, 153, 225, 0.2); border-color:#4299e1; background: #ebf8ff; }

/* Dynamic List Items */
.dynamic-list-item, .smart-habit-item, .time-block { display:flex; gap:10px; align-items:center; padding:10px; background:#f8fafc; border-radius:10px; border:1px solid #e6edf6; margin-bottom:10px; transition: box-shadow 0.2s; }
.dynamic-list-item:hover, .smart-habit-item:hover, .time-block:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.03); }

.dynamic-list-item { position: relative; padding-left: 40px; }
.dynamic-list-item .item-drag-handle { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); cursor: move; color: #cbd5e0; }

/* Fix inputs in flex containers */
.dynamic-list-item input[type="text"], .routine-item input[type="text"] { flex-grow: 1; min-width: 0; border: none; background: transparent; height: auto; padding: 5px; }
.dynamic-list-item input[type="text"]:focus { box-shadow: none; border-bottom: 1px solid #4299e1; border-radius: 0; }

/* Time blocks */
.time-blocking-container{ border:1px solid #eef2f7; border-radius:10px; padding:10px; background:#fbfdff; max-height:420px; overflow:auto; }
.time-block { flex-wrap: wrap; gap: 8px; height: auto; min-height: 80px; }
.time-block .block-drag-handle { color: #cbd5e0; cursor: move; margin-left: 5px; }
.time-block .block-start-time { width: 110px; height: 40px; }
.time-block .duration-select { width: 110px; height: 40px; }
.time-block .type-select { width: 110px; height: 40px; padding: 5px; }
.time-block .block-activity { flex: 1; min-width: 150px; height: 40px; } 

.time-block.study{ border-right:6px solid #3b82f6;} 
.time-block.work{ border-right:6px solid #10b981; } 
.time-block.leisure{ border-right:6px solid #f59e0b; } 
.time-block.exercise{ border-right:6px solid #ef4444; } 
.time-block.rest{ border-right:6px solid #8b5cf6; } 

.activity-type-btn { padding: 8px 12px; border-radius: 6px; border:none; cursor: pointer; opacity: 0.6; }
.activity-type-btn.selected { opacity: 1; transform: scale(1.05); font-weight: bold; }
.activity-type-btn.study-bg { background-color: #3b82f6; color: white; }
.activity-type-btn.work-bg { background-color: #10b981; color: white; }
.activity-type-btn.leisure-bg { background-color: #f59e0b; color: white; }
.activity-type-btn.exercise-bg { background-color: #ef4444; color: white; }
.activity-type-btn.rest-bg { background-color: #8b5cf6; color: white; }

/* Habits */
.habit-stats-grid{ display:grid; grid-template-columns:repeat(3,1fr); gap:10px; }
.stat-card{ padding:12px; border-radius:10px; color:#fff; text-align:center; position: relative; overflow: hidden; }
.habit-calendar{ display:grid; grid-template-columns:repeat(10,1fr); gap:4px; margin-top:10px; }
.calendar-day{ aspect-ratio: 1; display:flex; align-items:center; justify-content:center; border-radius:6px; background:#e6eef7; font-size: 12px; }

/* Export Widget */
.export-sidebar-widget { position: fixed; top: 22px; left: 50%; z-index: 100; display: flex; flex-direction: column; transform: translateX(-50%); }
.screenshot-actions { display: flex; flex-direction: column; gap: 8px; padding: 0 10px; background: #fff; border-radius: 0 0 8px 8px; border: 1px solid #e0e0e0; border-top: none; max-height: 0; overflow: hidden; opacity: 0; transition: all 0.3s ease-in-out; }
.export-sidebar-widget.open .screenshot-actions { padding: 10px; max-height: 500px; opacity: 1; }
.quick-notes-btn { display: block; padding: 10px 20px; border-radius: 20px; border: none; cursor: pointer; font-weight: 600; white-space: nowrap; }

/* Quick Notes */
.quick-notes-widget{ position:fixed; right:0; top:0; width:320px; height:100vh; background:#fff; transform:translateX(100%); transition:transform .25s cubic-bezier(0.4, 0, 0.2, 1); z-index:200; }
.quick-notes-widget.show{ transform:translateX(0); }

/* Overlays */
.loading-overlay{ position:fixed; inset:0; background:rgba(255,255,255,0.95); display:none; align-items:center; justify-content:center; z-index:2000; flex-direction: column;}
.loading-overlay.show{ display:flex; }
.spinner{ border:4px solid #f3f3f3; border-top:4px solid #3b82f6; border-radius:50%; width:50px; height:50px; animation:spin 1s linear infinite; }
@keyframes spin{ to { transform:rotate(360deg); } }

/* Modal - Base Styles (Updated to support Flexbox layout) */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
    padding: 20px; /* Added padding so it doesn't touch screen edges */
}
.modal-overlay.hidden{ display:none; }


/* CRITICAL FIX: Flexbox layout for scrolling */
.modal-content {
    background: #fff;
    width: 90%;
    max-width: 500px;
    border-radius: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    
    /* Flexbox setup */
    display: flex;
    flex-direction: column;
    max-height: 85vh; /* Never exceed 85% of screen height */
    position: relative;
    overflow: hidden; /* Hide overflow on the container itself */
}

/* Header stays fixed at top */
.modal-content .quick-notes-header, 
.modal-content .modal-header {
    flex-shrink: 0; /* Prevent header from shrinking */
}

/* Footer (buttons) stays fixed at bottom (using the class we added in HTML) */
.modal-content .modal-footer {
    flex-shrink: 0; /* Prevent footer from shrinking */
    background: #f9fafb; /* Light gray background for separation */
    border-top: 1px solid #e5e7eb;
}

/* The List area becomes scrollable */
#export-list {
    overflow-y: auto; /* Enable Vertical Scroll */
    flex: 1;          /* Take up all remaining space */
    min-height: 0;    /* Fix for Firefox flexbox scrolling */
    /* Removed padding here, as it's better applied to content inside if needed */
}

/* Responsive */
@media (max-width:768px){
  .container-wrapper{ margin:10px auto; padding:15px; border-radius: 15px; width: 95% !important; }
  .habit-stats-grid{ grid-template-columns:repeat(3,1fr); gap: 5px; }
  .stat-card { padding: 8px; }
  .stat-card .text-3xl { font-size: 1.25rem; }
  
  .export-sidebar-widget{ top: auto; bottom: 20px; left: 20px; right: auto; transform: none; align-items: flex-start; }
  .export-sidebar-widget #toggle-export-btn { order: 2; box-shadow: 0 4px 15px rgba(0,0,0,0.2); }
  .export-sidebar-widget .screenshot-actions { order: 1; width: auto; border-radius: 8px 8px 8px 0; border: 1px solid #e0e0e0; margin-bottom: 10px; background: white; }

  /* Time block adjustments for mobile */
  .time-block .block-activity { flex: 1 1 100%; order: 10; margin-top: 5px; }
  .time-block .block-remove-btn { position: absolute; top: 5px; left: 5px; }
  .time-block { position: relative; padding-bottom: 40px; }
}