/* ============================================================
   main.css — Design system, layout, component base styles
   ============================================================ */

/* ── Google Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── CSS Variables (Light Theme) ── */
:root {
  --font: 'Inter', system-ui, sans-serif;

  /* Surface */
  --bg:           #f8f9fc;
  --surface:      #ffffff;
  --surface-2:    #f1f3f9;
  --surface-3:    #e8eaf2;
  --border:       #e2e5f0;
  --border-hover: #c7cde0;

  /* Text */
  --text-primary:   #111827;
  --text-secondary: #6b7280;
  --text-muted:     #9ca3af;

  /* Brand */
  --brand:        #4f46e5;
  --brand-light:  #ede9fe;
  --brand-dark:   #3730a3;

  /* Status */
  --success: #10b981;
  --danger:  #ef4444;
  --warning: #f59e0b;

  /* Sidebar */
  --sidebar-width: 260px;
  --sidebar-bg:    #ffffff;

  /* Misc */
  --radius:    12px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --transition: .18s ease;

  /* Hour height in time-grid views */
  --hour-height: 64px;
}

/* ── Dark Theme ── */
.dark-mode {
  --bg:           #0f1117;
  --surface:      #1a1d27;
  --surface-2:    #1e2130;
  --surface-3:    #252840;
  --border:       #2d3148;
  --border-hover: #3d4260;

  --text-primary:   #f0f2ff;
  --text-secondary: #8b90b8;
  --text-muted:     #555c80;

  --brand:       #6366f1;
  --brand-light: #1e1f3b;
  --brand-dark:  #818cf8;

  --sidebar-bg: #13151f;
  --shadow:     0 1px 4px rgba(0,0,0,.4), 0 4px 20px rgba(0,0,0,.3);
  --shadow-lg:  0 10px 40px rgba(0,0,0,.5);
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  display: flex;
  height: 100vh;
  overflow: hidden;
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
  position: relative;
}

body::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 50% 50%, rgba(79, 70, 229, 0.05) 0%, transparent 60%),
              radial-gradient(circle at 80% 20%, rgba(16, 185, 129, 0.03) 0%, transparent 50%);
  z-index: 0;
  pointer-events: none;
  animation: bgPulse 30s ease-in-out infinite alternate;
}

.dark-mode body::before {
  background: radial-gradient(circle at 50% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
              radial-gradient(circle at 80% 20%, rgba(139, 92, 246, 0.05) 0%, transparent 50%);
}

@keyframes bgPulse {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-2%, 2%) scale(1.05); }
  100% { transform: translate(2%, -2%) scale(1); }
}

button { cursor: pointer; border: none; outline: none; background: none; font-family: inherit; }
input, textarea, select { font-family: inherit; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Layout ── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid rgba(226, 229, 240, 0.6);
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width var(--transition), min-width var(--transition), background var(--transition);
  z-index: 10;
  box-shadow: 1px 0 15px rgba(0,0,0,0.02);
}

.dark-mode .sidebar {
  background: rgba(19, 21, 31, 0.65);
  border-right: 1px solid rgba(45, 49, 72, 0.5);
  box-shadow: 1px 0 20px rgba(0,0,0,0.2);
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right-color: transparent;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  transition: background var(--transition);
}

/* ── Sidebar Header ── */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px;
  position: sticky;
  top: 0;
  background: inherit;
  backdrop-filter: blur(10px);
  z-index: 2;
  border-bottom: 1px solid rgba(226, 229, 240, 0.4);
}

.dark-mode .sidebar-header {
  border-bottom: 1px solid rgba(45, 49, 72, 0.4);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--brand);
  letter-spacing: -.3px;
}

.logo-icon { font-size: 1.4rem; }

/* ── Btn Create ── */
.btn-create-event {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 12px 8px;
  padding: 11px 18px;
  background: var(--brand);
  color: #fff;
  border-radius: 99px;
  font-weight: 600;
  font-size: .875rem;
  box-shadow: 0 4px 14px rgba(79,70,229,.35), inset 0 1px 1px rgba(255,255,255,0.2);
  transition: all var(--transition);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.btn-create-event::after {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 50%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: all 0.4s ease;
}

.btn-create-event:hover::after {
  left: 150%;
}

.btn-create-event:hover {
  background: var(--brand-dark);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(79,70,229,.5), inset 0 1px 1px rgba(255,255,255,0.3);
}

.btn-create-event:active {
  transform: translateY(1px);
  box-shadow: 0 2px 8px rgba(79,70,229,.3);
}

.plus-icon { font-size: 1.3rem; line-height: 1; }

/* ── Shared Icon Button ── */
.btn-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}

.btn-icon:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

