/* Hermes Credential Vault — Mobile-first Dark/Light Design System */
:root {
  --bg: #0b101b;
  --bg-elevated: #121928;
  --bg-card: #161f31;
  --bg-input: #0e1523;
  --border: #25324a;
  --text: #eef3fb;
  --text-muted: #93a4bf;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.16);
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.15);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.15);
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --radius-sm: 10px;
  --nav-height: 64px;
  --sidebar-width: 248px;
}

[data-theme="light"] {
  --bg: #f3f6fb;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f8fafc;
  --border: #dbe3ef;
  --text: #0f172a;
  --text-muted: #52627a;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --success: #059669;
  --success-soft: rgba(5, 150, 105, 0.12);
  --warning: #d97706;
  --warning-soft: rgba(217, 119, 6, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.12);
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

a:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

/* App Shell */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 58px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 0.9rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar {
  display: none;
}

.main-content {
  flex: 1;
  padding: 16px 14px calc(var(--nav-height) + 24px);
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

/* Mobile Bottom Nav */
.mobile-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom);
}

.mobile-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  gap: 2px;
  text-decoration: none;
}

.mobile-nav a.active {
  color: var(--accent);
}

.mobile-drawer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 70;
  display: flex;
  justify-content: flex-end;
}

.mobile-drawer-panel {
  width: 270px;
  background: var(--bg-elevated);
  height: 100%;
  padding: 18px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

@media (min-width: 900px) {
  .app-shell {
    flex-direction: row;
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    padding: 18px 12px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
  }

  .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 18px;
    flex: 1;
  }

  .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 500;
    min-height: 44px;
  }

  .nav-link:hover {
    background: var(--accent-soft);
    color: var(--text);
    text-decoration: none;
  }

  .nav-link.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
  }

  .desktop-main-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .mobile-nav,
  .mobile-menu-btn {
    display: none;
  }

  .main-content {
    padding: 24px 28px 40px;
  }
}

.desktop-main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Typography & Headers */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.page-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
}

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

/* Cards & Grids */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card-title {
  margin: 0 0 12px;
  font-size: 1.02rem;
  font-weight: 600;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

@media (min-width: 720px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 1.7rem;
  font-weight: 700;
  margin-top: 4px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 820px) {
  .grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Forms & Inputs */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 0.86rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.form-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

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

.input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  background: var(--bg-input);
  color: var(--text);
  border-color: var(--border);
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  filter: brightness(1.08);
  text-decoration: none;
}

.btn-sm {
  min-height: 36px;
  padding: 0 11px;
  font-size: 0.82rem;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.btn-warning {
  background: var(--warning);
  color: #111827;
  border-color: var(--warning);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}

.badge-active, .badge-success, .badge-valid {
  background: var(--success-soft);
  color: var(--success);
}

.badge-rotating, .badge-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge-revoked, .badge-danger, .badge-failure, .badge-denied, .badge-invalid {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-info, .badge-neutral {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Tables & Credential List Cards */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.cred-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 10px;
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@media (min-width: 720px) {
  .cred-item {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.86rem;
}

.secret-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  word-break: break-all;
}

/* Toolbar */
.toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

@media (min-width: 720px) {
  .toolbar {
    grid-template-columns: 2fr 1fr 1fr auto;
  }
}

/* Login Page */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

/* Modal & Toast */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 460px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.toast-container {
  position: fixed;
  top: 68px;
  right: 14px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 340px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  box-shadow: var(--shadow);
  font-size: 0.88rem;
}

.toast.error {
  border-left-color: var(--danger);
}

.toast.success {
  border-left-color: var(--success);
}

.qr-preview {
  background: #ffffff;
  padding: 10px;
  border-radius: 10px;
  display: inline-block;
  margin: 10px 0;
}

.qr-preview img {
  display: block;
  width: 180px;
  height: 180px;
}

.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 14px;
  font-size: 0.88rem;
}

.alert-warning {
  background: var(--warning-soft);
  border-color: var(--warning);
}

.alert-info {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* Password list items */
.pw-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.pw-item:last-child { border-bottom: none; }
.pw-left { flex: 1; min-width: 0; }
.pw-favicon {
  width: 40px; height: 40px;
  border-radius: var(--radius);
  background: var(--card-bg);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.25rem;
  color: var(--accent);
  flex-shrink: 0;
}
.pw-info { min-width: 0; }
.pw-name { font-size: 1rem; color: var(--text); word-break: break-word; }
.pw-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.pw-secret { display: flex; align-items: center; gap: 6px; min-width: 110px; }
.pw-secret .masked { color: var(--muted); user-select: none; }
.pw-actions { display: flex; gap: 6px; }
.pw-toggle { font-size: 0.8rem; }

/* Generator page */
.gen-card { max-width: 520px; margin: 0 auto; }
.gen-controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.gen-output { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.1rem; word-break: break-all; padding: 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--input-bg); color: var(--text); }
.gen-meta { font-size: 0.8rem; color: var(--muted); margin-top: 8px; }
