:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5f6b7a;
  --border: #dde3ea;
  --primary: #0f6e6a;
  --primary-dark: #0a524f;
  --primary-soft: #e3f2f1;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warning: #9a6700;
  --warning-soft: #fff5d6;
  --success: #1a7f37;
  --success-soft: #e6f4ea;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 15px; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* Layout: header tepada, menyu chap yon panelda */
:root { --header-h: 60px; --sidebar-w: 232px; }
.icon { flex-shrink: 0; }
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  height: var(--header-h);
  background: var(--primary);
  color: #fff;
  display: grid;
  grid-template-columns: 1fr minmax(0, 2fr) 1fr;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
.topbar a { color: #fff; }
.topbar-left { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.logo { display: inline-flex; align-items: center; gap: .55rem; font-weight: 800; font-size: 1.25rem; letter-spacing: .2px; }
.logo:hover { text-decoration: none; }
.logo-mark { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 8px; background: rgba(255,255,255,.16); }
.topbar-center {
  text-align: center; font-weight: 600; font-size: .95rem; letter-spacing: .3px; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.userbox { display: flex; align-items: center; justify-content: flex-end; gap: .75rem; font-size: .9rem; min-width: 0; }
.user-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { opacity: .8; }
.userbox form { margin: 0; }
.userbox button { background: transparent; border: 1px solid rgba(255,255,255,.5); color: #fff; padding: .3rem .7rem; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.userbox button:hover { background: rgba(255,255,255,.12); }
.menu-toggle { display: none; background: transparent; border: none; color: #fff; padding: .35rem; border-radius: 6px; cursor: pointer; }
.menu-toggle:hover { background: rgba(255,255,255,.12); }

.sidebar {
  position: fixed; top: var(--header-h); bottom: 0; left: 0; z-index: 30;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 1rem .75rem;
}
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-group { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); padding: .9rem .75rem .35rem; }
.side-group:first-child { padding-top: .2rem; }
.side-nav a {
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem .75rem; border-radius: 8px;
  color: var(--text); font-weight: 500;
}
.side-nav a:hover { background: var(--bg); text-decoration: none; }
.side-nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.side-nav a.active .icon { color: var(--primary); }
.side-nav .icon { color: var(--muted); }
.sidebar-backdrop { display: none; }

body.has-shell main.container { margin-left: var(--sidebar-w); margin-top: var(--header-h); }
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
body.has-shell main.container { max-width: 1280px; margin-right: 0; }
body.has-shell main.container.narrow { max-width: 640px; }
.narrow { max-width: 560px; }

@media (max-width: 960px) {
  .topbar { grid-template-columns: auto minmax(0, 1fr) auto; padding: 0 .75rem; gap: .5rem; }
  .menu-toggle { display: inline-flex; }
  .topbar-center { font-size: .8rem; }
  .user-name { display: none; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: 4px 0 16px rgba(0,0,0,.12); }
  body.menu-open .sidebar { transform: none; }
  body.menu-open .sidebar-backdrop { display: block; position: fixed; inset: var(--header-h) 0 0 0; background: rgba(16,24,40,.35); z-index: 25; }
  body.has-shell main.container { margin-left: 0; }
  body.has-shell main.container.narrow { max-width: 560px; margin-left: auto; margin-right: auto; }
}
@media (max-width: 560px) {
  .logo span:last-child { display: none; }
}

/* Cards & grid */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; }
.kpi .label { color: var(--muted); font-size: .82rem; }
.kpi .value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; margin-top: .15rem; }
.kpi .hint { color: var(--muted); font-size: .78rem; }
.kpi.danger .value { color: var(--danger); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; background: #fafbfc; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.overdue td { background: var(--danger-soft); }
.empty { color: var(--muted); padding: 1rem 0; }

/* Badges */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #eef1f4; color: var(--muted); }
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warning-soft); color: var(--warning); }
.badge.info { background: var(--primary-soft); color: var(--primary); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .5rem .95rem; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: .92rem; cursor: pointer;
  font-family: inherit; line-height: 1.3; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: #c4ccd6; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #f0c2bd; }
.btn-sm { padding: .3rem .6rem; font-size: .84rem; }
.btn-lg { padding: .7rem 1.3rem; font-size: 1rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.inline-form { display: inline; margin: 0; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .9rem 1.1rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field.full { grid-column: 1 / -1; }
.field label { font-weight: 600; font-size: .88rem; }
.field .req { color: var(--danger); }
.field .help { color: var(--muted); font-size: .8rem; }
.field .errors { color: var(--danger); font-size: .82rem; margin: 0; padding: 0; list-style: none; }
.field-error { color: var(--danger); font-size: .82rem; min-height: 0; }
.field-error:empty { display: none; }
input.invalid { border-color: var(--danger); }
.field.checkbox { flex-direction: row; align-items: flex-start; gap: .5rem; }
.field.checkbox label { font-weight: 400; }
input[type=text], input[type=tel], input[type=password], input[type=date], input[type=email], input[type=number], input[type=search], input:not([type]), select, textarea {
  width: 100%; padding: .5rem .65rem; border: 1px solid #c9d1db; border-radius: 6px;
  font-size: .95rem; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.field.has-error input, .field.has-error select { border-color: var(--danger); }
.radio-list { display: flex; gap: 1rem; flex-wrap: wrap; list-style: none; padding: 0; margin: 0; }
.radio-list label { font-weight: 400; display: flex; gap: .35rem; align-items: center; }
.form-actions { display: flex; gap: .6rem; margin-top: 1.25rem; flex-wrap: wrap; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; margin: 0 0 1.1rem; }
legend { font-weight: 700; padding: 0 .4rem; }

/* Search */
.search-hero { display: flex; gap: .6rem; }
.search-hero input { font-size: 1.1rem; padding: .7rem .9rem; }

/* Alerts */
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.alert { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: .6rem; border: 1px solid transparent; }
.alert.success { background: var(--success-soft); color: var(--success); border-color: #bfe3c9; }
.alert.error, .alert.danger { background: var(--danger-soft); color: var(--danger); border-color: #f5c6c1; }
.alert.warning { background: var(--warning-soft); color: var(--warning); border-color: #f2dc9b; }
.alert.info { background: var(--primary-soft); color: var(--primary); border-color: #bfe0de; }

/* Definition list */
.dl { display: grid; grid-template-columns: 180px 1fr; gap: .35rem 1rem; margin: 0; }
.dl dt { color: var(--muted); font-size: .88rem; }
.dl dd { margin: 0; }

/* Issue rows */
.issue-row { display: grid; grid-template-columns: 2.2fr 1.4fr 1fr .9fr 1.1fr auto; gap: .6rem; align-items: start; padding: .75rem 0; border-bottom: 1px dashed var(--border); }
.issue-row:last-child { border-bottom: none; }
.issue-row .field label { font-size: .8rem; }
.section-hint { font-size: .78rem; color: var(--primary); min-height: 1em; }
.section-hint.bad { color: var(--danger); }
.autocomplete { position: relative; }
.suggestions { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 6px 18px rgba(16,24,40,.12); max-height: 280px; overflow-y: auto; }
.suggestions button { display: block; width: 100%; text-align: left; background: none; border: none; padding: .5rem .7rem; cursor: pointer; font: inherit; }
.suggestions button:hover, .suggestions button.active { background: var(--primary-soft); }
.suggestions .meta { color: var(--muted); font-size: .8rem; }
.suggestions { max-height: 340px; }
.suggestions-head { padding: .45rem .7rem .25rem; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.suggestions-new { padding: .55rem .7rem; font-size: .82rem; color: var(--primary); background: var(--primary-soft); border-top: 1px solid var(--border); }

/* Bars in stats tables */
.bar { height: 8px; background: var(--primary); border-radius: 4px; min-width: 2px; }
.bar-cell { width: 35%; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { color: var(--primary); font-size: 1.6rem; margin-bottom: .25rem; }

.password-box { font-size: 1.6rem; font-weight: 700; letter-spacing: 1px; background: var(--warning-soft); border: 1px dashed var(--warning); padding: .8rem 1rem; border-radius: var(--radius); display: inline-block; margin: .5rem 0 1rem; }

.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { padding: .45rem 0; display: flex; gap: .6rem; align-items: center; }

@media (max-width: 860px) {
  .issue-row { grid-template-columns: 1fr 1fr; }
  .dl { grid-template-columns: 1fr; }
  .dl dt { margin-top: .4rem; }
  .search-hero { flex-direction: column; }
}

/* Sozlamalar sahifasidagi jonli namuna */
.preview { margin-top: 1rem; background: var(--bg); border: 1px dashed var(--border); border-radius: var(--radius); padding: .8rem 1rem; font-size: .92rem; }
.preview-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: .4rem; }
.sms-bubble { background: #fff; border: 1px solid var(--border); border-radius: 14px 14px 14px 4px; padding: .6rem .8rem; margin-bottom: .4rem; line-height: 1.4; }

/* Statistika: davr filtri va hisobotlar */
.stats-top { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
.stats-top .card { margin-bottom: 0; }
.filter-row { display: flex; flex-wrap: wrap; gap: .9rem 1rem; align-items: flex-start; }
.filter-row > .field { flex: 1 1 170px; }
.filter-range { display: flex; gap: 1rem; flex: 2 1 320px; }
.filter-range .field { flex: 1; }
.filter-submit { flex: 0 0 auto !important; }
.report-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .8rem 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.report-row:first-of-type { border-top: none; padding-top: 0; }
.report-title { font-weight: 600; }
.report-actions { display: flex; gap: .5rem; align-items: center; margin: 0; }
.report-actions select { width: auto; min-width: 90px; }
.stats-top + .kpis { margin-top: 1.25rem; }
@media (max-width: 1100px) { .stats-top { grid-template-columns: 1fr; } }
.kpis-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .kpis-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.applied { display: flex; flex-wrap: wrap; gap: .4rem 1.5rem; align-items: center; margin-top: .9rem; padding-top: .8rem; border-top: 1px solid var(--border); }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.chip { display: inline-block; padding: .1rem .55rem; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: .8rem; font-weight: 600; }

/* Kitobxonlar ro'yxati */
.list-filters .grow { flex: 3 1 320px; }
.reader-table td { vertical-align: middle; }
.pager { display: flex; justify-content: space-between; align-items: center; padding-top: .9rem; margin-top: .5rem; border-top: 1px solid var(--border); }

/* Inventar raqamlari (kitob nusxalari) */
.inv { display: inline-block; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .8rem; padding: .05rem .45rem; border-radius: 5px; margin: .1rem .25rem .1rem 0; border: 1px solid; white-space: nowrap; }
.inv-in { background: var(--success-soft); color: var(--success); border-color: #bfe3c9; }
.inv-out { background: var(--warning-soft); color: var(--warning); border-color: #f2dc9b; }
.narrow-card { max-width: 640px; }

/* Jadval ichida tahrirlash (inventar raqami) */
.inline-edit { position: relative; display: inline-block; }
.inline-edit > summary { list-style: none; }
.inline-edit > summary::-webkit-details-marker { display: none; }
.inline-edit[open] > summary { background: var(--bg); }
.inline-edit-form { position: absolute; right: 0; top: calc(100% + 4px); z-index: 10; display: flex; gap: .4rem; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: .5rem; box-shadow: 0 6px 18px rgba(16,24,40,.12); }
.inline-edit-form input { width: 170px; }