.btn-icon svg { pointer-events: none; }

/* ── Mini Calendar ── */
.mini-calendar {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.mini-cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.mini-cal-title {
  font-weight: 600;
  font-size: .82rem;
  color: var(--text-primary);
}

.mini-nav {
  width: 26px;
  height: 26px;
  font-size: 1.1rem;
  color: var(--text-secondary);
}

.mini-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.mini-day-header {
  text-align: center;
  font-size: .68rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 2px 0;
}

.mini-day {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  font-size: .75rem;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
  font-weight: 500;
}

.mini-day:hover { background: var(--surface-2); color: var(--text-primary); }
.mini-day.today { color: var(--brand); font-weight: 700; }
.mini-day.selected { background: var(--brand); color: #fff !important; }
.mini-day.other-month { color: var(--text-muted); }
.mini-day.empty { cursor: default; }

/* ── Task Backlog ── */
.backlog-section {
  padding: 14px 14px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.backlog-input-container {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.backlog-input-container input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: .8rem;
  outline: none;
  width: 100%;
}
.backlog-input-container input:focus { border-color: var(--brand); }

.backlog-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
  padding-bottom: 14px;
}

.backlog-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .8rem;
  color: var(--text-primary);
  cursor: grab;
  user-select: none;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
  transition: transform .1s, box-shadow .1s;
}

.backlog-item:active { cursor: grabbing; }

.backlog-item:hover {
  border-color: var(--brand);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
}

.backlog-item.dragging {
  opacity: 0.5;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}

.backlog-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.btn-remove-task {
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity .15s, background .15s, color .15s;
}

.backlog-item:hover .btn-remove-task { opacity: 1; }
.btn-remove-task:hover { background: rgba(239, 68, 68, 0.1); color: var(--danger); }

/* ── Calendar Filters ── */
.calendars-section {
  padding: 14px 14px 0;
  border-bottom: 1px solid var(--border);
}

.section-title {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.calendar-list { display: flex; flex-direction: column; gap: 4px; padding-bottom: 14px; }

.calendar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .82rem;
  color: var(--text-secondary);
  transition: background var(--transition);
  user-select: none;
}

.calendar-item:hover { background: var(--surface-2); }

.calendar-item input[type=checkbox] { display: none; }

.cal-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
  opacity: .7;
  transition: opacity var(--transition);
}

.calendar-item:has(input:checked) .cal-color { opacity: 1; }
.calendar-item:has(input:not(:checked)) { opacity: .5; }

/* ── Search ── */
.search-section { padding: 12px 14px; flex: 1; }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  transition: border-color var(--transition);
}

.search-box:focus-within { border-color: var(--brand); }

.search-icon { color: var(--text-muted); flex-shrink: 0; }

.search-box input {
  border: none;
  background: none;
  outline: none;
  font-size: .82rem;
  color: var(--text-primary);
  width: 100%;
}

.search-box input::placeholder { color: var(--text-muted); }

.search-results { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }

.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}

.search-result-item:hover { background: var(--surface-2); }

.search-color-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.search-result-info { display: flex; flex-direction: column; gap: 1px; overflow: hidden; }

.search-result-title {
  font-size: .82rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-date { font-size: .72rem; color: var(--text-muted); }

/* ── Top Header ── */
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(226, 229, 240, 0.6);
  transition: background var(--transition);
  flex-shrink: 0;
  z-index: 5;
}

.dark-mode .top-header {
  background: rgba(26, 29, 39, 0.5);
  border-bottom: 1px solid rgba(45, 49, 72, 0.5);
}

.header-left { display: flex; align-items: center; gap: 10px; }
.header-right { display: flex; align-items: center; gap: 10px; }

.btn-today {
  padding: 7px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--surface);
  transition: background var(--transition), border-color var(--transition);
}

.btn-today:hover { background: var(--surface-2); border-color: var(--border-hover); }

.nav-arrows { display: flex; gap: 2px; }
.nav-btn { border-radius: 8px; }

.current-period {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -.3px;
}

/* ── View Switcher ── */
.view-switcher {
  display: flex;
  background: var(--surface-2);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
}

.view-btn {
  padding: 6px 14px;
  border-radius: 7px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}

.view-btn:hover { color: var(--text-primary); }

.view-btn.active {
  background: var(--surface);
  color: var(--brand);
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}

/* ── Theme Toggle ── */
.theme-toggle { border-radius: 8px; }

/* ── Calendar Container ── */
.calendar-container {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 480px;
  max-width: calc(100vw - 32px);
  box-shadow: var(--shadow-lg);
  transform: translateY(20px) scale(.97);
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), opacity .2s;
  opacity: 0;
  overflow: hidden;
}

