:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #0ea5e9;
  --accent-hover: #0284c7;
  --danger: #ef4444;
  --success: #10b981;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans TC", sans-serif;
  background: radial-gradient(circle at top right, #0f172a, var(--bg) 60%);
  color: var(--text);
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Unlock Screen */
.unlock-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.unlock-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.brand-row h1 {
  margin: 0;
  font-size: 1.35rem;
}

.brand-row p {
  margin: 4px 0 0;
}

.brand-badge {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: rgba(14, 165, 233, 0.14);
  color: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field span {
  font-size: 0.82rem;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.94rem;
  outline: none;
  transition: border-color 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  color: var(--muted);
  cursor: pointer;
}

.checkbox-row input {
  width: auto;
}

.error-banner {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.5);
  color: #fecaca;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
}

.btn-primary,
.btn-ghost {
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-weight: 600;
  font-size: 0.94rem;
  cursor: pointer;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: #082f49;
}

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

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
}

/* Main App */
.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.sync-pill {
  font-size: 0.76rem;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.15);
  color: #6ee7b7;
}

.sync-pill.pending {
  background: rgba(245, 158, 11, 0.18);
  color: #fcd34d;
}

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

/* Pure Icon Buttons */
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.icon-btn:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.icon-btn.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #082f49;
}

.icon-btn.danger:hover {
  border-color: var(--danger);
  color: #fca5a5;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.search-box {
  flex: 1 1 260px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px;
}

.search-box input {
  border: none;
  background: transparent;
  padding: 10px 0;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.82rem;
  cursor: pointer;
}

.pill.active {
  background: rgba(14, 165, 233, 0.2);
  border-color: var(--accent);
  color: #bae6fd;
}

.toggle-archived {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.84rem;
  color: var(--muted);
  cursor: pointer;
}

.toggle-archived input {
  width: auto;
}

.stats-bar {
  font-size: 0.84rem;
  color: var(--muted);
  margin-bottom: 12px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}

.acc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.acc-card.archived {
  opacity: 0.68;
}

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

.card-title {
  margin: 0;
  font-size: 1.05rem;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.badge {
  font-size: 0.74rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

.card-actions {
  display: flex;
  gap: 6px;
}

.kv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg);
  border: 1px solid #1e293b;
  border-radius: 10px;
  padding: 8px 10px;
}

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

.kv-label {
  font-size: 0.72rem;
  color: var(--muted);
}

.kv-val {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kv-btns {
  display: flex;
  gap: 4px;
}

.notes-line {
  font-size: 0.84rem;
  color: #cbd5e1;
  line-height: 1.4;
}

/* Modal */
dialog.modal {
  border: none;
  background: transparent;
  padding: 16px;
  width: 100%;
  max-width: 620px;
  color: var(--text);
}

dialog.modal::backdrop {
  background: rgba(2, 6, 23, 0.75);
  backdrop-filter: blur(4px);
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.span-2 {
  grid-column: span 2;
}

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

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  z-index: 999;
}

.touch-tooltip {
  position: fixed;
  background: #020617;
  color: #f8fafc;
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 0.78rem;
  pointer-events: none;
  z-index: 1000;
}

@media (max-width: 600px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
  .span-2 {
    grid-column: span 1;
  }
}
