@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=IBM+Plex+Mono:wght@500&display=swap");

/* Design system — Служба механика СЛЦ */
:root,
[data-theme="dark"] {
  --primary: #6C5CE7;
  --primary-hover: #5A4FCF;
  --accent: #00D2FF;
  --bg: #0F1115;
  --bg-elev: #14171c;
  --surface: #1A1D23;
  --card: #1A1D23;
  --card-hover: #22262e;
  --fg: #FFFFFF;
  --muted: #A0A4B0;
  --line: rgba(255, 255, 255, 0.08);
  --line-soft: rgba(255, 255, 255, 0.05);
  --ok: #00C853;
  --soon: #FFB300;
  --over: #FF5252;
  --primary-fg: #FFFFFF;
  --ink: #0F1115;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-lg: 24px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35), 0 1px 0 rgba(255,255,255,0.04);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --font: "Inter", -apple-system, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 200ms;
  --space: 8px;
}

[data-theme="light"] {
  --bg: #F7F8FA;
  --bg-elev: #FFFFFF;
  --surface: #FFFFFF;
  --card: #FFFFFF;
  --card-hover: #F0F1F4;
  --fg: #111111;
  --muted: #6B7280;
  --line: rgba(0, 0, 0, 0.08);
  --line-soft: rgba(0, 0, 0, 0.04);
  --primary-fg: #FFFFFF;
  --ink: #111111;
  --shadow: 0 4px 24px rgba(15, 17, 21, 0.08), 0 1px 0 rgba(0,0,0,0.03);
  --shadow-sm: 0 2px 8px rgba(15, 17, 21, 0.06);
}

[data-theme="amoled"] {
  --bg: #000000;
  --bg-elev: #000000;
  --surface: #0A0A0A;
  --card: #0A0A0A;
  --card-hover: #141414;
  --fg: #FFFFFF;
  --muted: #8E8E93;
  --line: rgba(255, 255, 255, 0.1);
  --line-soft: rgba(255, 255, 255, 0.05);
  --shadow: none;
  --shadow-sm: none;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #F7F8FA;
    --bg-elev: #FFFFFF;
    --surface: #FFFFFF;
    --card: #FFFFFF;
    --card-hover: #F0F1F4;
    --fg: #111111;
    --muted: #6B7280;
    --line: rgba(0, 0, 0, 0.08);
    --line-soft: rgba(0, 0, 0, 0.04);
    --primary-fg: #FFFFFF;
    --ink: #111111;
    --shadow: 0 4px 24px rgba(15, 17, 21, 0.08);
    --shadow-sm: 0 2px 8px rgba(15, 17, 21, 0.06);
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1000px 480px at 8% -8%, rgba(108, 92, 231, 0.12), transparent 55%),
    radial-gradient(800px 420px at 100% 0%, rgba(0, 210, 255, 0.06), transparent 50%),
    var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

a { color: inherit; text-decoration: none; }
button, [type="submit"] { font-family: inherit; }

.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 22px 72px;
}

/* —— Header —— */
.top {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.03em;
  white-space: nowrap;
}
.brand::before {
  content: "";
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--primary), var(--accent));
  box-shadow: 0 0 0 1px rgba(108, 92, 231, 0.35), 0 4px 14px rgba(108, 92, 231, 0.3);
  flex-shrink: 0;
}

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

.nav a,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  background: transparent;
  border: 1px solid transparent;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  color: var(--muted);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease), transform 150ms var(--ease), box-shadow var(--dur) var(--ease);
}
.nav a:hover,
.btn:hover {
  color: var(--fg);
  background: var(--card-hover);
  border-color: var(--line);
}
.nav a:active,
.btn:active { transform: translateY(1px); }

