:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e1e6ed;
  --text: #1b2430;
  --text-muted: #667085;
  --primary: #2952e3;
  --primary-hover: #1f3fc0;
  --danger: #d64545;
  --danger-bg: #fdecec;
  --success: #1b8a5a;
  --success-bg: #e9f8f1;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--primary); }

.muted { color: var(--text-muted); }

/* ---------- Auth pages (login/signup/2fa) ---------- */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  width: 100%;
  max-width: 420px;
}

.auth-card h1 {
  font-size: 1.25rem;
  margin: 0 0 4px;
}

.auth-card .subtitle {
  color: var(--text-muted);
  margin: 0 0 24px;
  font-size: .9rem;
}

.auth-card form { display: flex; flex-direction: column; gap: 14px; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
}

input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 400;
}

input:focus, select:focus, textarea:focus, button:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

button, .btn {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  background: var(--primary);
  color: #fff;
  transition: background .15s;
}

button:hover, .btn:hover { background: var(--primary-hover); }

button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover { background: var(--bg); }

button.danger { background: var(--danger); }
button.danger:hover { background: #b93636; }

button.linklike {
  background: none;
  color: var(--text-muted);
  padding: 4px;
  font-weight: 500;
  text-decoration: underline;
}
button.linklike:hover { background: none; color: var(--text); }

.error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: .88rem;
  margin: 0 0 14px;
}

.success-box {
  background: var(--success-bg);
  color: var(--success);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: .88rem;
  margin: 0 0 14px;
}

.foot-link { margin-top: 18px; font-size: .88rem; text-align: center; color: var(--text-muted); }

.qr-wrap { display: flex; justify-content: center; margin: 16px 0; }
.qr-wrap canvas, .qr-wrap img { border: 8px solid #fff; border-radius: 8px; box-shadow: var(--shadow); background: #fff; }
.qr-wrap #qr { min-height: 180px; min-width: 180px; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: .85rem; }

.secret-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  word-break: break-all;
  font-size: .85rem;
  text-align: center;
}

.recovery-codes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin: 14px 0;
}

/* ---------- App shell (dashboard) ---------- */
.app-body { min-height: 100vh; display: flex; flex-direction: column; }

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.app-header .brand { font-weight: 700; }
.app-header .brand small { display: block; font-weight: 400; color: var(--text-muted); font-size: .75rem; }

.app-header nav { display: flex; gap: 8px; align-items: center; }

.pill {
  display: inline-block;
  font-size: .72rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.pill.warn { background: #fff6e6; color: #9a6700; border-color: #f4dca0; }

.app-main {
  flex: 1;
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 0;
}

@media (max-width: 780px) {
  .app-main { grid-template-columns: 1fr; }
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  background: var(--surface);
}

.sidebar h3 { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 18px 0 8px; }
.sidebar button.tab {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  color: var(--text);
  font-weight: 500;
  padding: 8px 10px;
  border-radius: 6px;
}
.sidebar button.tab:hover { background: var(--bg); }
.sidebar button.tab.active { background: #eaefff; color: var(--primary); }

.content { padding: 24px; max-width: 900px; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }

.search-box input { min-width: 240px; }

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.item-card .meta { min-width: 0; }
.item-card .title { font-weight: 600; }
.item-card .sub { color: var(--text-muted); font-size: .85rem; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-card .actions { display: flex; gap: 6px; flex-shrink: 0; }
.item-card .actions button { padding: 6px 10px; font-size: .85rem; }

.empty-state { color: var(--text-muted); text-align: center; padding: 48px 12px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16,24,40,.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 50;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%; max-width: 480px;
  padding: 24px;
}
.modal h2 { margin-top: 0; font-size: 1.1rem; }
.modal form { display: flex; flex-direction: column; gap: 12px; }
.modal .row { display: flex; gap: 10px; }
.modal .row label { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.reveal-field { position: relative; }
.reveal-field input { width: 100%; padding-right: 76px; }
.reveal-field .field-btns { position: absolute; right: 4px; top: 4px; display: flex; gap: 2px; }
.reveal-field .field-btns button {
  background: none; color: var(--text-muted); padding: 5px 8px; font-size: .75rem; border-radius: 6px;
}
.reveal-field .field-btns button:hover { background: var(--bg); color: var(--text); }

.banner {
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .87rem;
  margin-bottom: 16px;
}
.banner.info { background: #eaf1ff; color: #1f3fc0; }
.banner.warn { background: #fff6e6; color: #9a6700; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1b2430; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: .87rem; z-index: 100; box-shadow: var(--shadow);
}

/* ---------- Platform admin ---------- */
.admin-body { padding: 24px; }
.admin-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.admin-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.admin-table th, .admin-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; font-size: .88rem; }
.admin-table th { background: var(--bg); font-size: .75rem; text-transform: uppercase; color: var(--text-muted); }
.admin-main form > button { margin-top: 14px; }
