:root {
  --bg: #0d1116;
  --surface: #151b22;
  --surface-2: #1c242d;
  --border: #2a3440;
  --fg: #eef1f5;
  --muted: #95a1b2;
  --accent: #4f8cff;
  --accent-fg: #ffffff;
  --green: #36c27a;
  --warn: #f2b84b;
  --red: #ff6b6b;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7fa;
    --surface: #ffffff;
    --surface-2: #eef2f6;
    --border: #d6dde5;
    --fg: #121820;
    --muted: #5d6b7c;
    --accent: #2f6fe8;
    --green: #1d9a5b;
    --warn: #b7791f;
    --red: #d64545;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 24px 0 10px; }
.card h2:first-child, .modal h2 { margin-top: 0; }
h3 { font-size: 1rem; margin: 0; }
p { margin: 0; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.error { color: var(--red); font-size: 0.9rem; }
.warn { color: var(--warn); font-size: 0.9rem; }
[hidden] { display: none !important; }

/* ---------- formulare ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }
label.check { flex-direction: row; align-items: flex-start; gap: 10px; color: var(--fg); cursor: pointer; }
label.check input { margin-top: 3px; }
input, select, textarea {
  font: inherit;
  color: var(--fg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 42px;
  width: 100%;
}
input[type="checkbox"], input[type="radio"] { width: 18px; min-height: 18px; height: 18px; accent-color: var(--accent); flex: none; }
input[type="file"] { padding: 8px; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
input:user-invalid { border-color: var(--red); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
legend { padding: 0 6px; color: var(--muted); font-size: 0.85rem; }
.code-input { font-family: var(--mono); font-size: 1.4rem; letter-spacing: 0.3em; text-align: center; max-width: 220px; }
progress { width: 100%; height: 8px; accent-color: var(--accent); }

button, .btn {
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 9px 16px;
  min-height: 40px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--surface-2);
  color: var(--fg);
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-fg); }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.danger { background: var(--red); color: #fff; }
button.ghost, .btn.ghost { background: transparent; border-color: var(--border); }
button.ghost:hover, .btn.ghost:hover { background: var(--surface-2); }
button.small, .btn.small { padding: 4px 10px; min-height: 32px; font-size: 0.85rem; font-weight: 500; }
button.link { background: none; border: none; padding: 0; min-height: 0; color: var(--accent); font-weight: 500; text-align: left; }
.danger-text { color: var(--red) !important; }
.icon-btn { background: none; border: none; font-size: 1.5rem; line-height: 1; padding: 4px 10px; min-height: 0; color: var(--muted); }

.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.actions.left { justify-content: flex-start; }

/* ---------- autentificare ---------- */
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.auth-card h1 { margin-bottom: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand.big { font-size: 1.3rem; }

/* ---------- structura aplicației ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar .spacer { flex: 1; }
.topbar .user { color: var(--fg); text-decoration: none; font-weight: 500; }
.topbar .user.active { color: var(--accent); }
.ws-select { width: auto; min-height: 36px; padding: 6px 10px; }
.ws-name { color: var(--muted); }
.tabs { display: flex; gap: 4px; padding: 8px 16px; overflow-x: auto; border-bottom: 1px solid var(--border); background: var(--surface); }
.tab { padding: 8px 14px; border-radius: 8px; color: var(--muted); text-decoration: none; white-space: nowrap; font-weight: 500; }
.tab:hover { background: var(--surface-2); color: var(--fg); }
.tab.active { background: var(--surface-2); color: var(--fg); box-shadow: inset 0 -2px 0 var(--accent); }
.tab-sep { width: 1px; background: var(--border); margin: 6px 8px; }
.content { max-width: 1180px; margin: 0 auto; padding: 24px 20px 64px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .muted { max-width: 720px; }
.page-head input[type="search"] { max-width: 320px; }
.banner { background: color-mix(in srgb, var(--warn) 15%, transparent); border: 1px solid var(--warn); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.cards { display: flex; flex-direction: column; gap: 12px; }
.card-row { display: flex; gap: 14px; align-items: flex-start; }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.app-icon {
  width: 44px; height: 44px; border-radius: 12px; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 1.2rem;
  background: color-mix(in srgb, var(--accent) 20%, var(--surface-2)); color: var(--accent);
}
.versions { margin-top: 14px; overflow-x: auto; }
.empty { padding: 32px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }

.meter { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; max-width: 420px; }
.meter-bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.meter-fill { display: block; height: 100%; width: 0; background: var(--accent); }

.badge {
  display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 2px 8px; margin-left: 6px;
  border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); vertical-align: middle;
}
.badges .badge { margin: 2px 4px 2px 0; }
.badge-blue { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
.badge-green { color: var(--green); border-color: color-mix(in srgb, var(--green) 50%, transparent); }
.badge-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.badge-red { color: var(--red); border-color: color-mix(in srgb, var(--red) 50%, transparent); }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
tr.revoked td { opacity: 0.55; }
tr.warn-row td:nth-child(2) { color: var(--warn); }
td.right button, td.right .btn { margin-left: 4px; }

.qr-wrap { background: #fff; padding: 12px; border-radius: var(--radius); align-self: flex-start; width: min(100%, 420px); }
.qr-wrap.small-qr { width: min(100%, 240px); }
.qr { display: block; width: 100%; height: auto; }
.secret-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; word-break: break-all; user-select: all; }
.secret-box.big code { font-size: 1.3rem; letter-spacing: 0.08em; }
.recovery { columns: 2; font-size: 1.05rem; margin: 0; padding-left: 28px; }
.recovery li { padding: 2px 0; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.result { display: flex; flex-direction: column; gap: 14px; margin: 18px 0; border-color: var(--accent); }
.form-grid { max-width: 820px; }

/* ---------- ferestre și notificări ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 20px; width: 100%; max-width: 480px; max-height: 92vh; overflow: auto; }
.modal-wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 30; max-width: calc(100vw - 32px); }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--green); border-radius: 8px; padding: 10px 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3); }
.toast-error { border-left-color: var(--red); }

@media (max-width: 700px) {
  .topbar { padding: 10px 16px; }
  .content { padding: 16px 16px 48px; }
  .card-row { flex-wrap: wrap; }
  .card-actions { width: 100%; justify-content: flex-start; }
  .recovery { columns: 1; }
  .auth-card { padding: 20px; }
}

@media print {
  .topbar, .tabs, form, .actions, #toasts, h2 + .table-wrap, .banner { display: none !important; }
  .result { border: none; }
  .qr-wrap { width: 360px; }
}
