:root {
  --blue: #0069b4;
  --blue-dark: #004f87;
  --blue-light: #e6f1fa;
  --ink: #1f2933;
  --muted: #5b6770;
  --line: #d5dde4;
  --bg: #f3f6f9;
  --card: #ffffff;
  --error: #b42318;
  --error-bg: #fdecea;
  --ok: #0b6b3a;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

[hidden] { display: none !important; }

h1 { margin: 0; line-height: 1.25; }

:focus-visible {
  outline: 3px solid #f5a623;
  outline-offset: 2px;
}

/* ---------- buttons and inputs ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--blue); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { background: #7aa9cc; cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--blue); border-color: var(--blue); }
.btn-secondary:hover { background: var(--blue-light); }

label { display: block; margin: 18px 0 6px; font-weight: 600; }

input[type="email"],
input[type="password"],
input[type="text"] {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid #9aa7b2;
  border-radius: 8px;
  font: inherit;
  background: #fff;
}
input:focus { border-color: var(--blue); }

#code { font-size: 1.5rem; letter-spacing: 0.4em; text-align: center; }

form .btn { margin-top: 18px; }

.link-row { display: flex; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.link-btn {
  background: none;
  border: 0;
  padding: 6px 0;
  color: var(--blue);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.link-btn:disabled { color: var(--muted); cursor: not-allowed; text-decoration: none; }

/* ---------- login page ---------- */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px 28px 24px;
  box-shadow: 0 8px 28px rgba(15, 40, 65, 0.08);
}

.login-logo { display: block; width: 100%; max-width: 260px; height: auto; margin: 0 auto 22px; }
.login-card h1 { text-align: center; font-size: 1.4rem; }
.subtitle { text-align: center; margin: 4px 0 8px; color: var(--muted); }
.hint { margin: 18px 0 0; color: var(--muted); }

.message { min-height: 1.5em; margin: 16px 0 0; font-size: 0.95rem; }
.message-error { color: var(--error); background: var(--error-bg); padding: 10px 12px; border-radius: 8px; }
.message.is-error { color: var(--error); }
.message.is-info { color: var(--ok); }

.dev-box {
  margin-top: 16px;
  padding: 12px;
  border: 2px dashed #f5a623;
  background: #fff8e8;
  border-radius: 8px;
  display: grid;
  gap: 4px;
  font-size: 0.9rem;
}
.dev-box code { font-size: 1.6rem; letter-spacing: 0.25em; font-weight: 700; }

.footnote { margin: 22px 0 0; font-size: 0.8rem; color: var(--muted); text-align: center; }

/* ---------- home page ---------- */

.topbar { background: #fff; border-bottom: 1px solid var(--line); }
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.topbar-logo { height: 32px; width: auto; }
.topbar-title { font-weight: 600; color: var(--muted); border-left: 1px solid var(--line); padding-left: 16px; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.who { display: flex; flex-direction: column; text-align: right; }
.who-name { font-weight: 600; }
.who-roles { font-size: 0.8rem; color: var(--muted); }

.home-main { max-width: 1100px; margin: 0 auto; padding: 32px 20px 48px; }
.home-main h1 { font-size: 1.7rem; }
.lead { margin: 6px 0 26px; color: var(--muted); }

.app-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px;
}

.app-tile {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
  padding: 22px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: inherit;
  text-decoration: none;
}
a.app-tile:hover { border-color: var(--blue); box-shadow: 0 6px 18px rgba(0, 105, 180, 0.15); }

.app-icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--blue-light);
  color: var(--blue);
}
.app-icon svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app-name { font-size: 1.1rem; font-weight: 700; }
.app-desc { margin: 0; color: var(--muted); font-size: 0.93rem; flex: 1; }

