/* ============================================================
   Material Design 3 — Planner
   ============================================================ */

/* --- Design tokens (light) --- */
:root {
  --md-primary:             #4750EB;
  --md-on-primary:          #FFFFFF;
  --md-primary-container:   #E0E0FF;
  --md-on-primary-container:#00006E;

  --md-secondary:           #5C5D72;
  --md-secondary-container: #E1E0F9;
  --md-on-secondary-container: #191A2C;

  --md-error:               #B3261E;
  --md-error-container:     #F9DEDC;
  --md-on-error-container:  #410E0B;

  --md-bg:                  #FDFBFF;
  --md-surface:             #FDFBFF;
  --md-surface-lo:          #F5F3FF;   /* nav drawer bg */
  --md-surface-mid:         #EFEDFB;  /* card bg */
  --md-surface-hi:          #E9E7F6;  /* hover surface */
  --md-surface-highest:     #E3E1F0;  /* pressed / selected container */

  --md-on-surface:          #1A1B1F;
  --md-on-surface-var:      #47464F;
  --md-outline:             #78767F;
  --md-outline-var:         #C9C5D0;

  --md-inverse-surface:     #302F38;
  --md-inverse-on-surface:  #F3EFF7;
  --md-inverse-primary:     #BEC2FF;

  --md-shadow-1: 0 1px 2px rgba(0,0,0,.3), 0 1px 3px 1px rgba(0,0,0,.15);
  --md-shadow-2: 0 1px 2px rgba(0,0,0,.3), 0 2px 6px 2px rgba(0,0,0,.15);
  --md-shadow-3: 0 4px 8px 3px rgba(0,0,0,.15), 0 1px 3px rgba(0,0,0,.3);

  --nav-w: 260px;
  --nav-bar-height: 64px;

  --r-xs: 4px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 28px;
  --r-full: 9999px;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

/* --- Dark theme --- */
@media (prefers-color-scheme: dark) { :root {
  --md-primary:             #BEC2FF;
  --md-on-primary:          #1E21A2;
  --md-primary-container:   #3337D4;
  --md-on-primary-container:#E0E0FF;
  --md-secondary:           #C5C3DD;
  --md-secondary-container: #444559;
  --md-on-secondary-container: #E1E0F9;
  --md-error:               #F2B8B5;
  --md-error-container:     #8C1D18;
  --md-on-error-container:  #F9DEDC;
  --md-bg:                  #1A1B1F;
  --md-surface:             #1A1B1F;
  --md-surface-lo:          #21212B;
  --md-surface-mid:         #262631;
  --md-surface-hi:          #302F38;
  --md-surface-highest:     #3B3A42;
  --md-on-surface:          #E4E2E6;
  --md-on-surface-var:      #C9C5D0;
  --md-outline:             #938F9A;
  --md-outline-var:         #47464F;
  --md-inverse-surface:     #E4E2E6;
  --md-inverse-on-surface:  #302F38;
  --md-inverse-primary:     #4750EB;
}}
:root[data-theme="dark"] {
  --md-primary:             #BEC2FF;
  --md-on-primary:          #1E21A2;
  --md-primary-container:   #3337D4;
  --md-on-primary-container:#E0E0FF;
  --md-secondary:           #C5C3DD;
  --md-secondary-container: #444559;
  --md-on-secondary-container: #E1E0F9;
  --md-error:               #F2B8B5;
  --md-error-container:     #8C1D18;
  --md-on-error-container:  #F9DEDC;
  --md-bg:                  #1A1B1F;
  --md-surface:             #1A1B1F;
  --md-surface-lo:          #21212B;
  --md-surface-mid:         #262631;
  --md-surface-hi:          #302F38;
  --md-surface-highest:     #3B3A42;
  --md-on-surface:          #E4E2E6;
  --md-on-surface-var:      #C9C5D0;
  --md-outline:             #938F9A;
  --md-outline-var:         #47464F;
  --md-inverse-surface:     #E4E2E6;
  --md-inverse-on-surface:  #302F38;
  --md-inverse-primary:     #4750EB;
}
:root[data-theme="light"] {
  --md-primary:             #4750EB;
  --md-on-primary:          #FFFFFF;
  --md-primary-container:   #E0E0FF;
  --md-on-primary-container:#00006E;
  --md-bg:                  #FDFBFF;
  --md-surface:             #FDFBFF;
  --md-surface-lo:          #F5F3FF;
  --md-surface-mid:         #EFEDFB;
  --md-surface-hi:          #E9E7F6;
  --md-surface-highest:     #E3E1F0;
  --md-on-surface:          #1A1B1F;
  --md-on-surface-var:      #47464F;
  --md-outline:             #78767F;
  --md-outline-var:         #C9C5D0;
}

/* ============================================================
   Reset & base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--md-bg);
  color: var(--md-on-surface);
}

/* ============================================================
   App shell
   ============================================================ */
.app-content {
  flex: 1 1 0;
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
  padding: 24px 28px;
}

/* ============================================================
   Navigation Drawer (desktop)
   ============================================================ */
.app-nav {
  width: var(--nav-w);
  flex-shrink: 0;
  height: 100vh;
  background: var(--md-surface-lo);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--md-outline-var);
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-brand {
  padding: 20px 20px 12px;
  font-size: 1.375rem;  /* Title Large */
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--md-on-surface);
  flex-shrink: 0;
}

