/* ==========================================================================
   Klub CRM — dizayn tizimi
   Uslub: Apple. Toza fon, ko'p bo'sh joy, yumshoq soyalar, kam rang.
   Rang faqat MA'NO uchun: yashil — kirim, qizil — chiqim, ko'k — amal.
   ========================================================================== */

/* ------------------------------- Ranglar --------------------------------- */
:root {
  color-scheme: light dark;

  --bg:            #ffffff;
  --bg-grouped:    #f5f5f7;
  --surface:       #ffffff;
  --surface-2:     #f5f5f7;
  --surface-hover: #ebebed;
  --separator:     rgba(0, 0, 0, .08);
  --separator-strong: rgba(0, 0, 0, .14);

  --text:          #1d1d1f;
  --text-2:        #6e6e73;
  --text-3:        #a1a1a6;

  --accent:        #0071e3;
  --accent-soft:   rgba(0, 113, 227, .1);
  --green:         #1a9d55;
  --green-soft:    rgba(26, 157, 85, .1);
  --red:           #d70015;
  --red-soft:      rgba(215, 0, 21, .1);
  --orange:        #b25000;
  --orange-soft:   rgba(178, 80, 0, .1);

  --r-sm: 8px;
  --r:    12px;
  --r-lg: 18px;
  --r-xl: 24px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.04), 0 1px 3px rgba(0,0,0,.06);
  --shadow:    0 4px 16px rgba(0,0,0,.08);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.18);

  --nav-w: 240px;
  --ease: cubic-bezier(.4, 0, .2, 1);

  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display',
               'Inter', 'Segoe UI', system-ui, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #000000;
    --bg-grouped:    #000000;
    --surface:       #1c1c1e;
    --surface-2:     #2c2c2e;
    --surface-hover: #3a3a3c;
    --separator:     rgba(255, 255, 255, .1);
    --separator-strong: rgba(255, 255, 255, .18);

    --text:          #f5f5f7;
    --text-2:        #98989d;
    --text-3:        #6e6e73;

    --accent:        #0a84ff;
    --accent-soft:   rgba(10, 132, 255, .18);
    --green:         #30d158;
    --green-soft:    rgba(48, 209, 88, .16);
    --red:           #ff453a;
    --red-soft:      rgba(255, 69, 58, .16);
    --orange:        #ff9f0a;
    --orange-soft:   rgba(255, 159, 10, .16);

    --shadow-sm: none;
    --shadow:    0 4px 20px rgba(0,0,0,.5);
    --shadow-lg: 0 16px 60px rgba(0,0,0,.7);
  }
}

/* --------------------------------- Asos ---------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg-grouped);
  color: var(--text);
  line-height: 1.45;
  overscroll-behavior-y: none;
}
::selection { background: var(--accent-soft); }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.021em; line-height: 1.2; }
h1 { font-size: 1.75rem; letter-spacing: -.028em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.0625rem; }
p  { margin: 0; }

a { color: var(--accent); text-decoration: none; }

.t2  { color: var(--text-2); }
.t3  { color: var(--text-3); }
.sm  { font-size: .8125rem; }
.xs  { font-size: .75rem; }
.lg  { font-size: 1.125rem; }
.b   { font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.center { text-align: center; }
.hidden { display: none !important; }
.grow { flex: 1; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.row   { display: flex; align-items: center; gap: 12px; }
.row.w { flex-wrap: wrap; }
.col   { display: flex; flex-direction: column; gap: 12px; }
.gap-s { gap: 6px; }
.gap-l { gap: 20px; }

/* ------------------------------- Tugmalar -------------------------------- */
.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  font: inherit; font-weight: 500; font-size: .9375rem;
  background: var(--btn-bg); color: var(--btn-fg);
  border: none; border-radius: 980px;
  padding: 9px 18px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: opacity .15s var(--ease), transform .08s var(--ease), background .15s var(--ease);
  white-space: nowrap; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover  { opacity: .82; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .35; cursor: default; transform: none; }
