:root {
  color-scheme: dark;
  --bg: #101012;
  --surface: #1a1a1d;
  --surface-2: #202024;
  --border: #2b2b30;
  --text: #e9e9ec;
  --text-dim: #9a9aa2;
  --accent: #d9d9de;
  --accent-text: #101012;
  --danger: #d97070;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: 120px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 12px;
  background: rgba(16, 16, 18, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

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

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}
.sync-dot.online { background: #7fbf8a; }
.sync-dot.offline { background: var(--danger); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:active { background: var(--surface); }
.icon-btn.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.search-wrap {
  position: relative;
  margin: 14px 16px 6px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  height: 42px;
  padding: 0 14px 0 36px;
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.search-wrap input::placeholder { color: var(--text-dim); }
.search-wrap input:focus { border-color: #3c3c44; }

.search-wrap input::-webkit-search-cancel-button { -webkit-appearance: none; }

.notice {
  margin: 10px 16px 0;
  padding: 8px 12px;
  font-size: 13.5px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.list {
  margin-top: 8px;
}

.row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 0 16px;
  min-height: 60px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 17px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}
.row:first-child { border-top: 1px solid var(--border); }
.row:active { background: var(--surface); }

.row-avatar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-dim);
}

.row-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
  letter-spacing: -0.1px;
}

.row-chev {
  flex: none;
  color: var(--text-dim);
}

.row-delete {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
}
.row-delete:active { background: var(--surface); }

.empty {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-dim);
}
.empty-title { margin: 0 0 6px; font-size: 17px; color: var(--text); }
.empty-sub { margin: 0; font-size: 14.5px; }

.fab {
  position: fixed;
  right: max(18px, calc(50% - 320px + 18px));
  bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 20;
}
.fab:active { transform: scale(0.96); }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet[hidden] { display: none; }

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

.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 640px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  padding: 22px 20px calc(env(safe-area-inset-bottom, 0px) + 22px);
  animation: sheet-up 0.18s ease-out;
}

@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-panel h2 {
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.sheet-sub {
  margin: -8px 0 16px;
  font-size: 14.5px;
  color: var(--text-dim);
}

.sheet-panel input {
  width: 100%;
  height: 48px;
  margin-bottom: 10px;
  padding: 0 14px;
  font-size: 17px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.sheet-panel input::placeholder { color: var(--text-dim); }
.sheet-panel input:focus { border-color: #3c3c44; }

.sheet-error {
  margin: -2px 0 10px;
  font-size: 14px;
  color: var(--danger);
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.btn {
  flex: 1;
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 16.5px;
  font-weight: 500;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
}
.btn-ghost {
  background: transparent;
  color: var(--text);
}
.btn-ghost:active { background: var(--surface-2); }
.btn-solid {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}
.btn-solid:active { opacity: 0.85; }
.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(217, 112, 112, 0.4);
}
.btn-danger:active { background: rgba(217, 112, 112, 0.12); }

@media (min-width: 641px) {
  .sheet { align-items: center; }
  .sheet-panel {
    border-radius: 18px;
    border: 1px solid var(--border);
    margin: 20px;
    padding-bottom: 22px;
  }
}
