  :root {
    --bs-primary: #4f46e5;
    --bs-primary-rgb: 79, 70, 229;
    --accent: #4f46e5;
    --accent-soft: #eef0ff;
    --time-col: 64px;
    --header-h: 60px;
    --row-h: 58px;
    --prio-high: #ef4444;
    --prio-med:  #f59e0b;
    --prio-low:  #3b82f6;
    --done:      #16a34a;
    --grid-line: #e3e6ee;
    --grid-line-strong: #cdd2df;
    --cell-bg: #ffffff;
    --time-bg: #f6f7fb;
    --panel: #ffffff;
    --app-bg: #f4f5fa;
    --ink: #161b26;
    --muted: #6b7280;
  }

  [data-bs-theme="dark"] {
    --accent: #818cf8;
    --accent-soft: #20233a;
    --grid-line: #2a2f3b;
    --grid-line-strong: #3a4150;
    --cell-bg: #15181f;
    --time-bg: #11141a;
    --panel: #181b22;
    --app-bg: #0e1016;
    --ink: #e7e9ee;
    --muted: #98a0ad;
    --bs-body-bg: #0e1016;
    --bs-body-color: #e7e9ee;
  }

  * { box-sizing: border-box; }

  body {
    font-family: "Manrope", system-ui, sans-serif;
    background: var(--app-bg);
    color: var(--bs-body-color);
    -webkit-text-size-adjust: 100%;
  }

  h1, .brand-title { font-family: "Bricolage Grotesque", sans-serif; letter-spacing: -.02em; }

  .app-wrap { max-width: 1700px; margin: 0 auto; padding: 14px clamp(8px, 2vw, 22px) 40px; }

  /* ---------- Шапка ---------- */
  .topbar {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    margin-bottom: 12px;
  }
  .brand { display: flex; align-items: center; gap: 12px; }
  .brand .logo {
    width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--accent), #7c3aed); color: #fff; font-size: 19px;
    box-shadow: 0 6px 18px rgba(79,70,229,.35);
  }
  .brand-title { font-size: clamp(20px, 2.4vw, 28px); font-weight: 800; margin: 0; line-height: 1; }
  .brand-sub { color: var(--muted); font-size: 12.5px; font-weight: 600; }

  .save-pill {
    display: inline-flex; align-items: center; gap: 7px;
    font-size: 12.5px; font-weight: 700; color: var(--muted);
    padding: 6px 11px; border-radius: 999px; background: var(--panel);
    border: 1px solid var(--grid-line); white-space: nowrap;
  }
  .save-pill.saving { color: var(--accent); }
  .save-pill.saved  { color: var(--done); }
  .save-pill.error  { color: var(--prio-high); }
  .save-pill .fa-spin { animation-duration: .8s; }

  /* ---------- Панель инструментов ---------- */
  .toolbar {
    position: sticky; top: 0; z-index: 30;
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    backdrop-filter: blur(8px);
    border: 1px solid var(--grid-line);
    border-radius: 14px;
    padding: 9px 11px;
    margin-bottom: 12px;
    display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap;
  }
  .tool-sep { width: 1px; align-self: stretch; background: var(--grid-line); margin: 2px 0; }
  .tool-label { color: var(--muted); font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; }
  .tool-group { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }

  input[type="color"] {
    width: 34px; height: 32px; padding: 2px; border: 1px solid var(--grid-line);
    border-radius: 8px; background: var(--panel); cursor: pointer;
  }
  .swatches { display: flex; gap: 5px; flex-wrap: wrap; }
  .swatch {
    width: 26px; height: 26px; padding: 0; border: 1px solid rgba(0,0,0,.18);
    border-radius: 7px; cursor: pointer; transition: transform .08s;
  }
  .swatch:hover { transform: scale(1.12); }
  [data-bs-theme="dark"] .swatch { border-color: rgba(255,255,255,.18); }

  .prio-btn[data-prio="high"] i   { color: var(--prio-high); }
  .prio-btn[data-prio="medium"] i { color: var(--prio-med); }
  .prio-btn[data-prio="low"] i    { color: var(--prio-low); }
  .prio-btn.active[data-prio="high"]   { background: var(--prio-high); border-color: var(--prio-high); }
  .prio-btn.active[data-prio="medium"] { background: var(--prio-med);  border-color: var(--prio-med); }
  .prio-btn.active[data-prio="low"]    { background: var(--prio-low);  border-color: var(--prio-low); }
  .prio-btn.active i { color: #fff; }

  .dur-box { display: inline-flex; align-items: center; gap: 6px; }
  .dur-val { min-width: 58px; text-align: center; font-weight: 800; font-size: 13px; }

  #cellTags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
  .tag-toggle {
    border: 1px solid var(--grid-line); background: var(--panel); color: var(--ink);
    border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 700; cursor: pointer;
    display: inline-flex; align-items: center; gap: 6px;
  }
  .tag-toggle .dot { width: 10px; height: 10px; border-radius: 50%; }
  .tag-toggle.active { color: #fff; border-color: transparent; }

  .selinfo { margin-left: auto; color: var(--muted); font-size: 12.5px; font-weight: 700; max-width: 100%; }

  .toolbar.no-selection .needs-cell { opacity: .45; pointer-events: none; }

  /* ---------- Прогресс ---------- */
  .progress-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
  @media (max-width: 540px){ .progress-cards { grid-template-columns: 1fr; } }
  .pcard { background: var(--panel); border: 1px solid var(--grid-line); border-radius: 14px; padding: 12px 14px; }
  .pcard .pc-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
  .pcard .pc-title { font-weight: 800; font-size: 13.5px; display: flex; align-items: center; gap: 8px; }
  .pcard .pc-count { color: var(--muted); font-weight: 800; font-size: 13px; }
  .pcard .progress { height: 9px; border-radius: 999px; background: var(--accent-soft); }

  /* ---------- Дни (мобайл) ---------- */
  #dayTabs { display: none; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 6px; -webkit-overflow-scrolling: touch; }
  .day-tab {
    flex: 0 0 auto; min-width: 64px; border: 1px solid var(--grid-line); background: var(--panel);
    border-radius: 12px; padding: 8px 6px; text-align: center; cursor: pointer; color: var(--ink);
  }
  .day-tab .dt-name { font-weight: 800; font-size: 12.5px; text-transform: uppercase; }
  .day-tab .dt-date { font-size: 11px; color: var(--muted); font-weight: 700; }
  .day-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
  .day-tab.active .dt-date { color: rgba(255,255,255,.85); }
  .day-tab.today:not(.active) { border-color: var(--accent); }

  /* ---------- Сетка недели ---------- */
  .planner-shell { background: var(--panel); border: 1px solid var(--grid-line-strong); border-radius: 16px; overflow: hidden; }

  .planner-grid {
    display: grid;
    grid-template-columns: var(--time-col) repeat(7, minmax(0, 1fr));
    grid-template-rows: var(--header-h);
    grid-auto-rows: minmax(var(--row-h), auto);
    gap: 6px;
    padding: 10px;
  }
  .corner, .day-head {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
  }
  .corner { grid-column: 1; grid-row: 1; color: var(--muted); font-size: 16px; }
  .day-head { grid-row: 1; padding: 6px 2px; text-align: center; min-width: 0;
    background: var(--time-bg); border: 1px solid var(--grid-line); border-radius: 12px; }
  .day-head.today { background: var(--accent-soft); border-color: var(--accent); }
  .day-head .dh-name { font-weight: 800; font-size: clamp(11px, 1vw, 14px); text-transform: uppercase; line-height: 1.1; }
  .day-head .dh-date { font-size: clamp(10px,.85vw,12px); color: var(--muted); font-weight: 700; margin-top: 2px; }
  .day-head.today .dh-name { color: var(--accent); }

  .time-cell {
    grid-column: 1;
    display: grid; place-items: center;
    font-size: 12px; font-weight: 800; color: var(--muted);
  }

  .cell {
    position: relative; min-width: 0;
    display: flex; flex-direction: column;
    background: var(--cell-bg); color: var(--ink);
    border: 1px solid var(--grid-line);
    border-radius: 12px;
    overflow: hidden;
  }
  .cell[data-priority="high"]   { outline: 2.5px solid var(--prio-high); outline-offset: -2.5px; }
  .cell[data-priority="medium"] { outline: 2.5px solid var(--prio-med);  outline-offset: -2.5px; }
  .cell[data-priority="low"]    { outline: 2.5px solid var(--prio-low);  outline-offset: -2.5px; }
  .cell.done[data-priority]     { outline: none; }

  .cell.selected { z-index: 5; box-shadow: inset 0 0 0 2.5px var(--accent); }
  .cell.done .editor { text-decoration: line-through; opacity: .5; }
  .cell.done { background: var(--cell-bg); }

  .editor {
    flex: 1 1 auto;
    width: 100%; min-height: calc(var(--row-h) - 1px);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center;
    padding: 7px 30px; outline: none;
    white-space: pre-wrap; overflow-wrap: anywhere;
    font-size: clamp(12px,.92vw,14px); line-height: 1.28; font-weight: 600;
  }
  .cell:not(.has-text):hover .editor:empty::before {
    content: "\f067"; font-family: "Font Awesome 6 Free"; font-weight: 900;
    color: var(--muted); opacity: .35; font-size: 12px;
  }

  .done-toggle {
    position: absolute; left: 7px; top: 50%; transform: translateY(-50%);
    width: 22px; height: 22px; border-radius: 50%;
    border: 1.5px solid var(--grid-line-strong); background: var(--panel); color: transparent;
    display: grid; place-items: center; cursor: pointer; font-size: 11px; padding: 0;
    opacity: 0; transition: opacity .12s, background .12s, color .12s;
  }
  .cell:hover .done-toggle, .cell:focus-within .done-toggle,
  .cell.has-text .done-toggle, .cell.done .done-toggle { opacity: 1; }
  .done-toggle:hover { border-color: var(--done); color: var(--done); }
  .cell.done .done-toggle { background: var(--done); border-color: var(--done); color: #fff; }

  .cell-tags { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; padding: 0 8px 7px; margin-top: -3px; }
  .cell-tags .chip {
    font-size: 10.5px; font-weight: 800; line-height: 1; color: #fff;
    padding: 3px 7px; border-radius: 999px; white-space: nowrap;
  }

  /* ---------- Перетаскивание + кисть формата ---------- */
  .drag-handle {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    width: 20px; height: 20px; border-radius: 6px;
    display: grid; place-items: center; cursor: grab; color: var(--muted); padding: 0;
    background: color-mix(in srgb, var(--panel) 78%, transparent);
    border: 1px solid var(--grid-line); font-size: 10px; opacity: 0;
    transition: opacity .12s; touch-action: none; z-index: 4;
  }
  .drag-handle:active { cursor: grabbing; }
  .cell:hover .drag-handle, .cell:focus-within .drag-handle,
  .cell.selected .drag-handle, .cell.has-content .drag-handle { opacity: .9; }
  .cell.drop-target { box-shadow: inset 0 0 0 3px var(--accent); background: var(--accent-soft) !important; }
  .cell.drag-src { opacity: .35; }
  .drag-ghost {
    position: fixed; z-index: 9999; pointer-events: none; transform: translate(10px, 8px);
    max-width: 240px; padding: 8px 12px; border-radius: 10px; font-weight: 700; font-size: 13px;
    border: 1px solid var(--grid-line-strong); background: var(--panel); color: var(--ink);
    box-shadow: 0 14px 32px rgba(0,0,0,.3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .paint-active { background: var(--accent) !important; border-color: var(--accent) !important; color: #fff !important; }
  .paint-mode .editor { pointer-events: none; }
  .paint-mode .done-toggle, .paint-mode .drag-handle { pointer-events: none; opacity: 0 !important; }
  .paint-mode .cell { cursor: copy; }
  @media (max-width: 767.98px){
    .day-row .drag-handle { opacity: .9; width: 26px; height: 26px; font-size: 13px; }
  }

  /* ---------- Список одного дня (мобайл) ---------- */
  .day-list { padding: 8px; display: flex; flex-direction: column; gap: 8px; }
  .day-row { display: grid; grid-template-columns: 58px 1fr; gap: 8px; align-items: stretch; }
  .day-row-time {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: var(--time-bg); border: 1px solid var(--grid-line); border-radius: 10px;
    font-weight: 800; font-size: 12px; color: var(--muted); padding: 4px; text-align: center;
    white-space: pre-line; line-height: 1.25;
  }
  .day-row .cell {
    border: 1px solid var(--grid-line); border-radius: 10px; min-height: 52px;
  }
  .day-row .editor { min-height: 50px; font-size: 16px; padding: 9px 38px; }
  .day-row .done-toggle { width: 26px; height: 26px; font-size: 13px; }

  /* ---------- Теги: модалка ---------- */
  .tag-row { display: grid; grid-template-columns: 44px 1fr auto; gap: 8px; align-items: center; }
  .tag-preview { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
  .tag-preview .dot { width: 12px; height: 12px; border-radius: 50%; }

  .footnote { color: var(--muted); font-size: 12.5px; margin-top: 14px; line-height: 1.5; }
  kbd { background: var(--time-bg); border: 1px solid var(--grid-line-strong); border-bottom-width: 2px; border-radius: 6px; padding: 1px 6px; font-size: 11.5px; color: var(--ink); }

  /* ---------- Адаптив ---------- */
  @media (max-width: 767.98px) {
    #dayTabs { display: flex; }
    .planner-grid { display: none; }
    .selinfo { width: 100%; margin-left: 0; order: 99; }
    .toolbar { gap: 8px 10px; }
    .btn { --bs-btn-padding-y: .42rem; }
  }
  @media (min-width: 768px) {
    .day-list { display: none !important; }
  }

  @media print {
    .topbar, .toolbar, .progress-cards, #dayTabs, .footnote, .btn { display: none !important; }
    body { background: #fff; }
    .app-wrap { padding: 0; max-width: none; }
    .planner-shell { border: 1px solid #999; border-radius: 0; }
    .day-list { display: none !important; }
    .planner-grid { display: grid !important; }
    .cell, .time-cell { min-height: 40px; }
    .editor { font-size: 9px; min-height: 39px; }
    .done-toggle { display: none; }
  }
