/* Original / bright palette — indigo accent, cool neutrals, near-black dark mode.
   Inspired by Linear / Superhuman. */
:root {
  --accent: #6366F1;
  --accent-hover: #4F46E5;
  --accent-soft: rgba(99, 102, 241, 0.10);
  --accent-glow: rgba(99, 102, 241, 0.25);

  --bg: #FAFAFA;
  --bg-alt: #FFFFFF;
  --bg-pane: #FFFFFF;
  --bg-sidebar: #F4F4F5;
  --bg-iconbar: #EFEFF2;
  --bg-hover: rgba(0, 0, 0, 0.03);
  --bg-selected: rgba(99, 102, 241, 0.08);
  --unread-bg: rgba(99, 102, 241, 0.05);

  --border: rgba(0, 0, 0, 0.06);
  --border-strong: rgba(0, 0, 0, 0.10);

  --text: #09090B;
  --text-muted: #52525B;
  --text-faint: #A1A1AA;
  --text-quart: #D4D4D8;

  --summary-bg: rgba(99, 102, 241, 0.07);
  --summary-border: #6366F1;

  --danger: #EF4444;
  --success: #10B981;
  --warning: #F59E0B;
  --violet: #8B5CF6;
  --pink: #EC4899;
  --gold: #EAB308;
}
/* Тёмная тема по макету дизайнеров 14.07.2026 (msg 816): глубокий сине-
   фиолетовый вместо прежнего серого. Палитра: фон #0a0e1f, поверхности
   #141931/#1b2140, бордеры #272e52, текст #eef0fb/#9099c2, акцент #8a83ff. */
:root[data-theme="dark"] {
  --accent: #8a83ff;
  --accent-hover: #9c96ff;
  --accent-soft: rgba(138, 131, 255, 0.14);
  --accent-glow: rgba(138, 131, 255, 0.28);

  --bg: #0a0e1f;
  --bg-alt: #141931;
  --bg-pane: #141931;
  --bg-sidebar: #0d1226;
  --bg-iconbar: #080b1a;
  --bg-hover: rgba(144, 153, 194, 0.08);
  --bg-selected: rgba(138, 131, 255, 0.16);
  --unread-bg: rgba(138, 131, 255, 0.08);

  --border: #272e52;
  --border-strong: #3a4272;

  --text: #eef0fb;
  --text-muted: #9099c2;
  --text-faint: #5d6590;
  --text-quart: #3a4272;

  --summary-bg: rgba(138, 131, 255, 0.12);
  --summary-border: #9c96ff;

  --danger: #ff5c7a;
  --success: #3fd68d;
  --warning: #ffb020;
  --violet: #948dff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; font-family: 'Inter Tight', -apple-system, system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; letter-spacing: -0.005em; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
/* Корневой anti-pan для мобилки: html и body НЕ скроллятся
   горизонтально никогда, даже если внутри что-то выскочит за край.
   Без этого iOS Safari дает прокрутить весь документ влево-вправо
   когда любая sticky-колонка или overflow-auto'нутый блок чуть
   шире 100vw — что юзер и видит как «сайт гуляет под пальцем». */
html, body {
  overflow-x: hidden;
  overscroll-behavior-x: none;
  max-width: 100vw;
}
@media (max-width: 900px) {
  html, body { width: 100vw; }
}
.hidden { display: none !important; }
.error { color: var(--danger); font-size: 12px; margin-top: 8px; }

/* login */
#login-screen { display: flex; align-items: center; justify-content: center; height: 100vh; background: var(--bg-alt); }
.login-box { background: var(--bg); padding: 40px; border-radius: 20px; border: 1px solid var(--border); width: 360px; position: relative; }
.login-box h1 { margin: 0 0 24px; font-size: 1.5rem; font-weight: 800; letter-spacing: -0.5px; }
.login-box input { width: 100%; padding: 12px 14px; margin-bottom: 12px; border: 1.5px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); font-family: inherit; font-size: 0.9rem; transition: border-color .2s; }
.login-box input:focus { outline: none; border-color: var(--accent); }
.login-box button[type="submit"] { width: 100%; padding: 12px; background: var(--accent); color: white; border: none; border-radius: 10px; cursor: pointer; font-weight: 700; font-family: inherit; font-size: 0.9rem; letter-spacing: 0.2px; }
.login-box button[type="submit"]:hover { background: var(--accent-hover); }
.theme-toggle { position: absolute; top: 12px; right: 12px; background: none; border: none; font-size: 18px; cursor: pointer; }

/* app layout */
#app { display: grid; grid-template-columns: 56px var(--sidebar-w, 220px) 4px 380px 4px 1fr; height: 100vh; }
.resizer { background: var(--border); cursor: col-resize; transition: background 0.15s; }
.resizer:hover, .resizer.dragging { background: var(--accent); }
@media (max-width: 900px) { .resizer { display: none; } }

/* icon bar */
.icon-bar { background: var(--bg-iconbar); border-right: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; padding: 10px 0 14px; gap: 2px; overflow-y: auto; }
.icon-bar .ib-item { width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; border-radius: 8px; cursor: pointer; color: var(--text-muted); transition: background 0.12s, color 0.12s; position: relative; }
.icon-bar .ib-item:hover { background: var(--bg-hover); color: var(--text); }
.icon-bar .ib-item.active { background: var(--accent-soft); color: var(--accent); }
.icon-bar .ib-item.active::before { content: ""; position: absolute; left: -8px; top: 6px; bottom: 6px; width: 2.5px; border-radius: 0 3px 3px 0; background: var(--accent); }
.icon-bar .ib-item .ib-badge { position: absolute; top: 0; right: 0; background: var(--danger); color: white; font-size: 9px; min-width: 15px; height: 15px; padding: 0 3px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-weight: 700; border: 1.5px solid var(--bg-iconbar); }
.icon-bar .ib-logo { font-size: 18px; font-weight: 800; color: var(--accent); margin-bottom: 10px; cursor: default; letter-spacing: -0.02em; }
@media (max-width: 900px) { .icon-bar { display: none; } }