.nav-section {
  flex: 1;
  padding: 4px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 10px 16px;
  border-radius: var(--r-full);
  color: var(--md-on-surface-var);
  text-decoration: none;
  font-size: 0.875rem;  /* Label Large */
  font-weight: 500;
  letter-spacing: 0.006em;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: color-mix(in srgb, var(--md-on-surface) 8%, transparent);
  color: var(--md-on-surface);
}

.nav-item.active {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
  font-weight: 600;
}

.nav-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.nav-label { flex: 1; }

/* Кнопка выхода — в самом низу nav, с разделителем сверху */
.nav-logout {
  margin: 8px 12px 16px;
  flex-shrink: 0;
  width: calc(100% - 24px);
  border-top: 1px solid var(--md-outline-var);
  padding: 10px 16px;
  height: auto;
  min-height: 40px;
  border-radius: var(--r-full);
  color: var(--md-on-surface-var);
}

/* ============================================================
   Buttons
   ============================================================ */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.006em;
  font-family: inherit;
  padding: 0 24px;
  height: 40px;
  min-height: 40px;
  border-radius: var(--r-full);
  border: none;
  cursor: pointer;
  transition: box-shadow 0.15s, background 0.15s;
  white-space: nowrap;
  background: var(--md-primary);
  color: var(--md-on-primary);
}

button:hover { box-shadow: var(--md-shadow-1); }

button.secondary {
  background: transparent;
  color: var(--md-primary);
  border: 1px solid var(--md-outline);
}
button.secondary:hover {
  background: color-mix(in srgb, var(--md-primary) 8%, transparent);
  box-shadow: none;
}

button:disabled { opacity: 0.38; cursor: not-allowed; box-shadow: none; }

/* Tonal (filled-tonal in MD3) */
button.tonal {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
  border: none;
}
button.tonal:hover {
  box-shadow: var(--md-shadow-1);
  background: color-mix(in srgb, var(--md-secondary-container) 92%, black);
}

/* ============================================================
   Text fields
   ============================================================ */
input, textarea, select {
  font-size: 1rem;
  font-family: inherit;
  width: 100%;
  padding: 12px 16px;
  background: var(--md-surface);
  color: var(--md-on-surface);
  border: 1px solid var(--md-outline);
  border-radius: var(--r-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: auto;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--md-primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--md-primary) 20%, transparent);
}

textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--md-on-surface-var);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.error {
  font-size: 0.8125rem;
  color: var(--md-error);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ============================================================
   Cards
   ============================================================ */
.md-card {
  background: var(--md-surface);
  border-radius: var(--r-md);
  box-shadow: var(--md-shadow-1);
}

/* ============================================================
   Page header (content area top)
   ============================================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--md-on-surface);
}

/* ============================================================
   Modal (task create/edit)
   ============================================================ */
.task-modal {
  border: none;
  border-radius: var(--r-xl);
  padding: 0;
  max-width: 580px;
  width: calc(100vw - 48px);
  background: var(--md-surface);
  box-shadow: var(--md-shadow-3);
  color: var(--md-on-surface);
}

.task-modal::backdrop {
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(3px);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--md-outline-var);
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.modal-close {
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  font-size: 1rem;
  border-radius: var(--r-full);
}

.modal-body {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-textarea {
  min-height: 140px;
  resize: vertical;
}

.modal-footer {
  display: flex;
  gap: 8px;
  padding: 12px 24px 20px;
  flex-wrap: wrap;
}

/* ============================================================
   Task table (list view)
   ============================================================ */
.task-table {
  border: 1px solid var(--md-outline-var);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--md-surface);
}

.task-table-empty {
  padding: 32px 24px;
  text-align: center;
  color: var(--md-on-surface-var);
  font-size: 0.9rem;
}

.task-row {
  display: grid;
  grid-template-columns: 36px 1fr auto 36px;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 4px;
  min-height: 52px;
  border-bottom: 1px solid var(--md-outline-var);
  transition: background 0.1s;
}

.task-row:last-of-type { border-bottom: none; }
.task-row:hover { background: var(--md-surface-mid); }

.subtask-row {
  background: var(--md-surface-mid);
  padding-left: 28px;
}

.subtask-row:hover { background: var(--md-surface-hi); }

.task-expand-btn {
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  font-size: 0.7rem;
  border-radius: var(--r-sm);
  flex-shrink: 0;
}

.task-row-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  cursor: default;
}

