/*
 * Same design system as CMDB (test-cmdb/assets/css/style.css): same
 * color tokens, Inter typeface, card/button/table/alert/modal
 * components, and app-shell (white sidebar + topbar) layout, so the
 * two products read as one family. No Bootstrap here -- plain hand-
 * written CSS, same as CMDB.
 */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f4f6f9;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;

    --surface-sunken: #f8fafc;
    --surface-hover: #f1f5f9;
    --border-strong: #cbd5e1;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 8px 24px rgba(15, 23, 42, 0.10), 0 2px 6px rgba(15, 23, 42, 0.06);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --focus-ring: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
    --sidebar-bg: #ffffff;
    --sidebar-border: #eef1f6;
    --sidebar-width: 248px;
    --gradient-primary: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 65%, #7c3aed));
    --ease-out: cubic-bezier(.16, 1, .3, 1);
}

* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; scroll-behavior: smooth; }
body {
    margin: 0;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}
h1, h2, h3 { letter-spacing: -0.02em; font-weight: 700; margin-top: 0; }
h1 { font-size: 24px; }
h2 { font-size: 17px; }
a { color: var(--primary); }

@keyframes fadeInUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes driftA { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(20px, -16px); } }
@keyframes driftB { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-18px, 14px); } }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ---- form basics ---- */
label { display: block; margin-bottom: 16px; font-size: 14px; font-weight: 600; color: var(--text); }
input[type=text], input[type=email], input[type=password], input[type=search],
input[type=number], input[type=range], input[type=date], textarea, select {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: var(--card-bg);
    color: var(--text);
    transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus-ring); }
textarea { resize: vertical; }
input[readonly] { background: var(--surface-sunken); color: var(--text-muted); }
.form-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.form-row.cols-2 > * { flex: 1 1 0; min-width: 0; }
.form-row.cols-3 > * { flex: 1 1 0; min-width: 0; }
.field-hint { font-size: 12.5px; color: var(--text-muted); margin-top: -10px; margin-bottom: 16px; }

input[type=checkbox] { width: auto; display: inline-block; margin: 0 6px 0 0; accent-color: var(--primary); }
.check-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-weight: 500; }
.check-row label { margin: 0; font-weight: 500; }

/* ---- buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 14px;
    font-family: inherit;
    font-weight: 600;
    line-height: 1.5;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background-color .15s ease, box-shadow .15s ease, transform .15s var(--ease-out), filter .15s ease;
}
.btn:active { transform: translateY(1px) scale(.98); }
.btn[disabled] { opacity: .55; cursor: not-allowed; transform: none !important; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-primary { background: var(--gradient-primary); color: #fff; box-shadow: var(--shadow-sm); border: 1px solid transparent; }
.btn-primary:hover:not([disabled]) { filter: brightness(1.06); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.btn-secondary { background: var(--card-bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not([disabled]) { background: var(--surface-hover); border-color: var(--border-strong); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-danger { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.btn-danger:hover:not([disabled]) { background: #fee2e2; }
.btn-ghost { display: inline-flex; align-items: center; justify-content: center; background: transparent; color: var(--text-muted); border: none; padding: 6px; border-radius: var(--radius-sm); cursor: pointer; }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-ghost svg { width: 16px; height: 16px; }
.btn-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ---- card / alert / table ---- */
.card {
    background: var(--card-bg);
    border: 1px solid rgba(15, 23, 42, .06);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 24px;
    margin-bottom: 20px;
    animation: fadeInUp .4s var(--ease-out) both;
}
.card-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-h h2, .card-h h3 { margin: 0; font-size: 15px; font-weight: 700; }