.btn {
  background: var(--card);
  border-color: var(--line);
  color: var(--fg);
}
.btn.primary {
  background: linear-gradient(180deg, #7B6CF0, var(--primary));
  color: var(--primary-fg);
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(108, 92, 231, 0.35);
  border-color: transparent;
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 4px 12px rgba(232, 165, 75, 0.25);
}
.btn.primary:hover {
  filter: brightness(1.05);
  color: var(--primary-fg);
  border-color: transparent;
}
.btn.danger {
  background: rgba(212, 90, 72, 0.15);
  color: #f0a090;
  border-color: rgba(212, 90, 72, 0.35);
}
.btn.danger:hover {
  background: var(--over);
  color: var(--fg);
  border-color: transparent;
}

.nav-admin {
  border-color: rgba(232, 165, 75, 0.45) !important;
  color: var(--primary) !important;
}
.nav-admin:hover {
  background: rgba(232, 165, 75, 0.12) !important;
}

.spacer {
  margin-left: auto;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

/* —— Type —— */
h1 {
  font-size: clamp(26px, 4vw, 32px);
  font-weight: 700;
  letter-spacing: -0.035em;
  margin: 4px 0 18px;
  line-height: 1.2;
}
h2 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 14px;
}
.muted { color: var(--muted); }
.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--primary);
  margin: 0 0 6px;
}

/* —— Cards & stats —— */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 8px 0 28px;
}
.stat {
  background: var(--card);
  padding: 18px 18px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease;
}
.stat:hover { border-color: rgba(232, 165, 75, 0.35); }
.stat b {
  display: block;
  margin-top: 6px;
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  font-family: var(--mono);
}
.stat span {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
}

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

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

label {
  display: grid;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

input, select, textarea {
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 42px;
  padding: 10px 12px;
  font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: rgba(232, 165, 75, 0.55);
  box-shadow: 0 0 0 3px rgba(232, 165, 75, 0.12);
}
textarea { min-height: 88px; resize: vertical; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th, td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}
.ok { color: var(--ok); }
.soon { color: var(--soon); }
.overdue { color: var(--over); }
.error {
  color: #f0a090;
  background: rgba(212, 90, 72, 0.12);
  border: 1px solid rgba(212, 90, 72, 0.3);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0 0 14px;
}
p.ok {
  color: #7dcea0;
  background: rgba(61, 155, 106, 0.12);
  border: 1px solid rgba(61, 155, 106, 0.3);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0 0 14px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  align-items: center;
}

/* —— Login —— */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(800px 400px at 50% 20%, rgba(232, 165, 75, 0.1), transparent 60%),
    var(--bg);
}
.login .card {
  width: min(420px, 100%);
  padding: 32px 28px;
}
.login .brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(145deg, #f0b45c, #b8732a);
  margin-bottom: 18px;
  box-shadow: 0 8px 24px rgba(232, 165, 75, 0.3);
}
.login h1 {
  margin: 0 0 8px;
  font-size: 24px;
}
.login .actions { margin-top: 18px; }
.login .btn.primary { width: 100%; min-height: 44px; }

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .top { flex-wrap: wrap; gap: 10px; }
  .spacer { margin-left: 0; max-width: none; order: 3; width: 100%; }
  .nav { width: 100%; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .nav a { flex-shrink: 0; }
}
@media (max-width: 520px) {
  .grid { grid-template-columns: 1fr; }
  .wrap { padding: 20px 14px 56px; }
}

/* —— Notes —— */
.note-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.note-item {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
}
.note-item.due { border-color: rgba(212, 90, 72, 0.45); background: rgba(212, 90, 72, 0.08); }
.note-item.done { opacity: 0.55; }
.note-item.done strong { text-decoration: line-through; }
.note-main { flex: 1; min-width: 200px; }
.note-main p { margin: 6px 0; white-space: pre-wrap; }
.note-meta { font-size: 12px; margin-top: 6px; }
.note-edit summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  margin-top: 8px;
  user-select: none;
}
.note-edit summary:hover { color: var(--primary); }

/* —— PWA install bar —— */
.pwa-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: linear-gradient(180deg, rgba(232, 165, 75, 0.16), rgba(20, 23, 28, 0.98));
  border-bottom: 1px solid rgba(232, 165, 75, 0.35);
  padding: 12px 16px;
}
.pwa-bar-inner {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* —— App shell: large buttons & bottom nav —— */
.btn-lg {
  min-height: 48px;
  padding: 0 20px;
  font-size: 15px;
  width: 100%;
  max-width: 420px;
}

.app-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0 0 20px;
}
.app-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 88px;
  padding: 14px 8px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  color: var(--fg);
  font-weight: 600;
  font-size: 13px;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.app-tile:hover { border-color: rgba(232, 165, 75, 0.45); }