.task-row-name {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--md-on-surface);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-row-desc {
  font-size: 0.8rem;
  color: var(--md-on-surface-var);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-edit-btn {
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: var(--r-sm);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.task-subtasks {
  border-top: 1px dashed var(--md-outline-var);
}

.subtask-form {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px 8px 40px;
  background: var(--md-surface-mid);
}

.subtask-form input {
  flex: 1;
  height: 36px;
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.875rem;
}

.subtask-form button {
  flex-shrink: 0;
  height: 36px;
  min-height: 36px;
  padding: 0 14px;
  font-size: 0.8125rem;
}

/* status select — используется и в таблице и в канбане */
.status-select {
  padding: 4px 8px;
  height: 32px;
  min-height: unset;
  font-size: 0.8125rem;
  border-radius: var(--r-full);
  min-width: 110px;
  max-width: 160px;
}

/* task-title в канбан-карточках */
.task-title {
  font-size: 0.9rem;
  font-weight: 500;
  display: block;
  margin-bottom: 8px;
  color: var(--md-on-surface);
  overflow-wrap: anywhere;
}

/* ============================================================
   View switch tabs
   ============================================================ */
.view-switch, .description-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}


.view-tab, .description-tab {
  height: 36px;
  min-height: 36px;
  padding: 0 20px;
  font-size: 0.875rem;
  background: transparent;
  color: var(--md-on-surface-var);
  border: 1px solid var(--md-outline-var);
}

.view-tab[aria-selected="true"], .description-tab[aria-selected="true"] {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
  border-color: transparent;
  box-shadow: none;
}

/* MD preview area */
.task-description-preview {
  min-height: 80px;
  padding: 12px 16px;
  border: 1px solid var(--md-outline);
  border-radius: var(--r-sm);
  background: var(--md-surface);
}

.task-description-preview:empty::before {
  content: "Нечего показывать — описание пустое.";
  color: var(--md-on-surface-var);
  font-size: 0.875rem;
}

/* Markdown body */
.markdown-body { color: var(--md-on-surface-var); font-size: 0.9rem; }
.markdown-body :first-child { margin-top: 0; }
.markdown-body :last-child { margin-bottom: 0; }
.markdown-body p { margin: 0 0 8px; }
.markdown-body ul, .markdown-body ol { margin: 0 0 8px; padding-left: 24px; }
.markdown-body code {
  background: var(--md-surface-mid);
  border-radius: var(--r-xs);
  padding: 1px 5px;
  font-size: 0.875em;
}
.markdown-body pre {
  background: var(--md-surface-mid);
  border-radius: var(--r-sm);
  padding: 12px 16px;
  overflow-x: auto;
}
.markdown-body pre code { padding: 0; background: none; }
.markdown-body blockquote {
  margin: 0 0 8px;
  padding-left: 12px;
  border-left: 3px solid var(--md-outline-var);
  color: var(--md-on-surface-var);
}
.markdown-body a { color: var(--md-primary); }

/* ============================================================
   Kanban board (full-height via :has)
   ============================================================ */
.kanban-board {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.kanban-column {
  flex: 1 1 0;
  min-width: 220px;
  background: var(--md-surface-mid);
  border-radius: var(--r-lg);
  padding: 16px;
}

.kanban-column h2 {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--md-on-surface-var);
  margin-bottom: 14px;
}

.kanban-cards {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 60px;
}

.kanban-cards.drag-over {
  outline: 2px dashed var(--md-primary);
  outline-offset: 4px;
  border-radius: var(--r-md);
}

.kanban-card {
  background: var(--md-surface);
  border-radius: var(--r-md);
  padding: 14px 16px;
  box-shadow: var(--md-shadow-1);
  cursor: grab;
  transition: box-shadow 0.2s, opacity 0.2s;
}

.kanban-card:hover { box-shadow: var(--md-shadow-2); }
.kanban-card.dragging { opacity: 0.45; }

.kanban-card .status-select { max-width: none; width: 100%; min-width: unset; }

.kanban-card .task-edit-btn {
  margin-top: 6px;
  width: 100%;
  height: 28px;
  min-height: 28px;
  border-radius: var(--r-sm);
  font-size: 0.75rem;
}

/* Full-height kanban when board is visible */
body:has(#kanban-board:not([hidden])) .app-content { overflow: hidden; }

body:has(#kanban-board:not([hidden])) main {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body:has(#kanban-board:not([hidden])) .create-task-form { flex-shrink: 0; }

body:has(#kanban-board:not([hidden])) .view-switch {
  flex-shrink: 0;
  margin-bottom: 12px;
}

body:has(#kanban-board:not([hidden])) .kanban-board {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  align-items: stretch;
}

body:has(#kanban-board:not([hidden])) .kanban-column {
  overflow-y: auto;
  max-height: 100%;
}

/* ============================================================
   Diagram picker
   ============================================================ */
.diagram-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.diagram-picker select { margin: 0; max-width: 240px; flex: 1 1 auto; }

/* ============================================================
   Login
   ============================================================ */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--md-surface-lo);
  overflow: auto;
  height: 100vh;
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 40px;
  background: var(--md-surface);
  border-radius: var(--r-xl);
  box-shadow: var(--md-shadow-3);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.login-card h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
  color: var(--md-on-surface);
}

.login-card label {
  margin-top: 8px;
}

.login-card input {
  padding: 14px 16px;
}

.login-card button[type="submit"] {
  margin-top: 8px;
  width: 100%;
  height: 48px;
  font-size: 1rem;
}

/* ============================================================
   Notes
   ============================================================ */
.notes-layout {
  display: flex;
  gap: 0;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Override main padding for notes */
main.notes-layout {
  padding: 0;
}

.notes-sidebar {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--md-surface-mid);
  border-right: 1px solid var(--md-outline-var);
  overflow-y: auto;
  padding: 16px 12px;
}

.notes-sidebar > button {
  margin-bottom: 12px;
  flex-shrink: 0;
}

.notes-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.note-list-item-button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--md-on-surface);
  border: none;
  height: auto;
  min-height: 44px;
  padding: 10px 14px;
  font-size: 0.9rem;
  border-radius: var(--r-full);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: none;
}