/* sidebar — toggle with arrow button */
.sidebar {
  background: var(--bg-sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden;
  padding: 12px; z-index: 20; transition: width 0.2s ease, padding 0.2s ease;
  position: relative;
}
.sidebar.collapsed { width: 56px; min-width: 56px; padding: 8px; }
.sidebar.collapsed .brand, .sidebar.collapsed .compose-btn, .sidebar.collapsed .folder-title,
.sidebar.collapsed .user-box, .sidebar.collapsed .sidebar-label, .sidebar.collapsed .folder-item .count,
.sidebar.collapsed #mailboxes-group, .sidebar.collapsed #sheets-group, .sidebar.collapsed .folder-label { display: none; }
.sidebar .folder-item { white-space: nowrap; overflow: hidden; border-radius: 8px; padding: 8px 10px; }
.sidebar .folder-item svg { flex-shrink: 0; }
.sidebar-toggle-btn { background: none; border: none; width: 100%; padding: 8px; cursor: pointer; color: var(--text-muted); display: flex; align-items: center; justify-content: center; transition: color 0.15s; flex-shrink: 0; }
.sidebar-toggle-btn:hover { color: var(--accent); }
.sidebar-toggle-btn svg { transition: transform 0.2s; }
.sidebar.collapsed .sidebar-toggle-btn svg { transform: rotate(180deg); }
.brand { font-size: 18px; font-weight: 700; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center; }
.sidebar-close { display: none; background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text); padding: 4px 8px; }
@media (max-width: 900px) { .sidebar-close { display: block; } .sidebar { width: 280px; min-width: 280px; padding: 16px; } .sidebar .brand, .sidebar .compose-btn, .sidebar .folder-title, .sidebar .user-box, .sidebar .link-btn, .sidebar .folder-item .count { opacity: 1; } }
.badge { font-size: 11px; font-weight: 500; color: var(--text-muted); }
mark { background: yellow; color: inherit; padding: 0 2px; }
.compose-btn { width: 100%; padding: 9px 14px; background: var(--accent); color: white; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; font-family: inherit; font-size: 0.87rem; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; box-shadow: 0 1px 0 rgba(99,102,241,0.25); transition: background .12s, box-shadow .12s; }
.compose-btn:hover { background: var(--accent-hover); box-shadow: 0 4px 12px rgba(99,102,241,0.35); }
.compose-btn-mini { display: none; background: var(--accent); color: white; border: none; border-radius: 50%; width: 38px; height: 38px; cursor: pointer; align-items: center; justify-content: center; margin: 0 auto; }
.compose-btn-mini:hover { background: var(--accent-hover); }
.sidebar.collapsed .compose-btn { display: none; }
.sidebar.collapsed .compose-btn-mini { display: flex; }
.sidebar.collapsed .compose-wrap { display: flex; justify-content: center; }
.folders { flex: 1; }
.folder-group { margin-bottom: 16px; }
.folder-title { font-size: 11px; text-transform: uppercase; color: var(--text-muted); margin-bottom: 6px; letter-spacing: 0.5px; }
.folder-item { padding: 7px 10px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); transition: background .12s, color .12s; }
.folder-item:hover { background: var(--bg-hover); color: var(--text); }
.folder-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.folder-item .count { color: var(--text-faint); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.folder-item.active .count { color: var(--accent); opacity: 0.85; }
.user-box { padding-top: 12px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); display: flex; flex-direction: column; gap: 6px; }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; padding: 2px 0; text-align: left; font-size: 12px; }

/* list pane */
.list-pane { border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.toolbar { padding: 12px; border-bottom: 1px solid var(--border); display: flex; gap: 8px; }
.toolbar input, .toolbar select, .toolbar button { padding: 8px 12px; border: 1.5px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); font-family: inherit; font-size: 0.85rem; transition: border-color .2s; }
.toolbar input:focus, .toolbar select:focus { outline: none; border-color: var(--accent); }
.toolbar input { flex: 1; }
.messages-list { flex: 1; overflow-y: auto; }
/* Calm list item: dense, unread-dot left of name, 2-line preview, mailbox chip */
.list-pane { background: var(--bg-pane); }
.messages-list { background: var(--bg-pane); }
.msg-item {
  padding: 10px 14px 10px 12px;
  border-bottom: 1px solid var(--border);
  border-left: 2px solid transparent;
  cursor: pointer;
  display: flex; gap: 10px;
  transition: background .12s, border-color .12s;
  position: relative;
}
.msg-item:hover { background: var(--bg-hover); }
.msg-item.selected { background: var(--bg-selected); border-left-color: var(--accent); }
.msg-item.unread { background: var(--unread-bg); }
.msg-item.unread .msg-from { color: var(--text); font-weight: 700; }
.msg-item.unread .msg-subject { color: var(--text); font-weight: 600; }
.msg-avatar { display: none; }
.msg-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.msg-head { display: flex; align-items: center; gap: 8px; }
.msg-from { font-size: 13px; font-weight: 500; color: var(--text); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: -0.1px; }
.msg-date { font-size: 11px; color: var(--text-faint); white-space: nowrap; flex-shrink: 0; }
.msg-subject { font-size: 12.5px; font-weight: 500; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-snippet { font-size: 12px; color: var(--text-faint); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.msg-icons { font-size: 11px; color: var(--text-faint); margin-top: 4px; }
.msg-check { margin-top: 4px; }
.msg-unread-dot { margin-right: -2px; }
.msg-unread-dot:hover { transform: scale(1.3); }
.msg-star:hover { transform: scale(1.2); }
.msg-star, .msg-unread-dot { align-self: center; }
.list-group {
  padding: 10px 14px 6px;
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-faint);
  background: var(--bg-pane);
  position: sticky; top: 0; z-index: 1;
  border-bottom: 1px solid var(--border);
}
.prio { display: inline-block; width: 14px; height: 14px; line-height: 14px; text-align: center; border-radius: 50%; font-size: 10px; font-weight: 700; margin-right: 6px; }
.prio-high { background: var(--danger); color: white; }
.prio-spam { background: var(--text-muted); color: white; }
.bulk-bar { display: flex; gap: 8px; align-items: center; padding: 10px 14px; background: var(--bg-alt); border-bottom: 1px solid var(--border); font-size: 13px; }
.bulk-bar button { padding: 6px 12px; border: 1.5px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); cursor: pointer; font-family: inherit; font-size: 0.8rem; font-weight: 600; transition: all .15s; }
.bulk-bar button:hover { border-color: var(--accent); color: var(--accent); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 12px 20px; border-radius: 14px; font-size: 13px; font-weight: 600; z-index: 200; display: flex; gap: 12px; align-items: center; box-shadow: 0 8px 32px oklch(0 0 0 / 0.25); animation: toastIn .3s ease; }
@keyframes toastIn { from { opacity:0; transform:translateX(-50%) translateY(20px); } to { opacity:1; transform:translateX(-50%) translateY(0); } }
.toast button { background: none; border: 1px solid currentColor; color: inherit; padding: 4px 10px; border-radius: 4px; cursor: pointer; }
.toast-wide { display: block; text-align: left; font-weight: 400; padding: 16px 20px; max-width: calc(100vw - 32px); }
.toast-wide ul { list-style: disc; }

