/* =========================================================
   მარაგი და გაყიდვები — ერთი CSS ფაილი, გარე დამოკიდებულების გარეშე
   ========================================================= */

:root {
    --violet: #5b45e0;
    --violet-d: #4834c4;
    --pink: #ff4d8d;
    --orange: #ff8a3d;
    --teal: #12b8a6;
    --blue: #2f7cf6;
    --green: #17b06b;
    --red: #ef4444;
    --amber: #f5a524;

    --ink: #17162b;
    --ink-2: #4b4a63;
    --ink-3: #85849b;
    --line: #e8e7f2;
    --bg: #f6f5fb;
    --card: #fff;

    --grad-1: linear-gradient(135deg, #5b45e0, #8b5cf6);
    --grad-2: linear-gradient(135deg, #ff4d8d, #ff8a3d);
    --grad-3: linear-gradient(135deg, #12b8a6, #2f7cf6);
    --grad-4: linear-gradient(135deg, #f5a524, #ff6a3d);

    --r: 16px;
    --r-sm: 11px;
    --sh: 0 2px 10px rgba(23, 22, 43, .06);
    --sh-lg: 0 12px 34px rgba(23, 22, 43, .13);
    --side-w: 244px;
    --font: "Noto Sans Georgian", "BPG Arial", "Sylfaen", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--violet); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 .6rem; line-height: 1.25; font-weight: 700; }
img { max-width: 100%; display: block; }

/* ---------------- გვერდითი მენიუ ---------------- */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--side-w);
    background: linear-gradient(170deg, #2a1f6b, #45308f 55%, #5b45e0);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .25s ease;
}
.sidebar.open { transform: none; }

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 20px; }
.brand-badge {
    width: 38px; height: 38px; border-radius: 12px;
    background: rgba(255, 255, 255, .16);
    display: grid; place-items: center; font-size: 20px; flex: none;
}
.brand-name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 11px 13px; border-radius: 12px;
    color: rgba(255, 255, 255, .82); font-weight: 600; font-size: 14.5px;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.nav-item.active { background: #fff; color: var(--violet-d); box-shadow: 0 6px 16px rgba(0, 0, 0, .16); }
.nav-ico { font-size: 17px; width: 22px; text-align: center; }

.side-foot { border-top: 1px solid rgba(255, 255, 255, .15); padding-top: 12px; }
.who { display: flex; align-items: center; gap: 9px; font-size: 13.5px; margin-bottom: 9px; font-weight: 600; }

.scrim {
    position: fixed; inset: 0; background: rgba(20, 18, 45, .5);
    z-index: 55; opacity: 0; pointer-events: none; transition: opacity .25s;
}
.scrim.show { opacity: 1; pointer-events: auto; }

/* ---------------- მთავარი არე ---------------- */
.main { min-height: 100vh; display: flex; flex-direction: column; padding-bottom: 82px; }

.topbar {
    position: sticky; top: 0; z-index: 40;
    display: flex; align-items: center; gap: 10px;
    padding: 11px 14px;
    background: rgba(255, 255, 255, .88);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--line);
}
.page-title { flex: 1; font-size: 17px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
    width: 38px; height: 38px; border-radius: 11px; flex: none;
    border: 1px solid var(--line); background: #fff; color: var(--ink);
    font-size: 18px; line-height: 1; display: grid; place-items: center; cursor: pointer;
}
.icon-btn:active { transform: scale(.94); }

.content { padding: 16px 14px 24px; flex: 1; }
.flash-wrap { padding: 12px 14px 0; }

/* ---------------- ქვედა ტაბები (მობილური) ---------------- */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    display: grid; grid-template-columns: repeat(5, 1fr);
    background: rgba(255, 255, 255, .95);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
}
.tab {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 9px 2px 8px; color: var(--ink-3); font-size: 10.5px; font-weight: 600;
}
.tab-ico { font-size: 19px; line-height: 1; filter: grayscale(1) opacity(.6); transition: filter .15s; }
.tab.active { color: var(--violet); }
.tab.active .tab-ico { filter: none; transform: translateY(-1px); }

/* ---------------- ბარათები ---------------- */
.card {
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--r); box-shadow: var(--sh); padding: 16px; margin-bottom: 14px;
}
.card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    margin: -2px 0 14px;
}
.card-head h2, .card-head h3 { margin: 0; font-size: 16px; }
.card-pad-0 { padding: 0; overflow: hidden; }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin: 22px 0 10px; font-weight: 700; }