.btn.primary { --btn-bg: var(--accent); --btn-fg: #fff; }
.btn.success { --btn-bg: var(--green);  --btn-fg: #fff; }
.btn.danger  { --btn-bg: var(--red);    --btn-fg: #fff; }
.btn.quiet   { --btn-bg: transparent;   --btn-fg: var(--accent); padding-inline: 10px; }
.btn.lg  { padding: 13px 24px; font-size: 1.0625rem; }
.btn.sm  { padding: 6px 13px; font-size: .8125rem; }
.btn.block { width: 100%; }
.btn.icon  { padding: 9px; width: 38px; height: 38px; border-radius: 50%; }

/* -------------------------------- Formalar ------------------------------- */
.field { display: block; margin-bottom: 16px; }
.field > label { display: block; font-size: .8125rem; color: var(--text-2); margin-bottom: 6px; font-weight: 500; }
.field .hint { font-size: .75rem; color: var(--text-3); margin-top: 6px; }

input, select, textarea {
  font: inherit; width: 100%;
  background: var(--surface-2); color: var(--text);
  border: 1px solid transparent; border-radius: var(--r);
  padding: 11px 14px;
  transition: border-color .15s var(--ease), background .15s var(--ease);
  -webkit-appearance: none; appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236e6e73' stroke-width='1.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
textarea { resize: vertical; min-height: 76px; }
.field-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input { display: none; }
.switch .track {
  width: 51px; height: 31px; border-radius: 999px; background: var(--surface-hover);
  position: relative; transition: background .2s var(--ease); flex: none;
}
.switch .track::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px;
  border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,.2);
  transition: transform .2s var(--ease);
}
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(20px); }

/* ------------------------------- Kartochka ------------------------------- */
.card {
  background: var(--surface); border-radius: var(--r-lg);
  padding: 20px; box-shadow: var(--shadow-sm);
}
.card.flat { box-shadow: none; border: 1px solid var(--separator); }
.card.p0 { padding: 0; overflow: hidden; }

.stat { background: var(--surface); border-radius: var(--r-lg); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.stat .k { font-size: .75rem; color: var(--text-2); font-weight: 500; letter-spacing: .01em; }
.stat .v { font-size: 1.5rem; font-weight: 600; letter-spacing: -.02em; margin-top: 4px; }
.stat.green .v { color: var(--green); }
.stat.red   .v { color: var(--red); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

/* --------------------------------- Nishon -------------------------------- */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .75rem; font-weight: 600; padding: 3px 9px; border-radius: 980px;
  background: var(--surface-2); color: var(--text-2);
}
.tag.green  { background: var(--green-soft);  color: var(--green); }
.tag.red    { background: var(--red-soft);    color: var(--red); }
.tag.orange { background: var(--orange-soft); color: var(--orange); }
.tag.blue   { background: var(--accent-soft); color: var(--accent); }

/* ------------------------------- Bildirish ------------------------------- */
.note {
  display: flex; gap: 12px; align-items: center;
  padding: 13px 16px; border-radius: var(--r); font-size: .875rem;
  background: var(--surface-2); color: var(--text);
}
.note .ico { font-size: 1.15rem; flex: none; line-height: 1; }
.note.blue   { background: var(--accent-soft); }
.note.orange { background: var(--orange-soft); }
.note.red    { background: var(--red-soft); }
.note.green  { background: var(--green-soft); }

/* --------------------------------- Karkas -------------------------------- */
.shell { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100dvh; }

.nav {
  background: var(--bg); border-right: 1px solid var(--separator);
  padding: 20px 12px; display: flex; flex-direction: column; gap: 2px;
  position: sticky; top: 0; height: 100dvh; overflow-y: auto;
}
.nav .brand { padding: 4px 12px 20px; }
.nav .brand .name { font-size: 1.0625rem; font-weight: 600; letter-spacing: -.02em; }
.nav .brand .who  { font-size: .75rem; color: var(--text-2); margin-top: 2px; }

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 10px; color: var(--text);
  font-size: .9375rem; font-weight: 500; cursor: pointer;
  background: none; border: none; width: 100%; text-align: left;
  transition: background .12s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.nav-item .ico { font-size: 1.05rem; width: 22px; text-align: center; flex: none; }
.nav-item:hover { background: var(--surface-2); }
.nav-item.on { background: var(--accent); color: #fff; }
.nav-item .dot {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--red); color: #fff;
  font-size: .6875rem; font-weight: 700; display: grid; place-items: center;
}
.nav-item.on .dot { background: rgba(255,255,255,.28); }
.nav-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--separator); }

.main { min-width: 0; padding: 28px 32px 64px; }
.head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 22px; }
.head h1 { flex: 1; min-width: 200px; }

/* ---------------------------- Kartochka to'ri ---------------------------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; }
.tile {
  text-align: left; font: inherit; color: inherit; cursor: pointer;
  background: var(--surface); border: 1.5px solid transparent; border-radius: var(--r-lg);
  padding: 16px; min-height: 126px; display: flex; flex-direction: column; gap: 4px;
  box-shadow: var(--shadow-sm); transition: transform .12s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.tile:hover { transform: translateY(-2px); }
.tile:active { transform: scale(.985); }

/* Bufet savdo ekrani: chapda mahsulotlar, o'ngda savat */
.sale-layout { display: grid; grid-template-columns: 1fr minmax(260px, 300px); gap: 20px; align-items: start; }
@media (max-width: 900px) { .sale-layout { grid-template-columns: 1fr; } }