/* preview */
.preview-pane { overflow-y: auto; overflow-x: hidden; padding: 24px 32px; min-width: 0; background: var(--bg-pane); }
#tasks-view, #finance-view, #team-view, #admin-view { overflow: auto; word-break: break-word; grid-column: 2 / -1; height: 100vh; }
.preview-pane .empty { color: var(--text-muted); text-align: center; margin-top: 80px; }
.preview-header { padding-bottom: 16px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.preview-header h2 { margin: 0 0 10px; font-size: 20px; font-weight: 700; letter-spacing: -0.3px; color: var(--text); line-height: 1.3; }
.preview-meta { font-size: 13px; color: var(--text-muted); line-height: 1.6; }
.preview-actions { display: flex; gap: 6px; margin: 14px 0; flex-wrap: wrap; }
.preview-actions button { padding: 6px 12px; background: var(--bg-alt); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; color: var(--text); font-size: 12px; white-space: nowrap; }
.preview-actions button:hover { background: var(--bg-hover); }
.mobile-back { display: none; }
@media (max-width: 900px) { .mobile-back { display: inline-block; } }
.ai-block { background: var(--summary-bg); padding: 12px 14px; margin: 14px 0; border-radius: 10px; font-size: 13px; }
.ai-block .ai-label { font-size: 11px; text-transform: uppercase; color: var(--summary-border); font-weight: 600; margin-bottom: 4px; }
.preview-body { font-size: 14px; line-height: 1.6; white-space: pre-line; word-wrap: break-word; overflow-wrap: break-word; max-width: 100%; }
.attachments { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.attachment { display: inline-block; padding: 6px 10px; background: var(--bg-alt); border: 1px solid var(--border); border-radius: 5px; margin: 4px 6px 4px 0; text-decoration: none; color: var(--text); font-size: 12px; }
.attachment:hover { background: var(--bg-hover); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-box { background: var(--bg); border-radius: 10px; width: 640px; max-width: 90vw; max-height: 90vh; overflow-y: auto; }
.modal-box.wide { width: 1120px; max-width: 96vw; max-height: 94vh; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; }
.modal-header button { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text); }

/* Task detail: two-column layout (main text + comments | side meta).
   When the modal is .wide we want it to fill ~94vh so the description has
   real estate. The main column is a vertical flex with description (flex)
   and comments (fixed-flex-basis), separated by a draggable resizer. */
#task-form-modal .modal-box.wide { display: flex; flex-direction: column; height: 94vh; max-height: 94vh; overflow: hidden; }
#task-form-modal .modal-box.wide form { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }
#task-form-modal .modal-box.wide .task-detail-layout { flex: 1; min-height: 0; }
.task-detail-layout { display: grid; grid-template-columns: 1fr 220px; gap: 0; }
.modal-box:not(.wide) .task-detail-layout { grid-template-columns: 1fr; }
.modal-box:not(.wide) .task-detail-aside { background: transparent; border-left: none; padding: 4px 20px 12px; }
.modal-box:not(.wide) .task-detail-main { padding: 18px 20px 4px; }
.task-detail-main { padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; min-width: 0; min-height: 0; }
.task-detail-aside { padding: 14px 12px; background: var(--bg-alt); border-left: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
#task-form-modal .modal-box.wide #task-desc-label { flex: 1 1 auto; min-height: 80px; display: flex; flex-direction: column; gap: 4px; }
#task-form-modal .modal-box.wide #task-desc-input { flex: 1; min-height: 0; resize: none; }
#task-vsplit { height: 6px; cursor: row-resize; background: var(--border); border-radius: 3px; flex-shrink: 0; transition: background 0.1s; }
#task-vsplit:hover, #task-vsplit.dragging { background: var(--accent); }
#task-form-modal .modal-box.wide #task-comments-row { flex: 0 0 220px; min-height: 80px; overflow: hidden; }
#task-form-modal .modal-box.wide #task-comments-list { flex: 1; max-height: none !important; }
.task-detail-aside label { font-size: 10px; color: var(--text-muted); display: flex; flex-direction: column; gap: 3px; line-height: 1.2; }
.task-detail-aside select, .task-detail-aside input { width: 100%; padding: 5px 7px; border: 1px solid var(--border); border-radius: 5px; background: var(--bg); color: var(--text); font-size: 12px; }
.task-title-inline { font-size: 22px; font-weight: 600; line-height: 1.25; padding: 6px 0; border: none; background: transparent; color: var(--text); width: 100%; }
.task-title-inline:focus { outline: none; border-bottom: 1px solid var(--accent); }
.task-desc-inline { min-height: 180px; font-size: 14px; line-height: 1.5; padding: 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-alt); color: var(--text); font-family: inherit; resize: vertical; }
.task-review-banner { background: rgba(139,92,246,0.12); border: 1px solid rgba(139,92,246,0.4); border-radius: 8px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.task-review-banner h4 { margin: 0; font-size: 14px; color: var(--text); }
.task-review-banner .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.task-review-banner button { padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; font-size: 12px; background: var(--bg); color: var(--text); }
.task-review-banner button.primary { background: #10b981; color: white; border-color: #10b981; }
.task-review-banner button.secondary { background: #f59e0b; color: white; border-color: #f59e0b; }
.coassignee-pills { display: flex; flex-wrap: wrap; gap: 4px; }
.coassignee-pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; font-size: 11px; }
.coassignee-pill button { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 0; font-size: 12px; line-height: 1; }
@media (max-width: 900px) {
  .modal-box.wide { width: 100vw; max-width: 100vw; max-height: 100vh; border-radius: 0; }
  .task-detail-layout { grid-template-columns: 1fr; }
  .task-detail-aside { border-left: none; border-top: 1px solid var(--border); }
}

/* ----- iOS-style "New Task" sheet -----
   Activated by .task-create-sheet on the modal element. Reuses the existing
   form markup, restyled into a calm grouped-table layout (Reminders/Things).
   Edit-mode untouched. */
.task-create-sheet {
  background: oklch(0 0 0 / 0.32) !important;
  backdrop-filter: blur(8px) saturate(120%);
  -webkit-backdrop-filter: blur(8px) saturate(120%);
  align-items: center !important;
  padding: 28px 16px !important;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
}
.task-create-sheet .modal-box {
  width: 600px;
  height: calc(100vh - 56px);
  max-width: calc(100vw - 32px) !important;
  max-height: calc(100vh - 56px) !important;
  min-width: 480px;
  min-height: 480px;
  border-radius: 22px !important;
  background: var(--bg-alt) !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  box-shadow: 0 24px 60px oklch(0 0 0 / 0.32), 0 1px 0 oklch(1 0 0 / 0.04) inset;
  animation: taskSheetIn 320ms cubic-bezier(0.22, 1, 0.36, 1);
  letter-spacing: -0.01em;
  position: relative;
}
/* Visible custom resize handle in the bottom-right corner.
   Native CSS resize:both was unreliable here because of the modal's flex
   centering parent — handle never appeared in the right place and the
   browser's tiny default striped corner was easy to miss. */
.task-create-sheet .ios-sheet-resize-handle {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  color: color-mix(in oklch, var(--text-muted) 90%, transparent);
  user-select: none;
}
.task-create-sheet .ios-sheet-resize-handle::before {
  content: "";
  width: 14px;
  height: 14px;
  background:
    linear-gradient(135deg, transparent 50%, currentColor 50%, currentColor 56%, transparent 56%),
    linear-gradient(135deg, transparent 60%, currentColor 60%, currentColor 66%, transparent 66%),
    linear-gradient(135deg, transparent 70%, currentColor 70%, currentColor 76%, transparent 76%);
  background-size: 100% 100%;
  border-bottom-right-radius: 8px;
}
.task-create-sheet .ios-sheet-resize-handle:hover {
  color: var(--accent);
}
@keyframes taskSheetIn {
  from { transform: translateY(28px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Header: Cancel | Title | Save  +  Minimize handle on the far left.
   Native iOS pattern. The original X button is repurposed as the
   "Отмена" text on the left in JS; a Save button is added on the right. */
.task-create-sheet .modal-header {
  display: grid !important;
  grid-template-columns: auto 1fr auto !important;
  gap: 12px;
  padding: 12px 18px !important;
  border-bottom: 1px solid color-mix(in oklch, var(--border) 70%, transparent);
  background: var(--bg-alt);
  align-items: center;
}
.task-create-sheet .modal-header h3 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.2px;
  text-align: center;
  margin: 0;
  grid-column: 2;
  justify-self: center;
}
.task-create-sheet .ios-sheet-cancel {
  background: transparent;
  border: none;
  padding: 0;
  height: 32px;
  font-size: 15px;
  font-weight: 400;
  color: var(--accent);
  cursor: pointer;
  letter-spacing: -0.1px;
  grid-column: 1;
  justify-self: start;
}
.task-create-sheet .ios-sheet-cancel:hover { opacity: 0.7; }
.task-create-sheet .ios-sheet-save {
  background: transparent;
  border: none;
  padding: 0;
  height: 32px;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  letter-spacing: -0.1px;
  grid-column: 3;
  justify-self: end;
}
.task-create-sheet .ios-sheet-save:hover { opacity: 0.7; }
.task-create-sheet .ios-sheet-save:disabled {
  color: color-mix(in oklch, var(--accent) 35%, transparent);
  cursor: not-allowed;
}
/* Hide the original X button entirely in create mode — its job
   (close-on-click) is taken over by the styled "Отмена" text. */
.task-create-sheet .modal-header > button:not(.ios-sheet-cancel):not(.ios-sheet-save):not(.ios-sheet-minimize) {
  display: none !important;
}
.task-create-sheet .ios-sheet-minimize {
  background: transparent;
  border: none;
  padding: 0;
  width: 28px;
  height: 28px;
  font-size: 18px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  margin-right: 6px;
  border-radius: 6px;
}
.task-create-sheet .ios-sheet-minimize:hover { background: color-mix(in oklch, var(--text) 8%, transparent); }

/* Minimized state — collapses to a small bar at the bottom-right */
#task-form-modal.task-sheet-minimized {
  background: transparent !important;
  pointer-events: none;
  align-items: flex-end !important;
  justify-content: flex-end !important;
  padding: 16px !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
#task-form-modal.task-sheet-minimized .modal-box {
  pointer-events: auto;
  width: 240px !important;
  height: 44px !important;
  min-width: 0 !important;
  min-height: 0 !important;
  resize: none;
  border-radius: 22px !important;
  cursor: pointer;
  box-shadow: 0 6px 20px oklch(0 0 0 / 0.18) !important;
}
#task-form-modal.task-sheet-minimized .modal-box > *:not(.ios-sheet-minimized-bar) { display: none !important; }
.ios-sheet-minimized-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: 100%;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

/* Form layout */
.task-create-sheet form#task-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.task-create-sheet .task-detail-layout {
  display: block !important;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 14px 18px !important;
}
.task-create-sheet .task-detail-main,
.task-create-sheet .task-detail-aside {
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  gap: 0 !important;
  overflow: visible;
}

/* Hide irrelevant elements. NOTE: #task-attach-row was here but is now
   intentionally allowed — create mode buffers files in memory and
   uploads them after the task is saved. See renderTaskAttachments(null,)
   and saveTask() in app.js. */
.task-create-sheet #task-review-banner,
.task-create-sheet #task-vsplit,
.task-create-sheet #task-comments-row,
.task-create-sheet #task-tags-row,
.task-create-sheet #task-tracking-actions,
.task-create-sheet #task-status-label,
.task-create-sheet #task-priority-select { display: none !important; }

/* Files row in the create sheet — match the row layout of other aside
   items (Label / Project / Repetition) so the upload picker reads as
   another grouped-table row, not as a stray block. */
.task-create-sheet #task-attach-row {
  display: flex !important;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.task-create-sheet #task-attach-row > span:first-child {
  font-size: 14px;
  color: var(--text);
  min-width: 80px;
}
.task-create-sheet #task-attach-row #task-attach-list {
  flex: 1;
  flex-wrap: wrap;
}
.task-create-sheet #task-attach-row input[type="file"] {
  font-size: 13px;
}

/* Footer with delete | actions — replace with an inline helper line under fields */
.task-create-sheet form#task-form > div:last-of-type:not(.task-detail-layout) { display: none !important; }

/* Title field — inline display-style input on its own card */
.task-create-sheet #task-title-label {
  display: block;
  font-size: 0;
  margin: 0 0 6px;
}
.task-create-sheet #task-title-input {
  width: 100%;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
  border: none;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
}
.task-create-sheet #task-title-input::placeholder {
  color: color-mix(in oklch, var(--text-muted) 80%, transparent);
  font-weight: 500;
}
.task-create-sheet #task-title-input:focus {
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in oklch, var(--accent) 38%, transparent);
}