.modal-overlay.active .modal {
  transform: translateY(0) scale(1);
  opacity: 1;
}

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

.modal-title { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); }

.modal-close { border-radius: 8px; }

/* ── Form ── */
.modal-form { padding: 20px 22px; display: flex; flex-direction: column; gap: 16px; }

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label {
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.required { color: var(--danger); }

.form-group input,
.form-group textarea,
.form-group select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: .88rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}

.form-group input[type=color] { padding: 4px; height: 38px; cursor: pointer; }

/* ── Color Picker ── */
.color-picker { display: flex; gap: 8px; flex-wrap: wrap; }

.color-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid transparent;
  transition: transform .14s, border-color .14s;
  position: relative;
}

.color-dot:hover { transform: scale(1.2); }

.color-dot.active {
  border-color: var(--text-primary);
  transform: scale(1.15);
}

.color-dot.active::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
}

/* ── Form Error ── */
.form-error {
  font-size: .78rem;
  color: var(--danger);
  min-height: 16px;
}

/* ── Modal Actions ── */
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 4px;
}

.action-right { display: flex; gap: 8px; }

.btn-delete {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--danger);
  background: rgba(239,68,68,.08);
  transition: background var(--transition);
}

.btn-delete:hover { background: rgba(239,68,68,.15); }

.btn-cancel {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  transition: background var(--transition);
}

.btn-cancel:hover { background: var(--surface-2); }

.btn-save {
  padding: 8px 20px;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 700;
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 8px rgba(79,70,229,.3);
  transition: background var(--transition), box-shadow var(--transition);
}

.btn-save:hover {
  background: var(--brand-dark);
  box-shadow: 0 4px 14px rgba(79,70,229,.4);
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text-primary);
  color: var(--surface);
  padding: 10px 22px;
  border-radius: 99px;
  font-size: .82rem;
  font-weight: 600;
  z-index: 2000;
  opacity: 0;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1), opacity .25s;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.toast-error { background: var(--danger); }
.toast.toast-success { background: var(--success); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { width: 0; min-width: 0; position: fixed; height: 100vh; }
  .sidebar.mobile-open { width: var(--sidebar-width); min-width: var(--sidebar-width); }
  .current-period { font-size: .95rem; }
  .modal { max-height: 90vh; overflow-y: auto; }
}

/* ── Focus Mode Overlay ── */
.focus-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 23, 0.98);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.focus-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.focus-content {
  text-align: center;
  color: #fff;
  transform: translateY(20px) scale(0.95);
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.focus-overlay.active .focus-content {
  transform: translateY(0) scale(1);
}

.focus-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: rgba(255,255,255,0.8);
  letter-spacing: -0.5px;
}

.focus-timer {
  font-size: 8rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 40px;
  text-shadow: 0 0 40px rgba(99, 102, 241, 0.4);
  font-variant-numeric: tabular-nums;
}

.focus-controls {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.btn-focus-action, .btn-focus-danger {
  padding: 12px 32px;
  border-radius: 99px;
  font-size: 1.1rem;
  font-weight: 600;
  color: #fff;
  transition: all 0.2s ease;
}

.btn-focus-action {
  background: var(--brand);
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}
.btn-focus-action:hover {
  background: var(--brand-dark);
  transform: scale(1.05);
}

.btn-focus-danger {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
}
.btn-focus-danger:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.5);
  color: var(--danger);
}

/* ── AI Command Palette ── */
.ai-cmd-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.1) inset;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.dark-mode .ai-cmd-box {
  background: rgba(26, 29, 39, 0.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: 0 30px 80px rgba(0,0,0,0.5), 0 0 0 1px rgba(99,102,241,0.2) inset;
}

.ai-cmd-header {
  display: flex;
  align-items: center;
  padding: 18px 24px;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

.ai-cmd-input {
  flex: 1;
  background: transparent;
  border: none;
  font-size: 1.25rem;
  color: var(--text-primary);
  outline: none;
  font-weight: 500;
}

.ai-cmd-input::placeholder { color: var(--text-muted); font-weight: 400; }

.ai-cmd-hints {
  display: flex;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--surface-2);
  font-size: 0.75rem;
  color: var(--text-muted);
}
.dark-mode .ai-cmd-hints { background: rgba(0,0,0,0.2); }

.ai-cmd-hints strong { color: var(--text-primary); }

.btn-ai-breakdown {
  color: var(--warning);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity .15s, background .15s, transform .15s;
}

.backlog-item:hover .btn-ai-breakdown { opacity: 1; }
.btn-ai-breakdown:hover { background: rgba(245, 158, 11, 0.1); transform: scale(1.1); }