/* ---------------- სტატისტიკის ბარათები ---------------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 11px; margin-bottom: 16px; }
.stat {
    border-radius: var(--r); padding: 15px 14px; color: #fff;
    box-shadow: var(--sh-lg); position: relative; overflow: hidden; min-height: 96px;
    display: flex; flex-direction: column; justify-content: space-between;
}
.stat::after {
    content: ""; position: absolute; right: -26px; top: -26px;
    width: 92px; height: 92px; border-radius: 50%; background: rgba(255, 255, 255, .14);
}
.stat.v1 { background: var(--grad-1); }
.stat.v2 { background: var(--grad-2); }
.stat.v3 { background: var(--grad-3); }
.stat.v4 { background: var(--grad-4); }
.stat-lbl { font-size: 12.5px; opacity: .92; font-weight: 600; }
.stat-val { font-size: 22px; font-weight: 800; letter-spacing: -.02em; margin-top: 6px; }
.stat-sub { font-size: 11.5px; opacity: .85; margin-top: 2px; }

/* ---------------- ღილაკები ---------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 10px 16px; border-radius: 11px; border: 1px solid transparent;
    font: inherit; font-weight: 600; font-size: 14.5px; cursor: pointer;
    background: #eeecf8; color: var(--ink); transition: transform .1s, filter .15s, background .15s;
    text-align: center; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--grad-1); color: #fff; box-shadow: 0 6px 16px rgba(91, 69, 224, .3); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-pink { background: var(--grad-2); color: #fff; box-shadow: 0 6px 16px rgba(255, 77, 141, .3); }
.btn-green { background: var(--green); color: #fff; }
.btn-danger { background: #fde8e8; color: #c62828; }
.btn-danger:hover { background: #fbd5d5; }
.btn-ghost { background: rgba(255, 255, 255, .14); color: #fff; border-color: rgba(255, 255, 255, .25); }
.btn-outline { background: #fff; border-color: var(--line); color: var(--ink-2); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn-lg { padding: 13px 22px; font-size: 16px; border-radius: 13px; }
.btn-block { display: flex; width: 100%; }
.btn-row { display: flex; gap: 9px; flex-wrap: wrap; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------------- ფორმები ---------------- */
.field { margin-bottom: 14px; }
.fl { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; }
.req { color: var(--pink); }
.hint { display: block; color: var(--ink-3); font-size: 12px; margin-top: 4px; }
.err { display: block; color: var(--red); font-size: 12.5px; margin-top: 4px; font-weight: 600; }
.has-err input, .has-err select, .has-err textarea { border-color: var(--red) !important; background: #fff6f6; }

/* ყველა ტექსტური input — მათ შორის type-ის გარეშე დაწერილიც */
input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=hidden]):not([type=submit]):not([type=button]):not([type=reset]),
select, textarea {
    width: 100%; padding: 11px 13px; font: inherit; font-size: 16px; /* 16px — iOS არ აზუმებს */
    color: var(--ink); background: #fff;
    border: 1.5px solid var(--line); border-radius: var(--r-sm);
    transition: border-color .15s, box-shadow .15s; appearance: none;
}
input:not([type=checkbox]):not([type=radio]):focus, select:focus, textarea:focus {
    outline: none; border-color: var(--violet); box-shadow: 0 0 0 3.5px rgba(91, 69, 224, .14);
}
textarea { resize: vertical; min-height: 78px; }
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='%2385849b' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 13px center; padding-right: 34px;
}
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 12px; }

/* ჩამრთველი */
.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.slider {
    width: 46px; height: 27px; border-radius: 99px; background: #d8d6e8;
    position: relative; transition: background .2s; flex: none;
}
.slider::before {
    content: ""; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px;
    border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .25); transition: transform .2s;
}
.switch input:checked + .slider { background: var(--violet); }
.switch input:checked + .slider::before { transform: translateX(19px); }
.switch-txt { font-size: 14px; font-weight: 600; color: var(--ink-2); }

