:root {
  --sidebar-w: 264px;
  --font-main: "Segoe UI", Roboto, Arial, sans-serif;
  --font-menu: Inter, "Segoe UI", Roboto, Arial, sans-serif;

  --bg: #081120;
  --bg-2: #0c1730;
  --panel: rgba(16, 27, 51, .72);
  --panel-solid: #101b33;
  --panel-2: rgba(23, 38, 70, .7);
  --panel-soft: rgba(23, 38, 70, .7);
  --modal-panel: #0e1a2c;
  --modal-panel-soft: #111f34;
  --modal-field: #101d31;
  --modal-line: rgba(255, 255, 255, .1);
  --modal-backdrop: rgba(2, 7, 18, .72);
  --modal-shadow: 0 28px 70px rgba(0, 0, 0, .42);
  --text: #edf4ff;
  --muted: #9facbf;
  --muted-2: #74849a;
  --line: rgba(158, 180, 220, .18);
  --line-strong: rgba(170, 195, 240, .28);
  --field: rgba(7, 16, 33, .5);
  --field-focus: rgba(12, 26, 55, .76);
  --accent: #5b7cff;
  --accent-2: #8a6cff;
  --blue: #5b7cff;
  --blue-2: #8a6cff;
  --blue-soft: rgba(91, 124, 255, .16);
  --accent-soft: rgba(91, 124, 255, .16);
  --success: #45d483;
  --success-soft: rgba(69, 212, 131, .14);
  --danger: #ff6b86;
  --danger-soft: rgba(255, 107, 134, .14);
  --neutral-soft: rgba(155, 172, 204, .13);
  --shadow: 0 22px 70px rgba(0, 0, 0, .28);
  --shadow-soft: 0 14px 34px rgba(0, 0, 0, .18);
  --glow: 0 0 0 1px rgba(138, 108, 255, .08), 0 0 34px rgba(91, 124, 255, .14);
  --radius: 22px;
  --radius-sm: 14px;
  --radius-xl: 28px;
}

:root[data-theme="light"] {
  --bg: #eef3fb;
  --bg-2: #f7f9fd;
  --panel: rgba(255, 255, 255, .82);
  --panel-solid: #ffffff;
  --panel-2: rgba(245, 248, 253, .92);
  --panel-soft: rgba(245, 248, 253, .92);
  --modal-panel: #ffffff;
  --modal-panel-soft: #f8fbff;
  --modal-field: #ffffff;
  --modal-line: rgba(16, 24, 40, .1);
  --modal-backdrop: rgba(15, 23, 42, .36);
  --modal-shadow: 0 28px 70px rgba(16, 24, 40, .16);
  --text: #111827;
  --muted: #5d6b80;
  --muted-2: #8a98ad;
  --line: rgba(77, 96, 130, .16);
  --line-strong: rgba(77, 96, 130, .24);
  --field: rgba(255, 255, 255, .82);
  --field-focus: #ffffff;
  --accent: #315eea;
  --accent-2: #6b5cff;
  --blue: #315eea;
  --blue-2: #6b5cff;
  --blue-soft: rgba(49, 94, 234, .11);
  --accent-soft: rgba(49, 94, 234, .11);
  --success: #168a48;
  --success-soft: rgba(22, 138, 72, .1);
  --danger: #ce3652;
  --danger-soft: rgba(206, 54, 82, .1);
  --neutral-soft: rgba(79, 94, 124, .09);
  --shadow: 0 20px 54px rgba(31, 45, 75, .12);
  --shadow-soft: 0 10px 26px rgba(31, 45, 75, .08);
  --glow: 0 0 0 1px rgba(49, 94, 234, .06), 0 18px 46px rgba(49, 94, 234, .1);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  overflow-y: scroll;
  scrollbar-gutter: stable;
}

html.abs-scroll-locked {
  scrollbar-gutter: stable;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  font-family: var(--font-main);
  font-size: 14.5px;
  line-height: 1.6;
  background:
    radial-gradient(circle at 18% 10%, rgba(91, 124, 255, .22), transparent 30%),
    radial-gradient(circle at 78% 2%, rgba(138, 108, 255, .18), transparent 28%),
    linear-gradient(135deg, var(--bg) 0%, var(--bg-2) 48%, var(--bg) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 255, 255, .026) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .018) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.8), transparent 82%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

textarea {
  resize: vertical;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px 16px;
  color: #eef4ff;
  background: linear-gradient(180deg, rgba(11, 18, 39, .97), rgba(6, 11, 25, .98));
  border-right: 1px solid rgba(167, 190, 255, .12);
  box-shadow: 18px 0 58px rgba(0, 0, 0, .28);
  backdrop-filter: blur(22px);
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(150, 172, 255, .32) transparent;
}

.sidebar-main {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: none;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: .02em;
}

.brand strong {
  display: block;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

.brand span {
  display: block;
  margin-top: 2px;
  color: rgba(238, 244, 255, .58);
  font-size: 12px;
}

.side-nav {
  display: grid;
  gap: 7px;
}

.nav-item {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 15px;
  color: rgba(238, 244, 255, .72);
  background: transparent;
  font-family: var(--font-menu);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: .01em;
  text-align: left;
  transition: color .2s ease, background .2s ease, border-color .2s ease, transform .2s ease, box-shadow .2s ease;
}

.nav-item::before {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  flex: 0 0 22px;
  border-radius: 9px;
  color: rgba(238, 244, 255, .78);
  background: rgba(255, 255, 255, .06);
  font-size: 12px;
}

.nav-item[data-view="projects"]::before { content: "▦"; }
.nav-item[data-view="project-card"]::before { content: "◇"; }
.nav-item[data-view="stats"]::before { content: "▥"; }
.nav-item[data-view="reports"]::before { content: "≡"; }
.nav-item[data-view="site"]::before { content: "◎"; }
.nav-item[data-view="calculator"]::before { content: "∑"; }
.nav-item[data-view="settings"]::before { content: "⚙"; }
.nav-item[data-view="knowledge"]::before { content: "□"; }

.nav-item:hover {
  color: #fff;
  background: rgba(255, 255, 255, .07);
  border-color: rgba(255, 255, 255, .08);
  transform: translateX(3px);
}

.nav-item.active {
  color: #fff;
  background: linear-gradient(135deg, rgba(91, 124, 255, .24), rgba(138, 108, 255, .14));
  border-color: rgba(150, 172, 255, .28);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 14px 34px rgba(45, 80, 200, .14);
}

.nav-item.active::before {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 20px rgba(91, 124, 255, .38);
}

.sidebar-badge {
  min-width: 28px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  margin-left: auto;
  padding: 0 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 999px;
  box-shadow: 0 8px 22px rgba(91, 124, 255, .22);
  font-family: var(--font-menu);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
}

.sidebar-badge[hidden] {
  display: none;
}

.workspace {
  position: relative;
  width: 100%;
  margin-left: var(--sidebar-w);
  padding: 28px 30px 56px;
}

.project-page-head p,
.stats-page-head p {
  max-width: 760px;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: viewIn .18s ease-out both;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 18px;
}

.page-head h1 {
  max-width: 1040px;
  margin: 0 0 5px;
  color: var(--text);
  font-size: 28px;
  line-height: 1.18;
  font-weight: 600;
  letter-spacing: -.025em;
}

.page-head p,
.muted,
.card-subtitle,
.row-sub {
  color: var(--muted);
}

.page-head p,
.muted {
  margin: 0;
}

.card {
  position: relative;
  padding: 20px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
  transition: transform .22s ease, border-color .22s ease, box-shadow .22s ease, background .22s ease;
}

.card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow), var(--glow);
}

