:root {
  --navy: #203755;
  --blue: #014881;
  --blue-2: #0c5b9d;
  --white: #ffffff;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #dfe5ec;
  --text: #1f2937;
  --muted: #667085;
  --success: #14804a;
  --warning: #9a6700;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(32,55,85,.08);
  --font-ui: "Montserrat", "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-ui);
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body, button, input, select, textarea, table, th, td, label, a {
  font-family: var(--font-ui);
}
button, input, select, textarea { font: inherit; }
h1, h2, h3, h4, h5, h6 { font-family: var(--font-ui); font-weight: 700; letter-spacing: -.015em; }
strong, b { font-weight: 700; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 32px; background: linear-gradient(135deg, var(--navy), #11253e); }
.login-panel { width: min(460px, 100%); background: var(--white); border-radius: 18px; box-shadow: 0 24px 70px rgba(0,0,0,.25); padding: 34px; }
.brand-lockup, .sidebar-brand { display: flex; align-items: center; gap: 14px; }
.brand-lockup h1 { margin: 0 0 5px; color: var(--navy); }
.brand-lockup p { margin: 0; color: var(--muted); }
.brand-mark { width: 58px; height: 58px; border-radius: 15px; display: grid; place-items: center; background: var(--blue); color: white; font-weight: 800; letter-spacing: .04em; }
.brand-mark.small { width: 40px; height: 40px; border-radius: 10px; font-size: .85rem; }
.login-form { display: grid; gap: 18px; margin-top: 30px; }
.login-form label, .field label { display: grid; gap: 8px; color: #344054; font-weight: 600; font-size: .92rem; }
input, select, textarea { width: 100%; border: 1px solid #cfd7e3; border-radius: 9px; padding: 11px 12px; background: white; color: var(--text); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(1,72,129,.10); }
textarea { min-height: 100px; resize: vertical; }
.login-note { margin-top: 24px; padding: 14px; border-radius: 10px; background: #f7f9fc; color: var(--muted); display: grid; gap: 4px; font-size: .84rem; }
.form-error { color: var(--danger); margin: 0; }

.btn { border: 0; border-radius: 9px; padding: 10px 14px; font-weight: 700; transition: .16s ease; }
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--blue); color: white; }
.btn.secondary { background: #e9f1f8; color: var(--blue); }
.btn.success { background: #e8f7ef; color: var(--success); }
.btn.danger { background: #fff0ee; color: var(--danger); }
.btn.ghost { background: rgba(255,255,255,.08); color: white; border: 1px solid rgba(255,255,255,.16); }
.btn.wide { width: 100%; }
.btn.small { padding: 7px 10px; font-size: .8rem; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 255px 1fr; }
.sidebar { background: var(--navy); color: white; min-height: 100vh; display: flex; flex-direction: column; padding: 22px 16px; position: sticky; top: 0; height: 100vh; }
.sidebar-brand { padding: 2px 8px 22px; border-bottom: 1px solid rgba(255,255,255,.10); }
.sidebar-brand div:last-child { display: grid; gap: 3px; }
.sidebar-brand span { color: #b8c6d9; font-size: .75rem; }
.nav-menu { display: grid; gap: 6px; padding-top: 20px; }
.nav-item { width: 100%; border: 0; background: transparent; color: #dce6f0; text-align: left; padding: 11px 12px; border-radius: 9px; display: flex; align-items: center; gap: 11px; font-weight: 600; }
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.10); color: white; }
.nav-item.active { box-shadow: inset 3px 0 0 #fff; }
.sidebar-footer { margin-top: auto; display: grid; gap: 14px; }
.status-line { display: flex; gap: 8px; align-items: center; font-size: .78rem; color: #c8d4e2; padding: 0 6px; }
.status-line i { width: 8px; height: 8px; border-radius: 50%; background: #49c77a; }
.main-area { min-width: 0; }
.topbar { background: white; border-bottom: 1px solid var(--line); padding: 20px 28px; display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 5; }
.topbar h2 { margin: 0 0 3px; color: var(--navy); }
.topbar p { margin: 0; color: var(--muted); font-size: .88rem; }
.user-chip { display: flex; align-items: center; gap: 11px; }
.user-chip > div:last-child { display: grid; gap: 2px; text-align: right; }
.user-chip span { color: var(--muted); font-size: .75rem; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: #e9f1f8; color: var(--blue); display: grid; place-items: center; font-weight: 800; order: 2; }
.content { padding: 26px 28px 40px; }

.grid-cards { display: grid; grid-template-columns: repeat(4, minmax(180px,1fr)); gap: 16px; }
.stat-card { background: var(--panel); border: 1px solid var(--line); border-radius: 13px; padding: 18px; box-shadow: var(--shadow); }
.stat-card .label { color: var(--muted); font-size: .82rem; font-weight: 700; }
.stat-card .value { margin-top: 9px; font-size: 1.85rem; font-weight: 800; color: var(--navy); }
.stat-card .foot { margin-top: 4px; color: var(--muted); font-size: .75rem; }

.panel { margin-top: 20px; background: white; border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--shadow); overflow: hidden; }
.panel-header { padding: 17px 18px; display: flex; justify-content: space-between; align-items: center; gap: 15px; border-bottom: 1px solid var(--line); }
.panel-header h3 { margin: 0; color: var(--navy); }
.panel-header p { margin: 4px 0 0; color: var(--muted); font-size: .8rem; }
.toolbar { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 180px; padding: 9px 10px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; background: #f7f9fc; color: #526071; font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; padding: 12px 14px; border-bottom: 1px solid var(--line); }
td { padding: 13px 14px; border-bottom: 1px solid #edf1f5; vertical-align: middle; font-size: .88rem; }
tr:last-child td { border-bottom: 0; }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.actions { display: flex; gap: 7px; flex-wrap: wrap; }

.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 9px; font-size: .72rem; font-weight: 800; white-space: nowrap; }
.badge.neutral { background: #eef2f6; color: #566477; }
.badge.blue { background: #e9f1f8; color: var(--blue); }
.badge.green { background: #e8f7ef; color: var(--success); }
.badge.yellow { background: #fff6df; color: var(--warning); }
.badge.red { background: #fff0ee; color: var(--danger); }

.notice { border-left: 4px solid var(--blue); background: #f8fbfe; border-radius: 8px; padding: 14px 16px; color: #3c4b5f; margin-bottom: 20px; }
.notice strong { color: var(--navy); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(15,28,44,.55); z-index: 50; display: grid; place-items: center; padding: 24px; }
.modal { width: min(760px, 100%); max-height: 92vh; overflow: auto; background: white; border-radius: 15px; box-shadow: 0 30px 80px rgba(0,0,0,.25); }
.modal > header { padding: 18px 20px; display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); }
.modal h3 { margin: 0; color: var(--navy); }
.modal header p { margin: 4px 0 0; color: var(--muted); font-size: .8rem; }
.icon-btn { border: 0; background: #f1f4f8; color: var(--navy); width: 34px; height: 34px; border-radius: 50%; font-size: 1.4rem; }
.modal-body { padding: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.form-grid .full { grid-column: 1 / -1; }
.modal-actions { margin-top: 20px; display: flex; justify-content: flex-end; gap: 10px; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 100; background: #16283d; color: white; padding: 12px 16px; border-radius: 10px; box-shadow: 0 15px 40px rgba(0,0,0,.2); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; max-width: 380px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #8c251e; }

@media (max-width: 1100px) {
  .grid-cards { grid-template-columns: repeat(2, minmax(180px,1fr)); }
}
@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; min-height: auto; }
  .nav-menu { grid-template-columns: repeat(2,1fr); }
  .sidebar-footer { margin-top: 20px; }
  .topbar { position: static; padding: 16px; }
  .content { padding: 16px; }
  .grid-cards, .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .user-chip > div:last-child { display: none; }
}

/* v0.2.2 — perfil d'usuari i doble factor */
.security-step { display: grid; gap: 6px; padding: 14px; border-radius: 10px; background: #f7f9fc; color: var(--muted); }
.security-step strong { color: var(--navy); }
.user-chip { border: 0; background: transparent; padding: 4px 6px; border-radius: 10px; cursor: pointer; color: inherit; }
.user-chip:hover { background: #f4f7fa; }
.avatar { background-position: center; background-repeat: no-repeat; background-size: cover; overflow: hidden; }
.avatar.has-image { color: transparent; box-shadow: inset 0 0 0 1px rgba(32,55,85,.12); }
.profile-grid { display: grid; grid-template-columns: minmax(320px, .9fr) minmax(360px, 1.1fr); gap: 20px; align-items: start; }
.profile-card { overflow: visible; }
.profile-body { padding: 22px; display: grid; gap: 18px; }
.profile-avatar-large { width: 116px; height: 116px; border-radius: 50%; overflow: hidden; display: grid; place-items: center; background: #e9f1f8; color: var(--blue); font-size: 2rem; font-weight: 800; box-shadow: inset 0 0 0 1px rgba(32,55,85,.08); }
.profile-avatar-large img { width: 100%; height: 100%; object-fit: cover; display: block; }
.profile-data { display: grid; gap: 5px; }
.profile-data strong { color: var(--navy); font-size: 1.05rem; }
.profile-data span { color: var(--muted); font-size: .86rem; }
.profile-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.file-button { display: inline-flex; align-items: center; justify-content: center; }
.help-text { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.5; }
.security-status { display: flex; align-items: center; gap: 14px; padding: 15px; background: #f7f9fc; border: 1px solid var(--line); border-radius: 11px; }
.security-status > div { display: grid; gap: 4px; }
.security-status strong { color: var(--navy); }
.security-status span:not(.security-icon) { color: var(--muted); font-size: .82rem; }
.security-icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: #e9f1f8; color: var(--blue); font-size: 1.2rem; font-weight: 800; flex: 0 0 auto; }
.qr-setup { display: grid; justify-items: center; gap: 14px; margin-bottom: 18px; text-align: center; }
.qr-image { width: min(280px, 100%); aspect-ratio: 1; background: white; border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.manual-key { display: grid; gap: 6px; width: 100%; }
.manual-key span { color: var(--muted); font-size: .76rem; font-weight: 700; }
.manual-key code { padding: 10px; border-radius: 8px; background: #f4f6f9; color: var(--navy); overflow-wrap: anywhere; user-select: all; }
.recovery-box { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 16px; background: #f7f9fc; border: 1px solid var(--line); border-radius: 11px; }
.recovery-box code { display: block; padding: 10px; text-align: center; background: white; border: 1px solid var(--line); border-radius: 8px; color: var(--navy); font-weight: 700; letter-spacing: .05em; user-select: all; }
.warning-text { color: var(--warning); }
.user-cell { display: flex; align-items: center; gap: 9px; }
.user-avatar-mini { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: 0 0 30px; background: #e9f1f8; color: var(--blue); background-position: center; background-repeat: no-repeat; background-size: cover; font-size: .75rem; font-weight: 800; }

@media (max-width: 900px) {
  .profile-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .recovery-box { grid-template-columns: 1fr; }
}