/* --------------------------------- Jadval -------------------------------- */
.tbl-wrap { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); overflow: hidden; }
.tbl-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th {
  text-align: left; font-weight: 500; font-size: .6875rem; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-3);
  padding: 12px 16px; border-bottom: 1px solid var(--separator); white-space: nowrap;
}
td { padding: 13px 16px; border-bottom: 1px solid var(--separator); }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { padding: 48px 20px; text-align: center; color: var(--text-3); font-size: .9375rem; }

/* ---------------------------- Modal / panel ------------------------------ */
.scrim {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.35); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 20px;
  animation: fade .18s var(--ease);
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-lg);
  width: min(520px, 100%); max-height: min(86dvh, 760px);
  display: flex; flex-direction: column; overflow: hidden;
  animation: pop .22s var(--ease);
}
.modal.wide { width: min(860px, 100%); }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(8px); } }
.modal-head {
  padding: 18px 20px 14px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--separator);
}
.modal-head h2 { flex: 1; font-size: 1.0625rem; }
.modal-body { padding: 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-foot {
  padding: 14px 20px; display: flex; gap: 10px; justify-content: flex-end;
  border-top: 1px solid var(--separator); background: var(--surface);
}

/* ---------------------------------- Toast -------------------------------- */
#toasts {
  position: fixed; z-index: 300; bottom: 24px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: min(420px, calc(100% - 32px));
}
.toast {
  background: rgba(28,28,30,.94); color: #fff;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-radius: 14px; padding: 12px 18px; font-size: .875rem; font-weight: 500;
  box-shadow: var(--shadow-lg); animation: rise .22s var(--ease);
  display: flex; gap: 9px; align-items: center; max-width: 100%;
}
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
.toast.err { background: rgba(215,0,21,.96); }
.toast.ok  { background: rgba(26,157,85,.96); }

/* --------------------------------- Yuklanish ----------------------------- */
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--separator-strong); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; padding: 64px 0; }

/* ---------------------------------- Kirish ------------------------------- */
.login {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background: var(--bg);
}
.login-card { width: min(360px, 100%); text-align: center; }
.login-card .mark {
  width: 62px; height: 62px; border-radius: 16px; margin: 0 auto 18px;
  background: linear-gradient(135deg, var(--accent), #5856d6);
  display: grid; place-items: center; font-size: 1.8rem;
  box-shadow: 0 8px 24px rgba(0,113,227,.3);
}
.login-card h1 { font-size: 1.5rem; margin-bottom: 4px; }
.login-card .sub { color: var(--text-2); font-size: .9375rem; margin-bottom: 26px; }
.login-card .field { text-align: left; }

/* --------------------------------- Segment ------------------------------- */
.seg {
  display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 2px; gap: 2px;
  overflow-x: auto; max-width: 100%;
}
.seg button {
  font: inherit; font-size: .8125rem; font-weight: 500;
  border: none; background: none; color: var(--text-2);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ------------------------------- Telefon --------------------------------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .nav {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto;
    height: auto; width: 100%; flex-direction: row; padding: 6px 4px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    border-right: none; border-top: 1px solid var(--separator);
    background: rgba(255,255,255,.82); backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    z-index: 100; overflow-x: auto; gap: 0;
  }
  .nav .brand, .nav-foot { display: none; }
  .nav-item {
    flex-direction: column; gap: 3px; font-size: .625rem; font-weight: 500;
    padding: 6px 4px; min-width: 62px; text-align: center; border-radius: 8px;
  }
  .nav-item .ico { font-size: 1.3rem; width: auto; }
  .nav-item.on { background: none; color: var(--accent); }
  .nav-item .dot { position: absolute; margin: 0; transform: translate(16px, -8px); }
  .main { padding: 20px 16px calc(84px + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.5rem; }
  .field-2 { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(146px, 1fr)); gap: 10px; }
  .tile { padding: 13px; min-height: 112px; }
  .modal { width: 100%; max-height: 92dvh; border-radius: var(--r-xl) var(--r-xl) 0 0; align-self: end; }
  .scrim { padding: 0; align-items: end; }
  @keyframes pop { from { opacity: 0; transform: translateY(24px); } }
  #toasts { bottom: calc(90px + env(safe-area-inset-bottom)); }
}
@media (prefers-color-scheme: dark) and (max-width: 900px) {
  .nav { background: rgba(28,28,30,.8); }
}

@media print {
  .nav, .btn, .modal-foot { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  .main { padding: 0; }
  body { background: #fff; }
}