.card + .card {
  margin-top: 16px;
}

.card h2,
.card h3 {
  margin: 0 0 14px;
  color: var(--text);
  line-height: 1.25;
  letter-spacing: -.02em;
}

.card h2 {
  font-size: 21px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -.018em;
}

.card h3 {
  font-size: 16.5px;
  font-weight: 600;
  line-height: 1.32;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 14px;
}

.card-head h2,
.card-head h3 {
  margin: 0;
}

.card-subtitle {
  margin-top: 5px;
  font-size: 13px;
  line-height: 1.5;
}

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

.btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 15px;
  color: var(--text);
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: transform .18s ease, background .18s ease, border-color .18s ease, box-shadow .18s ease, color .18s ease;
}

.btn:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  box-shadow: 0 14px 32px rgba(0, 0, 0, .18), 0 0 26px rgba(91, 124, 255, .13);
}

.btn.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: rgba(170, 190, 255, .38);
}

.btn.soft,
.btn.ghost {
  background: var(--panel-2);
}

.btn.danger {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: rgba(255, 107, 134, .2);
}

.btn.small {
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 12px;
  font-size: 12px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 18px;
}

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

.input,
.field input,
.field select,
.field textarea,
.material-note,
.material-status {
  width: 100%;
  min-height: 46px;
  padding: 12px 13px;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .035);
  transition: background .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.field textarea,
.material-note {
  line-height: 1.5;
}

.input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus,
.material-note:focus,
.material-status:focus {
  background: var(--field-focus);
  border-color: rgba(117, 145, 255, .72);
  box-shadow: 0 0 0 4px rgba(91, 124, 255, .14);
}

