:root {
  --bg: #EDF1FA;
  --bg2: #E3E9F8;
  --card: rgba(255, 255, 255, .72);
  --card-solid: #FFFFFF;
  --card-press: rgba(255, 255, 255, .95);
  --line: rgba(20, 40, 110, .07);
  --text: #0B1230;
  --muted: #6A7594;
  --faint: #A3ACC4;
  --accent: #2F62F6;
  --accent-2: #4B3BE0;
  --accent-soft: rgba(47, 98, 246, .10);
  --danger: #E5484D;
  --danger-soft: rgba(229, 72, 77, .10);
  --ok: #19A35B;
  --badge: #D9F45A;
  --badge-text: #1A2200;
  --shadow: 0 10px 30px rgba(36, 64, 150, .10), 0 1px 0 rgba(255, 255, 255, .9) inset;
  --shadow-lg: 0 24px 60px rgba(30, 50, 130, .22);
  --blob: rgba(80, 120, 255, .22);
  --blob2: rgba(120, 90, 255, .16);
  --input: rgba(255, 255, 255, .8);
  --scrim: rgba(12, 18, 45, .35);
  --r: 22px;
  --r-sm: 14px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0A0A0C;
  --bg2: #111114;
  --card: #18181B;
  --card-solid: #1E1E22;
  --card-press: #232328;
  --line: rgba(255, 255, 255, .06);
  --text: #F4F4F6;
  --muted: #8C8C96;
  --faint: #55555E;
  --accent: #5B86FF;
  --accent-2: #6C5BFF;
  --accent-soft: rgba(91, 134, 255, .14);
  --danger: #FF5C61;
  --danger-soft: rgba(255, 92, 97, .14);
  --ok: #3DD68C;
  --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset;
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .6);
  --blob: rgba(70, 100, 255, .10);
  --blob2: rgba(110, 80, 255, .07);
  --input: #18181B;
  --scrim: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: var(--tg-viewport-stable-height, 100vh);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.4;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
svg { display: block; }

.blob { position: fixed; border-radius: 50%; filter: blur(2px); pointer-events: none; z-index: 0; }
.b1 { width: 340px; height: 340px; left: -170px; top: -150px; background: radial-gradient(circle at 70% 70%, var(--blob), transparent 70%); border: 1px solid var(--line); }
.b2 { width: 220px; height: 220px; right: -110px; top: 30%; background: radial-gradient(circle at 30% 40%, var(--blob2), transparent 70%); }
.b3 { width: 300px; height: 300px; right: -120px; bottom: -160px; background: radial-gradient(circle at 30% 30%, var(--blob), transparent 70%); border: 1px solid var(--line); }

#app { position: relative; z-index: 1; max-width: 560px; margin: 0 auto; padding: 16px 16px calc(28px + env(safe-area-inset-bottom)); }
.view { animation: fadeIn .22s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- lock ---------- */
.lock { min-height: calc(var(--tg-viewport-stable-height, 100vh) - 44px); display: flex; flex-direction: column; align-items: center; justify-content: space-between; text-align: center; padding-top: 18px; }
.lock-top { display: flex; flex-direction: column; align-items: center; }
.logo-badge { width: 112px; height: 112px; border-radius: 34px; padding: 10px; background: var(--card); box-shadow: var(--shadow); border: 1px solid var(--line); backdrop-filter: blur(12px); }
.logo-badge img { width: 100%; height: 100%; border-radius: 26px; display: block; }
.lock h1 { font-size: 30px; font-weight: 800; letter-spacing: -.02em; margin: 22px 0 4px; }
.caps { text-transform: uppercase; letter-spacing: .32em; font-size: 11px; font-weight: 600; color: var(--muted); }
.dots { display: flex; gap: 18px; margin: 30px 0 10px; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--faint); transition: all .15s; }
.dot.on { background: var(--accent); border-color: var(--accent); transform: scale(1.1); box-shadow: 0 0 0 5px var(--accent-soft); }
.dots.err .dot { border-color: var(--danger); background: var(--danger); box-shadow: none; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
.lock-msg { min-height: 20px; font-size: 13px; color: var(--danger); font-weight: 500; }
.lock-msg.muted { color: var(--muted); }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px 26px; justify-content: center; margin: 14px 0 18px; }
.key { width: 76px; height: 76px; border-radius: 50%; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: 28px; font-weight: 500; display: flex; align-items: center; justify-content: center; transition: transform .08s, background .12s; backdrop-filter: blur(10px); }
.key:active { transform: scale(.93); background: var(--accent-soft); }
.key svg { width: 30px; height: 30px; }
.key.ghost { background: none; border: 0; box-shadow: none; color: var(--muted); }
.key.ghost:active { background: var(--accent-soft); }
.key:disabled { opacity: .35; }
.lock-foot { font-size: 10px; letter-spacing: .34em; color: var(--muted); font-weight: 600; padding-bottom: 6px; }
.lock-foot i { font-style: normal; margin: 0 8px; opacity: .6; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 18px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { width: 46px; height: 46px; border-radius: 15px; box-shadow: 0 8px 18px rgba(60, 80, 220, .25); flex: none; }
.brand-name { font-size: 20px; font-weight: 800; letter-spacing: -.02em; }
.brand-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 10px; flex: none; }
.icon-btn { width: 44px; height: 44px; border-radius: 15px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center; color: var(--text); transition: transform .08s; }
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 20px; height: 20px; }

