/* TimeBlocker MVP styles */
@import url('https://fonts.googleapis.com/css2?family=Ubuntu:wght@300;400;500;700&display=swap');
:root {
  --bg: #0b0f14;
  --panel: #0f1720;
  --schedule-panel: #0d141c;
  --control-button: #111827;
  --text: #e5e7eb;
  --muted: #9aa3af;
  --accent: #3b82f6;
  --accent-weak: rgba(59,130,246,0.15);
  --danger: #ef4444;
  --hour-height: 60px; /* px per hour */
  --hour-line: #1f2937;
  --quarter-line: #16202c;
}

/* Loading spinner */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.3s ease-out;
}

.loading-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(59, 130, 246, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

* { box-sizing: border-box; }
html, body { height: 100%; min-height: 100vh; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-family: "Ubuntu", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, select, textarea {
  font-family: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  position: sticky;
  top: 0;
  z-index: 30;
  background: linear-gradient(180deg, rgba(15,23,32,0.75), rgba(15,23,32,0.55));
  backdrop-filter: saturate(160%) blur(8px);
  -webkit-backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid #1f2937;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  opacity: 0;
  animation: fadeInDown 0.5s ease-out 0.2s forwards;
}

.app-header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--accent) 15%, transparent 50%, var(--accent) 85%, transparent 100%);
  opacity: 0.25;
  pointer-events: none;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.title h1 { margin: 0 0 2px; font-size: clamp(18px, 2vw, 22px); font-weight: 700; letter-spacing: -0.015em; }
.title .subtitle { color: var(--muted); font-size: 12px; opacity: 0.9; }

