/* App shell: sidebar + workspace on desktop, bottom tab bar on phones. Home screen grid. */
.shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }

.nav {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: var(--space-5);
  padding: var(--space-6) var(--space-4);
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.nav-brand { padding: 0 var(--space-3); display: grid; gap: var(--space-1); }
.nav-brand b { font-family: var(--font-display); font-weight: 400; font-size: var(--fs-xl); letter-spacing: 0.02em; }
.nav-list { display: grid; gap: var(--space-1); }
.nav-link, .nav-more {
  position: relative;
  display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--tap);
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: var(--fs-sm); font-weight: 500;
  transition: background .2s var(--ease), color .2s var(--ease);
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link[aria-current="page"] { background: var(--accent-tint); color: var(--accent-deep); }
.nav-link[aria-current="page"]::before {
  content: ''; position: absolute; left: calc(-1 * var(--space-4)); top: var(--space-2); bottom: var(--space-2);
  width: var(--space-1); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--accent);
}
.nav-more { display: none; }
.nav-foot { margin-top: auto; display: grid; gap: var(--space-1); }
.nav-foot .nav-link { color: var(--muted); }

.workspace { min-width: 0; padding: var(--space-6) var(--space-6) var(--space-8); }
.screen { max-width: var(--content-max); margin: 0 auto; display: grid; gap: var(--space-5); }
.screen-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-4); }
.screen-head .eyebrow { margin-bottom: var(--space-2); }

/* Login */
.login {
  min-height: 100vh;
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
}
.login-art {
  background: var(--accent-deep); color: var(--on-accent);
  padding: var(--space-8) var(--space-7);
  display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.login-art .h1 { font-size: clamp(40px, 6vw, 72px); max-width: 10ch; }
.login-art .eyebrow { color: var(--accent-soft); }
.login-art::after {
  content: ''; position: absolute; right: -15%; bottom: -25%;
  width: 70%; aspect-ratio: 1; border-radius: 50%;
  border: 1px solid var(--accent); opacity: .5;
}
.login-form-wrap { display: flex; align-items: center; justify-content: center; padding: var(--space-6); }
.login-form { width: min(100%, 360px); display: grid; gap: var(--space-4); }

/* Home */
.home-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--space-5); }
.home-actions { grid-column: span 7; display: grid; grid-template-columns: 1.6fr 1fr; gap: var(--space-4); }
.home-kpis { grid-column: span 5; }
.home-debts { grid-column: span 7; align-self: start; }
.home-side { grid-column: span 5; display: grid; gap: var(--space-5); align-content: start; }

.action-tile {
  display: flex; flex-direction: column; justify-content: space-between; gap: var(--space-6);
  min-height: 184px;
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  text-align: left;
  transition: transform .2s var(--ease), box-shadow .2s var(--ease);
}
.action-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-hi); }
.action-tile b { font-family: var(--font-display); font-weight: 400; font-size: clamp(26px, 3vw, 38px); line-height: 1.05; }
.action-tile small { font-size: var(--fs-sm); opacity: .8; }
.action-tile .icon { width: var(--space-6); height: var(--space-6); }
.action-tile-main { background: var(--accent-deep); color: var(--on-accent); }
.action-tile-alt { background: var(--surface); border: 1px solid var(--border-hi); color: var(--accent-deep); }
/* «Новый заказ» is the big one; invoice and expense stack beside it */
.home-actions .action-tile-main { grid-row: span 2; }
.home-actions .action-tile-alt { min-height: 0; flex-direction: row; align-items: center; justify-content: flex-start; gap: var(--space-4); }
.home-actions .action-tile-alt b { font-size: var(--fs-xl); }
.home-actions .action-tile-alt .icon { flex: none; }

.kpi-list { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-5) var(--space-4); }
.kpi dt { font-size: var(--fs-xs); color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.kpi dd { font-family: var(--font-display); font-size: var(--fs-num); line-height: 1.15; }
.kpi .delta { font-family: var(--font-sans); font-size: var(--fs-xs); color: var(--muted); }
.kpi dd.kpi-delta { font-family: var(--font-sans); font-size: var(--fs-xs); line-height: 1.4; min-height: 2.8em; } /* room for a wrapped comparison: no jump on load */
.kpi .delta.up { color: var(--success); }
.kpi .delta.down { color: var(--danger); }

.debt-list { display: grid; gap: var(--space-3); }
.debt-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-1) var(--space-4);
  align-items: center;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}