.page-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; }
.page-head h2 { font-size: 24px; font-weight: 800; letter-spacing: -.02em; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-head .count { font-size: 13px; color: var(--muted); font-weight: 600; }

/* ---------- search ---------- */
.search { position: relative; margin-bottom: 18px; }
.search svg { position: absolute; z-index: 2; left: 16px; top: 50%; transform: translateY(-50%); width: 19px; height: 19px; color: var(--muted); pointer-events: none; }
.search input { width: 100%; height: 52px; border-radius: 17px; border: 1px solid var(--line); background: var(--input); box-shadow: var(--shadow); padding: 0 44px 0 46px; font-size: 16px; outline: none; transition: border-color .15s, box-shadow .15s; backdrop-filter: blur(10px); }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.search input::placeholder { color: var(--faint); }
.search .clear { z-index: 2; position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; display: none; align-items: center; justify-content: center; color: var(--muted); }
.search.has .clear { display: flex; }
.search .clear svg { position: static; transform: none; width: 16px; height: 16px; }

.label { text-transform: uppercase; letter-spacing: .22em; font-size: 11px; font-weight: 700; color: var(--muted); margin: 6px 4px 12px; display: flex; justify-content: space-between; align-items: center; }

/* ---------- tiles ---------- */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { position: relative; text-align: left; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: var(--r); padding: 16px; min-height: 128px; display: flex; flex-direction: column; justify-content: space-between; transition: transform .1s, background .12s; backdrop-filter: blur(12px); }
.tile:active { transform: scale(.97); background: var(--card-press); }
.tile-ic { width: 44px; height: 44px; border-radius: 14px; display: flex; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent); }
.tile:first-child .tile-ic { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.tile-ic svg { width: 22px; height: 22px; }
.tile-name { font-weight: 700; font-size: 15px; line-height: 1.25; margin-top: 14px; word-break: break-word; }
.tile-count { font-size: 12px; color: var(--muted); margin-top: 3px; }
.badge { position: absolute; top: 12px; right: 12px; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 12px; background: var(--badge); color: var(--badge-text); font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

.wide-btn { width: 100%; margin-top: 14px; display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--r); background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); text-align: left; transition: transform .1s; }
.wide-btn:active { transform: scale(.98); }
.wide-btn .tile-ic { width: 40px; height: 40px; }
.wide-btn b { display: block; font-size: 15px; }
.wide-btn small { color: var(--muted); font-size: 13px; }
.wide-btn .chev { margin-left: auto; color: var(--faint); }

/* ---------- lists ---------- */
.list { background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: var(--r); overflow: hidden; backdrop-filter: blur(12px); }
.row { width: 100%; display: flex; align-items: center; gap: 13px; padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); transition: background .1s; }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--accent-soft); }
.av { width: 40px; height: 40px; border-radius: 12px; flex: none; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 16px; color: #fff; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .chev, .row .tail { color: var(--faint); flex: none; }
.row .chev svg { width: 18px; height: 18px; }
.row mark { background: var(--accent-soft); color: var(--accent); border-radius: 4px; padding: 0 1px; }
.check { width: 24px; height: 24px; border-radius: 8px; border: 2px solid var(--faint); flex: none; display: flex; align-items: center; justify-content: center; transition: all .12s; }
.check svg { width: 14px; height: 14px; color: #fff; opacity: 0; }
.row.sel .check { background: var(--accent); border-color: var(--accent); }
.row.sel .check svg { opacity: 1; }
.row-actions { display: flex; gap: 6px; flex: none; }
.mini { width: 36px; height: 36px; border-radius: 11px; display: flex; align-items: center; justify-content: center; color: var(--muted); background: var(--accent-soft); }
.mini svg { width: 17px; height: 17px; }
.mini.danger { color: var(--danger); background: var(--danger-soft); }

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

/* ---------- segmented / chips ---------- */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); margin-bottom: 16px; }
.seg button { height: 38px; border-radius: 12px; font-weight: 600; font-size: 14px; color: var(--muted); transition: all .15s; }
.seg button.on { background: var(--card-solid); color: var(--text); box-shadow: 0 2px 10px rgba(20, 40, 120, .12); }
:root[data-theme="dark"] .seg button.on { background: #2A2A30; }
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 14px; padding: 2px 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 34px; padding: 0 14px; border-radius: 17px; background: var(--card); border: 1px solid var(--line); font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; }
.toolbar .search { flex: 1; margin: 0; }