.field span {
  display: block;
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.field.invalid input,
.field.invalid select,
.field.invalid textarea {
  border-color: rgba(255, 107, 134, .7);
  box-shadow: 0 0 0 4px rgba(255, 107, 134, .12);
}

.field-error {
  display: block;
  margin-top: 6px;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.35;
  font-weight: 500;
}

.form-grid,
.details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.field-wide,
.details-grid .field.wide {
  grid-column: 1 / -1;
}

.table-wrap {
  overflow: auto;
  background: rgba(255, 255, 255, .045);
  border: 1px solid var(--line);
  border-radius: 18px;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  background: rgba(255, 255, 255, .04);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .045em;
}

td {
  color: var(--text);
  font-size: 14px;
}

tr:last-child td {
  border-bottom: 0;
}

.project-row {
  cursor: pointer;
}

.project-row td {
  transition: background .16s ease;
}

.project-row:hover td {
  background: rgba(91, 124, 255, .07);
}

.row-title {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.project-pin-mark {
  margin-right: 7px;
  color: #6978e9;
  font-size: 9px;
  vertical-align: 2px;
}

.project-pin-button {
  color: #6474d9;
  background: rgba(99, 116, 234, .08);
  border-color: rgba(99, 116, 234, .15);
}

.project-pin-button.is-pinned {
  color: #fff;
  background: #6978e9;
  border-color: #6978e9;
}

.row-sub {
  margin-top: 3px;
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.badge.blue {
  color: #dbe5ff;
  background: rgba(91, 124, 255, .18);
  border-color: rgba(91, 124, 255, .22);
}

.badge.green {
  color: #c9f7dc;
  background: var(--success-soft);
  border-color: rgba(69, 212, 131, .2);
}

.badge.red {
  color: #ffd7df;
  background: var(--danger-soft);
  border-color: rgba(255, 107, 134, .22);
}

.badge.amber {
  color: #ffe9c7;
  background: rgba(232, 145, 35, .22);
  border-color: rgba(244, 164, 61, .36);
}

.badge.gray {
  color: var(--muted);
  background: rgba(110, 128, 151, .18);
  border-color: rgba(126, 145, 169, .3);
}

.badge.purple {
  color: #eee5ff;
  background: rgba(132, 91, 218, .22);
  border-color: rgba(147, 106, 232, .34);
}

:root[data-theme="light"] .badge.blue { color: #2446b7; }
:root[data-theme="light"] .badge.green { color: #12733d; }
:root[data-theme="light"] .badge.red { color: #a9253f; }
:root[data-theme="light"] .badge.amber { color: #8a4b08; }
:root[data-theme="light"] .badge.gray { color: #4d6075; }
:root[data-theme="light"] .badge.purple { color: #5f36a8; }

.empty {
  padding: 44px 18px;
  color: var(--muted);
  text-align: center;
}

.empty strong {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 18px;
}

.empty.compact {
  padding: 28px 12px;
}

.product-empty-state {
  min-height: 180px;
  padding: 34px 20px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}

.product-empty-state strong {
  color: var(--text);
  font-size: 17px;
}

.product-empty-state > span {
  max-width: 480px;
}

.product-empty-state > div {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
}

.product-empty-state button {
  min-height: 39px;
  padding: 0 13px;
  border-radius: 12px;
  font-weight: 650;
}

.product-empty-state button.is-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 0;
}

.product-empty-state button.is-secondary {
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--line);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: var(--modal-backdrop);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .18s ease, visibility 0s linear .18s;
}

.modal-backdrop.active,
.modal-backdrop.is-opening,
.modal-backdrop.is-closing {
  visibility: visible;
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
  transition: opacity .24s ease;
}

.modal-backdrop > .modal {
  opacity: 0;
  transform: translateY(6px) scale(.995);
  transition: opacity .2s ease, transform .24s cubic-bezier(.2, .75, .25, 1);
}

.modal-backdrop.active > .modal {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.modal-backdrop.is-closing {
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}

.modal-backdrop.is-closing > .modal {
  opacity: 0;
  transform: translateY(5px) scale(.995);
  transition-duration: .18s;
}

.modal,
.abs-modal {
  position: relative;
  width: min(780px, 100%);
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
  color: var(--text);
  background: var(--modal-panel);
  border: 1px solid var(--modal-line);
  border-radius: var(--radius-xl);
  box-shadow: var(--modal-shadow), 0 0 0 1px rgba(255, 255, 255, .04) inset;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.modal h2,
.modal-title {
  margin: 0;
  color: var(--text);
  font-size: 25px;
  font-weight: 600;
  line-height: 1.18;
  letter-spacing: -.025em;
}

.modal-header,
.file-preview-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin: 0;
  padding: 26px 28px 16px;
  border-bottom: 1px solid var(--modal-line);
  background: var(--modal-panel);
}

.modal-title-group {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.modal-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--blue-2));
  border-radius: 16px;
  box-shadow: 0 12px 26px rgba(91, 124, 255, .24);
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
}

.modal-title-group > div:last-child {
  min-width: 0;
}

.modal-subtitle,
.modal-header .muted,
.file-preview-head .muted {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.modal-body {
  min-height: 0;
  overflow: auto;
  padding: 22px 28px;
  background: var(--modal-panel);
}

.modal-close {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: var(--text);
  background: var(--modal-panel-soft);
  border: 1px solid var(--modal-line);
  border-radius: 15px;
  font-size: 24px;
  line-height: 1;
  transition: transform .16s ease, background .16s ease, border-color .16s ease, box-shadow .16s ease;
}

.modal-close:hover {
  transform: translateY(-1px);
  background: var(--accent-soft);
  border-color: rgba(91, 124, 255, .28);
  box-shadow: 0 0 0 4px var(--blue-soft);
}

.project-create-modal {
  width: min(840px, 100%);
}

.abs-modal.compact {
  max-width: 900px;
}

.abs-modal.wide {
  max-width: 1120px;
}

.project-modal-form {
  margin-top: 0;
}

.project-modal-form .field {
  display: grid;
  gap: 7px;
}

.project-modal-form .modal-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.project-modal-form .field:first-child,
.project-modal-form .field-wide {
  grid-column: 1 / -1;
}

.project-modal-form .field span {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}

.project-modal-form .field input,
.project-modal-form .field select,
.project-modal-form .field textarea {
  min-height: 46px;
  padding: 13px 15px;
  background: var(--modal-field);
  border-color: var(--modal-line);
  border-radius: 16px;
}

.project-modal-form .field input::placeholder,
.project-modal-form .field textarea::placeholder {
  color: var(--muted-2);
}

.project-modal-form textarea[name="comment"] {
  min-height: 112px;
}

.abs-modal .btn {
  min-height: 42px;
  border-radius: 15px;
  font-weight: 600;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  margin: 0;
  padding: 0;
  border-top: 0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 18px 28px 28px;
  border-top: 1px solid var(--modal-line);
  background: var(--modal-panel-soft);
}

.modal-footer .btn {
  min-width: 132px;
}

.file-preview-modal {
  width: min(1120px, 100%);
}

.file-preview-mark {
  font-size: 12px;
  letter-spacing: .02em;
}

.file-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.file-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  color: var(--blue);
  background: var(--blue-soft);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.file-preview-actions {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex: 0 0 auto;
}

.preview-zone,
.file-preview-body {
  min-height: 560px;
  max-height: 64vh;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 16px;
  background:
    linear-gradient(180deg, rgba(91, 124, 255, .055), transparent),
    var(--modal-panel-soft);
  border: 1px solid var(--modal-line);
  border-radius: 22px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .035);
}

.preview-paper {
  width: 100%;
  min-height: 520px;
  align-self: stretch;
  justify-self: stretch;
  overflow: auto;
  padding: 24px 28px;
  color: var(--text);
  background: var(--modal-panel);
  border: 1px solid var(--modal-line);
  border-radius: 18px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06);
}

.preview-paper-media {
  display: grid;
  place-items: center;
  padding: 0;
}

.file-preview-frame {
  width: 100%;
  height: min(64vh, 720px);
  min-height: 520px;
  border: 0;
  border-radius: inherit;
}

.file-preview-image,
.file-preview-video {
  max-width: 100%;
  max-height: min(64vh, 720px);
  border-radius: 16px;
}

.file-preview-video {
  width: 100%;
}

.file-preview-text {
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: auto;
  color: var(--text);
  font: 13px/1.55 Consolas, "SFMono-Regular", Menlo, monospace;
  text-align: left;
  white-space: pre-wrap;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.file-preview-empty {
  width: min(420px, 100%);
  display: grid;
  gap: 8px;
  justify-items: center;
  padding: 34px 24px;
  color: var(--muted);
  background: var(--modal-panel);
  border: 1px dashed var(--modal-line);
  border-radius: 18px;
  text-align: center;
}

.file-preview-empty strong {
  color: var(--text);
}

.preview-zone::-webkit-scrollbar,
.preview-paper::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.preview-zone::-webkit-scrollbar-thumb,
.preview-paper::-webkit-scrollbar-thumb {
  background: rgba(159, 172, 191, .45);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
}

.project-command-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.command-card {
  min-height: 128px;
  display: grid;
  align-content: space-between;
  gap: 10px;
  padding: 18px;
  color: var(--text);
  background: linear-gradient(180deg, rgba(255,255,255,.075), rgba(255,255,255,.04));
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}

button.command-card {
  width: 100%;
  font-family: inherit;
  text-align: left;
}

.command-payment-card {
  cursor: pointer;
}

.command-payment-card:focus-visible {
  outline: 3px solid rgba(99, 116, 234, .22);
  outline-offset: 3px;
}

.command-card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  box-shadow: var(--shadow), var(--glow);
}

.command-card.accent,
.project-status-card {
  background:
    radial-gradient(circle at 88% 8%, rgba(138,108,255,.26), transparent 38%),
    linear-gradient(135deg, rgba(91,124,255,.24), rgba(255,255,255,.045));
  border-color: rgba(120, 145, 255, .32);
}

.project-status-card {
  --status-rgb: 91, 124, 255;
  background:
    radial-gradient(circle at 84% 8%, rgba(var(--status-rgb), .34), transparent 38%),
    linear-gradient(135deg, rgba(var(--status-rgb), .22), rgba(255,255,255,.045));
  border-color: rgba(var(--status-rgb), .34);
  box-shadow: var(--shadow-soft), 0 0 34px rgba(var(--status-rgb), .13);
}

.project-status-card[data-status="preparing"] { --status-rgb: 68, 151, 255; }
.project-status-card[data-status="launch"] { --status-rgb: 138, 108, 255; }
.project-status-card[data-status="active"] { --status-rgb: 69, 212, 131; }
.project-status-card[data-status="brief"] { --status-rgb: 88, 128, 255; }
.project-status-card[data-status="renewal"] { --status-rgb: 34, 197, 204; }
.project-status-card[data-status="conditional_refusal"] { --status-rgb: 245, 150, 68; }
.project-status-card[data-status="refusal"] { --status-rgb: 255, 107, 134; }
.project-status-card[data-status="archive"] { --status-rgb: 148, 163, 184; }

.command-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.command-card strong {
  color: var(--text);
  font-size: 26px;
  line-height: 1.08;
  letter-spacing: -.035em;
  font-weight: 600;
}

.command-card small {
  color: var(--muted);
  font-size: 13px;
}

.project-workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(340px, .75fr);
  grid-template-areas:
    "info stages"
    "materials materials"
    "files files"
    "calculations calculations"
    "api api";
  gap: 18px;
  align-items: start;
}

.project-info-card { grid-area: info; }
.project-stages-card { grid-area: stages; }
.project-materials-card { grid-area: materials; }
.project-files-card { grid-area: files; }
.project-api-card { grid-area: api; }
.saved-calculations-card { grid-area: calculations; }

.project-workspace-grid > .card {
  min-height: 0;
  margin-top: 0;
}

.project-main,
.project-aside {
  display: grid;
  gap: 18px;
}

.project-stages-card {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-top: 0;
  background:
    radial-gradient(circle at 85% 0%, rgba(91, 124, 255, .2), transparent 34%),
    var(--panel);
}

.project-stages-card .card-head {
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.project-stages-card .card-head > div {
  min-width: 0;
}

.project-stages-card #toggleAllStages {
  min-width: 142px;
  flex: 0 0 auto;
  padding-right: 12px;
  padding-left: 12px;
  white-space: nowrap;
}

.project-stages-card .stage-list {
  min-height: 0;
  max-height: none;
  flex: 1 1 auto;
  overflow: auto;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(120, 145, 210, .45) transparent;
}

.stage-progress {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.stage-progress div {
  height: 10px;
  overflow: hidden;
  background: rgba(255,255,255,.075);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.stage-progress span {
  display: block;
  height: 100%;
  min-width: 8px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: inherit;
  box-shadow: 0 0 20px rgba(91,124,255,.28);
  transition: width .42s cubic-bezier(.2, .8, .2, 1);
}

.stage-progress strong {
  color: var(--text);
  font-size: 13px;
}

.stage-list,
.files-list,
.knowledge-list,
.kpi-list {
  display: grid;
  gap: 10px;
}

.stage-item {
  max-height: 180px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: flex-start;
  padding: 13px;
  color: var(--text);
  background: rgba(255, 255, 255, .055);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  transition: max-height .18s ease, padding .18s ease, opacity .18s ease, transform .18s ease, background-color .42s ease, border-color .18s ease;
}

.stage-item input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.stage-checkbox-ui {
  width: 23px;
  height: 23px;
  margin-top: 1px;
  display: grid;
  place-items: center;
  color: transparent;
  background: rgba(255, 255, 255, .18);
  border: 1.5px solid rgba(106, 126, 146, .52);
  border-radius: 7px;
  transition: color .18s ease, background .18s ease, border-color .18s ease, transform .18s ease;
}

.stage-checkbox-ui svg {
  width: 14px;
  height: 14px;
}

.abs-checkmark {
  display: block;
  flex: 0 0 auto;
  overflow: visible;
  pointer-events: none;
  transform: none !important;
  transform-origin: 12px 12px;
}

.stage-checkbox-ui path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 25;
  stroke-dashoffset: 25;
  transition: stroke-dashoffset .42s cubic-bezier(.2, .8, .2, 1);
}

.stage-item input:checked + .stage-checkbox-ui {
  color: #fff;
  background: #10b981;
  border-color: #10b981;
  transform: scale(1.04);
}

.stage-item input:checked + .stage-checkbox-ui path {
  stroke-dashoffset: 0;
}

.stage-item input:focus-visible + .stage-checkbox-ui {
  outline: 3px solid rgba(16, 185, 129, .22);
  outline-offset: 2px;
}

.stage-item.is-completing {
  background: rgba(16, 185, 129, .13);
  pointer-events: none;
}

.stage-item.is-collapsing {
  max-height: 0;
  padding-block: 0;
  opacity: 0;
  transform: translateY(-3px) scale(.995);
}

.stage-item-copy {
  min-width: 0;
}

.stage-item:hover {
  transform: translateY(-1px);
  background: rgba(91, 124, 255, .08);
  border-color: var(--line-strong);
}

.stage-item.completed {
  background: var(--success-soft);
  border-color: rgba(69, 212, 131, .2);
}

input[type="checkbox"] {
  accent-color: var(--accent);
}

.project-task-count {
  min-width: 34px;
  min-height: 30px;
  display: inline-grid;
  place-items: center;
  padding: 0 10px;
  color: #137a51;
  background: rgba(16, 185, 129, .11);
  border: 1px solid rgba(16, 185, 129, .2);
  border-radius: 10px;
  font-weight: 750;
}

@media (prefers-reduced-motion: reduce) {
  .stage-item,
  .stage-checkbox-ui,
  .stage-checkbox-ui path {
    transition: none;
  }
}

select option {
  color: #111827;
  background: #ffffff;
}

.stage-item strong {
  display: block;
  margin-bottom: 4px;
}

.stage-item small {
  color: var(--muted);
  line-height: 1.45;
}

.comment-box {
  min-height: 160px;
}

.materials-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
}

.material-card {
  display: grid;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  border-radius: 16px;
  transition: border-color .22s ease, background-color .22s ease, opacity .18s ease;
}

.material-card:hover {
  border-color: var(--line-strong);
}

.material-card[aria-busy="true"] {
  opacity: .76;
}

.material-card.received {
  background: var(--success-soft);
  border-color: rgba(69, 212, 131, .24);
}

.material-card.waiting {
  background: rgba(91, 124, 255, .1);
  border-color: rgba(91, 124, 255, .18);
}

.material-card.unspecified {
  background: rgba(255, 255, 255, .045);
}

.material-check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-weight: 500;
}

.material-check span {
  flex: 1;
}

.material-status {
  width: 132px;
  min-height: 32px;
  padding: 5px 8px;
  font-size: 12px;
}

.files-dropzone {
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px 24px;
  color: var(--muted);
  background: rgba(91, 124, 255, .065);
  border: 1.5px dashed rgba(91, 124, 255, .38);
  border-radius: 20px;
  text-align: center;
  transition: background .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.files-dropzone.has-files {
  display: block;
  padding: 12px;
  text-align: left;
}

.files-dropzone.is-dragover {
  background: rgba(91, 124, 255, .14);
  border-color: rgba(91, 124, 255, .72);
  box-shadow: 0 0 0 4px rgba(91, 124, 255, .12);
}

.files-empty-state {
  max-width: 620px;
  margin: 0 auto;
}

.files-empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.55;
}

.file-row,
.knowledge-item,
.kpi-card,
.result-box,
.saved-calc-card {
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.file-row,
.knowledge-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 12px;
}

.file-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  padding: 10px 11px;
}

.file-main {
  min-width: 0;
}

.file-type-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 13px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
}

.file-row strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-row span {
  color: var(--muted);
  font-size: 12px;
}

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

.api-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.api-summary-item {
  min-width: 0;
  padding: 12px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.api-summary-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.api-summary-item strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.api-actions {
  margin-top: 14px;
}

.accordion-body {
  display: block;
  max-height: 0;
  overflow: hidden;
  padding-top: 0;
  opacity: 0;
  transition: max-height .28s ease, opacity .22s ease, padding-top .22s ease;
}

.accordion.open .accordion-body {
  max-height: 920px;
  padding-top: 14px;
  opacity: 1;
}

.reminder {
  margin-bottom: 18px;
  padding: 14px 16px;
  color: #dbe5ff;
  background: rgba(91, 124, 255, .12);
  border: 1px solid rgba(91, 124, 255, .22);
  border-radius: 16px;
  line-height: 1.45;
}

:root[data-theme="light"] .reminder {
  color: #2446b7;
}

.dark-note {
  padding: 18px;
  color: var(--text);
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  border-radius: 18px;
  line-height: 1.6;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.tab-btn,
.metric-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  background: rgba(255, 255, 255, .055);
  border: 1px solid var(--line);
  border-radius: 999px;
  user-select: none;
  transition: background .18s ease, color .18s ease, border-color .18s ease;
}

.tab-btn {
  padding: 9px 13px;
  font-weight: 600;
}

.metric-chip {
  padding: 8px 11px;
  font-size: 13px;
}

.tab-btn.active,
.metric-chip:has(input:checked) {
  color: var(--text);
  background: var(--accent-soft);
  border-color: rgba(91, 124, 255, .28);
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
  animation: viewIn .2s ease both;
}

.calculator-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(340px, .65fr);
  gap: 18px;
  align-items: start;
}

.result-grid,
.saved-calc-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.result-box {
  padding: 14px;
}

.result-box strong {
  display: block;
  color: var(--text);
  font-size: 26px;
  line-height: 1.15;
  letter-spacing: -.025em;
  font-weight: 600;
}

.result-box span {
  color: var(--muted);
  font-size: 13px;
}

.saved-calculations-card {
  grid-column: 1 / -1;
}

.saved-work-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.saved-work-grid {
  display: grid;
  grid-template-columns: minmax(260px, .72fr) minmax(0, 1.28fr);
  gap: 14px;
  margin-top: 14px;
}

.saved-work-section {
  min-width: 0;
  padding: 14px;
  background: rgba(255, 255, 255, .035);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.saved-work-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.saved-work-head h3 {
  margin: 0;
  font-size: 16.5px;
  font-weight: 600;
  line-height: 1.32;
}

.saved-work-head span {
  min-width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: rgba(255, 255, 255, .045);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.saved-work-list {
  display: grid;
  gap: 10px;
}

.saved-work-empty {
  min-height: 112px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 16px;
  color: var(--muted);
  background: rgba(255, 255, 255, .04);
  border: 1px dashed var(--line);
  border-radius: 14px;
}

.saved-work-empty strong {
  color: var(--text);
  font-size: 14.5px;
  font-weight: 600;
}

.saved-work-empty span {
  font-size: 13px;
}

.saved-report-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 13px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.saved-report-card strong,
.saved-report-card span {
  display: block;
}

.saved-report-card strong {
  color: var(--text);
  font-size: 14.5px;
  font-weight: 600;
}

.saved-report-card span {
  color: var(--muted);
  font-size: 12px;
}

.saved-calc-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.saved-work-section .saved-calc-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.saved-calc-card {
  padding: 13px;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.saved-calc-card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-soft);
}

.saved-calc-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}

.saved-calc-head strong {
  font-size: 15px;
}

.saved-calc-head span,
.saved-calc-metrics span {
  color: var(--muted);
  font-size: 12px;
}

.saved-calc-head span {
  white-space: nowrap;
}

.saved-calc-metrics div {
  padding: 9px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.saved-calc-metrics span {
  display: block;
  margin-bottom: 4px;
}

.saved-calc-metrics strong {
  font-size: 14px;
}

.theme-switch {
  display: inline-flex;
  gap: 6px;
  padding: 6px;
  background: rgba(255, 255, 255, .055);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.theme-option {
  min-height: 38px;
  padding: 9px 14px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 12px;
  font-weight: 600;
  transition: color .18s ease, background .18s ease, box-shadow .18s ease;
}

.theme-option:hover {
  color: var(--text);
  background: rgba(255, 255, 255, .06);
}

.theme-option.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 12px 30px rgba(91, 124, 255, .22);
}

.settings-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 12px 14px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
}

.settings-toggle + .settings-toggle {
  margin-top: 10px;
}

.settings-toggle input {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

.settings-toggle span {
  min-width: 0;
  font-size: 14.5px;
  font-weight: 500;
  line-height: 1.45;
}

.mobile-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: 64px;
  display: none;
  align-items: center;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  color: #fff;
  background: rgba(7, 12, 28, .86);
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  backdrop-filter: blur(20px);
}

.mobile-topbar span {
  display: block;
  color: rgba(238, 244, 255, .62);
  font-size: 12px;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: none;
  background: rgba(2, 7, 18, .58);
  backdrop-filter: blur(4px);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

@keyframes viewIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(6px) scale(.995);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

@media (max-width: 1280px) {
  .project-command-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .saved-calc-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1100px) {
  .project-workspace-grid,
  .calculator-grid {
    grid-template-columns: 1fr;
  }

  .project-workspace-grid {
    grid-template-areas:
      "info"
      "stages"
      "materials"
      "files"
      "calculations"
      "api";
  }

  .project-stages-card {
    height: auto !important;
    position: static;
  }

  .project-stages-card .stage-list {
    max-height: none !important;
  }

  .api-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .saved-work-grid {
    grid-template-columns: 1fr;
  }

}

@media (max-width: 980px) {
  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  body.menu-open {
    overflow: hidden;
  }

  .mobile-topbar {
    display: flex;
  }

  .sidebar {
    width: min(86vw, 320px);
    transform: translateX(-110%);
    transition: transform .24s cubic-bezier(.2, .8, .2, 1);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop.active {
    display: block;
  }

  .workspace {
    margin-left: 0;
    padding: 18px 12px 38px;
  }

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

  .page-head h1 {
    font-size: 24px;
  }

  .filters,
  .project-command-grid,
  .form-grid,
  .details-grid,
  .saved-work-section .saved-calc-grid,
  .saved-calc-grid,
  .saved-calc-metrics,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .saved-work-badges {
    justify-content: flex-start;
  }

  .field-wide,
  .details-grid .field.wide {
    grid-column: auto;
  }

  .modal {
    padding: 0;
    border-radius: 24px;
  }

  .modal-header,
  .file-preview-head {
    flex-direction: column;
    gap: 12px;
    padding: 20px 18px 14px;
  }

  .project-create-modal .modal-header .modal-close {
    position: absolute;
    top: 18px;
    right: 18px;
  }

  .project-create-modal .modal-title-group {
    padding-right: 48px;
  }

  .modal-mark {
    width: 36px;
    height: 36px;
    border-radius: 13px;
  }

  .modal-title {
    font-size: 21px;
  }

  .modal-body {
    padding: 0 18px 18px;
  }

  .project-modal-form .modal-body {
    grid-template-columns: 1fr;
    gap: 13px;
  }

  .modal-footer {
    flex-direction: column;
    padding: 16px 18px 20px;
  }

  .file-preview-actions {
    width: 100%;
    align-items: center;
  }

  .file-preview-actions .btn {
    flex: 1 1 auto;
  }

  .actions,
  .modal-actions {
    width: 100%;
  }

  .actions .btn,
  .modal-actions .btn,
  .modal-footer .btn {
    flex: 1 1 auto;
  }

  .api-summary-grid {
    grid-template-columns: 1fr;
  }

  .file-row {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .file-actions {
    grid-column: 1 / -1;
    justify-content: stretch;
  }

  .file-actions .btn {
    flex: 1 1 96px;
  }

  .file-preview-body {
    min-height: 420px;
    max-height: 64vh;
    padding: 10px;
  }

  .preview-paper {
    min-height: 380px;
    padding: 18px;
  }

  .file-preview-frame {
    min-height: 380px;
    height: 64vh;
  }

  .theme-switch {
    width: 100%;
  }

  .theme-option {
    flex: 1;
  }
}

/* Avito statistics dashboard */
#view-stats.active {
  min-height: calc(100vh - 84px);
}

.stats-v6 {
  --stats-bg: var(--bg);
  --stats-panel: var(--panel);
  --stats-panel-2: var(--panel-2);
  --stats-text: var(--text);
  --stats-muted: var(--muted);
  --stats-muted-2: color-mix(in srgb, var(--muted) 74%, transparent);
  --stats-line: var(--line);
  --stats-blue: var(--accent);
  --stats-blue-soft: var(--accent-soft);
  --stats-violet: var(--accent-2);
  --stats-violet-soft: rgba(138, 108, 255, .14);
  --stats-green: var(--success);
  --stats-green-soft: var(--success-soft);
  --stats-red: var(--danger);
  --stats-red-soft: var(--danger-soft);
  --stats-progress-bg: var(--panel-2);
  --stats-shadow: var(--shadow);
  --stats-shadow-soft: var(--shadow-soft);
  min-height: calc(100vh - 84px);
  padding: 2px;
  color: var(--stats-text);
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.6;
  background:
    radial-gradient(circle at 14% 0%, rgba(59, 109, 246, .09), transparent 28%),
    radial-gradient(circle at 88% 8%, rgba(120, 87, 255, .06), transparent 26%),
    var(--stats-bg);
  border-radius: 24px;
}

:root[data-theme="light"] .stats-v6 {
  --stats-bg: #f3f6fb;
  --stats-panel: rgba(255, 255, 255, .9);
  --stats-panel-2: rgba(248, 250, 252, .95);
  --stats-text: #101828;
  --stats-muted: #667085;
  --stats-muted-2: #98a2b3;
  --stats-line: rgba(16, 24, 40, .09);
  --stats-blue: #3b6df6;
  --stats-blue-soft: rgba(59, 109, 246, .1);
  --stats-violet: #7857ff;
  --stats-violet-soft: rgba(120, 87, 255, .1);
  --stats-green: #12a36b;
  --stats-green-soft: rgba(18, 163, 107, .1);
  --stats-red: #d92d20;
  --stats-red-soft: rgba(217, 45, 32, .1);
  --stats-progress-bg: #e7ecf5;
  --stats-shadow: 0 14px 34px rgba(16, 24, 40, .07);
  --stats-shadow-soft: 0 8px 22px rgba(16, 24, 40, .05);
  color-scheme: light;
}

:root[data-theme="dark"] .stats-v6 {
  --stats-bg: #081120;
  --stats-panel: rgba(16, 27, 51, .72);
  --stats-panel-2: rgba(23, 38, 70, .7);
  --stats-text: #edf4ff;
  --stats-muted: #9facbf;
  --stats-muted-2: #7f8da3;
  --stats-line: rgba(158, 180, 220, .18);
  --stats-blue: #5b7cff;
  --stats-blue-soft: rgba(91, 124, 255, .16);
  --stats-violet: #8a6cff;
  --stats-violet-soft: rgba(138, 108, 255, .16);
  --stats-green: #45d483;
  --stats-green-soft: rgba(69, 212, 131, .14);
  --stats-red: #ff6b86;
  --stats-red-soft: rgba(255, 107, 134, .14);
  --stats-progress-bg: rgba(255, 255, 255, .07);
  --stats-shadow: 0 22px 70px rgba(0, 0, 0, .28);
  --stats-shadow-soft: 0 14px 34px rgba(0, 0, 0, .18);
  color-scheme: dark;
}

.stats-v6 * {
  box-sizing: border-box;
}

.stats-v6 h1,
.stats-v6 h2,
.stats-v6 h3,
.stats-v6 p {
  margin: 0;
}

.stats-v6 h1 {
  color: var(--stats-text);
  font-size: 28px;
  line-height: 1.18;
  font-weight: 600;
  letter-spacing: 0;
}

.stats-v6 h2 {
  color: var(--stats-text);
  font-size: 21px;
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: 0;
}

.stats-v6 h3 {
  color: var(--stats-text);
  font-size: 16.5px;
  line-height: 1.32;
  font-weight: 600;
  letter-spacing: 0;
}

.stats-v6 p,
.stats-v6-muted {
  color: var(--stats-muted);
  font-size: 13px;
}

.stats-v6-topbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(520px, auto);
  gap: 18px;
  align-items: end;
  padding: 18px 18px 14px;
}

.stats-v6-title-wrap {
  min-width: 0;
}

.stats-v6-title-wrap p {
  margin-top: 5px;
}

.stats-v6-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
  color: var(--stats-muted);
  font-size: 12px;
  font-weight: 500;
}

.stats-v6-eyebrow span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--stats-green);
  box-shadow: 0 0 0 5px var(--stats-green-soft);
}

