*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #141b27;
  --surface-hover: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warn: #f59e0b;
  --success: #22c55e;
  --chart-weak: #3b82f6;
  --chart-exposed: #ef4444;
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 260px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Fira Sans", system-ui, -apple-system, "Segoe UI", Roboto,
    sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ---------- App shell layout ---------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar content";
  min-height: 100vh;
  transition: filter 0.2s ease;
}

body.locked .app-shell {
  filter: blur(6px);
  pointer-events: none;
  user-select: none;
}

/* ---------- Sidebar ---------- */
.sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  overflow-y: auto;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.brand-title {
  font-size: 1.4rem;
  font-weight: 700;
}

.brand-email {
  font-size: 0.75rem;
  color: var(--text-muted);
  word-break: break-all;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.7rem;
  border: none;
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--surface-hover);
  color: var(--text);
  border-left-color: var(--accent);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.vault-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.7rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.vault-status svg {
  width: 16px;
  height: 16px;
}

.vault-status.locked {
  color: var(--warn);
}

.vault-status.unlocked {
  color: var(--success);
}

.folders-section {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.folders-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.folders-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.folder-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.folder-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.7rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.88rem;
  text-align: left;
  border-radius: var(--radius-sm);
  cursor: pointer;
  width: 100%;
  transition: background 0.15s, color 0.15s;
}

.folder-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.folder-item.active {
  background: var(--surface-hover);
  color: var(--text);
}

.folder-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.folder-item .folder-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-actions {
  display: none;
  gap: 0.25rem;
}

.folder-item:hover .folder-actions {
  display: flex;
}

/* ---------- Topbar ---------- */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--surface-hover);
  border: 1px solid var(--border);
}

.topbar-spacer {
  flex: 1;
}

.topbar-actions {
  display: flex;
  gap: 0.5rem;
}

.sidebar-toggle {
  display: none;
}

/* ---------- Content ---------- */
.content {
  grid-area: content;
  padding: 1.5rem 2rem;
  overflow-y: auto;
}

.view-title {
  margin: 0 0 1.25rem;
  font-size: 1.5rem;
}

/* ---------- Stat cards ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stat-card .stat-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--surface-hover);
  color: var(--accent);
}

.stat-card .stat-icon svg {
  width: 20px;
  height: 20px;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.stat-number {
  font-size: 1.75rem;
  font-weight: 700;
}

.stat-number .stat-unit {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 0.3rem;
}

/* ---------- Dashboard grid ---------- */
.dash-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.panel-title {
  margin: 0;
  font-size: 1.1rem;
}

/* ---------- Recent activity ---------- */
.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.activity-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.activity-item .activity-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--surface-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

.activity-item .activity-icon svg {
  width: 16px;
  height: 16px;
}

.activity-text {
  display: flex;
  flex-direction: column;
}

.activity-title {
  font-size: 0.9rem;
}

.activity-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ---------- Search ---------- */
.search-bar {
  position: relative;
  max-width: 280px;
}

.search-bar input {
  padding-left: 2.2rem;
}

.search-bar svg {
  position: absolute;
  left: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

/* ---------- Data table ---------- */
.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.8rem;
}

.data-table tbody tr:hover {
  background: var(--surface-2);
}

.data-table .cell-name {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.data-table .cell-name svg {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.data-table .row-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}

.copy-menu-wrap {
  position: relative;
}

.copy-trigger span {
  display: none;
}

@media (min-width: 900px) {
  .copy-trigger span {
    display: inline;
  }
}

.copy-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  z-index: 50;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.copy-menu-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

.copy-menu-item:hover {
  background: var(--surface-hover);
}

.copy-menu-item svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.field-with-copy {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.field-with-copy input,
.field-with-copy textarea {
  flex: 1;
}

.field-with-copy.textarea {
  align-items: flex-start;
}

.field-with-copy.textarea .field-copy-btn {
  margin-top: 0.35rem;
}

.field-copy-btn {
  flex-shrink: 0;
}

.copy-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  padding: 0.65rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  color: var(--text);
  pointer-events: none;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-radius: 4px;
}

.badge-account {
  background: #1e3a5f;
  color: #93c5fd;
}
.badge-password {
  background: #3b2f4a;
  color: #c4b5fd;
}
.badge-note {
  background: #1a3d2e;
  color: #86efac;
}
.badge-card {
  background: #4a3520;
  color: #fcd34d;
}
.badge-document {
  background: #1e3a4a;
  color: #7dd3fc;
}
.badge-other {
  background: #374151;
  color: #d1d5db;
}

/* ---------- Security charts ---------- */
.security-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.chart-block .chart-heading {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
}

.chart-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.7rem;
}

.chart-row .chart-label {
  width: 90px;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chart-track {
  flex: 1;
  height: 18px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}

.chart-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
  min-width: 2px;
}

.chart-bar.weak {
  background: var(--chart-weak);
}
.chart-bar.exposed {
  background: var(--chart-exposed);
}
.chart-bar.safe {
  background: var(--success);
}

.chart-row .chart-value {
  width: 32px;
  text-align: right;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Forms ---------- */
label {
  display: block;
  margin-top: 0.75rem;
  margin-bottom: 0.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

input,
select,
textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

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

textarea {
  min-height: 100px;
  resize: vertical;
}

/* ---------- Buttons ---------- */
.btn {
  padding: 0.55rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

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

.btn-secondary {
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  color: white;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* ---------- Empty / error ---------- */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
}

.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
}

/* ---------- Lock overlay ---------- */
.lock-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(8, 12, 20, 0.55);
}

.lock-overlay.hidden {
  display: none !important;
}

.lock-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.lock-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  background: var(--surface-hover);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.lock-icon svg {
  width: 28px;
  height: 28px;
}

.lock-card h1 {
  margin: 0 0 0.5rem;
  font-size: 1.4rem;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

#unlock-form {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 2.6rem;
}

.toggle-visibility {
  position: absolute;
  right: 0.3rem;
  top: 50%;
  transform: translateY(-50%);
}

.lock-links {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
}

/* ---------- Modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.modal-content.modal-sm {
  max-width: 380px;
}

.modal-content h2 {
  margin: 0 0 1rem;
  font-size: 1.25rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "content";
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--sidebar-w);
    z-index: 120;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  .dash-grid,
  .security-grid {
    grid-template-columns: 1fr;
  }

  .content {
    padding: 1.25rem;
  }
}

@media (max-width: 480px) {
  .topbar-actions .btn {
    padding: 0.5rem 0.7rem;
    font-size: 0.85rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