.badge {
  align-self: flex-start;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: #eef1f4;
  color: var(--muted);
}
.badge-open { background: #e3f5ea; color: var(--ok); }
.badge-dev { background: #fff3d6; color: #8a5a00; }

.app-tile.is-disabled .app-icon { background: #eef1f4; color: #7b8791; }

.home-footer { text-align: center; padding: 20px; font-size: 0.8rem; color: var(--muted); }

@media (max-width: 560px) {
  .topbar-title { display: none; }
  .who { text-align: left; }
}

@media (prefers-reduced-motion: no-preference) {
  .app-tile, .btn { transition: border-color 0.15s, box-shadow 0.15s, background 0.15s; }
}

/* ---------- second step (sign-in) and Security page ---------- */

.login-card h2 { margin: 22px 0 0; font-size: 1.15rem; }
.hint.small { font-size: 0.85rem; margin-top: 6px; }
.btn-block { width: 100%; }
.or { text-align: center; color: var(--muted); margin: 16px 0 0; }
.link-row.center { justify-content: center; }
.code-input { font-size: 1.5rem; letter-spacing: 0.4em; text-align: center; }

#enroll-choice .btn, #mfa-passkey .btn { margin-top: 18px; }
#enroll-choice .btn + .hint { margin-top: 6px; }
#enroll-choice .or + .btn { margin-top: 12px; }

.steps { margin: 16px 0 0; padding-left: 20px; color: var(--ink); }
.steps li { margin: 6px 0; }
.qr-box { display: flex; justify-content: center; margin: 16px 0 4px; }
.qr-box svg { width: 220px; height: 220px; border: 1px solid var(--line); border-radius: 8px; }
.secret-key {
  display: block;
  margin: 6px 0 0;
  padding: 10px 12px;
  background: #f0f4f8;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 1rem;
  letter-spacing: 0.08em;
  word-break: break-all;
  user-select: all;
}

.home-main.narrow { max-width: 760px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 22px; margin: 0 0 18px; }
.card h2 { margin: 0 0 4px; font-size: 1.15rem; }
.card .hint { margin: 4px 0 0; }
.method-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 10px; }
.method-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.inline-form { margin-top: 12px; }
.inline-form .btn { margin-top: 12px; width: auto; }
#totp-actions { margin-top: 12px; }
#totp-setup form .btn { width: 100%; }

/* ---------- password and admin additions ---------- */
label.check { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; font-weight: 400; }
label.check input { width: 18px; height: 18px; }
#setup-code { text-transform: uppercase; letter-spacing: 0.12em; }
.admin-table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
.admin-table th, .admin-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 0.93rem; }
.admin-table th { background: var(--blue-light); }
.table-wrap { overflow-x: auto; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.btn-small { min-height: 34px; padding: 0 12px; font-size: 0.85rem; }
.btn-danger { background: #fff; color: var(--error); border-color: var(--error); }
.btn-danger:hover { background: var(--error-bg); }
.role-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 4px 16px; margin-top: 6px; }
.code-reveal { margin-top: 16px; padding: 16px; background: #fff8e1; border: 2px solid #f5a623; border-radius: 8px; }
.code-reveal code { display: block; font-size: 1.8rem; letter-spacing: 0.15em; font-weight: 700; margin: 8px 0; }
.tag { display: inline-block; padding: 2px 8px; margin: 1px 2px 1px 0; border-radius: 10px; background: #eef2f6; font-size: 0.8rem; }
.tag-off { background: var(--error-bg); color: var(--error); }
.tag-ok { background: #e3f5ea; color: var(--ok); }
.audit-list { font-size: 0.85rem; font-family: ui-monospace, Menlo, Consolas, monospace; }

/* ---------- transport and tasks ---------- */
input[type="date"], input[type="time"], input[type="number"], input[type="tel"], select, textarea {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid #9aa7b2;
  border-radius: 8px;
  font: inherit;
  background: #fff;
}
textarea { padding: 10px 12px; min-height: 90px; resize: vertical; }
select:focus, textarea:focus, input[type="date"]:focus, input[type="time"]:focus, input[type="number"]:focus { border-color: var(--blue); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.page-nav { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.page-nav .btn { width: auto; }
.btn.is-current { background: var(--blue); color: #fff; }
.actions-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.actions-bar .btn { margin-top: 0; width: auto; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 8px 0 0; }
.facts dt { font-weight: 600; }
.facts dd { margin: 0; white-space: pre-wrap; }
.timeline { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 10px; }
.timeline li { padding: 10px 12px; border-left: 4px solid var(--blue); background: #fff; border-radius: 0 8px 8px 0; font-size: 0.93rem; }
.timeline .when { color: #5b6b78; font-size: 0.8rem; }
.timeline .reason { margin: 4px 0 0; white-space: pre-wrap; }
.tag-warn { background: #fff3d6; color: #8a5a00; }
.ot-box { background: var(--blue-light); border-radius: 10px; padding: 12px 14px; margin-top: 8px; }
.badge-count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 10px; background: var(--error); color: #fff; font-size: 0.8rem; text-align: center; }
.empty { color: #5b6b78; padding: 14px 0; }
.rating-row { display: flex; gap: 14px; flex-wrap: wrap; }
.rating-row label.check { margin-top: 6px; }
@media print {
  .topbar, .home-footer, .no-print, .page-nav, #status { display: none !important; }
  body { background: #fff; }
  .card { border: 0; padding: 0; }
}

/* ---------- phones and tablets (iOS and Android) ---------- */
input, select, textarea { font-size: 16px; } /* 16px stops iOS Safari zooming in when a field is tapped */
input[type="tel"] { width: 100%; min-height: 46px; padding: 0 12px; border: 1px solid #9aa7b2; border-radius: 8px; background: #fff; }
input[type="checkbox"] { width: 22px; height: 22px; flex: none; }
label.check { min-height: 44px; }
.btn { touch-action: manipulation; }
.btn-small { min-height: 40px; }
body { -webkit-text-size-adjust: 100%; }
.topbar-inner { padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }
.home-footer { padding-bottom: max(20px, env(safe-area-inset-bottom)); }

@media (max-width: 640px) {
  .home-main { padding: 20px 14px 36px; }
  .home-main h1 { font-size: 1.4rem; }
  .card { padding: 16px; border-radius: 12px; }
  .topbar-inner { padding-top: 8px; padding-bottom: 8px; gap: 8px; }
  .topbar-logo { height: 26px; }
  .topbar-user { margin-left: 0; width: 100%; flex-wrap: wrap; gap: 8px; }
  .topbar-user .btn { flex: 1 1 auto; min-height: 42px; padding: 0 12px; }
  .page-nav .btn, .actions-bar .btn { flex: 1 1 100%; width: 100%; }
  .actions-bar { flex-direction: column; }
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dt { margin-top: 10px; color: var(--muted); font-size: 0.85rem; }
  .method-item { flex-direction: column; align-items: flex-start; }
  .method-item .btn { width: 100%; }

  /* tables become one card per row */
  .admin-table.stack, .admin-table.stack tbody, .admin-table.stack tr, .admin-table.stack td { display: block; width: 100%; }
  .admin-table.stack thead { display: none; }
  .admin-table.stack tr { margin-bottom: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 4px 0; }
  .admin-table.stack td { border: 0; padding: 6px 12px; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .admin-table.stack td::before { content: attr(data-label); font-weight: 600; text-align: left; color: var(--muted); }
  .admin-table.stack td:empty { display: none; }
  .admin-table.stack td select { max-width: 60%; }
}
