/* ══════════════════════════════════════════════════
   TOKENS
══════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:        #f2f4f7;
    --surface:   #ffffff;
    --ink:       #0f172a;
    --ink2:      #475569;
    --ink3:      #94a3b8;
    --border:    #e2e8f0;
    --border2:   #cbd5e1;
    --accent:    #0f172a;

    --green-bg:  #dcfce7; --green-fg: #15803d;
    --blue-bg:   #dbeafe; --blue-fg:  #1d4ed8;
    --red-bg:    #fee2e2; --red-fg:   #b91c1c;
    --tag-bg:    #ede9fe; --tag-fg:   #5b21b6;
    --sel-ring:  #3b82f6;
    --sel-bg:    #eff6ff;

    --r10: 10px; --r14: 14px; --r20: 20px; --r99: 999px;
    --sh:  0 1px 3px rgba(0,0,0,.07), 0 4px 12px rgba(0,0,0,.05);
    --sh-modal: 0 -4px 40px rgba(0,0,0,.18);
}

html { -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg); color: var(--ink); direction: rtl;
    -webkit-font-smoothing: antialiased; min-height: 100dvh;
}
.hidden { display: none !important; }

/* ══════════════════════════════════════════════════
   TOP BAR
══════════════════════════════════════════════════ */
.topbar {
    position: sticky; top: 0; z-index: 200;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 14px;
    height: calc(54px + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 0 var(--border), 0 2px 8px rgba(0,0,0,.04);
}
.topbar-title {
    font-size: 17px; font-weight: 700; letter-spacing: -.2px; white-space: nowrap;
}
.topbar-actions { display: flex; align-items: center; gap: 6px; }

/* ── icon-btn (search, reset, select) */
.icon-btn {
    width: 38px; height: 38px; border-radius: var(--r10);
    border: none; background: var(--bg); color: var(--ink);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    transition: opacity .12s, transform .1s, background .15s;
}
.icon-btn:active { opacity: .6; transform: scale(.92); }
.icon-btn.active { background: var(--accent); color: #fff; }

/* ── add-btn */
.add-btn {
    height: 38px; padding: 0 13px; gap: 5px;
    border-radius: var(--r10); border: none;
    background: var(--accent); color: #fff;
    font-family: inherit; font-size: 14px; font-weight: 700;
    display: flex; align-items: center; white-space: nowrap;
    cursor: pointer; -webkit-tap-highlight-color: transparent;
    transition: opacity .12s, transform .1s;
}
.add-btn:active { opacity: .7; transform: scale(.93); }

/* ══════════════════════════════════════════════════
   BULK ACTION BAR
══════════════════════════════════════════════════ */
.bulk-bar {
    position: sticky;
    top: calc(54px + env(safe-area-inset-top, 0px));
    z-index: 190;
    background: var(--sel-bg);
    border-bottom: 1.5px solid var(--sel-ring);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.bulk-count {
    font-size: 14px; font-weight: 700; color: var(--sel-ring);
    white-space: nowrap; flex-shrink: 0;
}
.bulk-actions {
    display: flex; gap: 7px; flex-wrap: wrap; flex: 1;
    justify-content: flex-end;
}
.bulk-btn {
    border: none; font-family: inherit; font-size: 13px; font-weight: 700;
    padding: 8px 12px; border-radius: var(--r10); cursor: pointer;
    white-space: nowrap; -webkit-tap-highlight-color: transparent;
    transition: opacity .12s, transform .1s;
}
.bulk-btn:active { opacity: .7; transform: scale(.96); }
.bulk-btn:disabled { opacity: .35; cursor: not-allowed; }
.bulk-outline { background: var(--surface); color: var(--ink); border: 1.5px solid var(--border2); }
.bulk-green   { background: var(--green-bg); color: var(--green-fg); }
.bulk-gray    { background: var(--bg); color: var(--ink2); }
.bulk-red     { background: var(--red-bg); color: var(--red-fg); }

/* ══════════════════════════════════════════════════
   MAIN
══════════════════════════════════════════════════ */
.main {
    max-width: 640px; margin: 0 auto; padding: 14px 12px;
    padding-bottom: max(28px, env(safe-area-inset-bottom));
    display: flex; flex-direction: column; gap: 12px;
}

/* ══════════════════════════════════════════════════
   SEARCH
══════════════════════════════════════════════════ */
.search-wrap { display: flex; flex-direction: column; }
.search-shell {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; background: var(--surface);
    border: 1.5px solid var(--border2); border-radius: var(--r14); box-shadow: var(--sh);
}
.search-shell input {
    flex: 1; border: none; outline: none; font-size: 16px;
    font-family: inherit; background: transparent; color: var(--ink); min-width: 0;
}
.search-shell input::placeholder { color: var(--ink3); }
.clear-btn {
    border: none; background: var(--border); color: var(--ink2);
    width: 24px; height: 24px; border-radius: var(--r99);
    font-size: 11px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

/* ══════════════════════════════════════════════════
   CATEGORY TABS
══════════════════════════════════════════════════ */
.cat-tabs {
    display: flex; flex-direction: row; flex-wrap: nowrap;
    gap: 8px; overflow-x: auto; overflow-y: hidden; padding: 2px 0 6px;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.cat-tabs::-webkit-scrollbar { display: none; }
.tab-btn {
    flex-shrink: 0; border: none; padding: 9px 16px; border-radius: var(--r99);
    background: var(--surface); color: var(--ink);
    font-family: inherit; font-size: 14px; font-weight: 600;
    cursor: pointer; white-space: nowrap; box-shadow: var(--sh);
    -webkit-tap-highlight-color: transparent;
    transition: background .14s, color .14s;
}
.tab-btn:active { opacity: .7; }
.tab-btn.active { background: var(--accent); color: #fff; box-shadow: none; }

/* ══════════════════════════════════════════════════
   ITEMS
══════════════════════════════════════════════════ */
.items-list { display: flex; flex-direction: column; gap: 10px; }

/* ── item card */
.item-card {
    background: var(--surface); border-radius: var(--r20);
    padding: 14px 16px 12px; box-shadow: var(--sh);
    transition: opacity .2s, border-color .15s;
    border: 2px solid transparent;
    position: relative;
}
.item-card.is-done { opacity: .55; }

/* select mode hover */
.item-card.selectable { cursor: pointer; }
.item-card.selectable:active { opacity: .75; }

/* selected state */
.item-card.selected {
    border-color: var(--sel-ring);
    background: var(--sel-bg);
    opacity: 1 !important;
}

/* ── checkbox */
.item-checkbox {
    position: absolute;
    top: 14px; left: 14px;          /* left = start in RTL → visual left */
    width: 24px; height: 24px;
    border-radius: 7px;
    border: 2px solid var(--border2);
    background: var(--surface);
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, border-color .15s;
    flex-shrink: 0;
}
.item-checkbox.checked {
    background: var(--sel-ring);
    border-color: var(--sel-ring);
}

/* push content right when checkbox visible */
.item-card.selectable .card-main,
.item-card.selectable .card-note,
.item-card.selectable .cat-badge {
    padding-left: 36px;
}

.card-main {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.card-name {
    flex: 1; font-size: 18px; font-weight: 700;
    line-height: 1.3; letter-spacing: -.1px;
}
.card-name.struck { text-decoration: line-through; color: var(--ink3); }

.card-qty {
    font-size: 13px; font-weight: 600; color: var(--ink2);
    background: var(--bg); padding: 3px 10px; border-radius: var(--r99);
    border: 1px solid var(--border); white-space: nowrap;
}
.card-note { margin-top: 5px; font-size: 13px; color: var(--ink3); line-height: 1.45; }

.cat-badge {
    display: inline-flex; align-items: center; gap: 3px;
    margin-top: 6px; padding: 3px 9px; border-radius: var(--r99);
    background: var(--tag-bg); color: var(--tag-fg); font-size: 12px; font-weight: 600;
}

/* ── card action buttons */
.card-actions {
    display: grid; grid-template-columns: 2fr 1.2fr 1.2fr;
    gap: 7px; margin-top: 11px;
}
.card-actions button {
    border: none; font-family: inherit; font-size: 13px; font-weight: 700;
    padding: 10px 6px; border-radius: var(--r10); cursor: pointer;
    white-space: nowrap; -webkit-tap-highlight-color: transparent;
    transition: opacity .12s, transform .1s;
}
.card-actions button:active { opacity: .7; transform: scale(.97); }
.btn-check { background: var(--green-bg); color: var(--green-fg); }
.btn-edit  { background: var(--blue-bg);  color: var(--blue-fg);  }
.btn-del   { background: var(--red-bg);   color: var(--red-fg);   }

/* ── empty */
.empty-state {
    text-align: center; padding: 40px 20px; color: var(--ink3);
    font-size: 15px; font-weight: 500; background: var(--surface);
    border-radius: var(--r20); box-shadow: var(--sh);
}

/* ══════════════════════════════════════════════════
   MODAL
══════════════════════════════════════════════════ */
.modal-overlay {
    position: fixed; inset: 0; z-index: 500;
    background: rgba(15,23,42,.55);
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    display: flex; align-items: flex-end; justify-content: center;
}
.modal-sheet {
    width: 100%; max-width: 580px; background: var(--surface);
    border-radius: 28px 28px 0 0; box-shadow: var(--sh-modal);
    max-height: 92dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom, 16px);
    animation: slideUp .22s cubic-bezier(.32,.72,0,1) both;
}
@keyframes slideUp {
    from { transform: translateY(48px); opacity: .3; }
    to   { transform: translateY(0);    opacity: 1;  }
}
.modal-drag {
    width: 36px; height: 4px; background: var(--border2);
    border-radius: var(--r99); margin: 12px auto 0;
}
.modal-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 12px; padding: 16px 20px 8px;
}
.modal-title { font-size: 20px; font-weight: 800; letter-spacing: -.3px; }
.modal-sub { margin-top: 4px; font-size: 13px; color: var(--ink2); font-weight: 500; }
.close-btn {
    border: none; background: var(--bg); color: var(--ink2);
    width: 32px; height: 32px; border-radius: var(--r99); font-size: 13px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    -webkit-tap-highlight-color: transparent;
}
.modal-body { padding: 8px 20px 12px; display: flex; flex-direction: column; gap: 10px; }
.field {
    width: 100%; border: 1.5px solid var(--border); border-radius: var(--r14);
    padding: 14px 15px; font-family: inherit; font-size: 16px; color: var(--ink);
    background: var(--surface); outline: none; -webkit-appearance: none;
    transition: border-color .15s, box-shadow .15s;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15,23,42,.08); }
.field::placeholder { color: var(--ink3); }
.submit-btn {
    width: 100%; margin-top: 4px; border: none; padding: 16px;
    border-radius: var(--r14); background: var(--accent); color: #fff;
    font-family: inherit; font-size: 17px; font-weight: 800; letter-spacing: -.2px;
    cursor: pointer; -webkit-tap-highlight-color: transparent;
    transition: opacity .12s, transform .1s;
}
.submit-btn:active { opacity: .8; transform: scale(.98); }
body.modal-open { overflow: hidden; touch-action: none; }

/* ══════════════════════════════════════════════════
   LOGIN
══════════════════════════════════════════════════ */
.login-wrap {
    min-height: 100dvh; display: flex; align-items: center;
    justify-content: center; padding: 20px;
}
.login-card {
    width: 100%; max-width: 380px; background: var(--surface);
    border-radius: var(--r20); padding: 28px 24px;
    box-shadow: 0 4px 24px rgba(0,0,0,.1);
}
.login-card h1 { font-size: 22px; font-weight: 800; margin-bottom: 20px; letter-spacing: -.3px; }
.login-card input {
    width: 100%; border: 1.5px solid var(--border); border-radius: var(--r14);
    padding: 14px 15px; font-family: inherit; font-size: 16px; outline: none;
    -webkit-appearance: none; margin-bottom: 10px; transition: border-color .15s;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
    width: 100%; border: none; padding: 15px; border-radius: var(--r14);
    background: var(--accent); color: #fff; font-family: inherit;
    font-size: 16px; font-weight: 700; cursor: pointer;
}
.login-error { color: #b91c1c; font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.login-hint { margin-top: 12px; font-size: 13px; color: var(--ink3); text-align: center; }

/* ══════════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════════ */
@media (max-width: 360px) {
    .topbar-title { font-size: 15px; }
    .card-name { font-size: 16px; }
    .card-actions button { font-size: 12px; padding: 9px 4px; }
    .bulk-btn { font-size: 12px; padding: 7px 9px; }
}