/* Description — soft card, autogrows, no border */
.task-create-sheet #task-desc-label {
  display: block;
  font-size: 0;
  margin: 0 0 12px;
}
.task-create-sheet #task-desc-input {
  width: 100%;
  font-size: 14px;
  line-height: 1.45;
  border: none;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  min-height: 80px;
  resize: vertical;
  font-family: inherit;
}
.task-create-sheet #task-desc-input:focus {
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in oklch, var(--accent) 38%, transparent);
}

/* Aside fields rendered as a single grouped iOS Settings-style table.
   One rounded container with hairline separators between rows — much
   denser than the previous "card per field" layout. */
.task-create-sheet .task-detail-aside {
  display: flex !important;
  flex-direction: column !important;
  gap: 0 !important;
  background: var(--bg) !important;
  border-radius: 14px !important;
  padding: 0 !important;
  overflow: hidden;
}
.task-create-sheet .task-detail-aside > label {
  display: flex !important;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: transparent;
  border-radius: 0;
  padding: 8px 14px;
  margin: 0;
  font-size: 13px;
  color: var(--text);
  min-height: 36px;
  letter-spacing: -0.1px;
}
.task-create-sheet .task-detail-aside > label + label {
  border-top: 1px solid color-mix(in oklch, var(--border) 55%, transparent);
}
.task-create-sheet .task-detail-aside > label > select,
.task-create-sheet .task-detail-aside > label > input:not([type="hidden"]):not([type="number"]) {
  flex: 0 1 60%;
  border: none;
  background: transparent;
  text-align: right;
  font-size: 13px;
  color: var(--text);
  padding: 0 !important;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  height: 22px;
  line-height: 22px;
}
.task-create-sheet .task-detail-aside > label > select:focus,
.task-create-sheet .task-detail-aside > label > input:focus {
  outline: none;
}
.task-create-sheet .task-detail-aside > label > input[type="datetime-local"] {
  color: var(--text);
  font-feature-settings: "tnum" 1;
}

/* Priority row: full-width segmented control under the "Приоритет" label */
.task-create-sheet #task-priority-label {
  flex-direction: column !important;
  align-items: stretch !important;
  gap: 6px !important;
  padding: 8px 14px !important;
}
.task-create-sheet .ios-segmented {
  display: flex;
  background: color-mix(in oklch, var(--text) 8%, transparent);
  border-radius: 7px;
  padding: 2px;
  gap: 2px;
}
.task-create-sheet .ios-segmented button {
  flex: 1;
  padding: 5px 8px;
  border: none;
  background: transparent;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  letter-spacing: -0.1px;
  transition: background 140ms ease, transform 100ms ease;
}
.task-create-sheet .ios-segmented button.active {
  background: var(--bg);
  font-weight: 600;
  box-shadow: 0 1px 2px oklch(0 0 0 / 0.08), 0 0 0 0.5px oklch(0 0 0 / 0.04);
}
.task-create-sheet .ios-segmented button:active { transform: scale(0.97); }
.task-create-sheet #task-priority-segmented[data-prio="urgent"] button.active { color: oklch(0.55 0.21 25); }
.task-create-sheet #task-priority-segmented[data-prio="high"] button.active { color: oklch(0.62 0.16 65); }

