:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff4ff;
  --success: #16a34a;
  --success-soft: #ecfdf3;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #d97706;
  --shadow: 0 1px 2px rgb(15 23 42 / 0.04), 0 8px 24px rgb(15 23 42 / 0.06);
  --radius: 16px;
  color-scheme: light;
}


* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.75rem; line-height: 1.2; margin: 0 0 .35rem; letter-spacing: -0.02em; }
h2 { font-size: 1.35rem; margin: 0 0 .25rem; letter-spacing: -0.01em; }
.muted { color: var(--muted); margin: 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  border: 1px solid transparent; border-radius: 12px;
  padding: .7rem 1.1rem; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--surface); color: var(--text);
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 2px; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.secondary { border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; border-color: var(--border); padding: .5rem .9rem; font-size: .95rem; }
.btn.ghost:hover { background: var(--surface); }
.btn.link { background: none; color: var(--muted); font-weight: 500; padding: .5rem; }
.btn.big { padding: .95rem 1.4rem; font-size: 1.05rem; border-radius: 14px; }
.btn.block { width: 100%; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; padding: 32px 28px; box-shadow: var(--shadow);
}
.auth-card form { display: grid; gap: 16px; }
.auth-card h1 { margin-top: 8px; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 1.15rem; margin-bottom: 18px; }
.brand.small { margin: 0; font-size: 1.05rem; }
.brand img { border-radius: 10px; }

/* ---------- form fields ---------- */
.field { display: grid; gap: 6px; }
.field > span { font-weight: 600; font-size: .95rem; }
.field .hint { font-size: .88rem; color: var(--muted); font-weight: 400; }
input[type=text], input[type=password], input[type=search], input:not([type]), input[inputmode], select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1.5px solid var(--border); border-radius: 12px; padding: .75rem .9rem;
  transition: border-color .15s, background .15s;
}
input:focus, select:focus { border-color: var(--primary); background: var(--surface); outline: none; }
.code-input { font-size: 1.6rem; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }

.email-row { display: flex; align-items: stretch; border: 1.5px solid var(--border); border-radius: 12px; background: var(--surface-2); overflow: hidden; }
.email-row:focus-within { border-color: var(--primary); background: var(--surface); }
.email-row input, .email-row select { border: 0; border-radius: 0; background: transparent; min-width: 0; }
.email-row input { flex: 1 1 50%; }
.email-row .at { display: grid; place-items: center; padding: 0 .35rem; color: var(--muted); font-weight: 600; }
.email-row select, .email-row .domain-fixed { flex: 1 1 50%; color: var(--muted); }
.email-row .domain-fixed { display: flex; align-items: center; padding: 0 .9rem 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pw-row { display: flex; gap: 8px; }
.pw-row .pw-wrap { position: relative; flex: 1; min-width: 0; }
.pw-row input { padding-right: 3rem; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1rem; }
.icon-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; color: var(--muted); padding: 8px; border-radius: 8px; cursor: pointer; display: grid;
}
.icon-btn:hover { color: var(--text); background: var(--border); }

.rules { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.rules li { font-size: .82rem; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.rules li.ok { background: var(--success-soft); color: var(--success); border-color: transparent; }
.rules li.ok::before { content: "✓ "; }

.error { margin: 0; padding: .7rem .9rem; border-radius: 12px; background: var(--danger-soft); color: var(--danger); font-weight: 500; font-size: .95rem; }

/* ---------- app ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.who #who-name { font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.container { max-width: 880px; margin: 0 auto; padding: 32px 24px 64px; }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; }
.search { position: relative; flex: 1; display: block; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 44px; background: var(--surface); }
.toolbar select { width: auto; max-width: 45%; background: var(--surface); }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.avatar {
  flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; color: #fff; font-size: 1.05rem; text-transform: uppercase;
}
.item-main { flex: 1; min-width: 0; }
.item-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-email { color: var(--muted); font-size: .93rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { display: flex; align-items: center; gap: 10px; margin-top: 6px; font-size: .8rem; color: var(--muted); }
.bar { width: 90px; height: 6px; border-radius: 99px; background: var(--border); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.bar.high > i { background: var(--warn); }
.item-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.badge { font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--danger-soft); color: var(--danger); }

.empty {
  text-align: center; padding: 48px 24px; background: var(--surface); border: 1.5px dashed var(--border);
  border-radius: var(--radius); color: var(--muted);
}
.empty strong { display: block; color: var(--text); font-size: 1.15rem; margin-bottom: 4px; }

.skeleton { height: 76px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border: 1px solid var(--border); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- dialog ---------- */
dialog {
  border: 0; padding: 0; border-radius: 22px; width: min(480px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 24px 64px rgb(0 0 0 / .25);
}
dialog::backdrop { background: rgb(15 23 42 / .45); backdrop-filter: blur(3px); }
dialog[open] { animation: pop .18s ease-out; }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
.dialog-inner { display: grid; gap: 18px; padding: 26px 24px 22px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.close-x { border: 0; background: var(--surface-2); color: var(--muted); width: 36px; height: 36px; border-radius: 50%; font-size: 1.3rem; cursor: pointer; flex: none; }
.close-x:hover { color: var(--text); }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.actions .btn { flex: 1; }

.done-icon { width: 64px; height: 64px; border-radius: 50%; background: var(--success-soft); color: var(--success); display: grid; place-items: center; margin: 4px auto 0; }
.done { text-align: center; }
.creds { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 6px 16px; text-align: left; }
.creds div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.creds div:last-child { border-bottom: 0; }
.creds dt { color: var(--muted); font-size: .9rem; margin: 0; }
.creds dd { margin: 0; font-weight: 600; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .95rem; word-break: break-all; text-align: right; }
.warn-note { font-size: .88rem; color: var(--muted); margin: 0; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: .75rem 1.2rem; border-radius: 12px; font-weight: 600;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

/* ---------- small screens ---------- */
@media (max-width: 600px) {
  body { font-size: 16px; }
  .topbar { padding: 10px 16px; }
  .who #who-name { display: none; }
  .container { padding: 20px 16px 48px; }
  .hero .btn { width: 100%; }
  .toolbar { flex-direction: column; }
  .toolbar select { max-width: none; width: 100%; }
  .item { flex-wrap: wrap; }
  .item-actions { width: 100%; }
  .item-actions .btn { flex: 1; }
  .email-row { flex-direction: column; }
  .email-row .at { display: none; }
  .email-row select, .email-row .domain-fixed { border-top: 1px solid var(--border); padding: .75rem .9rem; }
  .actions { flex-direction: column-reverse; }
  .auth-card { padding: 26px 20px; }
  .creds div { flex-direction: column; gap: 2px; }
  .creds dd { text-align: left; }
}