.note-list-item-button:hover {
  background: color-mix(in srgb, var(--md-on-surface) 8%, transparent);
  box-shadow: none;
}

.note-list-item.active .note-list-item-button {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
}

.notes-editor {
  flex: 1;
  min-width: 0;
  background: var(--md-surface);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px 28px;
  overflow-y: auto;
}

.note-content-textarea { min-height: 200px; flex: 1; }
.note-content-preview { min-height: 200px; padding: 12px 16px; border: 1px solid var(--md-outline); border-radius: var(--r-sm); }

.notes-editor-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.notes-back-button { display: none; }

/* ============================================================
   Diagrams
   ============================================================ */
.diagram-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

.diagram-toolbar-spacer { flex: 1 1 auto; }

.diagram-tool {
  background: var(--md-surface-mid);
  color: var(--md-on-surface);
  border: 1px solid var(--md-outline-var);
  height: 36px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--r-sm);
  font-size: 0.875rem;
  box-shadow: none;
}

.diagram-tool:hover { background: var(--md-surface-hi); box-shadow: none; }

.diagram-tool.active {
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
  border-color: transparent;
}

.diagram-canvas {
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
  aspect-ratio: 800 / 480;
  background: var(--md-surface);
  border: 1px solid var(--md-outline-var);
  border-radius: var(--r-md);
  touch-action: none;
  cursor: crosshair;
  flex-shrink: 0;
}

.diagram-editor {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ============================================================
   Audit
   ============================================================ */
.audit-page {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.audit-filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  background: var(--md-surface);
  border-radius: var(--r-md);
  padding: 20px;
  box-shadow: var(--md-shadow-1);
}

.audit-filter-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--md-on-surface-var);
}

.audit-filter-form input, .audit-filter-form select {
  margin: 0;
  min-width: 140px;
  height: 40px;
  padding: 0 14px;
}

.audit-table-wrap { overflow-x: auto; border-radius: var(--r-md); box-shadow: var(--md-shadow-1); }

.audit-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--md-surface);
}

.audit-table th, .audit-table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--md-outline-var);
  font-size: 0.875rem;
}

.audit-table th {
  color: var(--md-on-surface-var);
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--md-surface-mid);
}

.audit-table tbody tr:hover td { background: var(--md-surface-mid); }

.audit-cards { list-style: none; display: none; flex-direction: column; gap: 10px; }

.audit-card {
  background: var(--md-surface);
  border-radius: var(--r-md);
  padding: 16px;
  box-shadow: var(--md-shadow-1);
}

.audit-card-when { font-size: 0.8rem; color: var(--md-on-surface-var); margin-bottom: 2px; }
.audit-card-who { font-weight: 600; font-size: 0.9rem; }

.audit-pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
}

.audit-pagination span { font-size: 0.875rem; color: var(--md-on-surface-var); }

.audit-undo-button {
  height: 32px;
  min-height: 32px;
  padding: 0 12px;
  font-size: 0.8125rem;
}

/* ============================================================
   Undo toast
   ============================================================ */
.undo-toast-container {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  min-width: 300px;
  max-width: 560px;
  width: max-content;
}

.undo-toast {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--md-inverse-surface);
  color: var(--md-inverse-on-surface);
  border-radius: var(--r-sm);
  padding: 12px 16px;
  box-shadow: var(--md-shadow-3);
}

.undo-toast-message { flex: 1 1 auto; font-size: 0.875rem; }

.undo-toast button {
  background: transparent;
  color: var(--md-inverse-primary);
  border: none;
  padding: 0 8px;
  height: 36px;
  min-height: 36px;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: none;
}

.undo-toast button:hover { background: color-mix(in srgb, var(--md-inverse-primary) 12%, transparent); box-shadow: none; }

.undo-toast-close {
  color: var(--md-inverse-on-surface) !important;
  opacity: 0.7;
  font-size: 1.1rem;
  min-width: 36px;
  padding: 0 !important;
}

/* ============================================================
   Diagram embed in markdown
   ============================================================ */
