/* ===========================================================================
   Smeta Platform — Light theme (qurilish / smeta sohasi)
   Palitra: oq fon, slate matn, ishonchli ko'k (#2563eb), qurilish amber (#f59e0b),
            pul/natija uchun yashil (#15803d).
=========================================================================== */
:root {
  --bg: #eef2f7; --panel: #ffffff; --ink: #1e293b; --muted: #64748b;
  --border: #e2e8f0; --border2: #cbd5e1; --blue: #2563eb; --blue-d: #1d4ed8;
  --amber: #f59e0b; --green: #15803d; --red: #dc2626;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; -webkit-font-smoothing: antialiased; }

/* ── Layout + Sidebar ──────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; align-items: stretch; }
.main-wrap { flex: 1; min-width: 0; }
#sidebar { width: 256px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  transition: width .2s ease; overflow: hidden; }
.sb-head { display: flex; align-items: center; gap: 12px; padding: 15px 16px; border-bottom: 1px solid var(--border); }
.sb-toggle { background: none; border: none; font-size: 19px; cursor: pointer; color: var(--muted); line-height: 1; padding: 2px; }
.sb-toggle:hover { color: var(--ink); }
.sb-title { font-weight: 700; font-size: 14px; white-space: nowrap; }
.sb-new { margin: 12px; padding: 9px 12px; background: #eff6ff; border: 1px solid #bfdbfe; color: var(--blue);
  border-radius: 9px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; text-align: left; }
.sb-new:hover { background: #dbeafe; }
.sb-list { flex: 1; overflow-y: auto; padding: 2px 8px 12px; }
.sb-item { display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 8px;
  cursor: pointer; font-size: 13px; color: var(--ink); }
.sb-item:hover { background: #f1f5f9; }
.sb-item.active { background: #eff6ff; color: var(--blue); font-weight: 600; }
.sb-icon { flex-shrink: 0; }
.sb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-x { opacity: 0; color: var(--red); font-size: 11px; flex-shrink: 0; }
.sb-item:hover .sb-x { opacity: .55; } .sb-x:hover { opacity: 1; }
.sb-empty { padding: 14px 12px; }
/* collapsed */
.layout.sb-collapsed #sidebar { width: 50px; }
.layout.sb-collapsed .sb-title,
.layout.sb-collapsed .sb-name,
.layout.sb-collapsed .sb-x,
.layout.sb-collapsed .sb-lbl,
.layout.sb-collapsed .sb-empty { display: none; }
.layout.sb-collapsed .sb-new { text-align: center; padding: 9px 0; margin: 12px 9px; }
.layout.sb-collapsed .sb-item { justify-content: center; padding: 9px 0; }

/* ── Header ─────────────────────────────────────────────────────────── */
header { display: flex; justify-content: space-between; align-items: center;
  padding: 12px 22px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10; box-shadow: var(--shadow); }
.brand { font-size: 18px; color: var(--ink); display: flex; align-items: baseline; gap: 8px; }
.brand b { font-weight: 700; }
.brand .sub { font-size: 12px; color: var(--muted); font-weight: 500;
  border-left: 2px solid var(--amber); padding-left: 8px; }
.header-right { display: flex; align-items: center; gap: 14px; }
.btn-ghost { background: #fff7ed; border: 1px solid #fed7aa; color: #b45309; border-radius: 8px;
  padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer; }
.btn-ghost:hover { background: #ffedd5; }
.stats { display: flex; gap: 10px; }
.stats span { background: #f1f5f9; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; font-size: 11px; color: var(--muted); text-align: center; }
.stats b { display: block; color: var(--blue); font-size: 15px; font-weight: 700; }

/* ── Layout ─────────────────────────────────────────────────────────── */
main { display: grid; grid-template-columns: 1fr 1.35fr 1.2fr; gap: 16px;
  padding: 18px; align-items: start; max-width: 1600px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; box-shadow: var(--shadow); }
h2 { font-size: 14px; margin-bottom: 12px; color: var(--ink); font-weight: 650; letter-spacing: -.01em; }

input, select { width: 100%; padding: 9px 11px; background: #fff; border: 1px solid var(--border2);
  border-radius: 8px; color: var(--ink); font-size: 13px; outline: none; transition: border .15s, box-shadow .15s; }
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
select { width: auto; }
.muted { color: var(--muted); font-size: 12px; }
#wt-wrap { font-weight: 400; float: right; }

/* ── Qidiruv natijalari ─────────────────────────────────────────────── */
.list { margin-top: 12px; max-height: 72vh; overflow-y: auto; }
.row { padding: 9px 11px; border-radius: 9px; cursor: pointer; border: 1px solid transparent;
  display: flex; justify-content: space-between; gap: 8px; transition: background .12s, border .12s; }
.row:hover { background: #f8fafc; border-color: var(--border); }
.row .code { color: var(--blue); font-family: ui-monospace, "SF Mono", monospace; font-size: 12px; font-weight: 600; white-space: nowrap; }
.row .title { font-size: 12px; color: var(--ink); margin-top: 2px; }
.row .add { color: #fff; background: var(--blue); width: 24px; height: 24px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; align-self: center; }
.row .add:hover { background: var(--blue-d); }

/* ── Namuna loyiha ──────────────────────────────────────────────────── */
.proj-bar { margin: 2px 0 14px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip { background: #fff7ed; border: 1px solid #fed7aa; color: #b45309; border-radius: 20px;
  padding: 6px 13px; font-size: 12px; cursor: pointer; font-weight: 600; transition: all .12s; }
.chip:hover { background: #ffedd5; border-color: var(--amber); }

/* ── Smeta jadvali ──────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 8px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .03em;
  background: #f8fafc; }
td input { width: 62px; padding: 5px 7px; }
.del { color: var(--red); cursor: pointer; font-weight: 700; opacity: .6; }
.del:hover { opacity: 1; }
#est-empty { padding: 24px 0; text-align: center; }

.btn-row { display: flex; gap: 8px; margin-top: 14px; }
.btn-row .primary { margin-top: 0; flex: 2; }
button.primary { margin-top: 14px; width: 100%; padding: 11px; background: var(--blue); color: #fff;
  border: none; border-radius: 9px; font-size: 14px; font-weight: 600; cursor: pointer; transition: background .12s; }
button.primary:disabled { background: #e2e8f0; color: #94a3b8; cursor: not-allowed; }
button.primary:hover:not(:disabled) { background: var(--blue-d); }
.btn-secondary { flex: 1; padding: 11px; background: #fff; border: 1px solid var(--border2); color: var(--ink);
  border-radius: 9px; font-size: 13px; font-weight: 600; cursor: pointer; transition: all .12s; }
.btn-secondary:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); }
.btn-secondary:disabled { color: #94a3b8; cursor: not-allowed; }
.chip-x { margin-left: 6px; opacity: .5; font-size: 10px; }
.chip-x:hover { opacity: 1; color: var(--red); }
.price-tools { display: flex; gap: 10px; align-items: center; }
.price-tools input { flex: 1; }
.import-btn { background: #f1f5f9; border: 1px solid var(--border2); border-radius: 8px; padding: 9px 14px;
  font-size: 13px; cursor: pointer; white-space: nowrap; font-weight: 600; color: var(--ink); }
.import-btn:hover { border-color: var(--blue); color: var(--blue); }
.price-row { display: flex; align-items: center; gap: 8px; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.price-row .pname { flex: 1; font-size: 12px; }
.price-row input { width: 110px; }

/* ── Natija (ССР) ───────────────────────────────────────────────────── */
.res-line { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.res-line .lbl { color: var(--muted); }
.res-line .val { font-family: ui-monospace, "SF Mono", monospace; color: var(--ink); font-weight: 500; }
.res-line.total { border-top: 2px solid var(--border2); border-bottom: none; margin-top: 6px; padding-top: 11px; font-weight: 600; }
.res-line.total .val { font-size: 15px; }
.res-line.grand { background: #f0fdf4; margin: 6px -10px 0; padding: 14px 12px; border-radius: 9px; border: 1px solid #bbf7d0; }
.res-line.grand .lbl { color: #166534; font-weight: 700; }
.res-line.grand .val { color: var(--green); font-weight: 800; font-size: 19px; }

.lineblock { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 11px; margin-bottom: 9px; }
.lineblock h4 { font-size: 12px; color: var(--blue); font-family: ui-monospace, monospace; margin-bottom: 6px; font-weight: 600; }
.warn { color: #b45309; background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: 8px 10px; font-size: 11px; margin-top: 10px; }

/* ── Bo'lim (section) ───────────────────────────────────────────────── */
.section-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.section-bar select { flex: 1; }
.mini-btn { background: #eff6ff; border: 1px solid #bfdbfe; color: var(--blue); border-radius: 7px;
  padding: 7px 11px; font-size: 12px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.mini-btn:hover { background: #dbeafe; }
.sec-row td { background: #eef2f7; font-weight: 700; color: var(--ink); font-size: 12px; padding: 7px 8px; }
.sec-h { font-size: 13px; color: var(--ink); margin: 16px 0 6px; font-weight: 700; }
.res-line.sec-sub { background: #f1f5f9; font-weight: 700; border-radius: 7px; padding: 9px 10px;
  margin: -2px 0 10px; border: none; }
.res-line.sec-sub .val { color: var(--ink); }

/* ── Eksport / hujjat / tablar ──────────────────────────────────────── */
.exp-row { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.exp-row .btn-secondary { flex: 1; padding: 9px; min-width: 90px; }
.doc-sel { flex: 1.6; min-width: 150px; padding: 9px; border: 1px solid var(--border2); border-radius: 9px;
  font-size: 12px; font-weight: 600; color: var(--ink); background: #fff; cursor: pointer; }
.doc-sel:hover { border-color: var(--blue); }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.tab { background: none; border: none; padding: 9px 13px; font-size: 13px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; font-weight: 600; margin-bottom: -1px; }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }

/* ── Resurs jamlamasi ───────────────────────────────────────────────── */
.rtot { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; font-size: 12px; color: var(--muted);
  background: #f8fafc; border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; }
.rtot b { color: var(--blue); font-size: 14px; }
.rtable { width: 100%; font-size: 11px; border-collapse: collapse; }
.rtable th { background: #f8fafc; position: sticky; top: 0; }
.rtable td, .rtable th { padding: 6px 7px; border-bottom: 1px solid var(--border); }

/* ── Koeffitsient ───────────────────────────────────────────────────── */
.coef-row { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.coef-row .coef-kind { flex: 1; font-size: 13px; font-weight: 500; }
.coef-row input { width: 90px; }

/* ── Modal ──────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; z-index: 50; backdrop-filter: blur(2px); }
.modal.hidden { display: none; }
.modal-box { background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 22px;
  max-width: 660px; max-height: 82vh; overflow-y: auto; position: relative; box-shadow: 0 20px 50px rgba(16,24,40,.25); }
.x { position: absolute; top: 12px; right: 16px; background: #f1f5f9; border: none; color: var(--muted);
  width: 30px; height: 30px; border-radius: 8px; font-size: 20px; cursor: pointer; }
.x:hover { background: #e2e8f0; }

/* ── Resurs tip teglari ─────────────────────────────────────────────── */
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 10px; font-weight: 600; margin-right: 5px; }
.tag.labor     { background: #dbeafe; color: #1d4ed8; }
.tag.machinist { background: #e0e7ff; color: #4338ca; }
.tag.machine   { background: #f3e8ff; color: #7e22ce; }
.tag.material  { background: #dcfce7; color: #15803d; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
