/* Layout: 1C "Taksi" uslubi — yuqorida sarlavha paneli, chapda bo'limlar, markazda ochiq oynalar tablari va ish maydoni */
:root {
  --bg: #eceae4; --panel: #f7f6f2; --paper: #ffffff; --ink: #1f2328; --muted: #6a6f76; --line: #d4d1c8; --line2: #e6e3db;
  --accent: #f5c518; --accent-ink: #3a2e00; --accent-soft: #fff4c4; --sel: #fbe9a6; --hover: #fdf6dc;
  --link: #1b4f8a; --ok: #2e7d32; --ok-soft: #e3f1e4; --err: #b3261e; --err-soft: #fbe5e2; --warn: #8a5a00; --warn-soft: #fbefd5;
  --side: #3b3f45; --side-ink: #e9e9e7; --side-sel: #f5c518;
  --f: "Segoe UI", "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: "Consolas", "SFMono-Regular", "Roboto Mono", monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 13px/1.4 var(--f); color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--link); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
.num, td.n, th.n { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #3b3f45 0 40%, var(--bg) 40%); }
.login form { background: var(--paper); width: min(380px, 100%); padding: 28px; border-radius: 6px; box-shadow: 0 8px 30px rgba(0,0,0,.18); display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login .brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 34px; height: 34px; border-radius: 6px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; font-size: 15px; letter-spacing: -.5px; flex: none; }

/* ---------- Shell */
.shell { display: grid; grid-template-columns: 92px 1fr; grid-template-rows: 44px 1fr; height: 100%; }
.top { grid-column: 1 / 3; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0; }
.top .appname { font-weight: 700; white-space: nowrap; }
.top select, .top input { height: 30px; border: 1px solid var(--line); border-radius: 4px; background: var(--paper); padding: 0 8px; }
.top .co { max-width: 320px; min-width: 120px; }
.top .search { flex: 1; max-width: 420px; min-width: 80px; }
.top .sp { flex: 1; }
.tbtn { height: 30px; border: 1px solid var(--line); background: var(--paper); border-radius: 4px; padding: 0 10px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.tbtn:hover { background: var(--hover); }
.tbtn.ai { border-color: #c9b25a; background: var(--accent-soft); }
.side { background: var(--side); color: var(--side-ink); overflow-y: auto; padding: 6px 0; }
.side button { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 100%; border: 0; background: none; color: inherit; padding: 9px 4px; cursor: pointer; font-size: 11px; line-height: 1.2; text-align: center; border-left: 3px solid transparent; }
.side button:hover { background: rgba(255,255,255,.07); }
.side button.on { background: rgba(245,197,24,.16); border-left-color: var(--side-sel); color: #fff; }
.side span { overflow-wrap: anywhere; max-width: 100%; }
.side svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.6; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tabs { display: flex; gap: 2px; padding: 4px 6px 0; background: var(--bg); overflow-x: auto; flex: none; border-bottom: 1px solid var(--line); }
.tab { display: flex; align-items: center; gap: 6px; padding: 6px 8px 6px 12px; background: #dedbd2; border: 1px solid var(--line); border-bottom: 0; border-radius: 5px 5px 0 0; cursor: pointer; white-space: nowrap; max-width: 260px; }
.tab span { overflow: hidden; text-overflow: ellipsis; }
.tab.on { background: var(--paper); font-weight: 600; }
.tab .x { border: 0; background: none; cursor: pointer; padding: 0 3px; color: var(--muted); font-size: 15px; line-height: 1; }
.tab .x:hover { color: var(--err); }
.work { flex: 1; overflow: auto; background: var(--paper); min-height: 0; }
.view { padding: 14px 16px 40px; min-width: 0; }
.view h1 { font-size: 18px; margin: 0 0 12px; font-weight: 600; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.view h2 { font-size: 14px; margin: 18px 0 8px; }

/* ---------- Funksiyalar paneli (bo'lim sahifasi) */
.fpanel { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 22px 28px; }
.fgroup h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line2); padding-bottom: 4px; }
.fgroup a { display: block; padding: 4px 0; color: var(--ink); }
.fgroup a:hover { color: var(--link); }
.fgroup a .kind { font-size: 10px; color: var(--muted); margin-left: 6px; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 18px; }

/* ---------- Toolbar va tugmalar */
.bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.btn { height: 28px; padding: 0 11px; border: 1px solid #bdb9ae; border-radius: 4px; background: linear-gradient(#fff, #f1efe9); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 5px; }
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.pri { background: linear-gradient(#ffd84d, #f5c518); border-color: #c9a210; color: var(--accent-ink); font-weight: 600; }
.btn.pri:hover { background: #ffd84d; }
.btn.danger { color: var(--err); }
.btn.sm { height: 24px; padding: 0 8px; font-size: 12px; }
.bar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 3px; }
.bar input, .bar select { height: 28px; border: 1px solid var(--line); border-radius: 4px; padding: 0 8px; background: var(--paper); }
.bar .grow { flex: 1; }
.help { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 700; color: var(--muted); }
.helptext { background: var(--accent-soft); border: 1px solid #ecd78b; border-radius: 5px; padding: 8px 12px; margin-bottom: 10px; max-width: 900px; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible, textarea:focus-visible { outline: 2px solid #c9a210; outline-offset: 1px; }

/* ---------- Jadvallar */
.grid { overflow: auto; border: 1px solid var(--line); border-radius: 4px; max-height: calc(100vh - 210px); background: var(--paper); }
table { border-collapse: collapse; width: 100%; }
.grid table { min-width: 100%; }
th { position: sticky; top: 0; z-index: 1; background: linear-gradient(#f7f6f2, #ebe8e0); border-bottom: 1px solid var(--line); border-right: 1px solid var(--line2); padding: 5px 7px; text-align: left; font-weight: 600; font-size: 12px; white-space: nowrap; }
td { border-bottom: 1px solid var(--line2); border-right: 1px solid #f0eee8; padding: 4px 7px; vertical-align: top; }
tbody tr:hover td { background: var(--hover); }
tbody tr.sel td { background: var(--sel); }
tr.del td { color: var(--muted); text-decoration: line-through; }
tr.grp td { font-weight: 600; background: #f6f4ee; }
tfoot td { font-weight: 700; background: #f4f2ec; position: sticky; bottom: 0; }
.st { width: 18px; text-align: center; }
.st i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; vertical-align: -1px; }
.st i.p { background: var(--ok); }
.st i.u { border: 1.5px solid var(--muted); }
.st i.d { background: var(--err); }
.lockic { color: var(--warn); font-size: 11px; }
.empty { padding: 26px; text-align: center; color: var(--muted); }
.clickable td { cursor: pointer; }

/* ---------- Formalar */
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px 16px; max-width: 1100px; margin-bottom: 12px; }
.fld { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.fld.wide { grid-column: 1 / -1; }
.fld > label { font-size: 12px; color: var(--muted); }
.fld.req > label::after { content: " *"; color: var(--err); }
.inp, .fld input:not([type=checkbox]), .fld select, .fld textarea { height: 28px; border: 1px solid var(--line); border-radius: 3px; padding: 0 7px; background: #fff; width: 100%; min-width: 0; }
.fld textarea { height: 60px; padding: 5px 7px; resize: vertical; }
.chk { flex-direction: row; align-items: center; gap: 7px; padding-top: 18px; }
.chk > label { color: var(--ink); font-size: 13px; }
input.money, input.numi { text-align: right; font-variant-numeric: tabular-nums; }
.ref { position: relative; display: flex; }
.ref input { flex: 1; border-top-right-radius: 0 !important; border-bottom-right-radius: 0 !important; }
.ref .pick { width: 26px; border: 1px solid var(--line); border-left: 0; background: var(--panel); cursor: pointer; border-radius: 0 3px 3px 0; color: var(--muted); }
.ref.bad input { border-color: var(--err); }
.docnum { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 10px; }
.docnum .fld { width: 150px; }
.status-pill { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
.status-pill.p { background: var(--ok-soft); color: var(--ok); }
.status-pill.u { background: #eee; color: var(--muted); }
.status-pill.d { background: var(--err-soft); color: var(--err); }
.lockbar { background: var(--warn-soft); color: var(--warn); border: 1px solid #ecd2a0; padding: 7px 10px; border-radius: 4px; margin-bottom: 10px; }

/* Jadval qismi (tabular section) */
.tp { border: 1px solid var(--line); border-radius: 4px; overflow: auto; max-height: 52vh; }
.tp table td { padding: 0; }
.tp table td.rn { padding: 4px 6px; color: var(--muted); text-align: right; width: 34px; background: #faf9f6; }
.tp input, .tp select { border: 0; height: 27px; width: 100%; padding: 0 6px; background: transparent; min-width: 50px; }
.tp input:focus, .tp select:focus { background: #fffbe8; outline: 1px solid #e3c34d; }
.tp .ro { padding: 4px 6px; text-align: right; color: var(--muted); white-space: nowrap; }
.tp tr.sel td { background: var(--sel); }
.tp .ref .pick { border: 0; background: transparent; }
.totals { display: flex; gap: 22px; justify-content: flex-end; padding: 8px 4px; flex-wrap: wrap; }
.totals b { font-variant-numeric: tabular-nums; }
.foot { display: flex; gap: 16px; color: var(--muted); font-size: 12px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- Dropdown */
.dd { position: fixed; z-index: 1000; background: #fff; border: 1px solid #bdb9ae; box-shadow: 0 6px 20px rgba(0,0,0,.18); border-radius: 4px; max-height: 300px; overflow-y: auto; min-width: 240px; }
.dd div { padding: 5px 9px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dd div.on, .dd div:hover { background: var(--sel); }
.dd div small { color: var(--muted); margin-left: 6px; }
.dd .new { border-top: 1px solid var(--line2); color: var(--link); }

/* ---------- Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(30,30,30,.35); z-index: 900; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--paper); border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,.3); width: min(880px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal.sm { width: min(460px, 100%); }
.modal header { padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 600; display: flex; align-items: center; gap: 8px; background: var(--panel); border-radius: 6px 6px 0 0; }
.modal header .x { margin-left: auto; border: 0; background: none; font-size: 18px; cursor: pointer; color: var(--muted); }
.modal .body { padding: 14px; overflow: auto; }
.modal footer { padding: 10px 14px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- Bosh sahifa */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { border: 1px solid var(--line); border-radius: 5px; padding: 10px 12px; background: var(--panel); cursor: pointer; }
.kpi:hover { border-color: #c9a210; }
.kpi .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .v { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 3px; overflow-wrap: anywhere; }
.cols2 { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 18px; }
@media (max-width: 1000px) { .cols2 { grid-template-columns: minmax(0, 1fr); } }
.box { border: 1px solid var(--line); border-radius: 5px; padding: 12px; min-width: 0; }
.box h2 { margin: 0 0 10px; font-size: 13px; display: flex; justify-content: space-between; align-items: center; }
.alerts { display: flex; flex-direction: column; gap: 5px; max-height: 320px; overflow: auto; }
.al { padding: 6px 9px; border-radius: 4px; border-left: 4px solid; cursor: pointer; }
.al.error { background: var(--err-soft); border-color: var(--err); }
.al.warn { background: var(--warn-soft); border-color: #d99a1b; }
.al.info { background: #eef3f8; border-color: #5b8bc1; }
.cal div { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line2); }
.cal .soon { color: var(--err); font-weight: 600; }
.chart svg { width: 100%; height: auto; display: block; }

/* ---------- Hisobot */
.rep-params { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; padding: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 5px; margin-bottom: 12px; }
.rep-params .fld { width: 170px; }
.rep-params .fld.w { width: 280px; }
.rep-title { font-size: 15px; font-weight: 600; margin: 4px 0 8px; }
.bline td { padding: 4px 8px; }
.bline tr.b td { font-weight: 700; background: #f6f4ee; }

/* ---------- AI panel */
.ai-panel { position: fixed; right: 0; top: 44px; bottom: 0; width: min(420px, 100%); background: var(--paper); border-left: 1px solid var(--line); box-shadow: -6px 0 20px rgba(0,0,0,.12); z-index: 800; display: flex; flex-direction: column; }
.ai-panel header { padding: 10px 12px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; background: var(--accent-soft); font-weight: 600; }
.ai-panel header .x { margin-left: auto; border: 0; background: none; font-size: 18px; cursor: pointer; }
.ai-msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.ai-msgs .m { padding: 8px 11px; border-radius: 8px; max-width: 92%; white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-msgs .u { background: #e7eef7; align-self: flex-end; }
.ai-msgs .a { background: var(--panel); border: 1px solid var(--line2); }
.ai-panel form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.ai-panel textarea { flex: 1; height: 58px; border: 1px solid var(--line); border-radius: 4px; padding: 6px; resize: none; }
.ai-sugg { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 12px 8px; }
.ai-sugg button { font-size: 12px; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 3px 9px; cursor: pointer; }

/* ---------- Toast */
.toasts { position: fixed; bottom: 16px; right: 16px; z-index: 1100; display: flex; flex-direction: column; gap: 6px; }
.toast { background: #2f3337; color: #fff; padding: 9px 14px; border-radius: 5px; max-width: 420px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.toast.err { background: var(--err); }
.toast.ok { background: var(--ok); }

/* ---------- Buyruqlar palitrasi */
.palette { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); width: min(600px, calc(100% - 32px)); background: #fff; z-index: 1000; border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,.3); overflow: hidden; }
.palette input { width: 100%; border: 0; border-bottom: 1px solid var(--line); padding: 12px 14px; font-size: 15px; outline: none; }
.palette .list { max-height: 400px; overflow-y: auto; }
.palette .list div { padding: 7px 14px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.palette .list div.on { background: var(--sel); }
.palette .list small { color: var(--muted); }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 44px auto 1fr; }
  .side { grid-row: 2; display: flex; overflow-x: auto; padding: 0; }
  .side button { width: auto; min-width: 74px; border-left: 0; border-bottom: 3px solid transparent; }
  .side button.on { border-bottom-color: var(--side-sel); }
  .top .appname, .top .search { display: none; }
  .top { overflow-x: auto; gap: 6px; padding: 0 8px; }
  .top .co { min-width: 90px; max-width: 38vw; }
  .top .tbtn { padding: 0 7px; }
  .main { grid-row: 3; }
}
@media print {
  .top, .side, .tabs, .bar, .rep-params, .noprint { display: none !important; }
  .shell { display: block; }
  .grid { max-height: none; overflow: visible; border: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
