/* Avenix CRM — sodda, ixcham, mobil va kompyuterga mos uslub */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --text: #17212f;
  --muted: #5f6b7c;
  --primary: #1f5fbf;
  --primary-ink: #ffffff;
  --primary-soft: #e8f0fc;
  --danger: #c23a32;
  --danger-soft: #fdecea;
  --ok: #1d8a52;
  --ok-soft: #e5f5ec;
  --warn: #b26b00;
  --warn-soft: #fff4e0;
  --side: #14243b;
  --side-ink: #c9d4e3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --st-new: #6366f1;
  --st-contacted: #0ea5e9;
  --st-negotiation: #f59e0b;
  --st-won: #16a34a;
  --st-lost: #94a3b8;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e141d; --surface: #151d29; --surface-2: #1a2331; --border: #273244;
    --text: #e6ebf2; --muted: #98a4b5; --primary: #5b9bf0; --primary-ink: #0b1220; --primary-soft: #1b2b45;
    --danger: #f0766d; --danger-soft: #3a1d1c; --ok: #4cc386; --ok-soft: #15301f; --warn: #f2b64c; --warn-soft: #33270f;
    --side: #0a1019; --side-ink: #aab6c7; --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.mobile-only { display: none; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  background: var(--bg); color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Layout */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: #fff; font-size: 17px; padding: 4px 10px 20px; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: #fff; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav .short { display: none; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--side-ink); font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 28px 6px; flex-wrap: wrap; }
