*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: #0a0a14;
  color: #eee;
}

.hidden { display: none !important; }

.panel {
  max-width: 360px;
  margin: 10vh auto;
  padding: 24px;
  background: #12122a;
  border: 1px solid #334;
  border-radius: 12px;
}

.panel h1 { margin: 0 0 8px; font-size: 1.4rem; }
.panel p { margin: 0 0 16px; color: #999; }
.panel input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid #334;
  border-radius: 8px;
  background: #0f0f23;
  color: #eee;
}
.panel button {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: #4361ee;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}
.error { color: #ff6b6b; font-size: 0.85rem; margin-top: 8px; }

.planner-standalone { overflow: hidden; }

.planner-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.planner-header {
  flex-shrink: 0;
  background: #12122a;
  border-bottom: 1px solid #334;
}

.planner-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 0;
}

.planner-logo { font-weight: 600; font-size: 1rem; }

.planner-status { font-size: 0.78rem; }
.status-ok { color: #6ee7a0; }
.status-warn { color: #ffb347; }
.status-error { color: #ff6b6b; }

.planner-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
}

.planner-subtabs { display: flex; gap: 4px; }

.planner-subtab {
  padding: 6px 12px;
  border: 1px solid #334;
  border-radius: 6px;
  background: #0f0f23;
  color: #ccc;
  cursor: pointer;
}

.planner-subtab.active { background: #4361ee; color: #fff; }

.planner-date-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
}

.planner-date-bar input[type="date"] {
  background: #0f0f23;
  border: 1px solid #334;
  color: #eee;
  padding: 6px 8px;
  border-radius: 6px;
}

.btn-planner {
  padding: 6px 10px;
  border: 1px solid #334;
  border-radius: 6px;
  background: #0f0f23;
  color: #ccc;
  cursor: pointer;
  font-size: 0.82rem;
}

.btn-planner:hover { background: #1a1a3a; color: #fff; }

.desktop-only { display: block; }
.mobile-only { display: none; }

.planner-menu-btn {
  margin-left: auto;
  margin-right: 8px;
  width: 36px;
  height: 36px;
  border: 1px solid #334;
  border-radius: 8px;
  background: #0f0f23;
  color: #eee;
  font-size: 1.1rem;
  cursor: pointer;
}

.backlog-row-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.backlog-menu-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: 1px solid #334;
  border-radius: 8px;
  background: #0f0f23;
  color: #ccc;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.btn-backlog-after:hover { background: #4361ee; color: #fff; }

.planner-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.planner-modal.hidden { display: none !important; }

.planner-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.planner-modal-panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow: auto;
  background: #12122a;
  border: 1px solid #334;
  border-radius: 16px 16px 0 0;
  padding: 16px;
  z-index: 1;
}

.planner-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.planner-modal-header h3 { margin: 0; font-size: 1rem; }

.planner-modal-close {
  border: none;
  background: transparent;
  color: #aaa;
  font-size: 1.2rem;
  cursor: pointer;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 0.82rem;
  color: #aaa;
}

.modal-field input,
.modal-field select {
  padding: 10px 12px;
  border: 1px solid #334;
  border-radius: 8px;
  background: #0f0f23;
  color: #eee;
  font-size: 1rem;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.modal-actions .btn-planner { width: 100%; text-align: left; }

.btn-danger { border-color: #c0392b !important; color: #ff8a80 !important; }

.planner-mobile-nav { display: none; }

.planner-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.planner-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.planner-split {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
}

.planner-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid #334;
}

.planner-pane:last-child { border-right: none; }

.planner-pane-head {
  background: #0a0a18;
  border-bottom: 1px solid #334;
  padding: 8px 12px;
}

.planner-pane-title {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: #aaa;
}

.planner-hint {
  margin: 4px 0 0;
  font-size: 0.72rem;
  color: #666;
}

.planner-backlog, .planner-daily {
  flex: 1;
  overflow: auto;
  padding: 8px;
  -webkit-overflow-scrolling: touch;
}

.planner-daily.drag-over {
  background: rgba(67, 97, 238, 0.08);
  outline: 2px dashed #4361ee;
}

.backlog-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 0;
  border-radius: 4px;
}

.backlog-row:hover { background: rgba(255,255,255,0.03); }
.backlog-row.in-plan {
  background: rgba(67, 97, 238, 0.14);
  box-shadow: inset 3px 0 0 #4361ee;
}
.backlog-row.in-plan .backlog-title { color: #c5d0ff; }
.backlog-row.dragging { opacity: 0.5; }

.backlog-toggle {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: #888;
  cursor: pointer;
  padding: 0;
  font-size: 0.85rem;
}

.backlog-toggle.empty { visibility: hidden; }

.backlog-title {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border-radius: 4px;
  outline: none;
  line-height: 1.3;
}

.backlog-title:focus {
  background: #1a1a3a;
  box-shadow: 0 0 0 1px #4361ee;
}

.backlog-title:empty::before {
  content: 'Назва…';
  color: #555;
}

.priority-input {
  width: 48px;
  flex-shrink: 0;
  background: #0f0f23;
  border: 1px solid #334;
  color: #eee;
  border-radius: 4px;
  padding: 4px;
  font-size: 0.75rem;
}

.mode-select {
  max-width: 100px;
  flex-shrink: 0;
  background: #0f0f23;
  border: 1px solid #334;
  color: #eee;
  border-radius: 4px;
  font-size: 0.72rem;
  padding: 4px;
}

.btn-backlog-child,
.btn-backlog-after,
.btn-plan-done,
.btn-plan-remove,
.btn-backlog-delete {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border: 1px solid #334;
  border-radius: 4px;
  background: #0f0f23;
  color: #ccc;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
}

.btn-backlog-delete:hover { background: #c0392b; color: #fff; }

.btn-backlog-child:hover,
.btn-plan-done:hover { background: #4361ee; color: #fff; }

.plan-toggle-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  width: 38px;
  height: 22px;
  cursor: pointer;
}

.plan-toggle {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.plan-toggle-slider {
  position: absolute;
  inset: 0;
  background: #334;
  border-radius: 11px;
  transition: background 0.15s;
}

.plan-toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: #ccc;
  border-radius: 50%;
  transition: transform 0.15s, background 0.15s;
}

.plan-toggle:checked + .plan-toggle-slider {
  background: #4361ee;
}

.plan-toggle:checked + .plan-toggle-slider::before {
  transform: translateX(16px);
  background: #fff;
}

.btn-plan-on {
  border-color: #4361ee !important;
  color: #c5d0ff !important;
  background: rgba(67, 97, 238, 0.2) !important;
}

.btn-plan-remove:hover { background: #c0392b; color: #fff; }

.plan-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px;
  margin-bottom: 8px;
  background: #12122a;
  border: 1px solid #334;
  border-radius: 8px;
}

.plan-row.completed { opacity: 0.55; text-decoration: line-through; }
.plan-row.overdue { border-color: #e76f51; }

.plan-path { flex: 1 1 100%; font-size: 0.9rem; }

.plan-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.plan-time {
  background: #0f0f23;
  border: 1px solid #334;
  color: #eee;
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 0.8rem;
}

.priority-badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: #334;
}

.mode-chip {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
}

.plan-auto {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: #2a9d8f;
  color: #fff;
}

.planner-empty { color: #666; text-align: center; padding: 24px; }

.planner-changelog {
  flex: 1;
  overflow: auto;
  padding: 12px;
}

.changelog-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.changelog-table th,
.changelog-table td {
  border: 1px solid #334;
  padding: 6px 8px;
  text-align: left;
}

.changelog-table th { background: #12122a; color: #aaa; }

.changelog-diff {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: monospace;
  font-size: 0.7rem;
  color: #888;
}

.changelog-undone { opacity: 0.45; }

.changelog-undo-cell { max-width: 140px; vertical-align: top; }

.btn-changelog-undo {
  padding: 4px 8px;
  border: 1px solid #4361ee;
  border-radius: 4px;
  background: transparent;
  color: #8ea4ff;
  cursor: pointer;
  font-size: 0.72rem;
  white-space: nowrap;
}

.btn-changelog-undo:hover { background: #4361ee; color: #fff; }

.changelog-block-reason {
  display: block;
  font-size: 0.68rem;
  color: #888;
  line-height: 1.3;
  max-width: 130px;
}

@media (max-width: 768px) {
  .desktop-only { display: none !important; }

  .mobile-only { display: flex !important; }

  .planner-header-row { padding-top: max(10px, env(safe-area-inset-top)); }

  .planner-toolbar { display: none !important; }

  .planner-pane-head { padding: 6px 10px; }

  .backlog-row-mobile {
    gap: 8px;
    padding: 8px 4px;
    border-bottom: 1px solid #1a1a2e;
  }

  .backlog-row-mobile .backlog-title {
    font-size: 1rem;
    padding: 10px 8px;
    min-height: 44px;
  }

  .backlog-row-mobile .row-controls { display: none !important; }

  .planner-mobile-nav {
    display: flex;
    gap: 0;
    border-top: 1px solid #334;
  }

  .planner-mobile-tab {
    flex: 1;
    padding: 12px 8px;
    border: none;
    border-right: 1px solid #334;
    background: #0f0f23;
    color: #aaa;
    cursor: pointer;
    font-size: 0.85rem;
  }

  .planner-mobile-tab:last-child { border-right: none; }
  .planner-mobile-tab.active { background: #4361ee; color: #fff; }

  .planner-split { grid-template-columns: 1fr; }

  .planner-pane-plan { display: none; }

  .planner-split.mobile-show-plan .planner-pane-backlog { display: none; }
  .planner-split.mobile-show-plan .planner-pane-plan { display: flex; }

  .plan-row .plan-meta,
  .plan-row .btn-plan-done,
  .plan-row .btn-plan-remove { display: none; }

  .plan-row { padding: 12px; }
}