.app-tile:active { transform: scale(0.97); }
.app-tile-ico {
  font-size: 22px;
  line-height: 1;
  color: var(--primary);
}
.app-tile-t { letter-spacing: -0.01em; }

.nav a.active {
  color: var(--fg);
  background: var(--card-hover);
  border-color: var(--line);
}

.app-bottom {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  background: rgba(10, 11, 13, 0.94);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
}
.app-bottom a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 52px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-decoration: none;
}
.app-bottom a .abi {
  font-size: 18px;
  line-height: 1.2;
  color: inherit;
}
.app-bottom a.active {
  color: var(--primary);
  background: rgba(232, 165, 75, 0.1);
}
.app-bottom a:active { background: var(--card-hover); }

body.has-app-nav .wrap {
  padding-bottom: 96px;
}

.hide-mobile { display: initial; }

@media (max-width: 900px) {
  .app-bottom { display: grid; }
  .nav-desktop { display: none; }
  .hide-mobile { display: none !important; }
  .top { padding: 10px 14px; }
  .brand { font-size: 14px; }
  .btn, .nav a { min-height: 44px; }
  input, select, textarea { min-height: 46px; font-size: 16px; }
  .app-actions { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 901px) {
  .app-bottom { display: none; }
  body.has-app-nav .wrap { padding-bottom: 72px; }
}
.app-bottom { display: none !important; }
.nav { flex-wrap: wrap; }
.nav a { min-height: 40px; }
body.has-app-nav .wrap { padding-bottom: 48px; }

.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.brand::before { display: none !important; }
.login-logo {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  margin-bottom: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}

/* —— Side menu —— */
.menu-toggle {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 42px;
  height: 42px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  cursor: pointer;
  flex-shrink: 0;
}
.menu-toggle span {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--fg);
  border-radius: 1px;
}

.top {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(10, 11, 13, 0.92);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.top .nav { display: none !important; }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(300px, 88vw);
  z-index: 100;
  background: #101216;
  border-right: 1px solid var(--line);
  transform: translateX(-105%);
  transition: transform 0.22s ease;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  box-shadow: 8px 0 32px rgba(0,0,0,0.4);
}
body.sidebar-open .sidebar { transform: translateX(0); }
body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
}
.side-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  overflow-y: auto;
}
.side-nav a {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  color: var(--muted);
  font-weight: 500;
  font-size: 15px;
  text-decoration: none;
  border: 1px solid transparent;
}
.side-nav a:hover { background: var(--card-hover); color: var(--fg); }
.side-nav a.active {
  background: rgba(232, 165, 75, 0.12);
  color: var(--primary);
  border-color: rgba(232, 165, 75, 0.35);
}
.side-nav a.nav-admin { color: var(--primary); }
.sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  margin-top: 8px;
}

@media (min-width: 1000px) {
  .menu-toggle { display: none; }
  .sidebar {
    transform: none;
    position: fixed;
  }
  .sidebar-backdrop { display: none !important; }
  body.with-sidebar .wrap {
    margin-left: 300px;
    max-width: none;
    padding-left: 28px;
  }
  body.with-sidebar .top {
    margin-left: 300px;
  }
}

/* —— Plans & parts mobile layout —— */
.stack-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.stack-form.compact { gap: 10px; }
.stack-form label { width: 100%; }
.stack-form .btn-lg { width: 100%; max-width: none; }
.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.plan-card .plan-title {
  font-size: 17px;
  letter-spacing: -0.02em;
}
.plan-meta { margin-top: 4px; font-size: 13px; }
.pos-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}
.part-card {
  padding: 14px 16px;
}
.part-edit summary {
  cursor: pointer;
  color: var(--primary);
  font-size: 14px;
  font-weight: 500;
  margin-top: 10px;
  user-select: none;
}
.part-edit summary:hover { text-decoration: underline; }

@media (max-width: 520px) {
  .row-2, .row-3 { grid-template-columns: 1fr; }
  .wrap { padding-left: 14px; padding-right: 14px; overflow-x: hidden; }
  table { display: block; overflow-x: auto; }
}

