:root {
  --navy: #0f2a43;
  --navy-2: #163a5c;
  --teal: #14b8a6;
  --teal-dark: #0d9488;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #16233b;
  --muted: #64748b;
  --line: #e2e8f0;
  --danger: #dc2626;
  --amber: #d97706;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 42, 67, .06), 0 8px 24px rgba(15, 42, 67, .07);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(150deg, #0f2a43 0%, #14395e 55%, #0d5c54 130%);
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--card); border-radius: 20px;
  padding: 40px 36px 32px; box-shadow: 0 24px 64px rgba(4, 16, 28, .45);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.brand-badge {
  width: 46px; height: 46px; border-radius: 13px; background: var(--navy);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.brand-badge svg { width: 26px; height: 26px; }
.brand-name { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.brand-title { font-size: 21px; font-weight: 800; color: var(--navy); line-height: 1.15; }
.login-card h2 { font-size: 16px; font-weight: 600; margin-bottom: 18px; color: var(--text); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 13px; border: 1.5px solid var(--line); border-radius: 10px;
  background: #fbfcfe; outline: none; transition: border .15s;
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--teal); background: #fff; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 16px; border-radius: 10px; border: none;
  font-size: 14px; font-weight: 600; transition: .15s;
}
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-teal { background: var(--teal); color: #fff; }
.btn-teal:hover { background: var(--teal-dark); }
.btn-ghost { background: transparent; color: var(--muted); border: 1.5px solid var(--line); }
.btn-ghost:hover { border-color: #c3ced9; color: var(--text); }
.btn-danger-ghost { background: transparent; color: var(--danger); border: 1.5px solid #fecaca; }
.btn-danger-ghost:hover { background: #fef2f2; }
.btn-block { width: 100%; padding: 12px; font-size: 15px; }
.btn:disabled { opacity: .55; cursor: default; }
.error-box {
  background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca;
  padding: 10px 12px; border-radius: 10px; font-size: 13.5px; margin-bottom: 14px;
}
.success-box {
  background: #f0fdfa; color: #115e59; border: 1px solid #99f6e4;
  padding: 10px 12px; border-radius: 10px; font-size: 13.5px; margin-bottom: 14px;
}
.password-status { color: var(--muted); font-size: 13px; line-height: 1.5; margin-top: 8px; }
.password-recovery { background: #fffbeb; border: 1px solid #fde68a; padding: 12px; border-radius: 10px; margin-top: 10px; }
.password-recovery p { font-size: 13px; line-height: 1.5; margin-bottom: 10px; }
.password-recovery .btn { margin: 3px 0; }
button:disabled { cursor: default; }
.link-btn:disabled { color: var(--muted); text-decoration: none; }
[hidden] { display: none !important; }
.login-foot { margin-top: 18px; text-align: center; font-size: 12.5px; color: var(--muted); }

/* ---------- App shell ---------- */
.topbar {
  background: var(--navy); color: #fff;
  padding: 0 clamp(16px, 4vw, 40px);
  display: flex; align-items: center; gap: 18px; height: 62px;
  position: sticky; top: 0; z-index: 40;
}
.topbar .brand-badge { width: 34px; height: 34px; border-radius: 9px; background: rgba(255,255,255,.12); }
.topbar .brand-badge svg { width: 20px; height: 20px; }
.topbar-title { font-weight: 700; font-size: 16px; }
.topbar-title small { display: block; font-size: 10.5px; font-weight: 600; opacity: .65; letter-spacing: .06em; text-transform: uppercase; }
.topbar-spacer { flex: 1; }
.topbar .who { text-align: right; margin-right: 4px; }
.topbar .who b { font-size: 13.5px; display: block; }
.topbar .who span { font-size: 11.5px; opacity: .65; }
.icon-btn {
  background: rgba(255,255,255,.1); border: none; color: #fff;
  width: 36px; height: 36px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center; transition: .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.22); }
.icon-btn svg { width: 18px; height: 18px; }

.wrap { max-width: 1160px; margin: 0 auto; padding: 26px clamp(16px, 4vw, 40px) 80px; }

.tabs { display: flex; gap: 6px; margin-bottom: 22px; background: #e8edf3; padding: 5px; border-radius: 12px; width: fit-content; }
.tab {
  border: none; background: transparent; padding: 8px 18px; border-radius: 9px;
  font-size: 14px; font-weight: 600; color: var(--muted); transition: .15s;
}
.tab.active { background: #fff; color: var(--navy); box-shadow: 0 1px 4px rgba(15,42,67,.12); }

.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; font-weight: 800; color: var(--navy); }
.page-head .sub { color: var(--muted); font-size: 13.5px; }
.page-head .grow { flex: 1; }
.search {
  display: flex; align-items: center; gap: 8px; background: #fff; border: 1.5px solid var(--line);
  border-radius: 10px; padding: 8px 12px; min-width: 220px;
}
.search svg { width: 16px; height: 16px; color: var(--muted); flex-shrink: 0; }
.search input { border: none; outline: none; background: transparent; width: 100%; }

/* ---------- Vault cards (team view) ---------- */
.cat-title {
  font-size: 12px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted); margin: 26px 0 12px;
}
.cat-title:first-of-type { margin-top: 4px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 14px; }
.cred-card {
  background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  border: 1px solid rgba(226,232,240,.7); display: flex; flex-direction: column; gap: 10px;
}
.cred-top { display: flex; align-items: flex-start; gap: 10px; }
.cred-name { font-weight: 700; font-size: 15.5px; color: var(--navy); flex: 1; line-height: 1.3; }
.cred-name a { color: inherit; text-decoration: none; }
.cred-name a:hover { color: var(--teal-dark); text-decoration: underline; }
.ext-ico { width: 13px; height: 13px; opacity: .5; margin-left: 3px; }
.cred-row { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.cred-row .lab { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; width: 68px; flex-shrink: 0; }
.cred-row .val {
  flex: 1; font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mini-btn {
  background: #f1f5f9; border: none; border-radius: 7px; width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center; color: #475569; transition: .12s; flex-shrink: 0;
}
.mini-btn:hover { background: #e2e8f0; color: var(--navy); }
.mini-btn svg { width: 15px; height: 15px; }
.cred-notes { font-size: 13px; color: var(--muted); background: #f8fafc; border-radius: 9px; padding: 10px 12px; line-height: 1.5; white-space: pre-wrap; }
.notes-toggle { background: none; border: none; color: var(--teal-dark); font-size: 12.5px; font-weight: 600; padding: 0; width: fit-content; }
.empty {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 54px 30px; text-align: center; color: var(--muted); font-size: 14.5px; line-height: 1.6;
}
.empty svg { width: 42px; height: 42px; color: #cbd5e1; margin-bottom: 12px; }

/* ---------- Tables (admin) ---------- */
.table-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th {
  text-align: left; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: 12px 14px; background: #f8fafc; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 11px 14px; border-bottom: 1px solid #eef2f6; font-size: 13.5px; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafcfe; }
td .svc { font-weight: 600; color: var(--navy); }
td .svc a { color: inherit; text-decoration: none; }
td .svc a:hover { color: var(--teal-dark); }
td .sub-line { font-size: 12px; color: var(--muted); margin-top: 1px; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 12.5px; }
.pw-cell { display: flex; align-items: center; gap: 6px; }
.pw-cell .mono { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: none; transition: .12s;
}
.chip svg { width: 12px; height: 12px; }
.chip-all { background: #ccfbf1; color: #0f766e; }
.chip-some { background: #dbeafe; color: #1d4ed8; }
.chip-none { background: #f1f5f9; color: #64748b; }
button.chip:hover { filter: brightness(.95); }
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.badge-admin { background: #0f2a43; color: #fff; }
.badge-owner { background: #fde68a; color: #78350f; }
.badge-staff { background: #e2e8f0; color: #475569; }
.badge-off { background: #fee2e2; color: #b91c1c; }
.badge-ok { background: #ccfbf1; color: #0f766e; }
.sync-cell { white-space: nowrap; }
.sync-cell .badge { margin-right: 4px; cursor: help; }
.row-actions { display: flex; gap: 5px; justify-content: flex-end; }
.link-btn { background: none; border: none; color: var(--teal-dark); font-weight: 600; font-size: 13px; padding: 0; }
.link-btn:hover { text-decoration: underline; }
select.inline-select {
  padding: 5px 8px; border-radius: 8px; border: 1.5px solid var(--line); background: #fff; font-size: 12.5px; font-weight: 600;
}

/* ---------- Activity ---------- */
.act-list { display: flex; flex-direction: column; }
.act-item { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid #eef2f6; align-items: flex-start; }
.act-item:last-child { border-bottom: none; }
.act-ico {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.act-ico svg { width: 15px; height: 15px; }
.act-ico.blue { background: #dbeafe; color: #1d4ed8; }
.act-ico.teal { background: #ccfbf1; color: #0f766e; }
.act-ico.amber { background: #fef3c7; color: #b45309; }
.act-ico.red { background: #fee2e2; color: #b91c1c; }
.act-ico.gray { background: #f1f5f9; color: #64748b; }
.act-body { flex: 1; font-size: 13.5px; line-height: 1.45; }
.act-body b { font-weight: 600; }
.act-time { font-size: 12px; color: var(--muted); white-space: nowrap; padding-top: 2px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 22, 36, .55); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 18px;
  backdrop-filter: blur(2px);
}
.modal {
  background: #fff; border-radius: 18px; width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto; padding: 26px; box-shadow: 0 24px 64px rgba(4,16,28,.4);
}
.modal h3 { font-size: 17px; font-weight: 800; color: var(--navy); margin-bottom: 4px; }
.modal .modal-sub { font-size: 13px; color: var(--muted); margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 480px) { .two-col { grid-template-columns: 1fr; } }
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; background: #f8fafc; border-radius: 11px; margin-bottom: 12px;
}
.switch-row .sw-lab { font-size: 14px; font-weight: 600; }
.switch-row .sw-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px; transition: .18s; cursor: pointer;
}
.slider:before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .18s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .slider { background: var(--teal); }
.switch input:checked + .slider:before { transform: translateX(18px); }
.member-pick { border: 1.5px solid var(--line); border-radius: 11px; max-height: 260px; overflow-y: auto; }
.member-pick label {
  display: flex; align-items: center; gap: 10px; padding: 9px 13px; border-bottom: 1px solid #f1f5f9;
  font-size: 13.5px; cursor: pointer;
}
.member-pick label:last-child { border-bottom: none; }
.member-pick label:hover { background: #f8fafc; }
.member-pick input { width: 15px; height: 15px; accent-color: var(--teal); }
.member-pick .mp-name { font-weight: 600; }
.member-pick .mp-user { color: var(--muted); font-size: 12px; margin-left: auto; }
.member-pick.disabled { opacity: .45; pointer-events: none; }

/* ---------- Toast ---------- */
#toast-wrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13.5px; font-weight: 600; box-shadow: 0 8px 24px rgba(4,16,28,.35);
  animation: toast-in .2s ease;
}
.toast.err { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (max-width: 640px) {
  .topbar .who span { display: none; }
  .page-head { align-items: stretch; flex-direction: column; }
  .search { min-width: 0; }
}
