:root {
  color-scheme: light;
  --bg: #ecfdf5;
  --surface: #ffffff;
  --text: #14532d;
  --muted: #4d7c59;
  --accent: #166534;
  --accent2: #22c55e;
  --danger: #b91c1c;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(20, 83, 45, 0.12);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'PingFang SC',
    'Microsoft YaHei', sans-serif;
  line-height: 1.45;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  min-height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.app-shell:has(.home-page) {
  max-width: 920px;
}

.home-layout {
  display: flex;
  align-items: flex-start;
  gap: 20px;
}

.home-main {
  flex: 1;
  min-width: 0;
}

.category-sidebar {
  flex-shrink: 0;
  width: 148px;
  position: sticky;
  top: max(16px, env(safe-area-inset-top));
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 10px;
}

.category-sidebar-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0 8px 8px;
  letter-spacing: 0.04em;
}

.category-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.category-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 0.88rem;
  cursor: pointer;
  text-align: left;
}

.category-item:hover {
  background: #ecfdf5;
}

.category-item.active {
  background: var(--accent);
  color: #fff;
}

.category-item.active .category-item-count {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.category-item-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.category-item-count {
  flex-shrink: 0;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 99px;
  background: #dcfce7;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.drawer-backdrop {
  display: none;
}

.drawer-toggle {
  display: none;
}

.top-nav-start {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.btn.icon {
  padding: 8px;
  min-width: 40px;
  min-height: 40px;
}

.btn.icon.secondary {
  background: #e2e8f0;
  color: var(--text);
}

@media (max-width: 640px) {
  .app-shell:has(.home-page) {
    max-width: 520px;
    padding: max(8px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(16px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .drawer-toggle {
    display: inline-flex;
    flex-shrink: 0;
  }

  .home-layout {
    display: block;
  }

  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 90;
    border: none;
    margin: 0;
    padding: 0;
    background: rgba(20, 83, 45, 0.4);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.22s ease, visibility 0.22s ease;
  }

  .home-page.drawer-open .drawer-backdrop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .category-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    width: min(272px, 82vw);
    margin: 0;
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: max(16px, env(safe-area-inset-top)) 12px
      max(16px, env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    transform: translateX(-105%);
    transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 24px rgba(20, 83, 45, 0.18);
  }

  .home-page.drawer-open .category-sidebar {
    transform: translateX(0);
  }

  .category-sidebar-title {
    font-size: 0.85rem;
    padding: 0 8px 10px;
  }

  .home-main .top-nav {
    margin-bottom: 8px;
  }

  .home-main .top-nav-title h1 {
    font-size: 1.15rem;
  }

  .home-main .top-nav-logo {
    width: 28px;
    height: 28px;
  }

  .home-main .sub {
    margin-bottom: 12px;
    font-size: 0.82rem;
  }

  .home-main .row-actions {
    gap: 6px;
    margin-bottom: 12px;
  }

  .home-main .row-actions .btn {
    padding: 8px 10px;
    font-size: 0.82rem;
  }

  .home-main .card {
    padding: 12px;
    margin-bottom: 10px;
  }

  .home-main .totp-code {
    font-size: 1.5rem;
    letter-spacing: 0.12em;
  }
}

h1 {
  margin: 0 0 8px;
  font-size: 1.5rem;
}

.sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 20px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.card-actions {
  display: flex;
  flex-shrink: 0;
  gap: 6px;
  align-self: flex-start;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.95rem;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}

.btn.secondary {
  background: #e2e8f0;
  color: var(--text);
}

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

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

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 6px;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  font-size: 1rem;
}

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

.totp-card {
  padding: 12px 14px;
}

.totp-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.totp-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.totp-card-label {
  font-weight: 600;
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.totp-card-issuer {
  font-size: 0.75rem;
  color: var(--muted);
  background: #ecfdf5;
  padding: 2px 8px;
  border-radius: 99px;
  flex-shrink: 0;
}

.icon-toolbar {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: #f1f5f9;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}

.icon-btn:hover {
  background: #e2e8f0;
}

.icon-btn.danger {
  background: #fee2e2;
  color: var(--danger);
}

.icon-btn.danger:hover {
  background: #fecaca;
}

.icon-btn.copied {
  background: #dcfce7;
  color: var(--accent);
}

.totp-code-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.totp-code-hit {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  border-radius: 8px;
}

.totp-code-hit:hover .totp-code {
  color: var(--accent);
}

.totp-code {
  font-family: ui-monospace, monospace;
  font-size: 1.85rem;
  letter-spacing: 0.16em;
  line-height: 1.2;
  color: var(--text);
  display: block;
}

.totp-card-foot {
  display: flex;
  align-items: center;
  gap: 10px;
}

.totp-card-foot .progress {
  flex: 1;
}

.totp-card-timer {
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 2.2em;
  text-align: right;
}

.progress {
  height: 5px;
  background: #dcfce7;
  border-radius: 99px;
  overflow: hidden;
}

.progress > i {
  display: block;
  height: 100%;
  background: var(--accent2);
  transition: width 0.2s linear;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 8px 0 0;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  text-align: center;
}

.brand-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  display: block;
}

.brand h1 {
  margin: 0;
}

.top-nav-logo {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex-shrink: 0;
}

.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.top-nav-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.segment {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.segment button {
  flex: 1;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  cursor: pointer;
}

.segment button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

video.scan {
  width: 100%;
  border-radius: var(--radius);
  background: #000;
  max-height: 260px;
}

.scan-wrap {
  position: relative;
  margin-bottom: 10px;
}

.share-page .app-shell,
.share-page {
  max-width: 520px;
}

