:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #7a8795;
  --line: #e3e8ee;
  --brand: #d6202a;          /* logotip qizili */
  --brand-dark: #b0161f;
  --brand-soft: #fdecec;
  --ink-btn: #22303c;        /* asosiy amal tugmasi */
  --ink-btn-dark: #16222c;
  --accent: #f0932b;
  --ok: #1f9d55;
  --warn: #e0a800;
  --danger: #d6202a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 45, .08);
  --tap: 40px;               /* barmoq uchun eng kichik o'lcham */
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin-top: 8px; min-height: 18px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(160deg, #d6202a, #7c1013 70%, #4a0b0d);
}
.login-card {
  background: #fff; padding: 30px 26px; border-radius: 16px; width: 100%; max-width: 360px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3); text-align: center;
}
.login-logo { width: 64px; height: 64px; }
.login-card h1 { margin: 10px 0 2px; font-size: 22px; }
.login-card p { margin: 0 0 18px; font-size: 13px; }
.login-card input { width: 100%; margin-bottom: 10px; height: var(--tap); }
.login-card button { width: 100%; height: var(--tap); background: var(--brand); border-color: var(--brand); }
.login-card button:hover { background: var(--brand-dark); }

/* ---------- Karkas ---------- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: #16222c; color: #cfd8de; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; z-index: 30;
}
.brand {
  padding: 16px; font-weight: 700; font-size: 16px; color: #fff;
  border-bottom: 1px solid #24333f; display: flex; align-items: center; gap: 9px;
}
.brand-logo { width: 26px; height: 26px; flex: none; }
#nav { flex: 1; overflow-y: auto; padding: 8px 0; -webkit-overflow-scrolling: touch; }
#nav a {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 11px 16px; color: #cfd8de; text-decoration: none; font-size: 14px;
}
#nav a:hover { background: #21323f; color: #fff; }
#nav a.active { background: var(--brand); color: #fff; font-weight: 600; }
#nav .badge { background: var(--accent); color: #fff; border-radius: 10px; padding: 0 6px; font-size: 11px; }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid #24333f; font-size: 12px; }
.sidebar-foot .link {
  background: none; border: none; color: #9fb4c0; cursor: pointer; padding: 6px 0; font-size: 12px;
}

.nav-overlay { display: none; }
.nav-toggle {
  display: none; background: none; border: none; color: var(--ink);
  font-size: 22px; padding: 0 10px 0 0; cursor: pointer; line-height: 1;
}

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 10px 20px; display: flex; align-items: center; gap: 10px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h2 { margin: 0; font-size: 18px; flex: 1; min-width: 0; }
#page-actions { flex: none; }
.view { padding: 18px 20px 60px; }

/* ---------- Elementlar ---------- */
input, select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink); max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #f6c6c8; border-color: var(--brand); }
label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 3px; }
button {
  font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--ink-btn);
  background: var(--ink-btn); color: #fff; cursor: pointer; min-height: 36px;
}
button:hover { background: var(--ink-btn-dark); }
button.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
button.ghost:hover { background: #f1f4f7; }
button.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
button.danger:hover { background: var(--brand-soft); }
button.small { padding: 5px 10px; font-size: 12px; min-height: 30px; }
button:disabled { opacity: .5; cursor: not-allowed; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.card h3 { margin: 0 0 12px; font-size: 15px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.form-grid .full { grid-column: 1 / -1; }

.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.brand { border-left: 3px solid var(--brand); }
.stat.ok { border-left: 3px solid var(--ok); }
.stat.warn { border-left: 3px solid var(--warn); }
.stat.danger { border-left: 3px solid var(--danger); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; position: sticky; top: 0; }
tbody tr:hover { background: #f8fafb; }
.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line); border-radius: var(--radius); background: #fff;
}
.clickable { cursor: pointer; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px;
  background: #eef2f5; color: #4a5867; white-space: nowrap;
}
.tag.ok { background: #e3f6ea; color: #1f7a45; }
.tag.warn { background: #fdf3d8; color: #8a6400; }
.tag.danger { background: var(--brand-soft); color: #a9161d; }
.tag.brand { background: #eef2f5; color: #33414f; }
.tag.gray { background: #edf0f3; color: #5b6875; }

.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 10px; -webkit-overflow-scrolling: touch; }
.kanban .col { min-width: 250px; flex: 0 0 250px; background: #eef1f4; border-radius: var(--radius); padding: 8px; }
.kanban .col h4 { margin: 4px 6px 8px; font-size: 12px; text-transform: uppercase; color: var(--muted); }
.kanban .item {
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; margin-bottom: 8px; cursor: pointer; font-size: 13px;
}
.kanban .item:hover { border-color: var(--brand); }
.kanban .item .t { font-weight: 600; }
.kanban .item .s { font-size: 12px; color: var(--muted); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters > div { display: flex; flex-direction: column; }

.modal-back {
  position: fixed; inset: 0; background: rgba(16, 27, 36, .5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 30px 16px; z-index: 50; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 760px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal.wide { max-width: 1000px; }
.modal-head {
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.x { background: none; border: none; font-size: 24px; color: var(--muted); cursor: pointer; padding: 0 6px; min-height: 0; }
.x:hover { background: none; color: var(--ink); }

#toast-root { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 90; }
.toast { background: #182833; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 20px;
  padding: 7px 14px; cursor: pointer; font-size: 13px; min-height: 34px;
}
.chip:hover { background: #f1f4f7; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.chip.on:hover { background: var(--brand-dark); }

.bar { height: 8px; background: #e9edf1; border-radius: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); }

.timeline { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.timeline li { padding: 6px 0 6px 14px; border-left: 2px solid var(--line); position: relative; }
.timeline li:before {
  content: ''; position: absolute; left: -5px; top: 12px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--brand);
}
.timeline .when { color: var(--muted); font-size: 12px; }

/* ---------- Planshet ---------- */
@media (max-width: 1024px) {
  .app { grid-template-columns: 186px 1fr; }
  .view { padding: 14px 14px 60px; }
  .topbar { padding: 10px 14px; }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
  #nav a { padding: 12px 14px; }
}

/* ---------- Telefon: yon menyu chekkadan chiqadi ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 250px; height: 100%;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, .25);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .nav-overlay {
    display: block; position: fixed; inset: 0; background: rgba(10, 18, 25, .45);
    opacity: 0; pointer-events: none; transition: opacity .22s ease; z-index: 25;
  }
  body.nav-open .nav-overlay { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }
  .nav-toggle { display: block; }

  .topbar { padding: 10px 12px; }
  .topbar h2 { font-size: 16px; }
  .view { padding: 12px 12px 70px; }
  .card { padding: 13px; margin-bottom: 12px; }

  /* Barcha ustunlar bitta qatorga */
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }

  /* Filtrlar ustma-ust, kengligi to'liq */
  .filters { gap: 10px; }
  .filters > div { flex: 1 1 100%; }
  .filters input, .filters select, .filters button { width: 100%; }

  /* Barmoq uchun kattaroq */
  input, select, textarea { font-size: 16px; min-height: var(--tap); }  /* 16px — iPhone zoom qilmasin */
  button { min-height: var(--tap); padding: 9px 14px; }
  button.small { min-height: 32px; }
  .chip { min-height: var(--tap); padding: 8px 14px; }

  /* Jadval — yon tomonga suriladi */
  table { font-size: 12.5px; }
  th, td { padding: 8px; }
  .table-wrap { position: relative; }

  /* Oyna butun ekranni egallaydi */
  .modal-back { padding: 0; align-items: stretch; }
  .modal, .modal.wide { max-width: 100%; border-radius: 0; min-height: 100%; display: flex; flex-direction: column; }
  .modal-head { position: sticky; top: 0; background: #fff; z-index: 2; }
  .modal-body { flex: 1; padding: 14px; }
  .modal-foot { position: sticky; bottom: 0; background: #fff; }
  .modal-foot button { flex: 1; }

  .kanban .col { min-width: 78vw; flex: 0 0 78vw; }
  #toast-root { left: 12px; right: 12px; bottom: 12px; }
  .stat .value { font-size: 20px; }
}

@media (max-width: 420px) {
  .topbar h2 { font-size: 15px; }
  #page-actions button { font-size: 13px; padding: 8px 10px; }
  .view { padding: 10px 10px 70px; }
}

/* ---------- Chop etish ---------- */
.print-only { display: none; }
@media print {
  .sidebar, .topbar, #page-actions, .modal-foot, .nav-toggle, .no-print { display: none !important; }
  .app { grid-template-columns: 1fr; }
  .print-only { display: block; }
  body { background: #fff; }
}
