:root {
  --bg: #f0f2f5;
  --bg-card: #ffffff;
  --bg-header: rgba(255,255,255,0.85);
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
}

[data-theme="dark"] {
  --bg: #0f111a;
  --bg-card: #1a1d2e;
  --bg-header: rgba(15,17,26,0.9);
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #2a2d3e;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background .3s, color .3s;
}

.hidden { display: none !important; }

/* Login Screen */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f111a 0%, #1e1b4b 50%, #312e81 100%);
}

.login-card {
  text-align: center;
  padding: 3rem 2.5rem;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  backdrop-filter: blur(20px);
  color: #fff;
  max-width: 380px;
  width: 90%;
}

.login-logo {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 1.5rem;
}

.login-card h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: .5rem; }
.login-card p { color: rgba(255,255,255,0.6); font-size: .9rem; margin-bottom: 2rem; }

.btn-login {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .75rem 1.5rem;
  background: #6366f1;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: .95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
}

.btn-login:hover { background: #4f46e5; transform: translateY(-1px); }

.login-error {
  margin-top: 1rem;
  font-size: .8rem;
  color: #f87171;
  min-height: 1.2em;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.5rem;
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-left { display: flex; align-items: center; gap: 1rem; }
.header-right { display: flex; align-items: center; gap: .5rem; }

.brand { display: flex; align-items: center; gap: .75rem; }

.brand-logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.brand h1 { font-size: 1.1rem; font-weight: 700; line-height: 1.2; }
.subtitle { font-size: .75rem; color: var(--text-muted); }

.search-input {
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  font-size: .85rem;
  font-family: inherit;
  width: 180px;
  transition: all .2s;
}

.search-input:focus { outline: none; border-color: var(--accent); width: 240px; }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  transition: all .2s;
}

.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* User menu */
.user-menu { position: relative; }

.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
}

.dropdown {
  position: absolute;
  top: calc(100% + .5rem);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  padding: .5rem;
  z-index: 200;
}

.dropdown-label { display: block; padding: .5rem; font-size: .8rem; color: var(--text-muted); }
.dropdown hr { border: none; border-top: 1px solid var(--border); margin: .25rem 0; }

.dropdown a, .dropdown button {
  display: block;
  width: 100%;
  padding: .5rem;
  text-align: left;
  font-size: .85rem;
  color: var(--text);
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}

.dropdown a:hover, .dropdown button:hover { background: var(--bg); }

/* Tabs */
.tabs {
  display: flex;
  gap: .25rem;
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem 1.5rem 0;
}

.tab {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .65rem 1.25rem;
  background: none;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  color: var(--text-muted);
  font-size: .9rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all .2s;
  position: relative;
}

.tab:hover { color: var(--text); background: var(--bg-card); }

.tab.active {
  color: var(--accent);
  background: var(--bg-card);
  border-color: var(--border);
}

.tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
}

.tailscale-btn {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  margin-left: .5rem;
  padding: .25rem .6rem;
  background: #4c8bf5;
  color: #fff !important;
  border-radius: 5px;
  font-size: .7rem;
  font-weight: 500;
  text-decoration: none;
  transition: all .2s;
}

.tailscale-btn:hover { background: #3b7be0; }

/* Main Content */
.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  min-height: 60vh;
}

.tab-content { display: none; padding: 1.25rem 0; }
.tab-content.active { display: block; }

/* Category */
.category { margin-bottom: 1.5rem; }

.category-label {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--accent);
  margin-bottom: .6rem;
  padding-left: .25rem;
}

/* Service Grid */
.service-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: .6rem;
}

/* Service Card */
.service-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .4rem;
  padding: .85rem .6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: all .2s;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.service-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
}

.service-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
  opacity: 0;
  transition: opacity .2s;
}

.service-card:hover::before { opacity: 1; }

.service-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: contain;
  background: var(--bg-card);
  padding: 4px;
}

.service-icon-fallback {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}

.service-name { font-size: .78rem; font-weight: 500; text-align: center; line-height: 1.2; }
.service-desc { font-size: .65rem; color: var(--text-muted); text-align: center; }

/* Footer */
.footer {
  text-align: center;
  padding: 1.5rem;
  font-size: .75rem;
  color: var(--text-muted);
}

.footer a { color: var(--text-muted); text-decoration: none; }
.footer a:hover { color: var(--accent); }

/* Responsive */
@media (max-width: 768px) {
  .header { padding: .5rem .75rem; }
  .brand h1 { font-size: .95rem; }
  .subtitle { display: none; }
  .search-input { width: 120px; font-size: .8rem; }
  .search-input:focus { width: 160px; }
  .tabs { padding: .75rem .75rem 0; }
  .tab { padding: .5rem .75rem; font-size: .82rem; }
  .main { padding: 0 .75rem .75rem; }
  .service-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; }
  .service-card { padding: .7rem .5rem; }
  .service-icon, .service-icon-fallback { width: 34px; height: 34px; }
  .service-name { font-size: .73rem; }
}

@media (max-width: 480px) {
  .service-grid { grid-template-columns: repeat(3, 1fr); gap: .4rem; }
  .service-card { padding: .6rem .35rem; }
  .service-name { font-size: .7rem; }
  .service-desc { display: none; }
  .search-input { width: 100px; }
  .search-input:focus { width: 140px; }
  .tab { padding: .45rem .6rem; font-size: .78rem; }
  .tailscale-btn span { display: none; }
}

/* Search */
.service-card.match-hidden { display: none; }
.category.cat-hidden { display: none; }