.stats-v6-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: end;
  gap: 8px;
}

.stats-v6-field {
  display: grid;
  gap: 5px;
}

.stats-v6-field span {
  color: var(--stats-muted);
  font-size: 12px;
  font-weight: 500;
}

.stats-v6-field select,
.stats-v6-field input {
  min-height: 38px;
  width: 100%;
  min-width: 134px;
  padding: 8px 11px;
  color: var(--stats-text);
  background: var(--stats-panel);
  border: 1px solid var(--stats-line);
  border-radius: 13px;
  outline: none;
  box-shadow: var(--stats-shadow-soft);
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

.stats-v6-field select:focus,
.stats-v6-field input:focus {
  border-color: rgba(59, 109, 246, .48);
  box-shadow: 0 0 0 4px rgba(59, 109, 246, .11), var(--stats-shadow-soft);
}

.stats-v6-field:first-child select {
  min-width: 210px;
}

.stats-v6-custom.is-hidden {
  display: none;
}

.stats-v6-btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 13px;
  color: var(--stats-text);
  background: var(--stats-panel);
  border: 1px solid var(--stats-line);
  border-radius: 13px;
  box-shadow: var(--stats-shadow-soft);
  font-size: 14px;
  font-weight: 500;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease, color .16s ease, background .16s ease;
}