.controls { display: flex; gap: 10px; align-items: center; position: relative; flex-wrap: wrap; }
.controls button {
  background: #0f1720;
  color: var(--text);
  border: 1px solid #1f2937;
  padding: 8px 14px;
  border-radius: 9999px;
  cursor: pointer;
  line-height: 1;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.06s ease;
}
.controls button:hover { background: #111827; border-color: #374151; box-shadow: 0 0 0 3px var(--accent-weak); }
.controls button:active { transform: translateY(1px); }
.controls button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Accented primary actions */
#todayBtn, #exportBtn {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
#todayBtn:hover, #exportBtn:hover { filter: brightness(0.95); box-shadow: 0 8px 24px rgba(37,99,235,0.35); }

/* Clear menu dropdown */
.menu-wrap { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: rgba(15,23,32,0.95);
  border: 1px solid #1f2937;
  border-radius: 12px;
  box-shadow: 0 14px 40px rgba(0,0,0,0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid;
  min-width: 180px;
  z-index: 30;
  overflow: hidden;
}
.menu.hidden { display: none; }
.menu button {
  text-align: left;
  background: transparent;
  border: none;
  padding: 10px 14px;
  color: var(--text);
  transition: background 0.15s ease;
}
.menu button:hover { background: #111827; }

/* Dropdown-style select buttons in modal */
.modal .dropdown-btn {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  background: #0d141c;
  color: var(--text);
  border: 1px solid #1f2937;
  text-align: left;
}
.modal .dropdown-btn:focus { outline: none; border-color: #374151; box-shadow: 0 0 0 3px var(--accent-weak); }
/* Make modal dropdown menus align to button width */
.modal .menu { left: 0; right: 0; }

.app-footer { 
  padding: 10px 20px; 
  color: var(--muted); 
  font-size: 12px;
  opacity: 0;
  animation: fadeIn 0.5s ease-out 0.4s forwards;
}

/* Floating info button (bottom-left) */
.info-btn {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 40;
  background: #0f1720;
  color: var(--text);
  border: 1px solid #1f2937;
  padding: 10px 12px;
  border-radius: 9999px;
  cursor: pointer;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.06s ease;
}
.info-btn:hover { background: #111827; border-color: #374151; box-shadow: 0 0 0 3px var(--accent-weak); }
.info-btn:active { transform: translateY(1px); }
.info-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.info-btn i { font-size: 18px; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Planner layout */
.planner {
  display: grid;
  grid-template-columns: 80px 1fr;
  grid-template-rows: 32px 1fr;
  grid-template-areas:
    "spacer days"
    "labels schedule";
  gap: 0;
  padding: 16px 20px 40px;
  flex: 1 1 auto;
  min-height: 0;
  opacity: 0;
  animation: fadeInUp 0.6s ease-out 0.3s forwards;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.day-spacer { grid-area: spacer; }
.days-header {
  grid-area: days;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0;
  padding: 0 8px 8px 8px;
  color: var(--muted);
  font-size: 12px;
}
.days-header .day {
  text-align: center;
}

.time-labels {
  grid-area: labels;
  padding-top: 0;
}
.time-labels .hour-label {
  height: var(--hour-height);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding-right: 10px;
  color: var(--muted);
  font-size: 12px;
}

.schedule {
  grid-area: schedule;
  position: relative;
  border: 1px solid #1f2937;
  border-radius: 10px;
  background: var(--schedule-panel);
  height: 100%;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  overflow: hidden;
}
.day-col {
  position: relative;
  /* Hour + quarter-hour lines per column */
  background-image:
    repeating-linear-gradient(to bottom, var(--hour-line) 0 2px, transparent 2px var(--hour-height)),
    repeating-linear-gradient(to bottom, var(--quarter-line) 0 1px, transparent 1px calc(var(--hour-height) / 4));
}
.day-col + .day-col { border-left: 1px solid #1f2937; }

/* Selection rectangle while dragging */
.selection-box {
  position: absolute;
  left: 0;
  right: 0;
  background: var(--accent-weak);
  border-top: 2px dashed var(--accent);
  border-bottom: 2px dashed var(--accent);
  pointer-events: none;
}

/* Drag ghost preview */
.drag-ghost {
  position: absolute;
  left: 8px;
  right: 8px;
  border: 2px dashed var(--accent);
  border-radius: 8px;
  background: transparent;
  pointer-events: none;
  z-index: 25;
}

/* Block */
.block {
  position: absolute;
  left: 8px;
  right: 8px;
  background: var(--accent-weak);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  overflow: hidden;
  user-select: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: blockFadeIn 0.3s ease-out;
}

@keyframes blockFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
.block.dragging { opacity: 0.9; }
/* Resize handles */
.block .handle {
  position: absolute;
  left: 0;
  right: 0;
  height: 6px;
  cursor: ns-resize;
  background: transparent;
}
.block .handle.handle-top { top: 0; }
.block .handle.handle-bottom { bottom: 0; }
/* Time and title header - can be on same line for small blocks */
.block .header {
  display: flex;
  gap: 6px;
  align-items: baseline;
  min-height: 0;
}

/* Stacked layout for larger blocks (time above label) */
.block .header-stacked {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

/* Inline layout for small blocks (time beside label) */
.block .header-inline {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 6px;
}

/* Time shown at top */
.block .time-range {
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
  white-space: nowrap;
}
/* Task label */
.block .label {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  flex: 1;
  min-width: 0;
}
/* Optional description below label */
.block .description {
  font-size: 12px;
  line-height: 1.3;
  color: var(--muted);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  margin-top: -2px;
}
/* Category at bottom */
.block .category {
  font-size: 11px;
  color: var(--muted);
  opacity: 0.8;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  margin-top: auto;
  align-self: flex-start;
}
/* Optional global setting to push content down */
body[data-block-align="bottom"] .block .content {
  margin-top: auto;
}
/* Ensure category follows content at bottom without centering */
body[data-block-align="bottom"] .block .category {
  margin-top: 2px; /* override default auto */
}
.block:focus { outline: 2px solid var(--accent); }

/* Popover */
.popover {
  position: absolute;
  min-width: 220px;
  max-width: 280px;
  padding: 12px;
  border: 1px solid #1f2937;
  background: #0b1220;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  z-index: 20;
}
.popover label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.popover .pop-input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #1f2937;
  background: #0d141c;
  color: var(--text);
}
.popover select, .popover input[type="date"] {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #1f2937;
  background: #0d141c;
  color: var(--text);
}
.popover-actions { display: flex; gap: 8px; margin-top: 10px; justify-content: flex-end; }
.popover-actions .btn-duplicate { background: #111827; color: var(--text); border: 1px solid #1f2937; padding: 8px 12px; border-radius: 8px; cursor: pointer; margin-right: auto; }
.popover-actions .btn-save { background: var(--accent); color: white; border: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.popover-actions .btn-delete { background: #1a0f10; color: var(--danger); border: 1px solid #3b1620; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.popover-actions .btn-cancel { background: #111827; color: var(--text); border: 1px solid #1f2937; padding: 8px 12px; border-radius: 8px; cursor: pointer; }

/* Popover extra controls */
.pop-field { margin-bottom: 8px; }
.pop-row { display: flex; gap: 10px; }
.pop-row .pop-field { flex: 1; }
.pop-textarea { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid #1f2937; background: #0d141c; color: var(--text); resize: vertical; min-height: 70px; }
.pop-color { width: 100%; height: 36px; padding: 0; border: 1px solid #1f2937; border-radius: 8px; background: transparent; }

/* Modal and theme styles */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.overlay.hidden { display: none; }
.modal {
  width: min(520px, 92vw);
  background: linear-gradient(180deg, rgba(15,23,32,0.85), rgba(15,23,32,0.75));
  color: var(--text);
  border: 1px solid #1f2937;
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.55);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  position: relative;
}

.modal::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  top: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--accent) 20%, transparent 50%, var(--accent) 80%, transparent 100%);
  opacity: 0.3;
  pointer-events: none;
}
.modal-header { padding: 14px 16px; border-bottom: 1px solid #1f2937; }
.modal-body { padding: 16px; display: grid; gap: 14px; }
.modal-actions { padding: 12px 16px; display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid #1f2937; }
.modal-actions button {
  background: #0f1720;
  color: var(--text);
  border: 1px solid #1f2937;
  padding: 10px 14px;
  border-radius: 9999px;
  cursor: pointer;
  line-height: 1;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.06s ease;
}
.modal-actions button:hover { background: #111827; border-color: #374151; box-shadow: 0 0 0 3px var(--accent-weak); }
.modal-actions button:active { transform: translateY(1px); }
.modal-actions button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.modal-actions #settingsSave { background: var(--accent); color: white; border: none; }
.modal-actions #settingsSave:hover { filter: brightness(0.95); box-shadow: 0 8px 24px rgba(37,99,235,0.35); }
.field .label { display: block; color: var(--muted); margin-bottom: 6px; font-size: 12px; }
.field .inline { display: flex; gap: 16px; }
.modal select { width: 100%; padding: 10px 12px; border-radius: 10px; background: #0d141c; color: var(--text); border: 1px solid #1f2937; transition: border-color 0.2s ease, box-shadow 0.2s ease; }
.modal select:focus { outline: none; border-color: #374151; box-shadow: 0 0 0 3px var(--accent-weak); }

/* Segmented controls for radios */
.segmented { display: inline-flex; background: #0d141c; border: 1px solid #1f2937; border-radius: 10px; overflow: hidden; }
.segmented .seg { position: relative; }
.segmented .seg input { position: absolute; opacity: 0; pointer-events: none; }
.segmented .seg span { display: inline-block; padding: 6px 10px; color: var(--muted); cursor: pointer; transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, transform 0.06s ease; }
.segmented .seg:hover span { background: #111827; color: var(--text); }
.segmented .seg:focus-within span { box-shadow: 0 0 0 3px var(--accent-weak) inset; }
.segmented .seg input:checked + span { background: var(--accent); color: white; box-shadow: none; }
.segmented .seg + .seg span { border-left: 1px solid #1f2937; }

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

/* Light theme overrides */
body[data-theme="light"] {
  --bg: #f8fafc;
  --panel: #ffffff;
  --schedule-panel: #f8fafc;
  --control-button: #e5e5e5;
  --text: #0f172a;
  --muted: #475569;
  --accent: #2563eb;
  --accent-weak: rgba(37,99,235,0.15);
  --hour-line: #d1d5db;
  --quarter-line: #e5e7eb;
}
@media (prefers-color-scheme: light) {
  body[data-theme="system"] {
    --bg: #f8fafc;
    --panel: #ffffff;
    --schedule-panel: #f8fafc;
    --control-button: #e5e5e5;
    --text: #0f172a;
    --muted: #475569;
    --accent: #2563eb;
    --accent-weak: rgba(37,99,235,0.15);
    --hour-line: #d1d5db;
    --quarter-line: #e5e7eb;
  }
}

/* Print styles: show only the schedule */
@media print {
  body { background: white; color: #111; }
  .app-header, .app-footer, .info-btn, #helpOverlay { display: none !important; }
  .planner { padding: 0; }
  .time-labels .hour-label { color: #333; }
  .schedule { border-color: #ccc; background: white; }
  .block { border-color: #1f3b8f; background: #dfe9ff; color: #111; }
  .popover { display: none !important; }
}
