/* Base theme and layout for Projects Tracker */
:root {
  color-scheme: light;
  font-family: "Inter", "Segoe UI", "Noto Sans", system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  --bg: #f4f6fb;
  --bg-alt: #eef1f6;
  --surface: #ffffff;
  --surface-muted: #f7f8fc;
  --surface-strong: #e9edf4;
  --text: #0f172a;
  --muted: #475569;
  --border: #d9e0ea;
  --divider: rgba(148, 163, 184, 0.35);
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
  --accent: #10a37f;
  --accent-strong: #19b88f;
  --accent-soft: rgba(16, 163, 127, 0.12);
  --danger: #ef4444;
  --warning: #f59e0b;
  --status-todo-bg: #f2f4f7;
  --status-todo-text: #475467;
  --status-todo-border: #e4e7ec;
  --status-inprogress-bg: #e0f2fe;
  --status-inprogress-text: #075985;
  --status-inprogress-border: #bae6fd;
  --status-done-bg: #ecfdf3;
  --status-done-text: #166534;
  --status-done-border: #bbf7d0;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c1017;
  --bg-alt: #0a0e15;
  --surface: #111827;
  --surface-muted: #161f2a;
  --surface-strong: #1c2435;
  --text: #e6edf3;
  --muted: #9aa6b6;
  --border: #1f2937;
  --divider: rgba(148, 163, 184, 0.25);
  --shadow: 0 22px 50px rgba(0, 0, 0, 0.5);
  --accent: #10a37f;
  --accent-strong: #19b88f;
  --accent-soft: rgba(16, 163, 127, 0.2);
  --danger: #f87171;
  --warning: #fbbf24;
  --status-todo-bg: rgba(148, 163, 184, 0.14);
  --status-todo-text: #d8e2f1;
  --status-todo-border: rgba(148, 163, 184, 0.32);
  --status-inprogress-bg: rgba(59, 130, 246, 0.18);
  --status-inprogress-text: #d2e4ff;
  --status-inprogress-border: rgba(59, 130, 246, 0.38);
  --status-done-bg: rgba(16, 163, 127, 0.2);
  --status-done-text: #baf4e0;
  --status-done-border: rgba(16, 163, 127, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  overflow-x: hidden;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 20% 20%, rgba(16, 163, 127, 0.06), transparent 32%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-alt) 100%);
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
  color: var(--text);
}

.muted {
  color: var(--muted);
}

.lead {
  margin: 6px 0 0;
  color: var(--muted);
  max-width: 70ch;
}

a {
  color: var(--accent);
}

a:hover {
  color: var(--accent-strong);
}

img {
  max-width: 100%;
  height: auto;
}

.app-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 20px 0;
}

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px 78px;
  display: grid;
  gap: 16px;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 12px;
  z-index: 8;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.logo img {
  width: 36px;
  height: 36px;
}

nav {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

nav a {
  padding: 8px 12px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
  background: var(--surface-muted);
}

nav a:hover,
nav a.active {
  box-shadow: var(--shadow);
  background: var(--surface);
}

.nav-dropdown,
.theme-menu {
  position: relative;
}

.nav-dropdown summary,
.theme-menu summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
  background: var(--surface-muted);
  cursor: pointer;
  user-select: none;
}

.nav-dropdown summary::-webkit-details-marker,
.theme-menu summary::-webkit-details-marker {
  display: none;
}

.nav-dropdown[open] summary,
.theme-menu[open] summary {
  box-shadow: var(--shadow);
  background: var(--surface);
}

.nav-dropdown-menu,
.theme-menu-dropdown {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 8px;
  display: none;
  flex-direction: column;
  gap: 4px;
  min-width: 200px;
  z-index: 940;
}

.theme-menu-dropdown {
  right: 0;
  left: auto;
  min-width: 35px;
  width: max-content;
  padding: 6px;
}

.nav-dropdown[open] .nav-dropdown-menu,
.theme-menu[open] .theme-menu-dropdown {
  display: flex;
}

.nav-dropdown-menu a {
  padding: 10px 12px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  white-space: nowrap;
}

.nav-dropdown-menu a:hover,
.nav-dropdown-menu a.active,
.theme-menu-dropdown button:hover,
.theme-menu-dropdown button[data-active="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.theme-menu-dropdown button {
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.page > header {
  margin-bottom: 28px;
}

.page-header .hint {
  color: var(--muted);
  margin: 6px 0 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--surface-muted);
  color: var(--accent);
  border-radius: 9px;
  border: 1px solid var(--border);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 12px;
  
}

.badge-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 999px;
}

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