.stats-v6-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(59, 109, 246, .34);
  box-shadow: var(--stats-shadow);
}

.stats-v6-btn.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--stats-blue), var(--stats-violet));
  border-color: rgba(59, 109, 246, .38);
}

.stats-v6-dashboard {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 14px;
  align-items: start;
  padding: 0 18px 18px;
}

.stats-v6-stack,
.stats-v6-right-stack {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.stats-v6-card {
  min-width: 0;
  color: var(--stats-text);
  background: var(--stats-panel);
  border: 1px solid var(--stats-line);
  border-radius: 18px;
  box-shadow: var(--stats-shadow-soft);
  backdrop-filter: blur(14px);
}

.stats-v6-card:hover {
  border-color: rgba(59, 109, 246, .18);
  box-shadow: var(--stats-shadow);
}

.stats-v6-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.stats-v6-card-head p {
  margin-top: 4px;
}

.stats-v6-hero-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.stats-v6-hero-card {
  padding: 16px;
}

.stats-v6-big-number {
  margin-top: 18px;
  color: var(--stats-text);
  font-size: 28px;
  line-height: 1.05;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stats-v6-mini-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.stats-v6-tag,
.stats-v6-delta,
.stats-v6-count,
.stats-v6-project-top b {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.25;
  font-weight: 500;
  white-space: nowrap;
}

.stats-v6-tag.is-good,
.stats-v6-delta.is-good,
.stats-v6-project-top b.is-good {
  color: var(--stats-green);
  background: var(--stats-green-soft);
}

.stats-v6-tag.is-blue {
  color: var(--stats-blue);
  background: var(--stats-blue-soft);
}

.stats-v6-tag.is-violet {
  color: var(--stats-violet);
  background: var(--stats-violet-soft);
}

.stats-v6-delta.is-bad,
.stats-v6-project-top b.is-bad {
  color: var(--stats-red);
  background: var(--stats-red-soft);
}

.stats-v6-delta.is-flat,
.stats-v6-project-top b.is-flat {
  color: var(--stats-muted);
  background: rgba(102, 112, 133, .1);
}

.stats-v6-progress {
  height: 8px;
  margin-top: 15px;
  overflow: hidden;
  background: var(--stats-progress-bg);
  border-radius: 999px;
}

.stats-v6-progress span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--stats-blue), var(--stats-violet));
  border-radius: inherit;
  transition: width .24s ease;
}

