:root {
  --ink: #16181D; --ink2: #3F4652; --muted: #5B6270; --faint: #8A909B; --line: #E3E6EB; --line2: #EEF0F3;
  --bg: #F4F5F7; --card: #fff; --blue: #1D4ED8; --blue-dark: #1E3A8A; --blue-bg: #EEF3FF; --brown: #9A3412; --grey: #6B7280;
  --violet: #7C3AED; --side: #16181D; --side-ink: #C9CDD4;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 14px; }
a { color: var(--blue); } a:hover { color: var(--blue-dark); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: #FAFBFC; position: sticky; top: 0; white-space: nowrap; z-index: 1; }
td { padding: 9px 12px; border-bottom: 1px solid var(--line2); font-size: 14px; vertical-align: top; }
th.r, td.r { text-align: right; }
tr.rowlink:hover td { background: #F2F5FF; cursor: pointer; }
.nm { text-align: left; border-radius: 6px; padding: 1px 5px; margin: -1px 1px -1px -5px; outline: 2px solid transparent; transition: outline-color .12s, background .12s; cursor: pointer; color: inherit; text-decoration: none; background: none; border: none; font: inherit; font-weight: inherit; }
.nm:hover, .nm:focus-visible { outline-color: var(--blue); background: #fff; }
input, select, textarea { font: inherit; font-size: 14px; padding: 9px 10px; border: 1px solid #CDD2DA; border-radius: 8px; background: #fff; color: var(--ink); min-height: 40px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }
label { font-size: 12px; font-weight: 600; color: var(--ink2); display: flex; flex-direction: column; gap: 6px; }
button { font: inherit; cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }

/* каркас */
.app { display: flex; min-height: 100vh; }
.side { width: 220px; flex: none; background: var(--side); color: #fff; padding: 20px 14px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 800; font-size: 22px; letter-spacing: .5px; padding: 0 8px; }
.who { padding: 0 8px; font-size: 12px; color: var(--side-ink); line-height: 1.4; }
.who b { color: #fff; font-weight: 600; font-size: 13px; display: block; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button { text-align: left; border: none; border-radius: 8px; padding: 10px 12px; min-height: 42px; font-size: 14px; font-weight: 500; background: transparent; color: var(--side-ink); }
.nav button:hover { background: #22262E; color: #fff; }
.nav button.on { background: #2E3440; color: #fff; font-weight: 600; }
.nav .sep { height: 1px; background: #343A46; margin: 8px 6px; }
.nav .badge { display: inline-block; margin-left: 6px; background: #E5C65A; color: #3A2A00; border-radius: 999px; padding: 1px 7px; font-size: 11px; font-weight: 700; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }
.side-foot button { background: none; border: none; color: var(--side-ink); text-align: left; padding: 6px 8px; font-size: 13px; border-radius: 6px; }
.side-foot button:hover { color: #fff; background: #22262E; }
.main { flex: 1; min-width: 0; padding: 24px 28px 60px; display: flex; flex-direction: column; gap: 18px; }
h1 { margin: 0; font-size: 26px; font-weight: 700; }
.sub { font-size: 14px; color: var(--muted); margin-top: 4px; line-height: 1.5; max-width: 980px; }
.box { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.box h2 { margin: 0; font-size: 16px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.scroll { overflow: auto; max-height: 620px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.muted { color: var(--muted); } .small { font-size: 12px; } .faint { color: var(--faint); }
.blue { color: var(--blue); } .brown { color: var(--brown); } .grey { color: var(--grey); }
.b { font-weight: 700; }

/* плитки */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; }
.tile .l { font-size: 13px; color: var(--muted); }
.tile .v { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 700; white-space: nowrap; }
.tile .s { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* кнопки */
.btn { border-radius: 9px; padding: 10px 16px; min-height: 42px; font-weight: 600; border: 1px solid #CDD2DA; background: #fff; color: var(--ink); }
.btn:hover { border-color: #9AA1AC; }
.btn.pri { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.pri:hover { background: #1A43BF; }
.btn.dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.danger { background: #fff; color: var(--brown); border-color: #F3C99A; }
.btn.danger.full { background: var(--brown); color: #fff; border-color: var(--brown); }
.btn.sm { padding: 6px 10px; min-height: 34px; font-size: 13px; border-radius: 8px; }
.pill { border-radius: 999px; padding: 8px 14px; min-height: 40px; font-size: 14px; font-weight: 500; background: #fff; color: var(--ink); border: 1px solid #CDD2DA; }
.pill.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.pill.reset { color: var(--brown); border-color: #E8B4A0; }
.link { background: none; border: none; color: var(--blue); padding: 0; font-size: 13px; text-align: left; }

/* период */
.period { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.period label { width: 170px; }
.hint { flex-basis: 100%; font-size: 13px; color: var(--muted); line-height: 1.45; }

/* сортировка */
.sorth { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.sorth button { border: 1px solid #CDD2DA; background: #fff; color: var(--muted); border-radius: 5px; width: 22px; height: 22px; padding: 0; font-size: 10px; line-height: 1; }
.sorth button.on { background: var(--blue); border-color: var(--blue); color: #fff; }

/* строка ввода в таблице */
tr.entry td { background: var(--blue-bg); padding: 8px 6px; vertical-align: middle; }

/* окна */
.overlay { position: fixed; inset: 0; background: rgba(22,24,29,.35); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { width: 440px; max-width: 100%; background: #fff; border-radius: 14px; padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.18); max-height: 92vh; overflow-y: auto; }
.modal h2 { margin: 0; font-size: 18px; }
.x { background: none; border: 1px solid #CDD2DA; border-radius: 8px; width: 36px; height: 36px; font-size: 17px; color: var(--ink2); flex: none; }
.drawer-wrap { position: fixed; inset: 0; background: rgba(22,24,29,.3); display: flex; justify-content: flex-end; z-index: 45; }
.drawer { width: 470px; max-width: 100%; height: 100%; background: #fff; padding: 22px 24px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; box-shadow: -8px 0 30px rgba(0,0,0,.12); }
.drawer h2 { margin: 0; font-size: 20px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.preview { font-size: 13px; color: var(--ink2); background: #F4F5F7; border-radius: 8px; padding: 8px 10px; white-space: pre-line; }
.err { color: var(--brown); font-size: 14px; }
.warn { font-size: 13px; color: #7A5200; background: #FFF7D6; border-radius: 8px; padding: 8px 10px; }
.chip { background: #EEF3FF; color: var(--blue); border: 1px solid #C9D6F5; border-radius: 999px; padding: 3px 9px; min-height: 26px; font-size: 12px; font-weight: 500; white-space: nowrap; align-self: flex-start; }
.stat { display: flex; gap: 18px; }
.stat > div { flex: 1; background: #F6F7F9; border-radius: 10px; padding: 10px 12px; }
.stat .l { font-size: 12px; color: var(--muted); }
.stat .v { font-family: var(--mono); font-size: 18px; font-weight: 700; }
.badge-st { align-self: flex-start; border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600; }
.st-done { background: #E8F0FF; color: var(--blue-dark); } .st-part { background: #FFF7D6; color: #7A5200; } .st-wait { background: #FFF4E5; color: var(--brown); }
.sect { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.sect h3 { margin: 0; font-size: 15px; }

/* тост */
.toast { position: sticky; top: 0; z-index: 15; border-radius: 10px; padding: 10px 14px; font-size: 14px; background: var(--blue-bg); color: var(--blue-dark); border: 1px solid #C9D6F5; display: flex; justify-content: space-between; gap: 10px; }
.toast.err { background: #FFF1EC; color: var(--brown); border-color: #F3C99A; }
.toast button { background: none; border: none; color: inherit; font-size: 16px; }

/* заявки */
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink2); align-items: center; flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 6px; }
.zgrid td { padding: 3px 6px; border-bottom: none; vertical-align: top; }
.zgrid td.rcol { border-left: 3px solid #C3C9D2; }
.zgrid th.rcol { border-left: 3px solid #C3C9D2; }
.zitem { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; text-align: left; font-size: 13px; line-height: 1.3; cursor: pointer; border-radius: 6px; padding: 4px 9px; border: 1px solid; }
.zitem .sub { font-size: 12px; opacity: .85; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 0; color: inherit; }
.zitem .amt { font-family: var(--mono); font-weight: 700; }
.zi-done { background: #E3EDFF; border-color: #9DB8F0; color: var(--blue-dark); }
.zi-part { background: #FFF2C4; border-color: #E5C65A; color: #5C3D00; }
.zi-wait { background: #FDE7E4; border-color: #F0B4AA; color: #8A2B12; }
.zi-exp { background: #F1F2F4; border: 1px dashed #B8BDC6; color: var(--ink2); }
.qbtn { flex: none; width: 36px; background: #fff; border: 1px solid #9DB8F0; color: var(--blue); border-radius: 6px; font-weight: 700; font-size: 15px; }
.dayrow td { background: #F4F5F7; padding: 7px 10px; border-top: 1px solid var(--line); }
.addcard { background: #fff; border: 2px solid var(--blue); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 2px 6px rgba(29,78,216,.08); }
.addcard .t { font-size: 13px; font-weight: 700; color: var(--blue); }
.addcard input { min-height: 38px; padding: 6px 8px; }
.pendcard { background: #FFFBEB; border: 1px dashed #E5C65A; border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.pendcard .k { font-size: 11px; font-weight: 700; color: #7A5200; background: #FFF2C4; border-radius: 999px; padding: 2px 8px; white-space: nowrap; }

/* вход */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login form { width: 360px; max-width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login .brand { color: var(--ink); padding: 0; font-size: 30px; }


/* режим просмотра глазами другой роли */
.viewas { padding: 0 8px 8px; font-size: 12px; font-weight: 500; color: var(--side-ink); gap: 4px; }
.viewas select { background: #22262E; color: #fff; border: 1px solid #3A3F4A; min-height: 34px; padding: 5px 8px; font-size: 13px; }
.preview-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: #fff4d6; border: 1px solid #f0c95a; color: #5c4400; border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; }

/* Заявки: строка «Списки за день» — день слева, фильтр справа */
.daybar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.daybar h2 { margin: 0 6px 0 0; font-size: 18px; }
.daybar input[type=date] { width: 160px; }
.daybar-r { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.titlebar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.titlebar h1 { margin: 0; }

/* формы новой заявки/поступления */
.ac-r1 { display: grid; grid-template-columns: 150px minmax(0,1fr) 110px; gap: 6px; }
.ac-r2 { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr) auto; gap: 6px; }
.mtop, .mtabs, .mbar { display: none; }

/* ================= телефон ================= */
@media (max-width: 760px) {
  html, body { font-size: 15px; }
  input, select, textarea { font-size: 16px; min-height: 44px; } /* 16px — чтобы iPhone не увеличивал страницу */
  .app { display: block; }
  .mtop { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 25; background: var(--side); color: #fff;
    padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); min-height: 52px; }
  .mburger { background: none; border: none; color: #fff; font-size: 24px; width: 40px; height: 40px; border-radius: 8px; }
  .mburger:active { background: #2E3440; }
  .mtitle { font-weight: 700; font-size: 17px; flex: 1; }
  .mbadge { border: none; font-size: 13px !important; padding: 4px 10px !important; }
  .mback { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 39; }
  /* «Ещё» — лист снизу, над нижней панелью */
  .side { position: fixed; left: 0; right: 0; top: auto; bottom: calc(60px + env(safe-area-inset-bottom)); width: 100%; height: auto; max-height: 75vh;
    z-index: 40; border-radius: 16px 16px 0 0; transform: translateY(110%); transition: transform .2s ease; padding: 16px 14px 12px; visibility: hidden; }
  .side.open { transform: none; visibility: visible; box-shadow: 0 -8px 30px rgba(0,0,0,.35); }
  .side .brand, .side .who { display: none; }
  .side .nav { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
  .side .nav .sep { display: none; }
  .side-foot { margin-top: 8px; border-top: 1px solid #343A46; padding-top: 8px; }
  .mbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 42; background: #fff; border-top: 1px solid var(--line);
    padding: 4px 4px env(safe-area-inset-bottom); box-shadow: 0 -2px 10px rgba(0,0,0,.05); }
  .mbar button { flex: 1; min-width: 0; height: 56px; background: none; border: none; color: var(--faint); display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 600; position: relative; border-radius: 10px; }
  .mbar button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mbar button.on { color: var(--blue); }
  .mbar button.on svg { stroke-width: 2.3; }
  .mbar .badge { position: absolute; top: 4px; left: 50%; margin-left: 6px; background: #E5C65A; color: #3A2A00; border-radius: 999px; padding: 0 6px; font-size: 10px; font-style: normal; font-weight: 700; line-height: 16px; }
  .mback { bottom: calc(60px + env(safe-area-inset-bottom)); }
  .nav button { min-height: 46px; font-size: 16px; }
  .main { padding: max(14px, env(safe-area-inset-top)) 12px 40px; gap: 12px; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .mob .main > h1, .mob .main > div > h1, .titlebar h1 { font-size: 22px; }
  .sub { font-size: 13px; }

  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 10px 12px; }
  .tile .l { font-size: 12px; }
  .tile .v { font-size: 17px; }

  .box { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  th { padding: 8px 8px; }
  td { padding: 9px 8px; font-size: 14px; }
  .ptable th:nth-child(n+4), .ptable td:nth-child(n+4) { display: none; }
  .sorth { gap: 3px; }
  .sorth button { width: 24px; height: 24px; }

  .period { padding: 10px; gap: 8px; }
  .period label { width: calc(50% - 4px); }
  .pill { min-height: 38px; padding: 7px 12px; font-size: 14px; }
  .row.between { align-items: stretch; }
  .row.between > label { width: 100% !important; }

  .daybar { gap: 6px; }
  .daybar h2 { flex-basis: 100%; font-size: 16px; }
  .daybar input[type=date] { width: auto; flex: 1; min-width: 0; }
  .daybar-r { margin-left: 0; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; }
  .legend { gap: 10px; font-size: 12px; }

  .mtabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; position: sticky; top: 0; padding-top: env(safe-area-inset-top); z-index: 5; background: var(--bg); padding: 4px 0; }
  .mtabs button { border: 1px solid #CDD2DA; background: #fff; border-radius: 10px; padding: 8px 10px; min-height: 52px; font-weight: 600; font-size: 15px;
    display: flex; flex-direction: column; align-items: flex-start; gap: 2px; position: relative; color: var(--ink); }
  .mtabs button .num { font-size: 13px; font-weight: 500; color: var(--muted); }
  .mtabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
  .mtabs button.on .num { color: #C9CDD4; }
  .mtabs .badge { position: absolute; top: 6px; right: 8px; background: #E5C65A; color: #3A2A00; border-radius: 999px; padding: 1px 7px; font-size: 11px; font-style: normal; font-weight: 700; }
  .mlist { overflow: hidden; }
  .mpad { padding: 10px; }
  .mday { display: flex; align-items: center; gap: 10px; background: #F4F5F7; padding: 7px 10px; border-top: 1px solid var(--line); }
  .mitems { display: flex; flex-direction: column; gap: 5px; padding: 6px 8px 10px; }
  .zitem { padding: 9px 10px; font-size: 14px; min-height: 44px; align-items: center; }
  .qbtn { width: 44px; font-size: 17px; }
  .ac-r1 { grid-template-columns: minmax(0,1fr) 120px; }
  .ac-r1 input[type=date] { grid-column: 1; }
  .ac-r1 input[list] { grid-column: 1 / -1; grid-row: 2; }
  .ac-r2 { grid-template-columns: 1fr; }
  .ac-r2 .btn { min-height: 44px; }

  .overlay { padding: 0; align-items: flex-end; }
  .modal { width: 100%; border-radius: 16px 16px 0 0; max-height: 92vh; padding: 16px 16px max(16px, env(safe-area-inset-bottom)); }
  .drawer { width: 100%; padding: 16px 14px max(20px, env(safe-area-inset-bottom)); }
  .grid2 { grid-template-columns: 1fr; }
  .stat { flex-direction: column; gap: 8px; }
  .btn { min-height: 44px; }
  .btn.sm { min-height: 38px; }
  .preview-bar { margin-bottom: 0; }
  .toast { top: 0; }
  .main .sub, .hint { display: none; }          /* длинные пояснения на телефоне лишние */
  .box h2 { font-size: 14px; padding: 10px 12px; font-weight: 600; }
  /* Сбор / Расход кассы / Мои расходы: каждая запись — компактная карточка в две строки */
  .ltable thead { display: none; }
  .ltable tr { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; padding: 9px 12px; border-bottom: 1px solid var(--line2); }
  .ltable tr::after { content: ''; order: 1; flex-basis: 100%; height: 0; }
  .ltable td { display: block; border: none; padding: 0; order: 2; font-size: 12px; color: var(--muted); }
  .ltable td:empty { display: none; }
  .ltable td:nth-child(1) { order: 0; font-size: 12px; }
  .ltable td:nth-child(2) { order: 0; flex: 1; min-width: 0; font-size: 15px; color: var(--ink); font-weight: 500; }
  .ltable:not(.lk) td:nth-child(3), .ltable.lk td:nth-child(4) { order: 0; font-size: 15px; font-weight: 700; color: var(--ink); }
  .box:has(.ltable) > h2 { display: none; }
  .ltable tr.entry { display: grid; grid-template-columns: 1fr 1fr; grid-auto-flow: dense; gap: 8px; padding: 10px; background: var(--blue-bg); }
  .ltable tr.entry td { background: none; }
  .ltable tr.entry::after { display: none; }
  .ltable tr.entry td { order: 0; font-size: 14px; color: var(--ink); }
  .ltable tr.entry td:has(input[list]), .ltable tr.entry td:has(input:not([type])), .ltable tr.entry td:has(.btn), .ltable tr.entry td:has(select) { grid-column: 1 / -1; }
  .ltable tr.entry input, .ltable tr.entry select { min-width: 0 !important; width: 100%; }
  .ltable tr.entry .btn { width: 100%; }
  .scroll { max-height: none; }
  .atable thead { display: none; }
  .atable tr { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; padding: 10px 12px; border-bottom: 1px solid var(--line2); }
  .atable td { display: block; padding: 0; border: none; white-space: normal !important; }
  .atable td:nth-child(1) { color: var(--muted); font-size: 12px; }
  .atable td:nth-child(2) { font-size: 12px; font-weight: 600; text-align: right; }
  .atable td:nth-child(3), .atable td:nth-child(4) { font-size: 12px; }
  .atable td:nth-child(5), .atable td:nth-child(6) { grid-column: 1 / -1; }
}
