* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f4f6fa; color: #1f2937; font-size: 14px;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 220px;
  background: #fff; border-right: 1px solid #e5e7eb; padding: 1.25rem 0;
  display: flex; flex-direction: column;
}
.brand {
  display: flex; align-items: center; gap: 0.75rem; padding: 0 1.25rem 1.5rem;
  border-bottom: 1px solid #f1f5f9;
}
.brand-icon { font-size: 1.75rem; }
.brand-name { font-weight: 600; color: #1f2937; }
.brand-sub { font-size: 0.75rem; color: #94a3b8; }
.sidebar nav { padding: 1rem 0; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 1.25rem; color: #475569; font-weight: 500;
}
.nav-link:hover { background: #f8fafc; text-decoration: none; color: #2563eb; }
.logout-form { padding: 0 1.25rem 1rem; }
.btn-link { background: none; border: none; color: #64748b; cursor: pointer; padding: 0.5rem 0; }
.btn-link:hover { color: #ef4444; }

main { padding: 2rem; }
main.with-sidebar { margin-left: 220px; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.page-header h1, .page-header h2 { margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; margin-top: 2rem; margin-bottom: 1rem; }
h3 { font-size: 1rem; margin: 0 0 1rem; }

.muted { color: #94a3b8; }

.btn {
  display: inline-block; padding: 0.5rem 1rem; border-radius: 6px;
  background: #fff; border: 1px solid #d1d5db; color: #374151;
  font-size: 0.875rem; cursor: pointer; font-weight: 500; line-height: 1.2;
}
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn.primary { background: #2563eb; border-color: #2563eb; color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { background: #fff; border-color: #fecaca; color: #dc2626; }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 0.3rem 0.6rem; font-size: 0.75rem; }
.btn.block { width: 100%; }

.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem; margin-bottom: 2rem;
}
.stat-card {
  background: #fff; padding: 1.25rem; border-radius: 10px; border: 1px solid #eef2f7;
}
.stat-label { color: #64748b; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 2rem; font-weight: 600; margin-top: 0.25rem; }
.stat-value.success { color: #16a34a; }
.stat-value.warn { color: #ea580c; }
.stat-value.danger { color: #dc2626; }

.device-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}
.device-card {
  background: #fff; padding: 1.25rem; border-radius: 10px; border: 1px solid #eef2f7;
  color: inherit;
}
.device-card:hover { border-color: #c7d2fe; text-decoration: none; }
.device-card-head { display: flex; justify-content: space-between; margin-bottom: 0.5rem; }

.badge {
  display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px;
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
}
.badge.success { background: #dcfce7; color: #166534; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.danger { background: #fee2e2; color: #991b1b; }
.badge.muted { background: #f1f5f9; color: #64748b; }

.empty {
  background: #fff; padding: 2rem; border-radius: 10px;
  border: 1px dashed #cbd5e1; text-align: center; color: #64748b;
}

.card {
  background: #fff; padding: 1.5rem; border-radius: 10px;
  border: 1px solid #eef2f7; margin-bottom: 1rem;
}

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.two-col-template { display: grid; grid-template-columns: 1.5fr 1fr; gap: 1.5rem; align-items: start; }
@media (max-width: 900px) { .two-col-template { grid-template-columns: 1fr; } }

.form-card {
  background: #fff; padding: 1.5rem; border-radius: 10px;
  border: 1px solid #eef2f7; max-width: 700px;
}
.form-card label, .card label {
  display: block; margin: 1rem 0 0.4rem; font-weight: 500; color: #374151;
}
.form-card input, .form-card select, .form-card textarea,
.card input {
  width: 100%; padding: 0.55rem 0.75rem; border-radius: 6px;
  border: 1px solid #d1d5db; font-size: 0.875rem; font-family: inherit;
}
.form-card textarea { font-family: 'Menlo', monospace; resize: vertical; }
.form-card small { display: block; margin-top: 0.25rem; }

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

.copy-row { display: flex; gap: 0.5rem; }
.copy-row input { font-size: 0.75rem; font-family: 'Menlo', monospace; }

.checkbox-row { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.checkbox-row input { width: auto; }

.template-card .template-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.template-preview {
  background: #f8fafc; padding: 1rem; border-radius: 6px;
  white-space: pre-wrap; word-break: break-word; font-family: inherit;
  margin: 0; font-size: 0.875rem; max-height: 300px; overflow: auto;
}

.var-table { width: 100%; font-size: 0.8rem; }
.var-table th, .var-table td { padding: 0.4rem 0.5rem; text-align: left; border-bottom: 1px solid #f1f5f9; }
.var-table code { background: #f1f5f9; padding: 0.1rem 0.35rem; border-radius: 3px; font-size: 0.75rem; }

.data-table {
  width: 100%; background: #fff; border-radius: 10px; overflow: hidden;
  border: 1px solid #eef2f7; border-collapse: collapse;
}
.data-table th, .data-table td { padding: 0.6rem 0.85rem; text-align: left; border-bottom: 1px solid #f1f5f9; }
.data-table th { background: #f8fafc; font-weight: 600; font-size: 0.75rem; text-transform: uppercase; color: #64748b; }

.pagination { display: flex; gap: 0.75rem; align-items: center; margin-top: 1rem; }

.alert.error { background: #fef2f2; color: #991b1b; padding: 0.75rem; border-radius: 6px; margin-bottom: 1rem; }

.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #eff6ff 0%, #f5f3ff 100%);
}
.login-card {
  background: #fff; padding: 2.5rem; border-radius: 12px;
  width: 100%; max-width: 380px; box-shadow: 0 10px 40px rgba(0,0,0,0.08);
}
.login-card h1 { margin: 0; }
.login-card p.muted { margin-top: 0.25rem; margin-bottom: 1.5rem; }
.login-card label { display: block; margin: 0.75rem 0 0.35rem; font-weight: 500; }
.login-card input {
  width: 100%; padding: 0.6rem 0.75rem; border-radius: 6px;
  border: 1px solid #d1d5db; font-size: 0.9rem;
}
.login-card button { margin-top: 1.25rem; }