/* Соисполнители row: same shape as the Исполнитель row above —
   label on the left, dropdown on the right. The pills container only
   takes a row when it has children. */
.task-create-sheet .task-detail-aside > label:has(#task-coassignee-editor) {
  flex-wrap: wrap;
}
.task-create-sheet #task-coassignee-editor {
  display: contents;
}
.task-create-sheet #task-coassignee-add {
  flex: 0 1 60%;
  text-align: right !important;
  padding: 0 !important;
  border: none;
  background: transparent !important;
  font-size: 13px;
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
  height: 22px;
}
.task-create-sheet #task-coassignee-pills {
  flex: 1 0 100%;
  margin-top: 6px;
}
.task-create-sheet #task-coassignee-pills:empty { display: none; }

/* Recurrence row: select on the right + tiny interval pill, single line */
.task-create-sheet .task-detail-aside > label:has(#task-recurrence-rule) {
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
}
.task-create-sheet #task-recurrence-rule {
  flex: 0 1 auto;
}
.task-create-sheet #task-recurrence-interval {
  width: 40px;
  padding: 2px 6px !important;
  text-align: right;
  background: color-mix(in oklch, var(--text) 6%, transparent);
  border: none;
  border-radius: 5px;
  font-size: 12px;
  color: var(--text);
  height: 22px;
}
.task-create-sheet .task-detail-aside > label:has(#task-recurrence-rule) > span {
  display: none !important;
}

/* iOS-style sheet footer with primary save action */
.task-create-sheet-footer {
  padding: 14px 18px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg-alt);
  border-top: 1px solid color-mix(in oklch, var(--border) 70%, transparent);
  display: flex;
  gap: 10px;
}
.task-create-sheet-footer button {
  flex: 1;
  height: 46px;
  border: none;
  border-radius: 13px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.2px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 100ms ease, opacity 140ms ease;
}
.task-create-sheet-footer button:active { transform: scale(0.985); }
.task-create-sheet-footer .ios-btn-primary {
  background: var(--accent);
  color: oklch(0.99 0 0);
  box-shadow: 0 1px 2px color-mix(in oklch, var(--accent) 50%, transparent);
}
.task-create-sheet-footer .ios-btn-primary:disabled {
  background: color-mix(in oklch, var(--accent) 35%, var(--bg-alt));
  cursor: not-allowed;
}

/* Mobile: full-screen sheet that anchors to the bottom of the viewport */
@media (max-width: 720px) {
  .task-create-sheet { padding: 0 !important; align-items: flex-end !important; }
  .task-create-sheet .modal-box {
    width: 100% !important;
    max-height: 92vh !important;
    border-radius: 22px 22px 0 0 !important;
    animation: taskSheetInMobile 320ms cubic-bezier(0.22, 1, 0.36, 1);
  }
  @keyframes taskSheetInMobile {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
}

/* Hide segmented control in edit mode (only the original select is shown) */
#task-form-modal:not(.task-create-sheet) #task-priority-segmented { display: none; }

/* Inline header actions sitting on the left of the title in edit mode.
   Two flavors share a base style: yellow for creator's "Завершить",
   green for the assignee's "На проверку". */
#task-form-modal .modal-header .task-header-action {
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border: none;
  border-radius: 8px;
  background: #f59e0b;
  color: white;
  cursor: pointer;
  margin-right: 12px;
  letter-spacing: -0.1px;
  box-shadow: 0 1px 2px oklch(0 0 0 / 0.08);
  transition: background 140ms ease, transform 100ms ease;
}
#task-form-modal .modal-header .task-header-action:hover { background: #d97706; }
#task-form-modal .modal-header .task-header-action:active { transform: scale(0.97); }
#task-form-modal .modal-header .task-header-action.task-header-action-green {
  background: #10b981;
}
#task-form-modal .modal-header .task-header-action.task-header-action-green:hover {
  background: #059669;
}

/* Compose modal — Mail.ru style */
.compose-box { width: min(90vw, 900px) !important; max-width: 900px !important; height: 85vh; max-height: 85vh !important; overflow: hidden !important; display: flex; flex-direction: column; border-radius: 12px; box-shadow: 0 8px 40px rgba(0,0,0,0.25); }
.compose-header { padding: 10px 16px !important; background: var(--bg-alt); flex-shrink: 0; }
.compose-header h3 { font-size: 15px; font-weight: 600; }
.compose-header-btns { display: flex; gap: 4px; }
.compose-header-btns button { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 6px; font-size: 16px; transition: background 0.15s; }
.compose-header-btns button:hover { background: var(--border); }

#compose-form { padding: 0; display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }
.compose-field-row { display: flex; align-items: center; gap: 8px; padding: 6px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.compose-field-label { font-size: 13px; color: var(--text-muted); min-width: 50px; flex-shrink: 0; }
.compose-field-row input, .compose-field-row select { flex: 1; border: none; outline: none; background: transparent; font-family: inherit; font-size: 14px; color: var(--text); padding: 6px 4px; min-width: 0; }
.compose-field-row select { max-width: 220px; cursor: pointer; }
.compose-field-row input:focus { background: var(--bg-alt); border-radius: 4px; }

.compose-attach-bar { display: flex; align-items: center; gap: 8px; padding: 6px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap; }
.compose-attach-btn { display: inline-flex; align-items: center; gap: 4px; padding: 5px 12px; background: var(--bg-alt); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text); transition: background 0.15s; }
.compose-attach-btn:hover { background: var(--border); }
.compose-attach-bar select { border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; font-size: 13px; background: var(--bg); color: var(--text); cursor: pointer; }
.compose-tpl-save { border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; font-size: 12px; background: var(--bg); color: var(--text-muted); cursor: pointer; }
.compose-tpl-save:hover { background: var(--bg-alt); }
.compose-file-list { display: flex; gap: 6px; flex-wrap: wrap; margin-left: 8px; font-size: 12px; color: var(--text-muted); }

#compose-form textarea { flex: 1; border: none; outline: none; resize: none; padding: 12px 16px; font-family: inherit; font-size: 14px; line-height: 1.6; background: var(--bg); color: var(--text); min-height: 0; }

.compose-bottom-bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-top: 1px solid var(--border); background: var(--bg-alt); flex-shrink: 0; }
.compose-bottom-left { display: flex; gap: 8px; align-items: center; }
.compose-bottom-right { display: flex; gap: 8px; align-items: center; }
.compose-btn-send { padding: 8px 24px; border-radius: 8px; border: none; background: var(--accent); color: white; font-weight: 600; font-size: 14px; cursor: pointer; transition: background 0.15s; }
.compose-btn-send:hover { background: var(--accent-hover); }
.compose-btn-secondary { padding: 7px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 13px; cursor: pointer; transition: background 0.15s; }
.compose-btn-secondary:hover { background: var(--bg-alt); }
.compose-schedule-label { display: inline-flex; align-items: center; gap: 6px; }
.compose-schedule-label input[type="datetime-local"] { border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; font-size: 12px; background: var(--bg); color: var(--text); }

