:root {
  --background: oklch(98.5% 0.006 85);
  --foreground: oklch(22% 0.02 240);
  --card: oklch(99.5% 0.004 85);
  --primary: oklch(32% 0.05 215);
  --primary-foreground: oklch(98% 0.005 85);
  --secondary: oklch(94% 0.012 85);
  --muted: oklch(94% 0.012 85);
  --muted-foreground: oklch(48% 0.02 240);
  --accent: oklch(86% 0.045 75);
  --border: oklch(90% 0.01 85);
  --danger: oklch(55% 0.18 25);
  --success: oklch(45% 0.12 155);
  --warning: oklch(65% 0.14 75);
  --shadow: 0 18px 50px -28px oklch(22% 0.02 240 / 0.35);
  --radius: 1rem;
  --radius-lg: 1.25rem;
  --font: "Inter", system-ui, sans-serif;
  --font-serif: "Fraunces", Georgia, serif;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  color: var(--foreground);
  background: var(--background);
  min-height: 100dvh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ——— Auth ——— */
.auth-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse 70% 50% at 0% 0%, oklch(86% 0.045 75 / 0.45), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 0%, oklch(32% 0.05 215 / 0.08), transparent 50%),
    var(--background);
}

.auth-card {
  width: min(100%, 420px);
  padding: 2rem;
  border-radius: var(--radius-lg);
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.auth-brand img {
  width: 40px;
  height: 40px;
  border-radius: 0.65rem;
}

.auth-brand h1 {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--primary);
}

.auth-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 1.5rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--secondary);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted-foreground);
}

.subtitle { color: var(--muted-foreground); font-size: 0.92rem; margin-bottom: 1.5rem; }

form label { display: block; text-align: left; margin-bottom: 1rem; }
form label span {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted-foreground);
  margin-bottom: 0.35rem;
}

input, select {
  width: 100%;
  padding: 0.72rem 0.85rem;
  border-radius: 0.65rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--foreground);
  font: inherit;
}

input:focus, select:focus {
  outline: 2px solid oklch(32% 0.05 215 / 0.25);
  border-color: var(--primary);
}

.search-input {
  max-width: 280px;
}

/* ——— Buttons ——— */
.btn-primary, .btn-secondary, .btn-ghost, .btn-danger, .btn-icon, .btn-sm {
  font: inherit;
  cursor: pointer;
  border-radius: 999px;
  border: none;
  transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  text-decoration: none;
}

.btn-primary {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.82rem 1.25rem;
  background: var(--primary);
  color: var(--primary-foreground);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.btn-primary:hover { transform: translateY(-1px); }

.btn-secondary {
  padding: 0.5rem 1rem;
  background: var(--secondary);
  color: var(--primary);
  border: 1px solid var(--border);
  font-weight: 500;
  font-size: 0.85rem;
}

.btn-ghost {
  padding: 0.5rem 0.95rem;
  background: transparent;
  color: var(--muted-foreground);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.btn-ghost:hover { background: var(--secondary); color: var(--foreground); }

.btn-danger {
  padding: 0.5rem 1rem;
  background: oklch(55% 0.18 25 / 0.1);
  color: var(--danger);
  border: 1px solid oklch(55% 0.18 25 / 0.25);
  font-size: 0.85rem;
}

.btn-icon, .btn-sm {
  padding: 0.42rem 0.75rem;
  background: var(--card);
  color: var(--foreground);
  border: 1px solid var(--border);
  font-size: 0.78rem;
}

.btn-sm { border-radius: 0.55rem; }

.btn-icon:hover, .btn-sm:hover { background: var(--secondary); }

.error { color: var(--danger); font-size: 0.85rem; margin: 0.5rem 0; }

/* ——— App shell ——— */
.app-shell { min-height: 100dvh; display: flex; flex-direction: column; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid oklch(90% 0.01 85 / 0.6);
  background: oklch(98.5% 0.006 85 / 0.82);
  backdrop-filter: blur(10px);
}

.site-header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: inherit;
}

.brand-link img { width: 36px; height: 36px; border-radius: 0.55rem; }

.brand-link .brand-name {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--primary);
}

.brand-link .brand-tag {
  display: none;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted-foreground);
}

@media (min-width: 640px) {
  .brand-link .brand-tag { display: inline; }
}

.header-actions { display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; }

.app-body {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem;
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 900px) {
  .app-body {
    grid-template-columns: 220px 1fr;
    align-items: start;
  }
}

/* ——— Sidebar ——— */
.sidebar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.75rem;
  box-shadow: var(--shadow);
}

.sidebar-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted-foreground);
  padding: 0.35rem 0.65rem 0.5rem;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.65rem 0.75rem;
  border: none;
  background: transparent;
  border-radius: 0.65rem;
  font: inherit;
  font-size: 0.88rem;
  color: var(--muted-foreground);
  cursor: pointer;
  text-align: left;
}

