:root {
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-primary: #8b5cf6;
  --accent-hover: #7c3aed;
  --danger-color: #ef4444;

  --hour-height: 60px; /* 1 hour = 60px height */
  --collision-glow: rgba(239, 68, 68, 0.8);
}

.block-collision-warning {
  border: 2px dashed var(--danger-color) !important;
  box-shadow: 0 0 12px var(--collision-glow) !important;
}

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

body {
  font-family:
    "Outfit",
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  padding: 1.5rem;
  line-height: 1.5;
}

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

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 1rem;
}

.back-link {
  color: #a5b4fc;
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  display: inline-block;
  margin-bottom: 0.4rem;
  transition: transform 0.2s;
}

.back-link:hover {
  transform: translateX(-4px);
}

.header h1 {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #c084fc, #818cf8, #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.date-selector-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-card);
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.date-selector-wrapper label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.date-selector-wrapper input[type="date"] {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
}

/* Toolbar Panel */
.toolbar-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.btn {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.btn-secondary {
  background: var(--bg-hover);
  border-color: var(--border-color);
  color: var(--text-main);
}
.btn-secondary:hover {
  background: var(--border-color);
}

.btn-outline {
  background: var(--bg-dark);
  border-color: var(--border-color);
  color: var(--text-main);
}
.btn-outline:hover {
  border-color: var(--accent-primary);
}

.btn-danger-outline {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--danger-color);
}
.btn-danger-outline:hover {
  background: rgba(239, 68, 68, 0.15);
}

.btn-danger {
  background: var(--danger-color);
  color: #fff;
}
.btn-danger:hover {
  background: #dc2626;
}

/* Export Dropdown */
.export-dropdown {
  position: relative;
}

.dropdown-content {
  position: absolute;
  right: 0;
  top: 110%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  min-width: 210px;
  z-index: 100;
  overflow: hidden;
}

.dropdown-content[hidden] {
  display: none !important;
}

.dropdown-content button,
.dropdown-file-label {
  background: none;
  border: none;
  color: var(--text-main);
  padding: 0.65rem 1rem;
  text-align: left;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}

.dropdown-content button:hover,
.dropdown-file-label:hover {
  background: var(--bg-hover);
}

/* Stats Bar */
.stats-bar {
  display: flex;
  gap: 0.65rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.stat-chip {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left-width: 4px;
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.stat-chip strong {
  font-family: "JetBrains Mono", monospace;
  color: var(--text-main);
}

/* Workspace Layout */
.planner-workspace {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 900px) {
  .planner-workspace {
    grid-template-columns: 1fr;
  }
}

/* Sidebar */
.sidebar {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.25rem;
}

.sidebar h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.sidebar-help {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.preset-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.preset-item {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: grab;
  user-select: none;
  transition: all 0.2s ease;
}

.preset-item:hover {
  border-color: var(--accent-primary);
  transform: translateX(3px);
  background: var(--bg-hover);
}

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

.preset-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 0.5rem;
}

.preset-name {
  font-size: 0.85rem;
  font-weight: 500;
  flex: 1;
}

.preset-duration {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: "JetBrains Mono", monospace;
}

.legend-card {
  margin-top: 1.5rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px dashed var(--border-color);
  border-radius: 8px;
  padding: 0.85rem;
}

.legend-card h3 {
  font-size: 0.85rem;
  color: #a5b4fc;
  margin-bottom: 0.4rem;
}

.legend-card ul {
  padding-left: 1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Timeline Container */
.timeline-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
}

.timeline-header {
  display: flex;
  background: rgba(15, 23, 42, 0.8);
  border-bottom: 1px solid var(--border-color);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.time-col-header {
  width: 80px;
  padding: 0.75rem;
  border-right: 1px solid var(--border-color);
  text-align: center;
}

.schedule-col-header {
  flex: 1;
  padding: 0.75rem 1rem;
}

.timeline-body {
  display: flex;
  position: relative;
  height: calc(24 * var(--hour-height)); /* 1440px total */
}

/* Time Scale Column */
.time-scale {
  width: 80px;
  border-right: 1px solid var(--border-color);
  background: rgba(15, 23, 42, 0.4);
  position: relative;
  user-select: none;
}

.time-scale-hour {
  height: var(--hour-height);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  line-height: var(--hour-height);
}

/* Timeline Track */
.timeline-track {
  flex: 1;
  position: relative;
  background: linear-gradient(
    to bottom,
    transparent 0px,
    transparent calc(var(--hour-height) - 1px),
    rgba(255, 255, 255, 0.06) calc(var(--hour-height) - 1px),
    rgba(255, 255, 255, 0.06) var(--hour-height)
  );
  background-size: 100% var(--hour-height);
}

/* Current Time Line */
.current-time-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: #f43f5e;
  z-index: 50;
  pointer-events: none;
}

.current-time-badge {
  position: absolute;
  left: -75px;
  top: -10px;
  background: #f43f5e;
  color: #fff;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}

/* Time Block Element */
.time-block {
  position: absolute;
  left: 8px;
  right: 16px;
  border-radius: 8px;
  padding: 6px 10px;
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  cursor: move;
  user-select: none;
  z-index: 10;
  transition:
    box-shadow 0.15s,
    transform 0.15s;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.time-block:hover {
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  z-index: 20;
}

.time-block.dragging {
  opacity: 0.8;
  transform: scale(0.99);
}

.block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.block-title {
  font-weight: 700;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.block-time {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  opacity: 0.9;
  white-space: nowrap;
}

.block-notes {
  font-size: 0.75rem;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

/* Resize Handles */
.resize-handle {
  position: absolute;
  left: 0;
  right: 0;
  height: 6px;
  cursor: ns-resize;
  z-index: 15;
}

.resize-handle.top {
  top: 0;
}

.resize-handle.bottom {
  bottom: 0;
}

.resize-handle:hover {
  background: rgba(255, 255, 255, 0.4);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  max-width: 500px;
  width: 100%;
  padding: 1.5rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  animation: modalIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.modal-close {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.form-group label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent-primary);
}

.form-row {
  display: flex;
  gap: 0.75rem;
}

.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.footer-right {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

/* Alert Container */
.alert-container {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 12px;
  padding: 12px 16px;
  color: #ef4444;
  font-size: 0.875rem;
  font-weight: 550;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 1.5rem;
  line-height: 1.4;
}
.alert-container.success {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.25);
  color: #10b981;
}
.alert-container .alert-icon {
  flex-shrink: 0;
}