.debt-row:last-child { border-bottom: 0; }
.debt-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.debt-sum { font-weight: 600; }
.debt-age { grid-column: 1 / -1; display: flex; align-items: center; gap: var(--space-3); font-size: var(--fs-xs); color: var(--muted); }
.age-bar { flex: 1; height: var(--space-2); border-radius: var(--radius-pill); background: var(--surface-2); overflow: hidden; }
.age-bar i { display: block; height: 100%; border-radius: inherit; background: var(--accent-soft); }
.age-bar i.old { background: var(--accent); }
.age-bar i.very-old { background: var(--accent-deep); }
.debt-total { font-family: var(--font-display); font-size: var(--fs-xl); }

.low-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-2); }
.low-row { display: flex; justify-content: space-between; gap: var(--space-3); font-size: var(--fs-sm); }
.low-row > :first-child { min-width: 0; }
.low-name { display: grid; gap: var(--space-1); }
.low-name > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.low-reason { font-size: var(--fs-xs); color: var(--text-dim); }
.low-row span:last-child { flex: none; }

.trend { display: grid; gap: var(--space-3); }
.trend svg { width: 100%; height: auto; overflow: visible; }
.trend .line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.trend .area { fill: var(--accent-tint); }

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

/* 1024: narrower sidebar, home stacks into two even columns */
@media (max-width: 1024px) {
  :root { --sidebar-w: 208px; }
  .workspace { padding: var(--space-5) var(--space-5) var(--space-7); }
  .home-actions, .home-kpis, .home-debts, .home-side { grid-column: 1 / -1; }
  .home-side { grid-template-columns: 1fr 1fr; }
}

/* 768: bottom tab bar; extra sections open from «Ещё» */
@media (max-width: 768px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav {
    position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; top: auto;
    height: auto; flex-direction: row; gap: 0;
    padding: 0 var(--space-1) env(safe-area-inset-bottom, 0px);
    border-right: 0; border-top: 1px solid var(--border);
    box-shadow: var(--shadow);
  }
  .nav-brand, .nav-foot { display: none; }
  .nav-list { display: flex; width: 100%; gap: 0; }
  .nav-link, .nav-more {
    flex: 1 1 0; min-width: 0;
    flex-direction: column; justify-content: center; gap: var(--space-1);
    min-height: var(--tabbar-h); padding: 0 var(--space-1);
    font-size: var(--fs-xs); text-align: center;
  }
  .nav-link span, .nav-more span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav-link[aria-current="page"] { background: none; }
  .nav-link[aria-current="page"]::before { left: 25%; right: 25%; top: 0; bottom: auto; width: auto; height: 3px; border-radius: 0 0 var(--radius-sm) var(--radius-sm); }
  .nav-more { display: flex; }
  .nav-list .nav-extra { display: none; }
  .nav[data-more-open] .nav-extras-panel { display: grid; }
  .workspace { padding: var(--space-5) var(--space-4) calc(var(--tabbar-h) + var(--space-6)); }
  .login { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .login-art { padding: var(--space-6) var(--space-5); min-height: 220px; }
}
.nav-extras-panel { display: none; }
@media (max-width: 768px) {
  .nav-extras-panel {
    position: absolute; right: var(--space-2); bottom: calc(100% + var(--space-2));
    min-width: 220px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-hi); padding: var(--space-2);
    gap: var(--space-1);
  }
  .nav-extras-panel .nav-link { flex-direction: row; justify-content: flex-start; min-height: var(--tap); font-size: var(--fs-sm); padding: 0 var(--space-3); gap: var(--space-3); }
  .nav-extras-panel .nav-link[aria-current="page"]::before { display: none; }
}

/* 480: single column everywhere */
@media (max-width: 480px) {
  .home-grid { gap: var(--space-4); }
  .home-actions { grid-template-columns: 1fr; }
  .home-actions .action-tile-main { grid-row: auto; }
  .action-tile { min-height: 0; flex-direction: row; align-items: center; justify-content: flex-start; gap: var(--space-4); }
  .home-side { grid-template-columns: minmax(0, 1fr); }
  .card { padding: var(--space-4); }
}

/* 360: tighter type */
@media (max-width: 360px) {
  .kpi-list { gap: var(--space-4) var(--space-3); }
  .workspace { padding-left: var(--space-3); padding-right: var(--space-3); }
}