/* Tracking toggle buttons */
.track-day-btn { padding: 4px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 12px; cursor: pointer; transition: all 0.15s; }
.track-day-btn:hover { background: var(--bg-alt); }
.track-day-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
.tracking-action-btn { padding: 6px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 12px; cursor: pointer; transition: all 0.15s; white-space: nowrap; }
.tracking-action-btn:hover { background: var(--bg-alt); border-color: var(--accent); }

/* Compose minimized bar */
.compose-minimized { position: fixed; bottom: 0; right: 20px; width: 300px; height: 42px; background: var(--accent); color: white; border-radius: 10px 10px 0 0; display: flex; align-items: center; padding: 0 12px; gap: 8px; cursor: pointer; z-index: 200; box-shadow: 0 -2px 12px rgba(0,0,0,0.15); }
.compose-minimized span { flex: 1; font-size: 14px; font-weight: 600; }
.compose-minimized button { background: none; border: none; color: white; font-size: 16px; cursor: pointer; padding: 4px 6px; border-radius: 4px; }
.compose-minimized button:hover { background: rgba(255,255,255,0.2); }

@media (max-width: 600px) {
  .compose-box { width: 100vw !important; height: 100vh !important; max-height: 100vh !important; border-radius: 0; }
  .compose-minimized { right: 0; width: 100vw; border-radius: 0; }
}

/* admin */
.admin-tabs { display: flex; flex-wrap: wrap; gap: 2px 4px; border-bottom: 1px solid var(--border); padding: 0 16px; }
.admin-tabs .tab { padding: 8px 12px; background: none; border: none; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; font-size: 13px; white-space: nowrap; }
.admin-tabs .tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
#admin-content { padding: 16px 20px; max-height: 65vh; overflow-y: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.admin-table th { color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; }
.admin-table button { padding: 4px 8px; font-size: 12px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg-alt); cursor: pointer; color: var(--text); }
.admin-table button.danger { color: var(--danger); border-color: var(--danger); }
.admin-form { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: end; }
.admin-form input, .admin-form select { padding: 8px 12px; border: none; border-bottom: 2px solid var(--border); border-radius: 0; background: transparent; color: var(--text); font-size: 14px; transition: border-color 0.2s; outline: none; }
.admin-form input:focus, .admin-form select:focus { border-bottom-color: var(--accent); }
.admin-form button { padding: 8px 16px; background: var(--accent); color: white; border: none; border-radius: 8px; cursor: pointer; font-weight: 500; }

/* Settings cards */
.settings-card { position: relative; background: var(--bg); border-radius: 16px; padding: 20px; margin-bottom: 16px; border: 1px solid var(--border); }

/* Info/help button placed in the top-right of any card */
.help-btn {
  position: absolute; top: 14px; right: 14px;
  width: 26px; height: 26px;
  border: none; background: var(--bg-hover);
  color: var(--text-muted);
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px; font-weight: 600; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.15s ease;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, sans-serif;
}
.help-btn:hover { background: var(--accent); color: #fff; transform: scale(1.08); }
.help-btn svg { width: 14px; height: 14px; }

/* Help modal */
.help-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999; padding: 20px;
  backdrop-filter: blur(4px);
  animation: help-fade-in 0.15s ease;
}
@keyframes help-fade-in { from { opacity: 0; } to { opacity: 1; } }
.help-modal-box {
  background: var(--bg-alt);
  border-radius: 16px;
  max-width: 560px; width: 100%;
  max-height: 80vh; overflow-y: auto;
  padding: 24px 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  border: 1px solid var(--border);
  animation: help-slide-in 0.2s cubic-bezier(.3,0,.2,1);
}
@keyframes help-slide-in { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.help-modal-title { font-size: 17px; font-weight: 600; margin: 0 0 4px; display: flex; align-items: center; gap: 8px; }
.help-modal-sub   { font-size: 12px; color: var(--text-muted); margin: 0 0 16px; }
.help-modal-box h4 { font-size: 13px; font-weight: 600; margin: 14px 0 6px; color: var(--text); }
.help-modal-box p  { font-size: 13px; line-height: 1.55; color: var(--text); margin: 6px 0; }
.help-modal-box ul { font-size: 13px; line-height: 1.55; color: var(--text); margin: 6px 0; padding-left: 20px; }
.help-modal-box li { margin: 4px 0; }
.help-modal-box code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; padding: 1px 6px; background: var(--bg-hover); border-radius: 4px; }
.help-modal-close {
  margin-top: 16px; width: 100%;
  padding: 10px; border: none; border-radius: 10px;
  background: var(--accent); color: #fff;
  font-size: 13px; font-weight: 500; cursor: pointer;
}
.help-modal-close:hover { background: var(--accent-hover); }
.settings-card legend, .settings-card-title { font-size: 14px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.settings-card label { font-size: 13px; color: var(--text); display: block; margin-bottom: 8px; }
.settings-card p { font-size: 11px; color: var(--text-muted); margin: 8px 0 0; }
.settings-card input[type="text"], .settings-card input[type="number"], .settings-card input[type="password"], .settings-card select { width: 100%; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 10px; background: var(--bg-alt); color: var(--text); font-size: 13px; font-family: inherit; box-sizing: border-box; outline: none; transition: border-color 0.2s; }
.settings-card input:focus, .settings-card select:focus { border-color: var(--accent); }

/* Toggle switch */
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-switch .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: #ccc; border-radius: 24px; transition: 0.3s; }
.toggle-switch .slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: 0.3s; }
.toggle-switch input:checked + .slider { background: var(--accent); }
.toggle-switch input:checked + .slider:before { transform: translateX(20px); }

.burger, .tabbar { display: none; }

/* mobile */
@media (max-width: 900px) {
  #app { display: flex; flex-direction: column; grid-template-columns: none; position: relative; }
  .burger {
    display: block; position: fixed; top: 10px; left: 10px; z-index: 50;
    width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--bg); color: var(--text); font-size: 20px; cursor: pointer;
  }
  .icon-bar { display: none; }
  .resizer { display: none; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 280px;
    transform: translateX(-100%); transition: transform 0.2s; z-index: 60;
    box-shadow: 4px 0 20px rgba(0,0,0,0.2);
  }
  #app.show-sidebar .sidebar { transform: translateX(0); }
  #sidebar-overlay { position: fixed; top: 0; right: 0; bottom: 0; left: 280px; background: rgba(0,0,0,0.45); z-index: 55; cursor: pointer; -webkit-tap-highlight-color: transparent; }
  /* Ignore desktop "collapsed" sidebar preference on mobile — always show full-width drawer */
  .sidebar.collapsed { width: 280px; min-width: 280px; padding: 14px; }
  .sidebar.collapsed .brand,
  .sidebar.collapsed .compose-btn,
  .sidebar.collapsed .folder-title,
  .sidebar.collapsed .sidebar-label,
  .sidebar.collapsed .folder-item .count,
  .sidebar.collapsed #mailboxes-group,
  .sidebar.collapsed #sheets-group,
  .sidebar.collapsed .folder-label { display: revert; }
  .sidebar.collapsed .brand-mini,
  .sidebar.collapsed .compose-btn-mini,
  .sidebar.collapsed .sidebar-toggle-btn { display: none; }
  .sidebar.collapsed .sidebar-close { display: inline-flex; }
  .list-pane { flex: 1; width: 100%; border-right: none; }
  .toolbar { padding-left: 60px; padding-top: 8px; }
  .preview-pane { display: none; }
  #app.show-preview .list-pane { display: none; }
  #app.show-preview .preview-pane { display: block; }
  #app.show-preview .burger { left: auto; right: 10px; }
  .messages-list, .preview-pane, #tasks-view, #finance-view, #team-view, #admin-view { padding-bottom: 60px; }
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: 56px;
    background: var(--bg); border-top: 1px solid var(--border); z-index: 40;
  }
  .tabbar button { flex: 1; background: none; border: none; font-size: 22px; color: var(--text-muted); cursor: pointer; padding: 0; line-height: 56px; }
  .tabbar button:active { background: var(--bg-hover); }
  .tabbar button.mtab-active { color: var(--accent); }
}