.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; border: 1px solid transparent; }
.alert-error { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.alert-success { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.alert-info { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }

.table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-md); }
.table-responsive .table { box-shadow: none; }
.table { width: 100%; border-collapse: collapse; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); overflow: hidden; }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.table th { background: var(--surface-sunken); font-weight: 600; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background-color .12s ease; }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 999px; }
.badge-primary { background: #eff6ff; color: #1d4ed8; }
.badge-success { background: #f0fdf4; color: #15803d; }
.badge-danger { background: #fef2f2; color: #b91c1c; }
.badge-secondary { background: var(--surface-sunken); color: var(--text-muted); }

code { background: var(--surface-sunken); padding: 1px 6px; border-radius: 5px; font-size: 13px; }

/* ---- tabs ---- */
.tab-row { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab-link { padding: 10px 14px; font-size: 13.5px; font-weight: 600; color: var(--text-muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab-link:hover { color: var(--text); }
.tab-link.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---- app shell (sidebar + topbar), same structure as CMDB ---- */
.app-shell { display: flex; min-height: 100vh; align-items: stretch; }
.app-sidebar {
    width: var(--sidebar-width); flex-shrink: 0; background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border); display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh; z-index: 40;
}
.app-sidebar-brand {
    display: flex; align-items: center; gap: 10px; padding: 18px 20px; font-weight: 700;
    font-size: 15px; color: var(--text); text-decoration: none; letter-spacing: -0.01em;
    border-bottom: 1px solid var(--sidebar-border);
}
.app-sidebar-brand .brand-mark { color: var(--primary); display: inline-flex; }
.app-sidebar-nav { flex: 1; padding: 12px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.app-nav-item {
    display: flex; align-items: center; justify-content: flex-start; width: 100%; gap: 10px;
    padding: 9px 12px; border-radius: var(--radius-sm); color: var(--text-muted); text-decoration: none;
    text-align: left; font-size: 13.5px; font-weight: 500; position: relative;
    transition: background-color .15s ease, color .15s ease, transform .15s var(--ease-out);
}
.app-nav-item:hover { background: var(--surface-hover); color: var(--text); transform: translateX(2px); }
.app-nav-item.active {
    background: linear-gradient(90deg, color-mix(in srgb, var(--primary) 12%, transparent), color-mix(in srgb, var(--primary) 4%, transparent));
    color: var(--primary-dark); font-weight: 600; box-shadow: inset 3px 0 0 var(--primary); animation: fadeIn .2s ease both;
}
.app-nav-icon { width: 18px; height: 18px; flex-shrink: 0; display: inline-flex; transition: transform .15s var(--ease-out); }
.app-nav-icon svg { width: 100%; height: 100%; }
.app-nav-item:hover .app-nav-icon { transform: scale(1.1); }
.app-nav-label { flex: 1 1 auto; min-width: 0; text-align: left; }

.app-sidebar-footer { padding: 10px; border-top: 1px solid var(--sidebar-border); position: relative; }
.app-user-trigger {
    display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border-radius: var(--radius-sm);
    background: transparent; border: none; cursor: pointer; text-align: left; font-family: inherit; color: var(--text);
}
.app-user-trigger:hover { background: var(--surface-hover); }
.avatar-fallback {
    width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.app-user-name { font-size: 13px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-user-role { font-size: 11.5px; color: var(--text-muted); }
.app-user-trigger-chevron { margin-left: auto; color: var(--text-muted); width: 14px; height: 14px; flex-shrink: 0; transition: transform .2s var(--ease-out); }
.app-user-trigger.open .app-user-trigger-chevron { transform: rotate(180deg); }
.app-user-dropdown {
    position: absolute; bottom: calc(100% + 6px); left: 10px; right: 10px; background: var(--card-bg);
    border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 6px; z-index: 50;
    opacity: 0; visibility: hidden; transform: translateY(6px) scale(.97); transform-origin: bottom; pointer-events: none;
    transition: opacity .15s var(--ease-out), transform .15s var(--ease-out), visibility 0s linear .15s;
}
.app-user-dropdown.open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); pointer-events: auto; transition: opacity .15s var(--ease-out), transform .15s var(--ease-out), visibility 0s linear; }
.app-user-dropdown a { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 6px; font-size: 13.5px; color: var(--text); text-decoration: none; transition: background-color .12s ease, transform .12s ease; }
.app-user-dropdown a:hover { background: var(--surface-hover); transform: translateX(2px); }
.app-user-dropdown a.danger { color: #b91c1c; }
.app-user-dropdown-divider { height: 1px; background: var(--border); margin: 4px 6px; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-topbar { display: flex; align-items: center; gap: 12px; padding: 16px 28px; background: var(--card-bg); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
.app-topbar-title { font-size: 20px; font-weight: 700; margin: 0; letter-spacing: -0.02em; color: var(--text); }
.sidebar-toggle { display: none; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); width: 34px; height: 34px; align-items: center; justify-content: center; cursor: pointer; color: var(--text); flex-shrink: 0; }
.sidebar-toggle svg { width: 18px; height: 18px; }
.app-sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 39; }
.app-sidebar-backdrop.open { display: block; }
.app-content { flex: 1; padding: 24px 28px 48px; }

.app-search { position: relative; flex: 1; max-width: 380px; }
.app-search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-muted); }
.app-search input { padding-left: 34px; border-radius: 999px; background: var(--surface-sunken); margin-top: 0; }

.app-topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; position: relative; }
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
    position: absolute; right: 0; top: calc(100% + 6px); min-width: 180px; background: var(--card-bg);
    border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 6px; z-index: 50;
    opacity: 0; visibility: hidden; transform: translateY(6px) scale(.97); transform-origin: top right; pointer-events: none;
    transition: opacity .15s var(--ease-out), transform .15s var(--ease-out), visibility 0s linear .15s;
}
.dropdown-menu.open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); pointer-events: auto; transition: opacity .15s var(--ease-out), transform .15s var(--ease-out), visibility 0s linear; }
.dropdown-menu a, .dropdown-menu button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border-radius: 6px; font-size: 13.5px; color: var(--text); text-decoration: none; background: none; border: none; text-align: left; cursor: pointer; font-family: inherit; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface-hover); }

@media (max-width: 880px) {
    .app-sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s var(--ease-out); }
    .app-sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: inline-flex; }
    .app-topbar { padding: 14px 16px; }
    .app-content { padding: 16px 16px 40px; }
}