/* ---------- buttons ---------- */
.btn { height: 52px; border-radius: 17px; padding: 0 20px; font-weight: 700; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 10px; transition: transform .08s, opacity .15s; white-space: nowrap; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; }
.btn svg { width: 19px; height: 19px; }
.btn.primary { background: linear-gradient(100deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 12px 26px rgba(55, 80, 240, .35); }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { height: 44px; border-radius: 14px; font-size: 14px; padding: 0 14px; }
.add-btn { width: 100%; margin-bottom: 14px; }

.bulkbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom)); width: calc(100% - 32px); max-width: 528px; display: flex; gap: 10px; padding: 10px; border-radius: 22px; background: var(--card-solid); border: 1px solid var(--line); box-shadow: var(--shadow-lg); z-index: 20; animation: up .2s ease; }
.bulkbar .btn { flex: 1; }
@keyframes up { from { transform: translate(-50%, 20px); opacity: 0; } }
.spacer { height: 90px; }

/* ---------- sheet ---------- */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 50; animation: fade .2s; backdrop-filter: blur(3px); }
@keyframes fade { from { opacity: 0; } }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 560px; max-height: 92vh; max-height: calc(var(--tg-viewport-height, 100vh) - 30px); overflow-y: auto; background: var(--bg); border-radius: 28px 28px 0 0; padding: 10px 18px calc(22px + env(safe-area-inset-bottom)); z-index: 51; box-shadow: var(--shadow-lg); animation: slide .26s cubic-bezier(.2, .9, .3, 1); overscroll-behavior: contain; }
@keyframes slide { from { transform: translateY(100%); } }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--faint); opacity: .5; margin: 0 auto 14px; }
.sheet-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.sheet-head .av { width: 52px; height: 52px; border-radius: 16px; font-size: 21px; }
.sheet-head h3 { margin: 0; font-size: 21px; font-weight: 800; letter-spacing: -.01em; word-break: break-word; }
.sheet-head .row-sub { font-size: 13px; }
.sheet h3.title { margin: 4px 0 18px; font-size: 21px; font-weight: 800; }

.fields { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 12px 10px 12px 16px; box-shadow: var(--shadow); }
.field-main { flex: 1; min-width: 0; }
.field-label { font-size: 11px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); font-weight: 700; margin-bottom: 3px; }
.field-val { font-size: 16px; font-weight: 600; word-break: break-all; font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; }
.field-val.masked { letter-spacing: .18em; }
.field-val.plain { font-family: inherit; font-weight: 500; font-size: 15px; word-break: break-word; white-space: pre-wrap; }
.field-val a { color: var(--accent); }
.field .mini { background: var(--accent-soft); color: var(--accent); }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions .btn { flex: 1; }
.warn { color: var(--danger); font-size: 13px; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 12px; }
.inp { display: block; }
.inp span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); font-weight: 700; margin: 0 0 6px 4px; }
.inp input, .inp select, .inp textarea { width: 100%; height: 50px; border-radius: 15px; border: 1px solid var(--line); background: var(--input); padding: 0 14px; font-size: 16px; outline: none; box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s; -webkit-appearance: none; appearance: none; }
.inp select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%238C8C96' stroke-width='2'%3E%3Cpath d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 16px center; padding-right: 40px; }
.inp textarea { height: auto; min-height: 96px; padding: 12px 14px; resize: vertical; line-height: 1.45; }
.inp input:focus, .inp select:focus, .inp textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.inp-row { display: flex; gap: 8px; }
.inp-row input { flex: 1; }
.inp-row .mini { width: 50px; height: 50px; border-radius: 15px; flex: none; color: var(--accent); }
.form-err { color: var(--danger); font-size: 13px; min-height: 18px; margin: -2px 4px 0; }
.note { font-size: 13px; color: var(--muted); margin: 0 4px; }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top)); transform: translate(-50%, -100%); visibility: hidden; background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 14px; font-weight: 600; font-size: 14px; z-index: 100; transition: transform .25s cubic-bezier(.2, .9, .3, 1); box-shadow: var(--shadow-lg); max-width: calc(100% - 32px); text-align: center; }
#toast.show { transform: translate(-50%, 0); visibility: visible; }
#toast:empty { display: none; }
#toast.err { background: var(--danger); color: #fff; }

.center-msg { min-height: 80vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; padding: 0 20px; }
.center-msg h2 { margin: 16px 0 0; font-size: 22px; font-weight: 800; }
.center-msg p { margin: 0; color: var(--muted); }
.spin { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: rot .8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

@media (max-width: 360px) {
  .keypad { grid-template-columns: repeat(3, 68px); gap: 12px 20px; }
  .key { width: 68px; height: 68px; font-size: 25px; }
  .tile { min-height: 116px; padding: 14px; }
}