/* ---------------- შეტყობინებები ---------------- */
.alert {
    border-radius: var(--r-sm); padding: 11px 14px; margin-bottom: 11px;
    font-size: 14px; font-weight: 600; border: 1px solid transparent;
}
.alert.ok { background: #e7f8f0; color: #0d6b45; border-color: #bfead7; }
.alert.err { background: #fdecec; color: #a12222; border-color: #f7cfcf; }
.alert.warn { background: #fff5e2; color: #8a5a06; border-color: #fae2b7; }
.alert.info { background: #e8f0fe; color: #1a4fa0; border-color: #cddffb; }
.alert p { margin: 6px 0; font-weight: 500; }
.warn-strong { color: #a12222; font-weight: 700 !important; }

/* ---------------- სია / ცხრილი ---------------- */
.list { display: flex; flex-direction: column; }
.row-item {
    display: flex; align-items: center; gap: 12px; padding: 12px 14px;
    border-bottom: 1px solid var(--line); color: inherit; transition: background .12s;
}
.row-item:last-child { border-bottom: 0; }
.row-item:active { background: #f7f6fd; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 700; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-end { text-align: right; flex: none; }
.row-amt { font-weight: 800; font-size: 15px; }

.thumb {
    width: 52px; height: 52px; border-radius: 12px; object-fit: cover; flex: none;
    background: #f0eefa; border: 1px solid var(--line);
}
.thumb.ph { display: grid; place-items: center; font-size: 22px; }
.avatar {
    width: 44px; height: 44px; border-radius: 50%; flex: none;
    display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px;
}
.avatar.sm { width: 30px; height: 30px; font-size: 12px; }
.avatar.lg { width: 66px; height: 66px; font-size: 23px; }

.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th, table.tbl td { padding: 10px 12px; text-align: right; white-space: nowrap; }
table.tbl th:first-child, table.tbl td:first-child { text-align: left; white-space: normal; }
table.tbl th {
    font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--ink-3); border-bottom: 1.5px solid var(--line);
}
table.tbl td { border-bottom: 1px solid var(--line); }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tfoot td { font-weight: 800; border-top: 2px solid var(--line); border-bottom: 0; }

/* ---------------- ნიშნულები ---------------- */
.pill {
    display: inline-block; padding: 3px 9px; border-radius: 99px;
    font-size: 11.5px; font-weight: 700; white-space: nowrap;
}
.pill.green { background: #dff5e9; color: #0d7a4d; }
.pill.red { background: #fde6e6; color: #b52121; }
.pill.amber { background: #fdf0d8; color: #8a5a06; }
.pill.blue { background: #e4edfd; color: #1a4fa0; }
.pill.grey { background: #eeedf5; color: var(--ink-2); }
.pill.violet { background: #ece8fd; color: var(--violet-d); }

.kv { display: grid; grid-template-columns: minmax(96px, 38%) 1fr; gap: 9px 12px; font-size: 14px; }
.kv dt { color: var(--ink-3); font-weight: 600; }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }

.empty { text-align: center; padding: 42px 18px; color: var(--ink-3); }
.empty-ico { font-size: 46px; margin-bottom: 10px; opacity: .5; }
.empty h3 { color: var(--ink-2); font-size: 16px; }

.toolbar { display: flex; gap: 9px; margin-bottom: 14px; align-items: center; }
.toolbar .search { flex: 1; position: relative; }
.toolbar .search input { padding-left: 38px; font-size: 15px; }
.toolbar .search::before {
    content: "🔍"; position: absolute; left: 13px; top: 50%;
    transform: translateY(-50%); font-size: 14px; opacity: .6; pointer-events: none;
}

/* ---------------- გაყიდვის რედაქტორი ---------------- */
.sale-line {
    display: grid; grid-template-columns: 1fr auto; gap: 10px;
    padding: 12px; border: 1.5px solid var(--line); border-radius: var(--r-sm);
    margin-bottom: 10px; background: #fcfcff;
}
.sale-line .ln-top { grid-column: 1 / -1; }
.sale-line .ln-nums { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; }
.ln-total { font-weight: 800; font-size: 15px; min-width: 84px; text-align: right; padding-bottom: 11px; }
.ln-del {
    width: 38px; height: 42px; border-radius: 10px; border: 1px solid #f5cfcf;
    background: #fdeeee; color: #c62828; font-size: 17px; cursor: pointer; flex: none;
}
.mini-lbl { font-size: 11px; font-weight: 700; color: var(--ink-3); display: block; margin-bottom: 4px; }
.stock-note { font-size: 11.5px; color: var(--ink-3); margin-top: 5px; }

.totals-box {
    background: var(--grad-1); color: #fff; border-radius: var(--r);
    padding: 15px; margin-top: 6px; box-shadow: var(--sh-lg);
}
.totals-row { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 7px; opacity: .93; }
.totals-row.big { font-size: 20px; font-weight: 800; opacity: 1; margin: 10px 0 0; padding-top: 10px; border-top: 1px solid rgba(255, 255, 255, .28); }

.picker-results {
    position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px);
    background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm);
    box-shadow: var(--sh-lg); max-height: 270px; overflow-y: auto; display: none;
}
.picker-results.show { display: block; }
.picker-item { padding: 10px 13px; cursor: pointer; border-bottom: 1px solid var(--line); font-size: 14px; }
.picker-item:last-child { border-bottom: 0; }
.picker-item:hover, .picker-item.hi { background: #f2effe; }
.picker-item small { color: var(--ink-3); display: block; font-size: 12px; }
.picker-wrap { position: relative; }

/* ---------------- ავტორიზაცია / ინსტალაცია ---------------- */
.auth-body, .install-body {
    display: grid; place-items: center; min-height: 100vh; padding: 22px 16px;
    background: linear-gradient(150deg, #2a1f6b, #5b45e0 48%, #ff4d8d 130%);
}
.auth-card, .install-card {
    width: 100%; max-width: 420px; background: #fff;
    border-radius: 22px; padding: 30px 24px; box-shadow: 0 22px 60px rgba(20, 14, 60, .35);
}
.install-card { max-width: 560px; }
.auth-head, .install-head { text-align: center; margin-bottom: 22px; }
.auth-head h1, .install-head h1 { font-size: 22px; margin-bottom: 5px; }
.auth-head p, .install-head p { color: var(--ink-3); font-size: 13.5px; margin: 0; }
.logo-badge {
    width: 62px; height: 62px; border-radius: 19px; margin: 0 auto 13px;
    background: var(--grad-1); display: grid; place-items: center;
    font-size: 30px; box-shadow: 0 10px 26px rgba(91, 69, 224, .38);
}
.sect {
    font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--ink-3); margin: 20px 0 11px; padding-bottom: 7px; border-bottom: 1px solid var(--line);
}
code { background: #f0eefa; padding: 2px 6px; border-radius: 5px; font-size: 13px; }

/* ---------------- სურათის ატვირთვა ---------------- */
.img-drop {
    border: 2px dashed #d5d2ea; border-radius: var(--r); padding: 18px;
    text-align: center; background: #faf9ff; cursor: pointer; transition: border-color .15s, background .15s;
}
.img-drop:hover { border-color: var(--violet); background: #f4f1ff; }
.img-drop input[type=file] { display: none; }
.img-preview { width: 128px; height: 128px; border-radius: 14px; object-fit: cover; margin: 0 auto 11px; border: 1px solid var(--line); }
.img-drop-ico { font-size: 34px; margin-bottom: 6px; }

/* ---------------- დამხმარეები ---------------- */
.muted { color: var(--ink-3); }
.tr { text-align: right; }
.tc { text-align: center; }
.mb0 { margin-bottom: 0; }
.mt16 { margin-top: 16px; }
.strong { font-weight: 800; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.nowrap { white-space: nowrap; }
.fade-in { animation: fade .22s ease both; }
@keyframes fade { from { opacity: 0; transform: translateY(5px); } }

.sortable-handle { cursor: grab; color: var(--ink-3); font-size: 17px; padding: 0 4px; touch-action: none; }
.drag-ghost { opacity: .45; }

/* ---------------- დესკტოპი ---------------- */
@media (min-width: 560px) {
    .grid2 { grid-template-columns: 1fr 1fr; }
    /* auto-fit — 2 ბარათი მთელ სიგანეს ავსებს, 4 კი ერთ რიგში ჯდება */
    .stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
    .content { padding: 20px; }
}

@media (min-width: 900px) {
    .sidebar { transform: none; }
    .scrim { display: none; }
    .main { margin-left: var(--side-w); padding-bottom: 0; }
    .tabbar { display: none; }
    .burger { display: none; }
    .topbar { padding: 13px 22px; }
    .page-title { font-size: 19px; }
    .content { padding: 22px; max-width: 1180px; }
    .flash-wrap { padding: 14px 22px 0; max-width: 1180px; }
    .stat-val { font-size: 25px; }
}

@media print {
    .sidebar, .tabbar, .topbar, .btn, .scrim { display: none !important; }
    .main { margin: 0; padding: 0; }
    .card { box-shadow: none; border-color: #ccc; }
}
