:root {
  --bg: #0b1020;
  --panel: #141b2e;
  --panel-2: #1b2440;
  --border: #2a3558;
  --text: #e7ecf7;
  --muted: #8d98b5;
  --accent: #4f7cff;
  --accent-2: #3a63e0;
  --danger: #e5484d;
  --warn: #f5a524;
  --ok: #30a46c;
  --radius: 12px;
  /* отступы под вырез камеры, скруглённые углы и полоску жестов */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
  color-scheme: dark;
}

* { box-sizing: border-box; }
html {
  /* не даём Android/iOS самовольно увеличивать текст */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html, body { margin: 0; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }

#app {
  width: 100%; max-width: 720px; margin: 0 auto;
  padding: 0 var(--gutter-r) 0 var(--gutter-l);
}
.screen.center {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: calc(20px + var(--safe-top)) 0 calc(20px + var(--safe-bottom));
}

.card {
  width: 100%; max-width: 420px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px;
  padding: 24px; display: flex; flex-direction: column; gap: 14px;
}
.logo { font-size: 44px; text-align: center; }
h1 { font-size: 22px; margin: 0; text-align: center; }
h2 { font-size: 19px; margin: 0 0 6px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.warn { color: var(--warn); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); min-width: 0; }
label.inline { flex-direction: row; align-items: center; gap: 8px; }

input, textarea {
  width: 100%; min-width: 0;
  font-family: inherit; color: var(--text);
  /* 16px обязательно: при меньшем шрифте iPhone увеличивает страницу при вводе */
  font-size: 16px; line-height: 1.3;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 12px; outline: none;
  -webkit-appearance: none; appearance: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
input[type=checkbox] { width: 20px; height: 20px; padding: 0; -webkit-appearance: auto; appearance: auto; accent-color: var(--accent); }
input[type=range] { flex: 1; width: auto; min-width: 90px; padding: 0; border: 0; background: none; -webkit-appearance: auto; appearance: auto; accent-color: var(--accent); }
textarea { resize: vertical; }

button, .btn {
  font: inherit; font-size: 16px; color: var(--text); text-decoration: none; text-align: center;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px; min-height: 44px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
button:hover, .btn:hover { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: progress; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-2); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.icon { padding: 8px 10px; min-width: 44px; line-height: 1; flex: none; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }

.field { display: flex; gap: 6px; min-width: 0; }
.field input { flex: 1; min-width: 0; }

code, .secret { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.secret {
  display: block; padding: 12px; border-radius: 10px; background: var(--bg); border: 1px dashed var(--border);
  word-break: break-all; overflow-wrap: anywhere; font-size: 15px; letter-spacing: .5px; user-select: all;
}
.secret.big { font-size: 18px; text-align: center; }
.totp-box { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: 12px; background: var(--panel-2); font-size: 14px; }

.meter { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; margin-top: -6px; }
.meter div { height: 100%; width: 0; transition: width .2s; }
.meter .weak { background: var(--danger); }
.meter .ok { background: var(--warn); }
.meter .strong { background: var(--ok); }

.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- vault ---- */
#screen-vault { position: relative; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: 8px;
  padding: calc(12px + var(--safe-top)) 0 10px;
  background: var(--bg);
}
.topbar input { flex: 1; min-width: 0; }
.menu {
  position: absolute; right: 0; top: calc(66px + var(--safe-top)); z-index: 10;
  display: flex; flex-direction: column; min-width: 220px; max-width: 100%;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  box-shadow: 0 12px 30px rgba(0,0,0,.4);
}
.menu button { border: 0; border-radius: 0; justify-content: flex-start; text-align: left; background: transparent; padding: 13px 16px; }
.menu button:hover { background: var(--panel-2); }

.list { list-style: none; margin: 6px 0 calc(40px + var(--safe-bottom)); padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 8px 6px 6px;
}
.item-main {
  flex: 1; min-width: 0; display: flex; align-items: center; justify-content: flex-start; gap: 12px;
  background: transparent; border: 0; padding: 6px; text-align: left;
}
.avatar {
  flex: none; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: var(--panel-2); color: var(--accent); font-weight: 700;
}
.item-text { display: flex; flex-direction: column; min-width: 0; }
.item-title, .item-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-title { font-weight: 600; }
.item-sub { color: var(--muted); font-size: 13px; }
.empty { text-align: center; padding: 60px 0; display: flex; flex-direction: column; gap: 6px; }

/* ---- dialogs ---- */
dialog {
  width: min(520px, calc(100vw - 24px)); max-width: none;
  max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 18px; padding: 20px;
}
dialog::backdrop { background: rgba(3, 6, 15, .7); }
dialog form { display: flex; flex-direction: column; gap: 12px; }
.gen { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; font-size: 14px; }
.gen label.inline:first-child { flex: 1 1 200px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); z-index: 100; width: max-content; max-width: calc(100vw - 32px); font-size: 14px;
  text-align: center;
}

/* ---- телефоны ---- */
@media (max-width: 560px) {
  .card { padding: 20px 16px; border-radius: 16px; }
  .logo { font-size: 38px; }

  /* окна выезжают снизу на всю ширину, как в обычных приложениях */
  dialog {
    width: 100%; margin: auto 0 0;
    max-height: calc(100vh - 12px); max-height: calc(100dvh - var(--safe-top) - 12px);
    border-radius: 18px 18px 0 0; border-bottom: 0;
    padding: 18px var(--gutter-r) calc(18px + var(--safe-bottom)) var(--gutter-l);
  }
  dialog .row.end > button { flex: 1 1 auto; }
  dialog .row.end > .grow { display: none; }
}

@media (max-width: 360px) {
  .topbar { gap: 6px; }
  button.icon { min-width: 40px; padding: 8px; }
  .item-main { gap: 8px; }
  .avatar { width: 34px; height: 34px; }
}
