/* Accounts: user menu, sign-in page, admin dashboard. Builds on the tokens in styles.css. */
:root { --ok: #1f8a4c; --ok-soft: #e3f5ea; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --ok: #4cc27f; --ok-soft: #173424; } }
:root[data-theme="dark"] { --ok: #4cc27f; --ok-soft: #173424; }

a.brand, a.tab { color: inherit; text-decoration: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- User menu ---------- */
.user-menu { position: relative; margin-left: auto; }
.header-note ~ .user-menu { margin-left: 4px; }
.user-btn {
  display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 8px 0 4px; border: 1px solid transparent;
  border-radius: 20px; background: transparent; cursor: pointer;
}
.user-btn:hover, .user-btn[aria-expanded="true"] { background: var(--panel-2); border-color: var(--border); }
.user-btn > svg.ic { width: 15px; height: 15px; color: var(--muted); }
.user-name { font-weight: 550; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 30px; height: 30px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text); font-size: 12px; font-weight: 650; letter-spacing: .02em;
}
.avatar.admin, .user-btn .avatar { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 230px; padding: 6px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 32px rgb(0 0 0 / .16);
}
.menu-head { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-head span { color: var(--muted); font-size: 12.5px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); text-decoration: none; cursor: pointer; text-align: left;
}
.menu-item:hover { background: var(--panel-2); }
.menu-item svg.ic { width: 16px; height: 16px; color: var(--muted); }
.menu-item.danger, .menu-item.danger svg.ic { color: var(--danger); }

/* ---------- Forms & dialogs ---------- */
.form { display: flex; flex-direction: column; }
.form-body { padding: 4px 16px; display: flex; flex-direction: column; gap: 14px; }
.form-field { display: flex; flex-direction: column; gap: 6px; border: 0; margin: 0; padding: 0; min-width: 0; }
.form-field > span, .form-field > legend { font-weight: 560; font-size: 13.5px; padding: 0; }
.form-field small { color: var(--muted); font-size: 12.5px; }
.form-field input:not([type="radio"]):not([type="checkbox"]) {
  height: 40px; padding: 0 12px; width: 100%; border: 1px solid var(--border-strong); border-radius: 9px;
  background: var(--panel); color: var(--text); font-size: 14.5px;
}
.form-field input:focus-visible, .search:focus-within, .filters select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.pw-wrap { position: relative; display: flex; gap: 8px; align-items: center; }
.pw-wrap input { flex: 1; }
.pw-wrap.with-gen input { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.pw-toggle {
  position: absolute; right: 6px; width: 30px; height: 30px; border: 0; border-radius: 6px; background: transparent;
  color: var(--muted); cursor: pointer; display: grid; place-items: center;
}
.pw-toggle:hover { background: var(--panel-2); color: var(--text); }
.form-error { padding: 9px 12px; border-radius: 8px; background: var(--accent-soft); color: var(--danger); font-size: 13.5px; }
.btn.block { width: 100%; height: 42px; font-size: 15px; }
.btn.danger-fill, .btn.danger-fill:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.dialog.narrow { width: min(460px, calc(100vw - 32px)); }
.dialog-text { margin: 0; color: var(--muted); }
.dialog-text strong { color: var(--text); }
.role-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.role-option { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 10px; cursor: pointer; }
.role-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.role-option input { accent-color: var(--accent); margin-top: 3px; }
.role-option span { display: flex; flex-direction: column; gap: 2px; }
.role-option small { color: var(--muted); font-size: 12px; line-height: 1.35; }
.cred-box { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--border); }
.cred-box div { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.cred-box span { color: var(--muted); font-size: 13px; }
.cred-box code { font: 15px/1.3 ui-monospace, "Cascadia Mono", Consolas, monospace; user-select: all; word-break: break-all; text-align: right; }

/* ---------- Sign-in page ---------- */
body.auth-page {
  overflow: auto; padding: 24px 16px;
  background: radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent 70%), var(--bg);
}
.auth-card {
  width: 100%; max-width: 420px; margin: auto; padding: 28px 26px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 10px 40px rgb(0 0 0 / .08);
}
.auth-card .form { gap: 16px; }
.auth-brand { display: flex; align-items: center; gap: 12px; font-size: 18px; font-weight: 700; margin-bottom: 22px; }
.auth-title h1 { margin: 0 0 4px; font-size: 21px; }
.auth-title p { margin: 0; color: var(--muted); }
.auth-foot { margin: 0; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- Admin dashboard ---------- */
body.admin-page { overflow: auto; }
.admin-main { width: 100%; max-width: 1240px; margin: 0 auto; padding: 26px 16px 48px; display: flex; flex-direction: column; gap: 18px; }
.admin-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.admin-head h1 { margin: 0 0 4px; font-size: 24px; }
.admin-head p { margin: 0; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat { display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 28px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.1; }
.admin-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 16px; }
.card-head .btn.icon.small { width: 30px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.search { display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
.search svg.ic { width: 16px; height: 16px; color: var(--muted); }
.search input { border: 0; outline: 0; background: transparent; width: 200px; min-width: 0; }
.filters select { height: 34px; }
.table-wrap { overflow-x: auto; }
.users-table { width: 100%; border-collapse: collapse; }
.users-table th {
  text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.users-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.users-table tbody tr:last-child td { border-bottom: 0; }
.users-table tbody tr:hover { background: var(--panel-2); }
.users-table tr.is-disabled .u-cell, .users-table tr.is-disabled .badge { opacity: .55; }
.users-table td.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.u-cell { display: flex; align-items: center; gap: 12px; }
.u-name { font-weight: 560; }
.u-sub { color: var(--muted); font-size: 12.5px; }
.you {
  margin-left: 6px; padding: 1px 7px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--border);
  font-size: 11px; font-weight: 600; color: var(--muted); vertical-align: 1px;
}
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px; font-size: 12.5px; font-weight: 550; background: var(--panel-2); border: 1px solid var(--border); }
.badge svg.ic { width: 13px; height: 13px; }
.badge-admin { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.status { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.status.off { color: var(--muted); }
.status.off::before { background: var(--border-strong); }
.actions-col { width: 1%; }
.users-table td.actions { text-align: right; }
.icon-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn svg.ic { width: 17px; height: 17px; }
.icon-btn:hover:not(:disabled) { background: var(--bg); color: var(--text); }
.icon-btn.danger:hover:not(:disabled) { color: var(--danger); background: var(--accent-soft); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.activity { list-style: none; margin: 0; padding: 6px 0; max-height: 560px; overflow: auto; }
.activity li.empty { color: var(--muted); padding: 24px 16px; text-align: center; }
.act { display: flex; gap: 12px; padding: 9px 16px; }
.act-icon { width: 28px; height: 28px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); color: var(--muted); }
.act-icon svg.ic { width: 14px; height: 14px; }
.act-create .act-icon, .act-login .act-icon { background: var(--ok-soft); color: var(--ok); }
.act-delete .act-icon, .act-login_failed .act-icon { background: var(--accent-soft); color: var(--danger); }
.act-msg { font-size: 13.5px; }
.act time { color: var(--muted); font-size: 12px; }

@media (max-width: 1000px) {
  .admin-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .user-name, .user-btn > svg.ic { display: none; }
  .user-btn { padding: 0 4px; }
  .role-options { grid-template-columns: 1fr; }
  .filters, .search { width: 100%; }
  .search input { width: 100%; }
  /* The table becomes stacked cards on phones. */
  .users-table thead { display: none; }
  .users-table, .users-table tbody, .users-table tr, .users-table td { display: block; width: 100%; }
  .users-table tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
  .users-table td { border: 0; padding: 4px 16px; white-space: normal; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
  .users-table td[data-label]:not([data-label="User"])::before { content: attr(data-label); color: var(--muted); font-size: 13px; }
  .users-table td.actions { justify-content: flex-end; }
}