/* ---- modal overlay, same pattern as CMDB (.actions-trigger[data-modal] opens, .modal-close-btn / backdrop closes) ---- */
.modal-overlay {
    display: flex; align-items: center; justify-content: center; position: fixed; inset: 0;
    background: rgba(15, 23, 42, .5); z-index: 60; opacity: 0; visibility: hidden;
    transition: opacity .18s var(--ease-out), visibility 0s linear .18s;
}
.modal-overlay.open { opacity: 1; visibility: visible; transition: opacity .18s var(--ease-out), visibility 0s linear; }
.modal-overlay .card { transform: scale(.94) translateY(8px); opacity: 0; transition: transform .18s var(--ease-out), opacity .18s var(--ease-out); max-width: 560px; width: 92%; max-height: 86vh; overflow-y: auto; margin: 0; }
.modal-overlay.open .card { transform: scale(1) translateY(0); opacity: 1; }
.modal-overlay .card.modal-sm { max-width: 360px; }
.modal-overlay .card.modal-lg { max-width: 720px; }
.modal-close-btn { position: absolute; top: 14px; right: 14px; width: 30px; height: 30px; border-radius: 50%; border: none; background: var(--surface-sunken); color: var(--text-muted); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.modal-close-btn:hover { background: var(--surface-hover); color: var(--text); }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.modal-footer .mr-auto { margin-right: auto; }

/* ---- auth pages ---- */
.container { max-width: 960px; margin: 0 auto; padding: 24px 16px 48px; }
.container.centered { display: flex; align-items: center; justify-content: center; min-height: 100vh; position: relative; overflow: hidden; isolation: isolate; }
.container.centered::before, .container.centered::after { content: ""; position: absolute; z-index: -1; width: 55vmax; height: 55vmax; border-radius: 50%; filter: blur(2px); pointer-events: none; }
.container.centered::before { top: -18%; left: -12%; background: radial-gradient(circle, color-mix(in srgb, var(--primary) 10%, transparent), transparent 60%); animation: driftA 22s ease-in-out infinite; }
.container.centered::after { bottom: -20%; right: -14%; background: radial-gradient(circle, color-mix(in srgb, var(--primary) 8%, transparent), transparent 60%); animation: driftB 26s ease-in-out infinite; }
.auth-form { width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); border-radius: var(--radius-lg); padding: 32px 28px; animation: fadeInUp .45s var(--ease-out) both; }
.auth-form h1 { text-align: center; font-size: 20px; margin-bottom: 4px; }
.auth-form .auth-sub { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 20px; }
.auth-logo { display: block; text-align: center; margin-bottom: 6px; color: var(--primary); }
.auth-logo svg { width: 34px; height: 34px; }
.auth-form .btn-primary { width: 100%; justify-content: center; }
.auth-form-footer { text-align: center; margin-top: 16px; font-size: 13.5px; color: var(--text-muted); }

/* ---- vault-specific ---- */
.vault-toolbar { background: var(--card-bg); border-bottom: 1px solid var(--border); padding: 10px 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.filter-pill-row { display: flex; gap: 6px; }
.filter-pill { padding: 6px 13px; border-radius: 999px; border: 1px solid var(--border); background: var(--card-bg); color: var(--text-muted); font-size: 12.5px; font-weight: 600; cursor: pointer; }
.filter-pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.vault-list { background: var(--card-bg); min-height: 55vh; border-radius: var(--radius-md); margin: 16px 20px; border: 1px solid var(--border); overflow: hidden; box-shadow: var(--shadow-sm); }
.vault-item { display: flex; align-items: center; gap: 14px; padding: 12px 18px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background-color .12s ease; }
.vault-item:last-child { border-bottom: none; }
.vault-item:hover { background: var(--surface-hover); }
.vault-item-icon { width: 36px; height: 36px; border-radius: var(--radius-sm); background: var(--surface-sunken); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; color: var(--primary); flex-shrink: 0; }
.vault-item-main { flex: 1; min-width: 0; }
.vault-item-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vault-item-sub { color: var(--text-muted); font-size: 12.5px; }
.vault-item-actions { display: flex; gap: 2px; }

.unlock-gate { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: flex; align-items: center; justify-content: center; z-index: 70; }
.unlock-gate-card { background: var(--card-bg); border-radius: var(--radius-lg); padding: 32px; width: 320px; text-align: center; box-shadow: var(--shadow-lg); }
.unlock-gate-icon { color: var(--primary); margin-bottom: 8px; }

.backup-codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; font-family: monospace; margin-top: 10px; }
.backup-codes code { background: var(--surface-sunken); padding: 6px 10px; border-radius: 6px; text-align: center; }

.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 18px; text-align: center; box-shadow: var(--shadow-sm); }
.stat-card .stat-num { font-size: 28px; font-weight: 700; }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.progress-track { height: 6px; border-radius: 999px; background: var(--surface-sunken); overflow: hidden; margin-bottom: 16px; }
.progress-fill { height: 100%; border-radius: 999px; transition: width .2s ease; }

.d-none { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-3 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }
