:root {
  --bg: #fafafa;
  --card: #ffffff;
  --raised: #f4f4f5;
  --line: rgba(23, 23, 23, 0.08);
  --line-strong: rgba(23, 23, 23, 0.16);
  --text: #171717;
  --text-2: #525252;
  --muted: #737373;
  --accent: #173b30;
  --accent-hover: #1f4d3f;
  --accent-ink: #173b30;
  --accent-soft: rgba(23, 59, 48, 0.08);
  --on-accent: #ffffff;
  --ok: #16a34a;
  --bad: #dc2626;
  --warn: #b45309;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  --float: 0 8px 24px rgba(0, 0, 0, 0.08);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141415;
    --card: #19191b;
    --raised: #232325;
    --line: rgba(237, 237, 237, 0.08);
    --line-strong: rgba(237, 237, 237, 0.16);
    --text: #ededed;
    --text-2: #a1a1a6;
    --muted: #85858b;
    --accent: #ededed;
    --accent-hover: #ffffff;
    --accent-ink: #7cc4a4;
    --accent-soft: rgba(124, 196, 164, 0.12);
    --on-accent: #141415;
    --ok: #4cc38a;
    --bad: #e5484d;
    --warn: #f0a35b;
    --shadow: none;
    --float: 0 8px 24px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/22px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12px; line-height: 16px; }
.muted { color: var(--muted); }
.sub { color: var(--text-2); font-size: 14px; line-height: 20px; }
.small { font-size: 13px; line-height: 20px; color: var(--text-2); }
.hidden { display: none !important; }

/* --- каркас ----------------------------------------------------------------------------------------------------- */
.shell { min-height: 100vh; display: flex; }
.side {
  display: none;
  width: 240px;
  flex: none;
  padding: 16px 12px;
  border-right: 1px solid var(--line);
  background: var(--card);
  position: sticky;
  top: 0;
  height: 100vh;
  flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 8px; font-weight: 500; font-size: 16px; }
.brand img { width: 24px; height: 24px; }
.brand span { color: var(--muted); font-weight: 400; }
.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 24px; }
.nav a {
  display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border-radius: 8px;
  color: var(--text-2); font-size: 14px; transition: background-color 150ms var(--ease), color 150ms var(--ease);
}
.nav a:hover { background: var(--raised); color: var(--text); text-decoration: none; }
.nav a.on { background: var(--raised); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.side .me { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--line); }
.me-name { font-size: 14px; }
.me-role { font-size: 13px; color: var(--muted); }
.me-links { display: flex; gap: 16px; margin-top: 8px; font-size: 13px; }
.me-links button { background: none; border: 0; padding: 0; color: var(--text-2); cursor: pointer; }
.me-links button:hover { color: var(--text); }

.main { flex: 1; min-width: 0; padding: 16px 16px 96px; }
.page { max-width: 960px; margin: 0 auto; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 40px; margin-bottom: 16px; }
.top h1 { margin: 0; font-size: 22px; line-height: 28px; font-weight: 500; }
.top .mobile-me { background: none; border: 0; padding: 4px; color: var(--text-2); cursor: pointer; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0;
  font-size: 12px; line-height: 16px; color: var(--muted); border-radius: 8px;
}
.tabbar a.on { color: var(--accent-ink); }
.tabbar a:hover { text-decoration: none; }

@media (min-width: 960px) {
  .side { display: flex; }
  .tabbar, .top .mobile-me { display: none; }
  .main { padding: 24px 32px 48px; }
}

/* --- элементы --------------------------------------------------------------------------------------------------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 16px; }
.card + .card, .card + .section, .section + .card, .section + .section { margin-top: 16px; }
.card h2, .section h2 { margin: 0 0 12px; font-size: 16px; line-height: 22px; font-weight: 500; }
.section h2 { padding: 0 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--raised); color: var(--text); font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease), transform 120ms var(--ease);
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row + .row { margin-top: 8px; }

.field { display: block; margin-top: 12px; }
.field > span { display: block; margin-bottom: 4px; font-size: 13px; line-height: 20px; color: var(--text-2); }
input[type=text], input[type=tel], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--card);
  transition: border-color 150ms var(--ease);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-ink); }
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; font-size: 14px; line-height: 20px; }
.check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--accent-ink); flex: none; }

.error { margin-top: 12px; color: var(--bad); font-size: 14px; line-height: 20px; }
.empty { padding: 24px 8px; text-align: center; color: var(--muted); font-size: 14px; }
.loading { padding: 48px 8px; text-align: center; color: var(--muted); font-size: 14px; }

/* бирка заказа - как на партии в цеху */
.tag {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px 0 6px;
  border: 1px solid var(--line-strong); border-radius: 4px; background: var(--card);
  font-family: var(--mono); font-size: 12px; color: var(--text-2); white-space: nowrap;
}
.tag::before { content: ""; width: 5px; height: 5px; border-radius: 50%; box-shadow: inset 0 0 0 1px var(--muted); }

.chip { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; background: var(--raised); font-size: 12px; line-height: 16px; color: var(--text-2); white-space: nowrap; }
.chip.ok { color: var(--ok); }
.chip.bad { color: var(--bad); }
.chip.warn { color: var(--warn); }
.chip.accent { color: var(--accent-ink); background: var(--accent-soft); }