/* Collapsible sidebar sections */
.collapsed-group > :not(.folder-title) { display: none !important; }
.collapsed-group > .folder-title::after { content: ''; }

/* Brand mini (collapsed) */
.brand-mini { display: none; font-size: 16px; font-weight: 800; letter-spacing: 2px; color: var(--text); width: 38px; height: 38px; border-radius: 10px; background: var(--bg-hover); align-items: center; justify-content: center; }
.sidebar.collapsed .brand-mini { display: flex; }
.sidebar.collapsed .brand { display: flex !important; justify-content: center; margin-bottom: 8px; }
.sidebar.collapsed .sidebar-close { display: none; }

/* Scroll to top button */
.scroll-top-btn { display:none; }
.scroll-top-btn:hover { opacity:0.85; }


/* Sidebar drag & drop */
.sidebar .folder-group[draggable="true"] { cursor: grab; }
.sidebar .folder-group.dragging { opacity: 0.4; }
.sidebar .folder-group.drag-over { border-top: 2px solid var(--accent); }
.sidebar .folder-item[draggable="true"] { cursor: grab; }
.sidebar .folder-item.dragging { opacity: 0.4; }
.sidebar .folder-item.drag-over { border-top: 2px solid var(--accent); }

/* Panel scroll-to-top buttons */
.scroll-top-panel { position:absolute; bottom:12px; right:12px; width:32px; height:32px; border-radius:50%; background:var(--bg); color:var(--text-muted); border:1px solid var(--border); cursor:pointer; display:none; align-items:center; justify-content:center; z-index:10; box-shadow:0 2px 8px oklch(0 0 0/0.12); }
.scroll-top-panel:hover { color:var(--accent); border-color:var(--accent); }
.scroll-top-panel.show { display:flex; }

/* ───────────── Home dashboard ───────────── */
#home-view { grid-column: 2 / -1; height: 100vh; overflow-y: auto; background: var(--bg); }
.home-scroll { max-width: 1280px; margin: 0 auto; padding: 32px 36px 60px; }
.home-loading, .home-err { padding: 60px 40px; color: var(--text-muted); text-align: center; }

.home-head { margin-bottom: 22px; }
.home-day { font-size: 10.5px; font-weight: 700; letter-spacing: 0.12em; color: var(--text-faint); text-transform: uppercase; margin-bottom: 4px; }
.home-title { font-size: 22px; font-weight: 600; letter-spacing: -0.4px; margin: 0; color: var(--text); line-height: 1.2; }

.home-ai {
  background: linear-gradient(135deg, rgba(99,102,241,0.07), rgba(139,92,246,0.05));
  border: 1px solid rgba(99, 102, 241, 0.22);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 24px;
}
:root[data-theme="dark"] .home-ai {
  background: linear-gradient(135deg, rgba(129,140,248,0.12), rgba(167,139,250,0.08));
  border-color: rgba(129, 140, 248, 0.3);
}
.home-ai-label { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; color: var(--accent); text-transform: uppercase; margin-bottom: 8px; }
.home-ai-label svg { color: var(--accent); }
.home-ai-text { font-size: 15px; line-height: 1.5; color: var(--text); letter-spacing: -0.1px; }
.home-ai-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.home-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; font-size: 12.5px; font-weight: 600;
  background: var(--bg-pane); border: 1px solid var(--border); color: var(--accent);
  border-radius: 6px; cursor: pointer; font-family: inherit;
  transition: background .12s, border-color .12s;
}
.home-chip:hover { background: var(--accent-soft); border-color: var(--accent); }

.home-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 28px; }
.home-stat {
  background: var(--bg-pane);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  cursor: pointer;
  transition: border-color .12s, transform .08s, box-shadow .12s;
}
.home-stat:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,0.04); }
.home-stat.warn { border-color: rgba(239, 68, 68, 0.3); }
.home-stat.warn:hover { border-color: var(--danger); }
.home-stat-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--text-muted); }
.home-stat-icon { color: var(--accent); display: inline-flex; }
.home-stat.warn .home-stat-icon { color: var(--danger); }
.home-stat-label { font-size: 12.5px; font-weight: 500; }
.home-stat-value { font-size: 30px; font-weight: 700; color: var(--text); letter-spacing: -0.6px; line-height: 1.1; margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.home-stat-sub { font-size: 11.5px; color: var(--text-faint); }
.home-stat.warn .home-stat-sub { color: var(--danger); font-weight: 600; }

.home-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }

.home-block {
  background: var(--bg-pane);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 4px 6px;
  min-height: 240px;
  min-width: 0;
  overflow: hidden;
}
.home-block-wide { padding: 14px 16px 16px; }
.home-block-head { display: flex; justify-content: space-between; align-items: center; padding: 0 14px 10px; }
.home-block-head h3 { margin: 0; font-size: 13.5px; font-weight: 700; letter-spacing: -0.1px; color: var(--text); }
.home-block-all { font-size: 11.5px; color: var(--text-muted); cursor: pointer; }
.home-block-all:hover { color: var(--accent); }
.home-empty { padding: 24px 18px; color: var(--text-faint); font-size: 13px; font-style: italic; text-align: center; }