/* —— Collapsible plan positions —— */
.fold > summary,
.pos-fold > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}
.fold > summary::-webkit-details-marker,
.pos-fold > summary::-webkit-details-marker { display: none; }

.pos-fold {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 8px;
  overflow: hidden;
}
.pos-summary {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  min-height: 48px;
  justify-content: center;
}
.pos-summary:hover { background: rgba(255,255,255,0.03); }
.pos-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--fg);
}
.pos-sub { font-size: 12px; line-height: 1.35; }
.pos-body {
  padding: 0 14px 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.pos-fold[open] .pos-summary {
  background: rgba(232, 165, 75, 0.08);
}
.add-pos > summary {
  width: 100%;
  text-align: center;
  display: flex;
  justify-content: center;
}
.fold > summary.btn {
  display: inline-flex;
  margin-top: 10px;
}
.plan-actions { margin-top: 14px; flex-wrap: wrap; }
.inline-form { display: inline; margin: 0; }
.delete-order-form { margin-top: 12px; }
.delete-order-form .btn-lg { width: 100%; }

.delete-order-box { margin-top: 14px; }
.del-panel {
  margin-top: 12px;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid rgba(212, 90, 72, 0.45);
  background: rgba(212, 90, 72, 0.1);
}
.del-question {
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 1.4;
}
.del-panel .actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 0;
}
.del-details { margin-top: 14px; }
.del-summary { width: 100%; text-align: center; list-style: none; }
.del-summary::-webkit-details-marker { display: none; }

.new-order-fold { margin-bottom: 16px; }
.new-order-fold > summary {
  list-style: none;
  cursor: pointer;
}
.new-order-fold > summary::-webkit-details-marker { display: none; }
.plan-owner { margin-top: 8px; }
.badge-own {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(61, 155, 106, 0.2);
  color: #7dcea0;
}
.badge-view {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  color: var(--muted);
}
.plan-card.theirs { opacity: 0.95; border-style: dashed; }
.welcome-card {
  border-color: rgba(232, 165, 75, 0.35);
  background: linear-gradient(135deg, rgba(232,165,75,0.12), rgba(10,11,13,0.4));
  margin-bottom: 16px;
}
.welcome-hi {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.35;
}
.due-toast{
  position:fixed;left:12px;right:12px;top:calc(12px + env(safe-area-inset-top,0));
  z-index:99999;background:var(--surface);color:var(--fg);border:1px solid var(--line);border-radius:14px;
  padding:14px 16px;box-shadow:0 10px 30px rgba(0,0,0,.35);
  display:flex;flex-direction:column;gap:4px;cursor:pointer;
  transform:translateY(-120%);opacity:0;transition:transform .25s ease,opacity .25s ease;
  font-size:15px;
}
.due-toast.show{transform:translateY(0);opacity:1}
.due-toast strong{font-size:13px;opacity:.85;font-weight:600}
.due-toast span{font-size:16px;font-weight:700}
.pager-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0 18px;
}
.pager-info {
  color: var(--muted);
  font-size: 14px;
  min-width: 64px;
  text-align: center;
}
.pager-nums {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.catalog-fold { margin-bottom: 12px; }
.catalog-sum { width: 100%; text-align: left; list-style: none; }
.catalog-sum::-webkit-details-marker { display: none; }

.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 8px 4px 16px;
  margin-bottom: 12px;
}
.chat-bubble {
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
}
.chat-bubble.mine {
  align-self: flex-end;
  background: rgba(232, 165, 75, 0.12);
  border-color: rgba(232, 165, 75, 0.35);
}
.chat-bubble.theirs { align-self: flex-start; }
.chat-author {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 4px;
}
.chat-text { white-space: pre-wrap; word-break: break-word; line-height: 1.4; }
.chat-time { font-size: 11px; color: var(--muted); margin-top: 6px; }
.chat-photo {
  max-width: 100%;
  max-height: 240px;
  border-radius: 10px;
  display: block;
  margin-bottom: 6px;
}
.chat-compose { position: sticky; bottom: 0; background: var(--bg); padding-top: 8px; }
.chat-compose-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.chat-compose-row input[name="body"] {
  flex: 1;
  min-width: 0;
  min-height: 44px;
}
.chat-attach { cursor: pointer; margin: 0; }
.emoji-bar {
  display: none;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 120px;
  overflow-y: auto;
  margin-bottom: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}
