:root {
  --bg: #ffffff; --side: #f4f5f7; --text: #1f2329; --muted: #7a818c; --border: #e4e6ea; --head: #f6f7f9;
  --hover: #eef5ff; --blue: #1a73e8; --blue-d: #1462c9; --blue-l: #e8f1fd;
  --red: #e5352b; --red-l: #fde8e7; --orange: #ef8c0e; --orange-l: #fff3e0; --green: #1f9d55; --green-l: #e3f6ec;
  --violet: #7c4dda; --violet-l: #f0eafd;
  --radius: 8px; --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.45 var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); margin: 0; font-size: 13px; }
.error:empty { display: none; }
.hint { margin-top: 14px; max-width: 640px; }
svg { display: block; }
i[data-icon] { display: inline-flex; }
a.link { color: var(--blue); font-weight: 500; font-size: 13px; cursor: pointer; }

/* логотип */
.logo { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(145deg, #4cb5ff, #1a73e8); display: grid; place-items: center; box-shadow: 0 2px 6px rgba(26,115,232,.3); }
.logo span { width: 20px; height: 20px; border-radius: 50%; background: #ffd23f; }
.logo.big { width: 56px; height: 56px; border-radius: 14px; margin-bottom: 8px; }
.logo.big span { width: 28px; height: 28px; }

/* ворид */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--side); }
.login-card { width: 100%; max-width: 360px; background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 32px 28px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0 0 6px; }

/* сохтор */
#app { display: flex; min-height: 100vh; }
.sidebar { width: 88px; flex: none; background: var(--side); border-right: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; padding: 16px 0 12px; position: sticky; top: 0; height: 100vh; }
.sidebar > .logo { margin-bottom: 14px; }
#nav { display: flex; flex-direction: column; gap: 4px; width: 100%; padding-top: 14px; border-top: 1px solid var(--border); flex: 1; }
#nav a, .profile { display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); cursor: pointer; padding: 6px 2px; user-select: none; }
#nav a i, .profile i { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: #e7e9ed; color: #8a919c; border: 1.5px solid transparent; transition: .15s; }
#nav a:hover i { background: #dfe2e7; color: #5d6470; }
#nav a.active { color: var(--blue); font-weight: 600; }
#nav a.active i { background: var(--blue-l); color: var(--blue); border-color: var(--blue); }
.profile span { max-width: 78px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile i.avatar { border-radius: 50%; background: #c9ced6; color: #fff; }

main { flex: 1; min-width: 0; padding: 24px 28px 48px; max-width: 1300px; }
.page-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; min-height: 40px; }
.page-head h1 { font-size: 22px; font-weight: 700; margin: 0; flex: 1; letter-spacing: -.01em; }
.head-actions { display: flex; gap: 8px; }

/* тугмаҳо */
.btn { font: inherit; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--border); background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f5f6f8; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-d); }
.btn.danger { color: var(--red); }
.btn.danger-fill { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.icon { width: 38px; padding: 0; justify-content: center; }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; height: 42px; }
.btn svg { width: 16px; height: 16px; }

