/* TimeBlocker MVP styles */
: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;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--panel);
  border-bottom: 1px solid #1f2937;
  position: sticky;
  top: 0;
  z-index: 10;
}
.title h1 { margin: 0 0 4px; font-size: 20px; }
.title .subtitle { color: var(--muted); font-size: 12px; }

.controls { display: flex; gap: 8px; position: relative; }
.controls button {
  background: var(--control-button);
  color: var(--text);
  border: 1px solid #1f2937;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.controls button:hover { border-color: #374151; }

/* Clear menu dropdown */
.menu-wrap { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--panel);
  border: 1px solid #1f2937;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  display: grid;
  min-width: 160px;
  z-index: 30;
}
.menu.hidden { display: none; }
.menu button {
  text-align: left;
  background: transparent;
  border: none;
  padding: 10px 12px;
  color: var(--text);
}
.menu button:hover { background: #0f1720; }

.app-footer { padding: 10px 20px; color: var(--muted); font-size: 12px; }

/* Planner layout */
.planner {
  display: grid;
  grid-template-columns: 80px 1fr;
  grid-template-rows: 32px auto;
  grid-template-areas:
    "spacer days"
    "labels schedule";
  gap: 0;
  padding: 16px 20px 40px;
}

.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: #0d141c;
  height: calc(12 * var(--hour-height)); /* 8am-8pm inclusive of 12 hours */
  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;
}
.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 shown at top */
.block .time-range {
  font-size: 12px;
  color: var(--muted);
}
/* Task label */
.block .label {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
/* 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-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;
}
.overlay.hidden { display: none; }
.modal {
  width: min(520px, 92vw);
  background: var(--panel);
  color: var(--text);
  border: 1px solid #1f2937;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.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: 8px; border-top: 1px solid #1f2937; }
.modal-actions button {
  background: var(--control-button);
  color: var(--text);
  border: 1px solid #1f2937;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.modal-actions button:hover { border-color: #374151; }
.modal-actions #settingsSave { background: var(--accent); color: white; border: none; }
.field .label { display: block; color: var(--muted); margin-bottom: 6px; font-size: 12px; }
.field .inline { display: flex; gap: 16px; }
.modal select { width: 100%; padding: 8px 10px; border-radius: 8px; background: var(--schedule-panel); color: var(--text); border: 1px solid #1f2937; }

/* 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); }
.segmented .seg input:checked + span { background: var(--accent); color: white; }
.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;
    --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 { 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; }
}