/* --- вход ------------------------------------------------------------------------------------------------------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-box { width: 100%; max-width: 360px; }
.auth-box .brand { padding: 0; margin-bottom: 32px; }
.auth-box h1 { margin: 0 0 4px; font-size: 24px; line-height: 30px; font-weight: 500; }
.auth-box .btn { margin-top: 20px; }
.auth-note { margin-top: 16px; font-size: 13px; line-height: 20px; color: var(--muted); }

/* --- список заказов --------------------------------------------------------------------------------------------- */
.filters { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters input { flex: 1; }
.seg { display: inline-flex; padding: 2px; border-radius: 8px; background: var(--raised); flex: none; }
.seg button { height: 36px; padding: 0 12px; border: 0; border-radius: 6px; background: none; color: var(--text-2); font-size: 13px; cursor: pointer; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.list { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.item { display: block; padding: 12px 16px; color: inherit; border-top: 1px solid var(--line); transition: background-color 150ms var(--ease); }
.item:first-child { border-top: 0; }
.item:hover { background: var(--raised); text-decoration: none; }
.item-top { display: flex; align-items: center; gap: 8px; }
.item-title { margin-top: 6px; font-size: 15px; line-height: 22px; }
.item-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 2px; font-size: 13px; line-height: 20px; color: var(--text-2); }
.count { margin: 0 4px 8px; font-size: 13px; color: var(--muted); }

/* --- карточка заказа -------------------------------------------------------------------------------------------- */
.back { display: inline-flex; align-items: center; gap: 4px; height: 32px; margin: -4px 0 8px -6px; padding: 0 6px; color: var(--text-2); font-size: 14px; }
.order-head h1 { margin: 8px 0 0; font-size: 22px; line-height: 28px; font-weight: 500; }
.order-head .row { margin-top: 8px; }

/* путь заказа - главное место карточки */
.track { margin-top: 16px; overflow-x: auto; scrollbar-width: none; }
.track::-webkit-scrollbar { display: none; }
.track ol { display: flex; gap: 0; margin: 0; padding: 0; list-style: none; min-width: max-content; }
.track li { flex: none; min-width: 88px; padding-right: 8px; }
.track li:last-child { padding-right: 0; }
.track .bar { height: 6px; border-radius: 3px; background: var(--raised); box-shadow: inset 0 0 0 1px var(--line); }
.track .done .bar { background: var(--accent-ink); box-shadow: none; opacity: 0.45; }
.track .cur .bar { background: var(--accent-ink); box-shadow: none; }
.track .name { margin-top: 6px; font-size: 12px; line-height: 16px; color: var(--muted); white-space: nowrap; }
.track .done .name { color: var(--text-2); }
.track .cur .name { color: var(--text); font-weight: 500; }

.kv { display: grid; grid-template-columns: 136px 1fr; gap: 6px 12px; font-size: 14px; line-height: 20px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; white-space: pre-line; }
@media (max-width: 480px) { .kv { grid-template-columns: 1fr; gap: 0; } .kv dd { margin-bottom: 8px; } }

.acts .row { margin-top: 12px; }
.form { margin-top: 12px; padding: 12px; border-radius: 10px; background: var(--raised); }
.form .field:first-child { margin-top: 0; }

.lines { border-top: 1px solid var(--line); }
.line { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; line-height: 20px; }
.line:last-child { border-bottom: 0; }
.line .grow { flex: 1; min-width: 0; }
.line .side-info { text-align: right; font-size: 13px; color: var(--text-2); flex: none; }

.work + .work { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.work-title { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-weight: 500; }
.work .checks { margin-top: 8px; }
.warnbox { margin-top: 8px; padding: 8px 12px; border-radius: 8px; background: var(--raised); font-size: 14px; line-height: 20px; color: var(--warn); }

.photo { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.photo label { cursor: pointer; }
.photo img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.photo input { display: none; }

/* лента */
.feed { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.post { font-size: 14px; line-height: 20px; }
.post-head { display: flex; gap: 8px; font-size: 13px; color: var(--muted); }
.post-head b { font-weight: 500; color: var(--text-2); }
.post-text { margin-top: 2px; white-space: pre-line; overflow-wrap: anywhere; }
.compose { display: flex; gap: 8px; align-items: flex-end; }
.compose textarea { min-height: 40px; height: 40px; }
.compose .btn { flex: none; width: 40px; padding: 0; }

/* мои работы */
.task { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.task + .task { margin-top: 12px; }
.task-top { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.task-title { margin-top: 8px; font-size: 15px; font-weight: 500; }
.task-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; font-size: 13px; line-height: 20px; color: var(--text-2); }
.group-label { margin: 24px 4px 8px; font-size: 13px; color: var(--muted); }
.group-label:first-child { margin-top: 0; }

/* календарь */
.cal { overflow-x: auto; }
.cal table { border-collapse: separate; border-spacing: 0; font-size: 13px; }
.cal th, .cal td { padding: 0; border-bottom: 1px solid var(--line); }
.cal th { position: sticky; top: 0; height: 40px; background: var(--card); font-weight: 400; color: var(--muted); }
.cal th.day { width: 40px; text-align: center; font-size: 12px; line-height: 16px; }
.cal th.day.weekend { opacity: 0.5; }
.cal th.day.today { color: var(--accent-ink); font-weight: 500; opacity: 1; }
.cal .who { position: sticky; left: 0; z-index: 1; width: 200px; min-width: 160px; max-width: 200px; padding: 8px 12px 8px 0; background: var(--card); text-align: left; }
.cal .who div { font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal .cell { height: 44px; text-align: center; }
.cal .cell span { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 28px; border-radius: 6px; font-size: 12px; color: var(--text-2); }
.cal .off span { color: var(--muted); opacity: 0.5; }
.cal .l1 span { background: var(--accent-soft); }
.cal .l2 span { background: var(--accent-soft); color: var(--accent-ink); box-shadow: inset 0 0 0 1px var(--accent-ink); }
.cal .l3 span { background: var(--bad); color: #fff; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 12px; font-size: 13px; color: var(--muted); }

/* люди */
.person { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.person:first-child { border-top: 0; }
.person .grow { flex: 1; min-width: 0; }
.person.off { opacity: 0.55; }
.roles { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 4px; }
.secret { margin-top: 12px; padding: 12px; border-radius: 8px; background: var(--accent-soft); font-size: 14px; line-height: 20px; }
.secret b { font-family: var(--mono); font-size: 18px; letter-spacing: 0.08em; font-weight: 500; }

#toast {
  position: fixed; left: 50%; bottom: 88px; z-index: 20; max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 10px; background: var(--text); color: var(--bg);
  font-size: 14px; line-height: 20px; box-shadow: var(--float);
  opacity: 0; transform: translate(-50%, 8px); pointer-events: none;
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--bad); color: #fff; }
@media (min-width: 960px) { #toast { bottom: 24px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