/* амалҳои тез */
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.q-btn { font: inherit; text-align: left; border: 1px solid var(--border); background: #fff; border-radius: 12px; padding: 14px 16px; cursor: pointer; display: grid; grid-template-columns: 40px 1fr; column-gap: 12px; align-items: center; transition: .15s; }
.q-btn:hover { border-color: currentColor; box-shadow: 0 2px 10px rgba(20,30,50,.06); }
.q-btn i { grid-row: span 2; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; }
.q-btn b { font-size: 15px; color: var(--text); }
.q-btn span { font-size: 12px; color: var(--muted); }
.q-btn.in { color: var(--green); } .q-btn.in i { background: var(--green-l); }
.q-btn.out { color: var(--blue); } .q-btn.out i { background: var(--blue-l); }
.q-btn.writeoff { color: var(--red); } .q-btn.writeoff i { background: var(--red-l); }
.q-btn.count { color: var(--violet); } .q-btn.count i { background: var(--violet-l); }

/* табҳо */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tab { position: relative; padding: 9px 12px; color: var(--muted); cursor: pointer; white-space: nowrap; font: inherit; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--blue); }
.tab.active::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: 0; height: 2px; background: var(--blue); border-radius: 2px; }
.tab .count { font-size: 11px; background: #eef0f3; color: var(--muted); border-radius: 99px; padding: 0 7px; line-height: 18px; }
.tab .count:empty { display: none; }
.tab.active .count { background: var(--blue-l); color: var(--blue); }

/* филтрҳо ва майдонҳо */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.search { position: relative; flex: 0 1 340px; min-width: 200px; }
.search i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: #9aa0a9; pointer-events: none; }
.search input { width: 100%; padding-left: 36px; }
.search.big { flex: 1; max-width: none; }
.search.big input { height: 46px; font-size: 15px; }
.pill { font: inherit; display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 10px 0 12px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; }
.pill:hover { border-color: #cfd3d9; }
.pill.open, .pill.on { border-color: var(--blue); color: var(--blue); }
.pill.open { box-shadow: 0 0 0 3px var(--blue-l); }
.pill b { font-weight: 500; color: var(--blue); max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.pill .chev { color: #9aa0a9; }
label.pill.date { flex-direction: row; font-size: 14px; font-weight: 400; cursor: default; padding-right: 4px; color: var(--muted); }
.pill.date input { border: 0; padding: 4px; height: 32px; color: var(--text); }
.pill.date input:focus { box-shadow: none; }

input, select, textarea { font: inherit; height: 38px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: var(--text); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-l); }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 500; }
.row { display: flex; gap: 6px; }
.row select { flex: 1; }

/* ҷадвал */
.box { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; }
.box-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; font-weight: 600; border-bottom: 1px solid var(--border); background: var(--head); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 0 12px; height: 46px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table th { height: 42px; font-size: 13px; font-weight: 500; color: var(--muted); background: var(--head); }
.table tfoot td { font-weight: 600; background: var(--head); border-top: 1px solid var(--border); border-bottom: 0; }
.table.click tbody tr[data-id] { cursor: pointer; }
.table tbody tr:hover { background: var(--hover); }
.table .r { text-align: right; font-variant-numeric: tabular-nums; }
.table .act { width: 48px; text-align: center; padding: 0 4px; }
.table td.empty { text-align: center; color: var(--muted); height: 110px; white-space: normal; }
.table td.empty .btn { margin-top: 10px; }
.table .name { font-weight: 500; max-width: 380px; overflow: hidden; text-overflow: ellipsis; }
.table .sub { font-weight: 400; color: var(--muted); font-size: 12px; }
.table input { height: 34px; width: 110px; text-align: right; }
.sortable { cursor: pointer; user-select: none; }
.sortable:hover { color: var(--text); }
.sortable.asc::after { content: " ↑"; } .sortable.desc::after { content: " ↓"; }
.qty-low { color: var(--orange); font-weight: 600; }
.qty-zero { color: var(--red); font-weight: 600; }
.plus { color: var(--green); } .minus { color: var(--red); }
.cancelled td { color: #a3a9b2 !important; text-decoration: line-through; }
.cancelled td .badge { text-decoration: none; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 6px; font-size: 12px; font-weight: 500; text-decoration: none; }
.badge.in { background: var(--green-l); color: #17834a; }
.badge.out { background: var(--blue-l); color: var(--blue); }
.badge.writeoff { background: var(--red-l); color: #c42b22; }
.badge.count { background: var(--violet-l); color: var(--violet); }
.badge.grey { background: #eef0f3; color: #6b7280; }
.x-btn { border: 0; background: none; color: #a3a9b2; cursor: pointer; font-size: 18px; width: 32px; height: 32px; border-radius: 6px; }
.x-btn:hover { background: var(--red-l); color: var(--red); }

/* саҳифабандӣ */
.pager { display: flex; align-items: center; gap: 8px; padding-top: 14px; color: var(--muted); }
.pager .spacer { flex: 1; }
.pages { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.pages button { font: inherit; min-width: 34px; height: 34px; border: 0; border-left: 1px solid var(--border); background: #fff; color: var(--blue); cursor: pointer; padding: 0 6px; }
.pages button:first-child { border-left: 0; }
.pages button:hover:not(:disabled) { background: var(--blue-l); }
.pages button.cur { background: var(--blue); color: #fff; }
.pages button:disabled { color: #c3c7cd; cursor: default; }
.pages span { min-width: 34px; height: 34px; display: grid; place-items: center; border-left: 1px solid var(--border); }

/* омор */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stats:empty { display: none; }
.stat { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat.warn .value { color: var(--orange); } .stat.bad .value { color: var(--red); } .stat.good .value { color: var(--green); }
.stat.click { cursor: pointer; } .stat.click:hover { border-color: #cfd3d9; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }

/* таҳрири ҳуҷҷат */
.ed-head { display: grid; grid-template-columns: 170px 300px 1fr; gap: 12px; margin-bottom: 16px; }
.ed-add { position: relative; margin-bottom: 12px; display: flex; }
.ed-results { position: absolute; top: 50px; left: 0; right: 0; z-index: 20; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(20,30,50,.14); padding: 6px; max-height: 360px; overflow-y: auto; }
.ed-results .opt { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 6px; cursor: pointer; }
.ed-results .opt.hl, .ed-results .opt:hover { background: var(--hover); }
.ed-results .opt .grow { flex: 1; min-width: 0; }
.ed-results .opt .muted { font-size: 12px; }
.ed-results .none { padding: 12px; color: var(--muted); }
.ed-foot { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.ed-total { flex: 1; font-size: 16px; }
.ed-total b { font-size: 20px; }
.warn-line td { background: #fff7f6; }
.warn-text { color: var(--red); font-size: 12px; }

/* popover */
.popover { position: fixed; z-index: 40; min-width: 200px; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 28px rgba(20,30,50,.14); padding: 6px; max-height: 340px; overflow-y: auto; }
.popover .opt { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.popover .opt:hover { background: #f3f5f8; }
.popover .opt.sel { color: var(--blue); font-weight: 500; }
.popover .opt.danger { color: var(--red); }
.popover .opt svg { width: 16px; height: 16px; }
.popover .ph { padding: 6px 10px; font-size: 12px; color: var(--muted); }
.popover hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* модал */
dialog { border: none; border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 24px 60px rgba(20,30,50,.25); color: var(--text); }
dialog.wide { width: min(860px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(20,28,40,.4); }
#modal-form { padding: 18px 22px 20px; }
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.modal-head h3 { flex: 1; margin: 0; font-size: 17px; }
#modal-body { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
#modal-body .full { grid-column: 1 / -1; }
#modal-body p { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-actions .left { margin-right: auto; }
.info { grid-column: 1 / -1; background: var(--head); border: 1px solid var(--border); padding: 10px 12px; border-radius: var(--radius); }
.kv { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kv div { background: var(--head); border-radius: 8px; padding: 8px 12px; }
.kv span { display: block; font-size: 12px; color: var(--muted); }
.kv b { font-weight: 600; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 10px); background: #1f2329; color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 60; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--red); }

/* чоп */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; font-size: 12px; color: #000; }
  #print-area h2 { margin: 0 0 6px; }
  #print-area table { width: 100%; border-collapse: collapse; margin: 12px 0; }
  #print-area th, #print-area td { border: 1px solid #999; padding: 4px 6px; text-align: left; }
  #print-area .r { text-align: right; }
  #print-area .sign { display: flex; justify-content: space-between; margin-top: 40px; }
}

/* телефон */
@media (max-width: 860px) {
  .quick { grid-template-columns: 1fr 1fr; }
  .ed-head { grid-template-columns: 1fr 1fr; }
  .ed-head .grow { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  #app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; flex-direction: row; z-index: 10; padding: 6px 4px; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar > .logo { display: none; }
  #nav { flex-direction: row; border-top: 0; padding-top: 0; justify-content: space-around; gap: 0; }
  #nav a, .profile { font-size: 10px; padding: 4px 0; }
  #nav a i, .profile i { width: 32px; height: 32px; }
  .profile span { display: none; }
  main { padding: 16px; }
  .grid2, #modal-body { grid-template-columns: 1fr; }
  .search { flex-basis: 100%; }
  .quick { gap: 8px; }
  .q-btn { grid-template-columns: 1fr; padding: 12px; gap: 6px; }
  .q-btn i { grid-row: auto; }
  .q-btn span { display: none; }
  .ed-head { grid-template-columns: 1fr; }
  .head-actions .btn.primary { padding: 0 12px; }
}
