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

:root {
  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface-hover: #f9f9f8;
  --border: rgba(0,0,0,.09);
  --border-strong: rgba(0,0,0,.16);
  --text: #1a1a18;
  --text-2: #5a5a56;
  --text-3: #9a9a94;
  --accent: #1a6ef5;
  --accent-bg: #eff5ff;
  --danger: #d63a3a;
  --radius: 10px;
  --sidebar-w: 220px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --surface: #1c1c1a;
    --surface-hover: #242422;
    --border: rgba(255,255,255,.08);
    --border-strong: rgba(255,255,255,.14);
    --text: #e8e8e4;
    --text-2: #9a9a94;
    --text-3: #5a5a56;
    --accent: #4d8ef7;
    --accent-bg: #0f1f3d;
  }
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 15px; }

/* Layout */
.layout { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow-y: auto;
}

.logo {
  padding: 1.25rem 1.25rem 1rem;
  display: flex;
  align-items: baseline;
  gap: 6px;
  border-bottom: 0.5px solid var(--border);
  margin-bottom: .5rem;
}

.logo-mark {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.5px;
  color: var(--accent);
}
.logo-sub {
  font-size: 13px;
  color: var(--text-3);
  font-weight: 500;
}

nav { flex: 1; padding: 0 .5rem; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: .45rem .75rem;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.active { background: var(--accent-bg); color: var(--accent); font-weight: 500; }
.nav-item i { font-size: 16px; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  font-size: 11px;
  background: var(--border);
  color: var(--text-3);
  padding: 1px 6px;
  border-radius: 99px;
  min-width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: .75rem .5rem;
  border-top: 0.5px solid var(--border);
}

/* Main content */
.content { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 1rem 1.5rem;
  border-bottom: 0.5px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 400px;
}
.search-wrap i {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  font-size: 16px;
  pointer-events: none;
}
#search {
  width: 100%;
  padding: 7px 36px 7px 34px;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
#search:focus { border-color: var(--accent); }
#search-kbd {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--text-3);
  background: var(--border);
  padding: 1px 5px;
  border-radius: 4px;
  pointer-events: none;
}

.section { padding: 1.5rem; }
.section-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 1rem;
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
}

.card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  padding: .9rem 1rem;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  text-decoration: none;
  transition: border-color .13s, background .13s;
  position: relative;
}
.card:hover { border-color: var(--border-strong); background: var(--surface-hover); }

.card-edit {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  cursor: pointer;
  transition: opacity .13s, background .13s;
}
.card:hover .card-edit { opacity: 1; }
.card-edit:hover { background: var(--border); color: var(--text); }

.favicon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: var(--bg);
  border: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.favicon img { width: 22px; height: 22px; object-fit: contain; }
.favicon .fallback { font-size: 13px; font-weight: 600; color: var(--text-2); }

.card-info { min-width: 0; flex: 1; }
.card-name { font-size: 13px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-host { font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 4rem 0;
  color: var(--text-3);
}
.empty i { font-size: 32px; }
.empty p { font-size: 14px; }

/* Buttons */
.btn-primary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .13s;
  white-space: nowrap;
}
.btn-primary:hover { opacity: .88; }

.btn-ghost {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: none;
  color: var(--text-2);
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: background .13s, color .13s;
  white-space: nowrap;
}
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }

.btn-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--text-2);
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  transition: background .13s;
}
.btn-icon:hover { background: var(--border); }

/* Modal */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border: 0.5px solid var(--border-strong);
  border-radius: 14px;
  width: 100%;
  max-width: 420px;
  margin: 1rem;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.25rem .9rem;
  border-bottom: 0.5px solid var(--border);
}
.modal-header h2 { font-size: 15px; font-weight: 600; }

.modal-body {
  padding: 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .9rem;
}

.modal-body label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.modal-body input {
  padding: 8px 10px;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .13s;
}
.modal-body input:focus { border-color: var(--accent); }

.modal-footer {
  display: flex;
  align-items: center;
  padding: .9rem 1.25rem 1.1rem;
  border-top: 0.5px solid var(--border);
}

.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}
.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform .13s, border-color .13s;
  flex-shrink: 0;
}
.swatch:hover { transform: scale(1.15); }
.swatch.selected { border-color: var(--text); transform: scale(1.15); }
.card-accent {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  border-radius: 12px 0 0 12px;
}

@media (max-width: 640px) {
  .sidebar { display: none; }
  .section { padding: 1rem; }
  .grid { grid-template-columns: 1fr 1fr; }
}