.stats-v6-split,
.stats-v6-result-line,
.stats-v6-chart-foot,
.stats-v6-project-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  color: var(--stats-muted);
  font-size: 13px;
}

.stats-v6-split strong,
.stats-v6-result-line strong,
.stats-v6-chart-foot strong,
.stats-v6-project-foot span:first-child {
  color: var(--stats-text);
  font-weight: 600;
}

.stats-v6-kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.stats-v6-kpi {
  min-height: 128px;
  display: grid;
  gap: 12px;
  align-content: space-between;
  padding: 14px;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}

.stats-v6-kpi:hover,
.stats-v6-project:hover {
  transform: translateY(-2px);
}

.stats-v6-kpi-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.stats-v6-kpi-top span {
  color: var(--stats-muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .035em;
}

.stats-v6-kpi-top i {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  flex: 0 0 28px;
  color: var(--stats-blue);
  background: var(--stats-blue-soft);
  border-radius: 10px;
  font-size: 13px;
  font-style: normal;
  font-weight: 600;
}

.stats-v6-kpi strong {
  color: var(--stats-text);
  font-size: 26px;
  line-height: 1.08;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stats-v6-kpi-bottom {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.stats-v6-kpi-bottom small {
  min-width: 0;
  color: var(--stats-muted);
  font-size: 13px;
  line-height: 1.35;
}

.stats-v6-kpi-bottom b {
  color: var(--stats-muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.stats-v6-kpi-bottom b.is-good {
  color: var(--stats-green);
}

.stats-v6-kpi-bottom b.is-bad {
  color: var(--stats-red);
}

.stats-v6-mid-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(250px, .65fr);
  gap: 14px;
  align-items: stretch;
}

.stats-v6-chart-card,
.stats-v6-source-card,
.stats-v6-projects-card,
.stats-v6-balance-card,
.stats-v6-metric-picker {
  padding: 15px 16px;
}

.stats-v6-segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--stats-panel-2);
  border: 1px solid var(--stats-line);
  border-radius: 13px;
}

.stats-v6-segmented button {
  min-height: 28px;
  padding: 4px 9px;
  color: var(--stats-muted);
  background: transparent;
  border: 0;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
}

.stats-v6-segmented button.active {
  color: #fff;
  background: var(--stats-blue);
}

.stats-v6-chart {
  width: 100%;
  height: 240px;
  display: block;
  margin-top: 10px;
}

.stats-v6-grid line {
  stroke: var(--stats-line);
  stroke-dasharray: 5 7;
}

.stats-v6-chart-area {
  fill: url(#statsV6Area);
}

.stats-v6-chart-line {
  fill: none;
  stroke: var(--stats-blue);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stats-v6-chart-dot {
  fill: var(--stats-panel);
  stroke: var(--stats-blue);
  stroke-width: 4;
}

.stats-v6-chart-labels text {
  fill: var(--stats-muted-2);
  font-size: 11px;
}

.stats-v6-channel-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.stats-v6-channel {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.stats-v6-channel-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: var(--stats-blue);
  background: var(--stats-blue-soft);
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
}

.stats-v6-channel strong {
  display: block;
  color: var(--stats-text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
}

.stats-v6-channel span {
  color: var(--stats-muted);
  font-size: 13px;
}

.stats-v6-channel-bar {
  grid-column: 2;
  height: 6px;
  overflow: hidden;
  background: var(--stats-progress-bg);
  border-radius: 999px;
}

.stats-v6-channel-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--stats-blue), var(--stats-violet));
  border-radius: inherit;
}

.stats-v6-project-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.stats-v6-project {
  min-width: 0;
  padding: 14px;
  color: var(--stats-text);
  background: var(--stats-panel);
  border: 1px solid var(--stats-line);
  border-radius: 18px;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}

.stats-v6-project:hover,
.stats-v6-project:focus-visible {
  border-color: rgba(59, 109, 246, .28);
  box-shadow: var(--stats-shadow);
  outline: none;
}

.stats-v6-project-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.stats-v6-project-top strong {
  display: block;
  color: var(--stats-text);
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.28;
}

.stats-v6-project-top span {
  display: block;
  margin-top: 3px;
  color: var(--stats-muted);
  font-size: 12px;
  line-height: 1.35;
}

.stats-v6-project-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.stats-v6-project-metrics span {
  min-width: 0;
  padding: 8px;
  color: var(--stats-muted);
  background: var(--stats-panel-2);
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.3;
}

.stats-v6-project-metrics b {
  display: block;
  color: var(--stats-text);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stats-v6-balance-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.stats-v6-balance-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid var(--stats-line);
}

.stats-v6-balance-row:last-child {
  border-bottom: 0;
}

.stats-v6-balance-row strong,
.stats-v6-balance-row b {
  display: block;
  color: var(--stats-text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}

.stats-v6-balance-row span {
  display: block;
  margin-top: 3px;
  color: var(--stats-muted);
  font-size: 12px;
  line-height: 1.35;
}

.stats-v6-balance-row > div:last-child {
  text-align: right;
}

.stats-v6-toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.stats-v6-toggle {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 8px 9px;
  color: var(--stats-muted);
  background: var(--stats-panel-2);
  border: 1px solid var(--stats-line);
  border-radius: 13px;
  font-size: 12px;
  font-weight: 500;
  user-select: none;
  transition: border-color .16s ease, background .16s ease, color .16s ease;
}

.stats-v6-toggle:has(input:checked) {
  color: var(--stats-blue);
  background: var(--stats-blue-soft);
  border-color: rgba(59, 109, 246, .24);
}

.stats-v6-toggle input {
  width: 15px;
  height: 15px;
  accent-color: var(--stats-blue);
  flex: 0 0 auto;
}

.stats-v6-toggle span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-v6-empty {
  display: grid;
  place-items: center;
  min-height: 140px;
  padding: 20px;
  color: var(--stats-muted);
  text-align: center;
  font-size: 14px;
}

.stats-v6-empty.compact {
  min-height: 76px;
  padding: 12px;
}

@media (max-width: 1320px) {
  .stats-v6-dashboard {
    grid-template-columns: minmax(0, 1fr) 300px;
  }

  .stats-v6-project-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1160px) {
  .stats-v6-topbar,
  .stats-v6-dashboard {
    grid-template-columns: 1fr;
  }

  .stats-v6-toolbar {
    justify-content: flex-start;
  }

  .stats-v6-right-stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 940px) {
  .stats-v6-hero-grid,
  .stats-v6-mid-grid,
  .stats-v6-right-stack {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .stats-v6 {
    border-radius: 18px;
  }

  .stats-v6-topbar,
  .stats-v6-dashboard {
    padding-left: 12px;
    padding-right: 12px;
  }

  .stats-v6-toolbar,
  .stats-v6-field,
  .stats-v6-btn {
    width: 100%;
  }

  .stats-v6-field select,
  .stats-v6-field input {
    min-width: 0;
  }

  .stats-v6-kpi-grid,
  .stats-v6-project-grid,
  .stats-v6-project-metrics,
  .stats-v6-toggle-grid {
    grid-template-columns: 1fr;
  }

  .stats-v6-big-number {
    font-size: 26px;
  }
}

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

.app-notice-region {
  position: fixed;
  z-index: 5000;
  top: 18px;
  right: 18px;
  width: min(380px, calc(100vw - 36px));
  pointer-events: none;
}

.app-notice {
  padding: 13px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  color: var(--text);
  background: var(--panel-solid);
  box-shadow: var(--shadow-soft);
  font-size: 14px;
  line-height: 1.45;
}

.app-notice.success {
  border-color: color-mix(in srgb, var(--success) 45%, transparent);
  background: color-mix(in srgb, var(--panel-solid) 88%, var(--success));
}

.app-notice.error {
  border-color: color-mix(in srgb, var(--danger) 55%, transparent);
  background: color-mix(in srgb, var(--panel-solid) 88%, var(--danger));
}

.save-status {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--neutral-soft);
  font-size: 12px;
  font-weight: 700;
}

.save-status[hidden] {
  display: none;
}

.save-status.success {
  color: var(--success);
  background: var(--success-soft);
}

.save-status.error {
  color: var(--danger);
  background: var(--danger-soft);
}

.save-status.saving {
  color: var(--accent);
  background: var(--accent-soft);
}

.project-form-error {
  margin: 0 24px;
}

@media (max-width: 720px) {
  .app-notice-region {
    top: 12px;
    right: 12px;
    width: calc(100vw - 24px);
  }
}