/* Modals (shared across pages) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top));
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  z-index: 9999;
}

.modal {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px;
  width: min(640px, 96vw);
  max-height: calc(100vh - 32px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.modal-wide {
  width: min(920px, 96vw);
}

.modal-xl {
  width: min(1024px, 96vw);
}

.modal-medium {
  width: min(640px, 96vw);
}

.modal-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.modal-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  cursor: pointer;
}

.modal-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.12);
  display: none;
  z-index: 10000;
}

.global-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  pointer-events: none;
  z-index: 12;
}

.global-loading.is-fixed {
  position: fixed;
}

.global-loading-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-weight: 600;
}

.global-loading-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: global-spin 0.7s linear infinite;
  flex: 0 0 auto;
}

@keyframes global-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 768px) {
  .modal {
    width: min(100%, 96vw);
    padding: 16px;
  }
  .modal-heading {
    align-items: flex-start;
  }
  .modal-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
  .modal-actions button,
  .modal-actions a {
    width: 100%;
    justify-content: center;
  }
}

.section-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.grid-two {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
}

.hint {
  color: var(--muted);
  margin: 0;
}

button,
.button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 9px 14px;
  border-radius: 12px;
  color: var(--text);
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  text-decoration: none;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-content: space-around;
}

button.primary,
.button.primary {
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 12px 30px rgba(16, 163, 127, 0.2);
}

button:hover,
.button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.ghost {
  background: var(--surface-muted);
  border-color: var(--border);
  color: var(--text);
}

.ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-small {
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 0.92rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--surface-muted);
  border-radius: 12px;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
}

.badge.soft {
  color: var(--muted);
}

.table-wrap {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-scroll table,
.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  min-width: 650px;
}

.card table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

thead th {
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

[data-theme="dark"] thead th {
  background: var(--surface-strong);
}

.table-scroll table tr:hover td,
.card table tr:hover td {
  background: var(--surface-muted);
}

[data-theme="dark"] .card table tr:hover td,
[data-theme="dark"] .table-scroll table tr:hover td {
  background: rgba(25, 184, 143, 0.08);
}

.note-editor.note-frame {
  border-radius: 14px;
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.note-editor .note-toolbar {
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
}

[data-theme="dark"] .note-editor .note-toolbar {
  background: var(--surface-strong);
}

.note-editor .note-editing-area {
  background: var(--surface);
}

[data-theme="dark"] .note-editor .note-editing-area {
  background: var(--surface);
  color: var(--text);
}

.note-editor .note-statusbar {
  background: var(--surface-muted);
  border-top: 1px solid var(--border);
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea,
.summernote-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
}

.form-field textarea {
  resize: vertical;
}

[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]),
[data-theme="dark"] select,
[data-theme="dark"] textarea,
[data-theme="dark"] .summernote-input {
  background: var(--surface-muted);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

[data-theme="dark"] .chip {
  background: var(--surface-strong);
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.filters-card {
  display: grid;
  gap: 12px;
}

.filters-grid {
  display: grid;
  gap: 12px 16px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  align-items: end;
}

.filters-inline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px 16px;
  align-items: start;
}

.filter-section {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-muted);
  padding: 10px 12px;
}

.filter-section h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  color: var(--muted);
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.checkbox {
  --checkbox-control-size: 20px;
  --checkbox-control-radius: 7px;
  --checkbox-padding-block: 8px;
  --checkbox-padding-inline: 12px;
  display: inline-grid;
  grid-template-columns: var(--checkbox-control-size) minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 40px;
  max-width: 100%;
  padding: var(--checkbox-padding-block) var(--checkbox-padding-inline);
  border: 1px solid color-mix(in srgb, var(--border) 80%, var(--text) 20%);
  border-radius: 14px;
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--surface) 88%, white 12%) 0%,
      color-mix(in srgb, var(--surface) 82%, var(--surface-muted) 18%) 100%
    );
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  line-height: 1.3;
  user-select: none;
  transition:
    border-color 0.18s ease,
    background-color 0.18s ease,
    box-shadow 0.18s ease,
    color 0.18s ease,
    transform 0.18s ease;
}

.checkbox:hover {
  border-color: color-mix(in srgb, var(--accent) 28%, var(--border) 72%);
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--surface) 78%, white 22%) 0%,
      color-mix(in srgb, var(--accent-soft) 14%, var(--surface) 86%) 100%
    );
}

.checkbox:has(input:checked) {
  border-color: color-mix(in srgb, var(--accent) 44%, var(--border) 56%);
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--accent-soft) 42%, var(--surface) 58%) 0%,
      color-mix(in srgb, var(--surface) 84%, white 16%) 100%
    );
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 10px 24px rgba(15, 23, 42, 0.06);
}

.checkbox:focus-within {
  border-color: color-mix(in srgb, var(--accent) 48%, var(--border) 52%);
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--accent-soft) 70%, transparent 30%),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.checkbox--chip {
  --checkbox-padding-block: 7px;
  --checkbox-padding-inline: 12px;
  min-height: 38px;
  border-radius: 999px;
}

.checkbox > span,
.checkbox > strong,
.checkbox > small {
  min-width: 0;
  overflow-wrap: anywhere;
}

.checkbox input {
  appearance: none;
  inline-size: var(--checkbox-control-size);
  block-size: var(--checkbox-control-size);
  margin: 0;
  border-radius: var(--checkbox-control-radius);
  border: 1.5px solid color-mix(in srgb, var(--border) 78%, var(--text) 22%);
  background: color-mix(in srgb, var(--surface) 94%, var(--surface-muted) 6%);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.58);
  position: relative;
  transition:
    border-color 0.18s ease,
    background-color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s ease;
}

.checkbox input::after {
  content: "";
  inline-size: 10px;
  block-size: 6px;
  border-left: 2.5px solid #fff;
  border-bottom: 2.5px solid #fff;
  transform: translateY(-1px) rotate(-45deg) scale(0.55);
  opacity: 0;
  transition: transform 0.16s ease, opacity 0.16s ease;
}

.checkbox input:checked {
  border-color: var(--accent);
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--accent) 88%, white 12%) 0%,
      color-mix(in srgb, var(--accent) 96%, black 4%) 100%
    );
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 0 0 3px color-mix(in srgb, var(--accent-soft) 70%, transparent 30%);
}

.checkbox input:checked::after {
  opacity: 1;
  transform: translateY(-1px) rotate(-45deg) scale(1);
}

.checkbox input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.checkbox input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.checkbox:has(input:disabled) {
  opacity: 0.7;
  cursor: not-allowed;
}

.filter-actions {
  margin-top: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
}

.filter-buttons {
  display: flex;
  gap: 10px;
  align-items: center;
}

.alert {
  border-radius: 12px;
  padding: 12px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: #b91c1c;
  font-weight: 600;
}

[data-theme="dark"] .alert {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.3);
  color: #fca5a5;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.8rem;
}

.status.todo {
  background: var(--status-todo-bg);
  color: var(--status-todo-text);
  border-color: var(--status-todo-border);
}

.status.in-progress {
  background: var(--status-inprogress-bg);
  color: var(--status-inprogress-text);
  border-color: var(--status-inprogress-border);
}

.status.done {
  background: var(--status-done-bg);
  color: var(--status-done-text);
  border-color: var(--status-done-border);
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
}

.tag.warn {
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.3);
  color: #92400e;
}

[data-theme="dark"] .tag.warn {
  background: rgba(251, 191, 36, 0.15);
  border-color: rgba(251, 191, 36, 0.35);
  color: #fde68a;
}

.tasks-table-wrapper {
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.tasks-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: inherit;
  font-size: 13px;
}

.tasks-table th,
.tasks-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.tasks-table thead th {
  background: var(--surface-muted);
  color: var(--muted);
  font-weight: 700;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.01em;
  font-size: 12px;
}

.tasks-table tbody tr:hover {
  background: var(--surface-muted);
}

[data-theme="dark"] .tasks-table tbody tr:hover {
  background: rgba(25, 184, 143, 0.08);
}

.cell-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 750;
  line-height: 1.25;
  word-break: break-word;
}

.cell-title a {
  color: inherit;
  text-decoration: none;
}

.cell-title a:hover {
  color: var(--accent);
}

.cell-meta-stack {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.tasks-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.summary-tile {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--surface-muted);
}

.summary-tile strong {
  font-size: 1.3rem;
}

.sticky-table-head {
  position: sticky;
  top: 0;
  z-index: 5;
}

@media (max-width: 960px) {
  .app-shell {
    padding: 12px 14px 0;
  }

  .page {
    padding: 16px 14px 72px;
  }

  .card {
    padding: 16px;
  }

  .page-header {
    flex-direction: column;
  }

  nav {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
  }

  nav a,
  .nav-dropdown summary,
  .theme-menu summary {
    flex-shrink: 0;
  }

  .filter-actions {
    flex-direction: column;
    align-items: flex-start;
  }

}

@media (max-width: 720px) {
  body {
    background-attachment: scroll;
  }

  .page {
    display: block;
    gap: 12px;
    padding: 16px 12px 70px;
  }

  .section-header {
    flex-direction: column;
  }

  .page-header {
    flex-direction: column;
  }

  .page-header .toolbar,
  .section-header .admin-actions,
  .section-header .filter-row,
  .section-header .filter-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .page-header .toolbar button,
  .section-header .admin-actions button {
    width: 100%;
    justify-content: center;
  }

  .grid-two {
    grid-template-columns: 1fr;
  }

  .filters-grid,
  .filters-inline {
    grid-template-columns: 1fr;
  }

  .checkbox {
    white-space: normal;
    min-height: 38px;
  }

  .filter-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-buttons {
    width: 100%;
    flex-wrap: wrap;
  }

  .filter-buttons button {
    width: 100%;
    justify-content: center;
  }

  th,
  td {
    padding: 8px 10px;
  }

  .table-scroll th,
  .table-scroll td,
  .table-wrap th,
  .table-wrap td,
  .table-wrapper th,
  .table-wrapper td,
  .file-table th,
  .file-table td,
  .tasks-table th,
  .tasks-table td,
  .characteristics-table th,
  .characteristics-table td,
  .hm-table-wrapper th,
  .hm-table-wrapper td,
  .tc-table-wrapper th,
  .tc-table-wrapper td {
    white-space: nowrap;
    overflow-wrap: normal;
    word-break: normal;
  }

  pre,
  code {
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .modal {
    width: min(100%, 96vw);
  }

  .modal-backdrop {
    align-items: flex-start;
    overflow-y: auto;
  }

  .modal-toolbar {
    width: 100%;
    justify-content: flex-start;
  }

  .table-scroll,
  .table-wrap,
  .table-wrapper,
  .file-table-scroll,
  .tasks-table-wrapper,
  .characteristics-table-wrapper,
  .hm-table-wrapper,
  .tc-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-gutter: stable;
  }

  .table-scroll table,
  .table-wrap table,
  .table-wrapper table,
  .file-table,
  .tasks-table,
  .characteristics-table,
  .hm-table-wrapper table,
  .tc-table-wrapper table {
    min-width: 100%;
    width: max-content;
    table-layout: auto;
  }

  dialog,
  .dialog-body,
  .dialog-body.large,
  .dialog-body.large-form {
    min-width: 0 !important;
    width: 100% !important;
  }

  .compact-toolbar-actions {
    position: static !important;
    display: block !important;
    width: 100%;
    margin-bottom: 10px;
  }
}

@media (max-width: 540px) {
  .app-shell {
    padding: 10px 10px 0;
  }

  .page {
    padding: 14px 10px 66px;
    gap: 10px;
  }

  .card {
    padding: 14px;
    margin: 15px 0;
  }

  .modal-backdrop {
    padding: 12px;
    padding-top: calc(12px + env(safe-area-inset-top));
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    padding-left: calc(12px + env(safe-area-inset-left));
    padding-right: calc(12px + env(safe-area-inset-right));
  }

  .modal {
    padding: 14px;
    max-height: calc(100vh - 24px);
  }

  .modal-heading {
    flex-direction: column;
    align-items: flex-start;
  }

  .modal-toast {
    left: 16px;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .pill {
    font-size: 12px;
    padding: 6px 10px;
  }

  .tasks-table thead th {
    white-space: normal;
    text-transform: none;
    letter-spacing: 0;
    font-size: 11px;
  }
}

@supports (height: 100dvh) {
  .modal {
    max-height: calc(100dvh - 32px);
  }

  @media (max-width: 540px) {
    .modal {
      max-height: calc(100dvh - 24px);
    }
  }
}

@media (max-width: 720px) {
  .page[class*="-page"] {
    display: block !important;
    gap: 0 !important;
    row-gap: 0 !important;
    column-gap: 0 !important;
  }

  .page[class*="-page"] > :is(.layout-two, .grid-two, .grid, .chart-grid, .kpi-grid, .recent-grid, .dashboard-status-grid, .digest-grid),
  .page[class*="-page"] > :is(div, section, article, main):has(> .card),
  .page[class*="-page"] > :is(div, section, article, main) > :is(div, section, article):has(> .card) {
    display: block !important;
    gap: 0 !important;
    row-gap: 0 !important;
    column-gap: 0 !important;
  }

}

/* ===== LOADING STATES ===== */
.loading-spinner {
  display: none !important;
  width: 0;
  height: 0;
}
.lazy-loading:not(.lazy-error) {
  opacity: 0.9;
}
.lazy-error {
  opacity: 1 !important;
  filter: grayscale(0.6);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
/* Image loading states */
.image-loading,
.image-loading::before,
.image-loading-overlay {
  display: none !important;
}
/* Cover loading states */
.cover-loading::after {
  content: '';
}
/* Gallery item loading */
.gallery-item-loading {
  background: var(--surface-muted);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4/3;
  border: 1px solid var(--border);
  flex-direction: column;
}
.gallery-item-loading .loading-spinner {
  margin-bottom: 4px;
}
.gallery-item-loading::after {
  content: 'Изображение';
  font-size: 11px;
  color: var(--muted);
}
/* Loading overlay */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
[data-theme="dark"] .loading-overlay {
  background: rgba(0, 0, 0, 0.6);
}