.nav-item svg { width: 1rem; height: 1rem; flex-shrink: 0; }

.nav-item:hover { background: var(--secondary); color: var(--foreground); }

.nav-item.active {
  background: var(--accent);
  color: var(--primary);
  font-weight: 500;
}

/* ——— Main ——— */
.main-content { min-width: 0; }

.view { display: none; animation: fadeIn 0.25s ease; }
.view.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.page-head {
  margin-bottom: 1.25rem;
}

.page-head h2 {
  font-family: var(--font-serif);
  font-size: clamp(1.35rem, 3vw, 1.75rem);
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 0.25rem;
}

.page-head p { color: var(--muted-foreground); font-size: 0.92rem; }

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

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.stat {
  padding: 1.1rem;
  border-radius: var(--radius-lg);
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.stat span {
  display: block;
  font-family: var(--font-serif);
  font-size: 1.65rem;
  font-weight: 600;
  color: var(--primary);
  line-height: 1.1;
}

.stat label {
  font-size: 0.72rem;
  color: var(--muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.panel h3 { font-size: 0.95rem; font-weight: 600; color: var(--primary); }

.panel-actions { display: flex; gap: 0.45rem; flex-wrap: wrap; align-items: center; }

.grid-2 {
  display: grid;
  gap: 1rem;
}

@media (min-width: 768px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
}

/* ——— Devices ——— */
.devices { display: grid; gap: 0.75rem; }

.device {
  display: grid;
  gap: 0.85rem;
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  background: var(--background);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.device:hover {
  border-color: oklch(32% 0.05 215 / 0.25);
  box-shadow: var(--shadow);
}

@media (min-width: 720px) {
  .device { grid-template-columns: 1fr auto; align-items: center; }
}

.device-head { display: flex; align-items: flex-start; gap: 0.75rem; }

.device-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.75rem;
  background: var(--accent);
  color: var(--primary);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.device-icon svg { width: 1.15rem; height: 1.15rem; }

.device h4 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.15rem; }

.device-meta { font-size: 0.78rem; color: var(--muted-foreground); line-height: 1.5; }

.device-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.badge-online { background: oklch(45% 0.12 155 / 0.12); color: var(--success); }
.badge-recent { background: oklch(65% 0.14 75 / 0.15); color: var(--warning); }
.badge-offline { background: var(--secondary); color: var(--muted-foreground); }

.empty {
  text-align: center;
  padding: 2rem 1rem;
}

/* ——— Detail drawer ——— */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: oklch(22% 0.02 240 / 0.35);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(100%, 420px);
  height: 100dvh;
  background: var(--card);
  border-left: 1px solid var(--border);
  z-index: 51;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  box-shadow: -20px 0 60px -30px oklch(22% 0.02 240 / 0.3);
}

.drawer.open { transform: none; }

.drawer-head {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.drawer-head h3 {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  color: var(--primary);
}

.drawer-body {
  flex: 1;
  overflow: auto;
  padding: 1.25rem;
}

.detail-grid {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.detail-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.detail-row dt { color: var(--muted-foreground); }
.detail-row dd { word-break: break-all; }

.drawer-actions {
  display: grid;
  gap: 0.45rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

/* ——— Activity log ——— */
.log-list { display: grid; gap: 0.55rem; }

.log-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.65rem;
  align-items: start;
  padding: 0.75rem;
  border-radius: 0.65rem;
  background: var(--background);
  border: 1px solid var(--border);
  font-size: 0.82rem;
}

.log-type {
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
}

.log-meta { color: var(--muted-foreground); font-size: 0.75rem; }

.log-status-queued { color: var(--success); }
.log-status-error { color: var(--danger); }

/* ——— System cards ——— */
.service-card {
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--background);
}

.service-card h4 {
  font-size: 0.88rem;
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.service-card p { font-size: 0.8rem; color: var(--muted-foreground); }

.copy-row {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  margin-top: 0.65rem;
}

.copy-row input {
  flex: 1;
  font-size: 0.78rem;
  padding: 0.55rem 0.65rem;
}

.profile-card {
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--background);
}

.profile-card + .profile-card { margin-top: 0.65rem; }

.profile-card strong { display: block; font-size: 0.88rem; margin-bottom: 0.25rem; }

.profile-card p { font-size: 0.8rem; color: var(--muted-foreground); margin-bottom: 0.65rem; }

/* ——— Dialog ——— */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.35rem;
  background: var(--card);
  color: var(--foreground);
  max-width: 420px;
  box-shadow: var(--shadow);
}

dialog::backdrop { background: oklch(22% 0.02 240 / 0.4); }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 60;
  padding: 0.75rem 1rem;
  border-radius: 0.65rem;
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: none; }