.home-list { list-style: none; margin: 0; padding: 0; }
.home-row { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-radius: 6px; cursor: pointer; transition: background .1s; min-width: 0; }
.home-row:hover { background: var(--bg-hover); }
.home-row-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; margin-top: 6px; align-self: flex-start; }
.home-row-dot.unread { background: var(--accent); }
.home-row-dot.urgent { background: var(--danger); }
.home-row-dot.high { background: var(--warning); }
.home-row-dot.overdue { background: var(--danger); }
.home-row-dot.credit { background: transparent; width: auto; height: auto; color: var(--success); font-weight: 700; font-size: 13px; margin: 0; align-self: center; }
.home-row-main { flex: 1; min-width: 0; }
.home-row-title { font-size: 13px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 2px; }
.home-row-sub { font-size: 11.5px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-row-date { font-size: 11.5px; color: var(--text-faint); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.home-row-date.overdue { color: var(--danger); font-weight: 600; }
.home-row-amount { font-size: 13px; font-weight: 700; flex-shrink: 0; font-variant-numeric: tabular-nums; white-space: nowrap; max-width: 40%; overflow: hidden; text-overflow: ellipsis; }
.home-row-amount.credit { color: var(--success); }

.home-calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.home-cal-day { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; min-height: 110px; display: flex; flex-direction: column; gap: 6px; }
.home-cal-day.today { background: var(--accent-soft); border-color: var(--accent); }
.home-cal-date { display: flex; align-items: baseline; gap: 6px; font-weight: 700; }
.home-cal-dow { font-size: 10px; color: var(--text-faint); letter-spacing: 0.08em; }
.home-cal-day.today .home-cal-dow { color: var(--accent); }
.home-cal-n { font-size: 15px; color: var(--text); }
.home-cal-day.today .home-cal-n { color: var(--accent); }
.home-cal-tasks { display: flex; flex-direction: column; gap: 4px; margin-top: 2px; flex: 1; }
.home-cal-task { font-size: 11px; line-height: 1.3; padding: 3px 6px; border-radius: 4px; background: var(--bg-pane); border: 1px solid var(--border); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.home-cal-task.prio-urgent { background: rgba(239,68,68,0.08); color: var(--danger); border-color: rgba(239,68,68,0.2); }
.home-cal-task.prio-high { background: rgba(245,158,11,0.08); color: var(--warning); border-color: rgba(245,158,11,0.2); }
.home-cal-more { font-size: 10.5px; color: var(--text-faint); padding: 2px 6px; font-weight: 600; }

@media (max-width: 1100px) {
  .home-stats { grid-template-columns: repeat(2, 1fr); }
  .home-grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .home-scroll { padding: 20px 16px 80px; }
  .home-title { font-size: 19px; }
  .home-stats { gap: 8px; }
  .home-stat { padding: 12px 14px; }
  .home-stat-value { font-size: 22px; }
  .home-calendar { grid-template-columns: repeat(2, 1fr); }
}

/* Briefing highlights */
.home-ai-text .bi-danger { color: var(--danger); font-weight: 700; }
.home-ai-text .bi-warning { color: var(--warning); font-weight: 700; }
.home-ai-text .bi-accent { color: var(--accent); font-weight: 700; }
.home-ai-text .bi-ok { color: var(--success); font-weight: 700; }
.home-ai-text .bi-muted { color: var(--text-muted); font-weight: 600; }
.home-ai-text .bi-date { color: var(--text); font-weight: 700; background: var(--bg-hover); padding: 1px 5px; border-radius: 4px; }
.home-ai-text .bi-money { color: var(--success); font-weight: 700; font-variant-numeric: tabular-nums; }
.home-ai-text .bi-pct { color: var(--success); font-weight: 700; font-variant-numeric: tabular-nums; }

/* Apple-style avatars (used in admin Telegram tab, could be reused elsewhere) */
.ap-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  flex-shrink: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, sans-serif;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    inset 0 -1px 0 rgba(0, 0, 0, 0.10),
    0 1px 2px rgba(0, 0, 0, 0.16),
    0 0 0 0.5px rgba(0, 0, 0, 0.06);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
}
.ap-avatar svg { width: 20px; height: 20px; display: block; }

/* Task rows with unread/new comments */
.task-row { position: relative; transition: background 0.15s ease; }
.task-row.has-new {
  background: linear-gradient(90deg, var(--accent-soft), transparent 40%);
  box-shadow: inset 3px 0 0 var(--accent);
}
.task-row.has-new:hover { background: linear-gradient(90deg, var(--accent-soft), var(--bg-hover) 60%); }
.task-new-dot {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  flex-shrink: 0;
  margin-right: 2px;
  animation: task-pulse 1.8s ease-in-out infinite;
}
@keyframes task-pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--accent-soft); }
  50% { box-shadow: 0 0 0 6px var(--accent-soft); }
}

/* ── Realty section responsive layout ─────────────────────────── */
/* The realty section needs to survive every browser zoom level
   (Ctrl+/-). Past attempts to clip the section with overflow-x:hidden
   on #realty-view + a universal `*{min-width:0}` actually CAUSED the
   tab strip + filter bar to be cut off at zoom 125%+: the heavy-handed
   universal selector defeats the children's own overflow:auto rules
   (no scrollbar can appear inside a hidden parent), and clips sticky
   columns. New rules below scope min-width:0 only to grid/flex parents
   that need it. */
#realty-view { min-width: 0; }
/* Desktop: horizontal scroll on the section when zoom shrinks the
   viewport below the natural width of the tab strip / card. User
   gets a scrollbar instead of silently-clipped content. */
#realty-view { overflow-x: auto; }
/* Mobile (≤720px): NEVER let the whole section pan horizontally —
   it makes the page feel «not glued», как «гуляет под пальцем».
   Tables and grids inside the section still scroll horizontally
   through their own overflow-x:auto wrapper, but the outer card / hero
   / tab strip stay fixed. Without this, touch-pan on iOS happily
   drags everything left-right because the section's own scroll axis
   takes precedence. */
@media (max-width: 720px) {
  #realty-view { overflow-x: hidden; max-width: 100vw; }
  #realty-view * { max-width: 100%; }
  /* Tables и сетки внутри — переопределяем, чтобы они МОГЛИ
     горизонтально скроллиться (внешний max-width:100% сжал бы их). */
  #realty-view table { max-width: none; }
  #realty-view [style*="overflow-x:auto"],
  #realty-view [style*="overflow-x: auto"] {
    max-width: 100%;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  /* Card hero (синяя верхняя плашка) и плитки KPI — пусть переносятся
     внутри grid'а без выхода за края. Уже работают через
     auto-fit minmax, но max-width:100% перестраховка. */
}
/* Tabs are flex-wrap by inline style — keep them wrapping cleanly.
   flex-shrink:0 prevents the «mid-word truncation» that happens when
   a button is partially squeezed at zoom levels. */
#realty-tabs { padding-bottom: 4px; }
#realty-tabs > button { flex-shrink: 0; }
#realty-mode-bar { overflow-x: auto; padding-bottom: 2px; }
#realty-actions { flex-wrap: wrap; }
/* Body must NOT clip — sticky-right (Итог column) needs a horizontal
   scroll container, not a hidden one. */
#realty-body { max-width: 100%; }
/* Direct children of body get min-width:0 so their inline width:100%
   doesn't blow up the section width. */
#realty-body > * { min-width: 0; }
/* Cells word-break on long sentences but not so aggressively that
   numeric content gets split. */
#realty-body td, #realty-body th { word-break: normal; overflow-wrap: anywhere; }
/* The mode-switch pills lose some padding on narrow screens. */
@media (max-width: 720px) {
  #realty-mode-bar button { padding: 8px 12px !important; font-size: 12px !important; }
  #realty-tabs button { padding: 6px 10px !important; font-size: 12px !important; }
  #realty-view h2 { font-size: 20px !important; }
  /* The object hero card */
  #realty-body > div[style*="linear-gradient"] h2 { font-size: 18px !important; }
}
/* Drawer fills the screen on mobile so forms don't get clipped. */
@media (max-width: 600px) {
  #realty-drawer { width: 100vw !important; }
}