.diagram-embed {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 12px;
  margin: 8px 0;
  border: 1px solid var(--md-outline-var);
  border-radius: var(--r-md);
  background: var(--md-surface);
  color: var(--md-on-surface-var);
  font-size: 0.875rem;
}

.diagram-embed-missing { color: var(--md-error); }
.diagram-embed-title { font-weight: 600; color: var(--md-on-surface); }

.diagram-embed-canvas {
  border: 1px solid var(--md-outline-var);
  border-radius: var(--r-sm);
  background: var(--md-surface);
  max-width: 100%;
}

/* ============================================================
   Mobile — Navigation Bar
   ============================================================ */
@media (max-width: 719px) {
  body {
    flex-direction: column;
    overflow: hidden;
  }

  .app-nav {
    order: 2;
    width: 100%;
    height: var(--nav-bar-height);
    flex-direction: row;
    align-items: stretch;
    border-right: none;
    border-top: 1px solid var(--md-outline-var);
    overflow: hidden;
    background: var(--md-surface);
  }

  .nav-brand { display: none; }

  .nav-section {
    flex: 1;
    flex-direction: row;
    padding: 0;
    gap: 0;
  }

  .nav-item {
    flex: 1;
    flex-direction: column;
    gap: 4px;
    padding: 8px 4px 10px;
    border-radius: 0;
    font-size: 0.6875rem;
    letter-spacing: 0.02em;
    justify-content: center;
    color: var(--md-on-surface-var);
  }

  .nav-item.active {
    background: transparent;
    color: var(--md-primary);
  }

  .nav-icon {
    width: 24px;
    height: 24px;
  }

  /* Кнопка выхода на мобиле: скрываем из nav-bar и показываем как фиксированную кнопку */
  .nav-logout {
    display: none;
  }

  #logout-button {
    display: inline-flex;
    position: fixed;
    top: 10px;
    right: 12px;
    z-index: 200;
    width: auto;
    padding: 0 14px;
    height: 36px;
    min-height: 36px;
    font-size: 0.8125rem;
    background: var(--md-surface-mid);
    color: var(--md-on-surface-var);
    border: 1px solid var(--md-outline-var);
    border-top: 1px solid var(--md-outline-var);
    box-shadow: none;
    margin: 0;
  }

  .app-content {
    order: 1;
    height: calc(100dvh - var(--nav-bar-height));
    padding-top: 56px; /* space for fixed logout button */
  }

  main { padding: 16px; }

  /* Notes: mobile full-screen toggle */
  main.notes-layout { padding: 0; display: block; overflow-y: auto; }
  .notes-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--md-outline-var); }
  .notes-back-button { display: inline-flex; }
  .notes-editor { display: none; padding: 16px; }
  .notes-layout.show-editor .notes-sidebar { display: none; }
  .notes-layout.show-editor .notes-editor { display: flex; }

  /* Audit */
  .audit-page { padding: 16px; }
  .audit-filter-form { flex-direction: column; align-items: stretch; }
  #audit-table-wrapper { display: none; }
  .audit-cards { display: flex; }

  /* Kanban mobile */
  body:has(#kanban-board:not([hidden])) .kanban-board {
    flex: none;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    align-items: flex-start;
  }
  body:has(#kanban-board:not([hidden])) .kanban-column {
    flex: 0 0 85%;
    scroll-snap-align: start;
    max-height: none;
    overflow-y: visible;
  }

  /* Таблица задач на мобиле: компактный статус */
  .status-select { min-width: 90px; font-size: 0.75rem; }
  .task-row { padding-right: 8px; gap: 6px; }
  .subtask-form { padding-left: 12px; }
  .task-modal { width: calc(100vw - 24px); border-radius: var(--r-lg); }
  .modal-header { padding: 16px 16px 12px; }
  .modal-body { padding: 12px 16px; }
  .modal-footer { padding: 8px 16px 16px; }
  .diagram-picker { flex-direction: column; align-items: stretch; }
  .diagram-picker select { max-width: none; }
}