.emoji-bar.open { display: flex; }
.emoji-btn {
  border: none;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  line-height: 1.2;
  padding: 2px;
}
.chat-row:hover { border-color: rgba(232,165,75,0.4); }

/* —— Telegram-style chat —— */
.tg-wrap {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 70px);
  max-height: calc(100dvh - 70px);
  margin: -8px -4px 0;
  background: #0e1621;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.06);
}
.tg-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #17212b;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.tg-back {
  color: #6ab3f3;
  font-size: 28px;
  text-decoration: none;
  line-height: 1;
  padding: 0 4px;
}
.tg-header-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.tg-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--primary); color: var(--fg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; flex-shrink: 0;
  text-transform: uppercase;
}
.tg-avatar.lg { width: 48px; height: 48px; font-size: 18px; }
.tg-title { font-weight: 600; font-size: 15px; color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tg-sub { font-size: 12px; color: #6d7f8f; }
.tg-icon-btn {
  border: none; background: transparent; color: #6ab3f3;
  font-size: 22px; cursor: pointer; padding: 4px 8px;
}
.tg-members-panel {
  background: #17212b; padding: 12px; border-bottom: 1px solid rgba(255,255,255,0.06);
  max-height: 40vh; overflow-y: auto;
}
.tg-member { padding: 6px 0; color: #e4ecf2; font-size: 14px; }
.tg-thread {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px 16px;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(43,82,120,0.15), transparent 50%),
    #0e1621;
  display: flex; flex-direction: column; gap: 6px;
}
.tg-msg { display: flex; }
.tg-msg.out { justify-content: flex-end; }
.tg-msg.in { justify-content: flex-start; }
.tg-bubble {
  max-width: 82%;
  padding: 6px 10px 4px;
  border-radius: 12px;
  position: relative;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.tg-msg.in .tg-bubble { background: #182533; border-bottom-left-radius: 4px; }
.tg-msg.out .tg-bubble { background: var(--primary); border-bottom-right-radius: 4px; }
.tg-name { font-size: 13px; font-weight: 600; color: #6ab3f3; margin-bottom: 2px; }
.tg-text { color: #e4ecf2; font-size: 15px; line-height: 1.35; white-space: pre-wrap; word-break: break-word; }
.tg-img { max-width: 100%; max-height: 260px; border-radius: 8px; display: block; margin: 2px 0 4px; }
.tg-meta {
  display: flex; justify-content: flex-end; align-items: center; gap: 4px;
  margin-top: 2px;
}
.tg-time { font-size: 11px; color: rgba(255,255,255,0.45); }
.tg-msg.out .tg-time { color: rgba(255,255,255,0.55); }
.tg-checks { font-size: 11px; color: #6ab3f3; }
.tg-emoji {
  display: none; flex-wrap: wrap; gap: 2px;
  max-height: 110px; overflow-y: auto;
  padding: 8px; background: #17212b;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.tg-emoji.open { display: flex; }
.tg-e {
  border: none; background: transparent; font-size: 22px;
  cursor: pointer; padding: 4px; line-height: 1;
}
.tg-compose {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 8px 10px; background: #17212b;
  border-top: 1px solid rgba(255,255,255,0.06); flex-shrink: 0;
}
.tg-tool {
  border: none; background: transparent; color: #6d7f8f;
  font-size: 22px; cursor: pointer; padding: 6px; line-height: 1;
  display: inline-flex; align-items: center;
}
.tg-input {
  flex: 1; min-width: 0; min-height: 40px !important;
  border-radius: 20px !important; border: none !important;
  background: #242f3d !important; color: var(--fg) !important;
  padding: 8px 14px !important; font-size: 15px;
}
.tg-send {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: var(--primary); color: var(--fg); font-size: 16px; cursor: pointer;
}
.tg-chat-list { margin-top: 12px; }
.tg-chat-item {
  display: flex; gap: 12px; align-items: center;
  padding: 12px 10px; border-radius: 12px;
  text-decoration: none; color: inherit;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.tg-chat-item:hover { background: rgba(255,255,255,0.04); }
.tg-chat-body { flex: 1; min-width: 0; }
.tg-chat-top { display: flex; justify-content: space-between; gap: 8px; }
.tg-chat-preview {
  font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px;
}

body.with-sidebar .wrap:has(.tg-wrap) {
  max-width: none;
  padding-left: 12px;
  padding-right: 12px;
}


/* —— Design system components —— */
.card {
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.btn {
  border-radius: var(--radius-sm) !important;
  min-height: 40px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.btn.primary:hover {
  background: var(--primary-hover) !important;
  filter: none;
}
.btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
input, select, textarea {
  border-radius: var(--radius-sm) !important;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.badge, .chip {
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
}
.ds-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}
.ds-empty strong {
  display: block;
  color: var(--fg);
  font-size: 18px;
  margin-bottom: 8px;
}
.ds-skeleton {
  background: linear-gradient(90deg, var(--line-soft), var(--card-hover), var(--line-soft));
  background-size: 200% 100%;
  animation: ds-shimmer 1.2s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
@keyframes ds-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
@keyframes ds-fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.ds-enter {
  animation: ds-fade-up var(--dur) var(--ease) both;
}
.theme-fab {
  position: fixed;
  right: 14px;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  z-index: 90;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.theme-fab:active { transform: scale(0.94); }

/* Sidebar polish */
.sidebar {
  background: var(--surface) !important;
  border-right: 1px solid var(--line);
}
.side-nav a.active {
  background: rgba(108, 92, 231, 0.15) !important;
  color: var(--primary) !important;
  border-radius: var(--radius-sm);
}


/* theme-force-light — ensure no black leftovers in light mode */
[data-theme="light"] body,
[data-theme="light"] .wrap,
[data-theme="light"] .sidebar,
[data-theme="light"] .top,
[data-theme="light"] main {
  color: var(--fg) !important;
}
[data-theme="light"] .top {
  background: rgba(247, 248, 250, 0.92) !important;
  border-bottom-color: var(--line) !important;
}
[data-theme="light"] .sidebar {
  background: #FFFFFF !important;
  color: #111111 !important;
}
[data-theme="light"] .sidebar .muted,
[data-theme="light"] .muted {
  color: #6B7280 !important;
}
[data-theme="light"] .card,
[data-theme="light"] .note-item,
[data-theme="light"] .cab-sec,
[data-theme="light"] details,
[data-theme="light"] table {
  background: #FFFFFF !important;
  color: #111111 !important;
  border-color: rgba(0,0,0,0.08) !important;
}
[data-theme="light"] input,
[data-theme="light"] select,
[data-theme="light"] textarea {
  background: #F7F8FA !important;
  color: #111111 !important;
  border-color: rgba(0,0,0,0.12) !important;
}
[data-theme="light"] .btn:not(.primary):not(.danger) {
  background: #FFFFFF !important;
  color: #111111 !important;
  border-color: rgba(0,0,0,0.12) !important;
}
[data-theme="light"] .side-nav a {
  color: #374151 !important;
}
[data-theme="light"] .side-nav a.active {
  background: rgba(108, 92, 231, 0.12) !important;
  color: #5A4FCF !important;
}
[data-theme="light"] .theme-fab {
  background: #FFFFFF !important;
  color: #111111 !important;
  border-color: rgba(0,0,0,0.1) !important;
}
[data-theme="light"] h1, [data-theme="light"] h2, [data-theme="light"] h3,
[data-theme="light"] strong, [data-theme="light"] label {
  color: #111111 !important;
}

/* dark/amoled readable secondary text */
[data-theme="dark"] .muted,
[data-theme="amoled"] .muted,
:root:not([data-theme]) .muted {
  color: #A0A4B0 !important;
}
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea,
[data-theme="amoled"] input,
[data-theme="amoled"] select,
[data-theme="amoled"] textarea {
  background: var(--card-hover) !important;
  color: var(--fg) !important;
  border-color: var(--line) !important;
}
[data-theme="dark"] .card,
[data-theme="amoled"] .card {
  background: var(--card) !important;
  color: var(--fg) !important;
}

/* Chat list/room inherit */
[data-theme="light"] .mx,
[data-theme="light"] .tgx {
  color: #111111 !important;
}