.topbar h1 { font-size: 22px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.view { padding: 14px 28px 40px; }

/* Buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; min-height: 38px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.icon { padding: 6px; min-height: 32px; width: 32px; justify-content: center; }
.btn:disabled { opacity: .6; cursor: default; }
.btn:focus-visible, .input:focus-visible, select:focus-visible, textarea:focus-visible, .nav a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; min-height: 38px;
}
textarea { min-height: 80px; resize: vertical; }

/* Toolbar (qidiruv, filtrlar) */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.toolbar .search { flex: 1 1 240px; position: relative; }
.toolbar .search .input { padding-left: 34px; }
.toolbar .search svg { position: absolute; left: 10px; top: 10px; color: var(--muted); }
.toolbar select { width: auto; min-width: 150px; }
.count { color: var(--muted); font-size: 13px; margin-left: auto; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; gap: 8px; }
.card-b { padding: 10px 16px 16px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.kpi .sub b { color: var(--danger); font-weight: 600; }
.two { grid-template-columns: 1.3fr 1fr; margin-top: 14px; }

/* Voronka chizig'i */
.funnel { display: flex; flex-direction: column; gap: 10px; }
.funnel-row { display: grid; grid-template-columns: 120px 1fr 130px; gap: 10px; align-items: center; font-size: 14px; }
.bar { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.bar > span { display: block; height: 100%; border-radius: 99px; }
.months { display: flex; align-items: flex-end; gap: 10px; height: 140px; padding-top: 10px; }
.month { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; font-size: 12px; color: var(--muted); }
.month .col { width: 100%; max-width: 46px; background: var(--primary); border-radius: 6px 6px 2px 2px; min-height: 2px; }

/* Badge */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; }
.badge.overdue { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.today { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.done { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

/* Jadval */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
.t th, .t td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.t th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.t th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
.t th button:focus-visible { outline: 2px solid var(--primary); }
.t tr:last-child td { border-bottom: none; }
.t tbody tr:hover { background: var(--surface-2); }
.t td.actions { text-align: right; white-space: nowrap; width: 1%; }
.t .title-cell { font-weight: 600; }

/* Kanban */
.board { display: grid; grid-template-columns: repeat(5, minmax(190px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 6px; }
.column { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 200px; }
.column.drop { outline: 2px dashed var(--primary); outline-offset: -4px; }
.column-h { padding: 12px 12px 8px; border-top: 3px solid; border-radius: var(--radius) var(--radius) 0 0; }
.column-h .name { font-weight: 700; display: flex; justify-content: space-between; }
.column-h .sum { font-size: 13px; color: var(--muted); }
.column-b { padding: 4px 10px 10px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.deal-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; cursor: grab; box-shadow: var(--shadow); }
.deal-card:active { cursor: grabbing; }
.deal-card.dragging { opacity: .5; }
.deal-card .dt { font-weight: 600; font-size: 14px; }
.deal-card .meta { font-size: 13px; color: var(--muted); }
.deal-card .row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; margin-top: 6px; gap: 6px; }
.deal-card .row .num { white-space: nowrap; }
.deal-card select { width: 100%; min-height: 30px; padding: 2px 6px; font-size: 13px; }
.empty-col { font-size: 13px; color: var(--muted); text-align: center; padding: 18px 6px; border: 1px dashed var(--border); border-radius: 8px; }

/* Faoliyatlar ro'yxati */
.alist { list-style: none; margin: 0; padding: 0; }
.alist li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--border); }
.alist li:last-child { border-bottom: none; }
.alist .type-ico { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex: none; }
.alist .body { flex: 1; min-width: 0; }
.alist .at { font-weight: 600; }
.alist li.is-done .at { text-decoration: line-through; color: var(--muted); }
.check { width: 20px; height: 20px; margin-top: 6px; accent-color: var(--ok); flex: none; cursor: pointer; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs button { all: unset; cursor: pointer; padding: 8px 12px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--primary); border-color: var(--primary); }
.tabs button:focus-visible { outline: 2px solid var(--primary); }

/* Profil */
.profile { display: grid; grid-template-columns: 320px 1fr; gap: 14px; align-items: start; }
.avatar { width: 56px; height: 56px; border-radius: 14px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 20px; }
.dl { display: grid; grid-template-columns: 110px 1fr; gap: 8px 10px; font-size: 14px; margin: 14px 0 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-word; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.back { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 10px; font-size: 14px; }

.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty b { display: block; color: var(--text); margin-bottom: 4px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 16, 26, .5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 14px; width: min(620px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.sm { width: min(420px, 100%); }
.modal-h { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-h h2 { font-size: 18px; }
.modal-b { padding: 16px 18px; overflow-y: auto; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; }
.field label .req { color: var(--danger); }
.field .hint { font-size: 12px; color: var(--muted); }
.field .err { font-size: 13px; color: var(--danger); }
.field.has-err .input, .field.has-err select, .field.has-err textarea { border-color: var(--danger); background: var(--danger-soft); }
.form-alert { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; }
.checkbox-row { flex-direction: row; align-items: center; gap: 8px; }
.checkbox-row input { width: 18px; height: 18px; }

/* Toast */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: 8px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 340px; }
.toast.error { background: var(--danger); color: #fff; }

.loading { padding: 40px; text-align: center; color: var(--muted); }

/* Kirish ekrani */
.login-screen { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; padding: 16px; z-index: 70; }
.login-card { width: min(380px, 100%); padding: 28px 24px; }
body.locked .layout { visibility: hidden; }
.logout { color: var(--side-ink); margin: 16px 10px 0; width: calc(100% - 20px); justify-content: flex-start; }
.logout:hover { background: rgba(255,255,255,.06); }

/* Planshet */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two, .profile { grid-template-columns: 1fr; }
}

/* Mobil: yon menyu pastki panelga aylanadi, jadvallar kartochkaga */
@media (max-width: 760px) {
  body { font-size: 15px; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); z-index: 40; }
  .brand, .logout { display: none !important; }
  .mobile-only:not([hidden]) { display: inline-flex; }
  .nav { flex-direction: row; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; font-size: 10.5px; padding: 6px 2px; flex: 1; text-align: center; line-height: 1.2; }
  .nav .long { display: none; }
  .nav .short { display: block; white-space: nowrap; }
  .main { padding-bottom: 72px; }
  .topbar { padding: 14px 16px 4px; }
  .topbar h1 { font-size: 20px; }
  .view { padding: 10px 16px 24px; }
  .kpi .value { font-size: 21px; }
  .funnel-row { grid-template-columns: 96px 1fr; }
  .funnel-row .num { grid-column: 2; font-size: 13px; color: var(--muted); }
  .form-grid { grid-template-columns: 1fr; }
  .toolbar select { flex: 1 1 140px; min-width: 0; }
  .count { width: 100%; margin-left: 0; }
  .board { grid-template-columns: repeat(5, 82%); scroll-snap-type: x mandatory; }
  .column { scroll-snap-align: start; }
  .modal-bg { align-items: end; padding: 0; }
  .modal { border-radius: 14px 14px 0 0; max-height: 92vh; }
  .toasts { left: 16px; right: 16px; bottom: 84px; }

  /* Jadval -> kartochka */
  table.t thead { display: none; }
  table.t, .t tbody, .t tr, .t td { display: block; width: 100%; }
  .t tr { border-bottom: 1px solid var(--border); padding: 10px 12px; position: relative; }
  .t tr:last-child { border-bottom: none; }
  .t td { border: none; padding: 2px 0; display: flex; gap: 8px; }
  .t td[data-label]:not([data-label=""])::before { content: attr(data-label); color: var(--muted); min-width: 96px; font-size: 13px; }
  .t td.title-cell { font-size: 15px; padding-right: 80px; }
  .t td.title-cell::before { display: none; }
  .t td.actions { position: absolute; top: 6px; right: 6px; width: auto; }
  .dl { grid-template-columns: 96px 1fr; }
}
