/* ── 변수 ───────────────────────────────────────────── */
:root {
  --blue: #0071e3;
  --blue-hover: #0077ed;
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --sidebar-bg: #1d1d1f;
  --sidebar-width: 220px;
  --surface: #ffffff;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ── 로그인 ─────────────────────────────────────────── */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1d1d1f 0%, #2d2d30 100%);
}

.login-box {
  background: var(--surface);
  padding: 48px 40px;
  border-radius: 20px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.login-logo { margin-bottom: 16px; }

.login-box h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--gray-500);
  font-size: 14px;
  margin-bottom: 32px;
}

.form-group {
  margin-bottom: 16px;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--blue);
}

.error-msg {
  color: var(--red);
  font-size: 13px;
  margin-top: 12px;
}

/* ── 버튼 ───────────────────────────────────────────── */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
}
.btn-primary:hover { background: var(--blue-hover); }

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
}
.btn-secondary:hover { background: var(--gray-200); }

.btn-danger {
  background: var(--red);
  color: #fff;
}
.btn-danger:hover { opacity: .9; }

.btn-connect {
  background: var(--green);
  color: #fff;
  padding: 6px 12px;
  font-size: 12px;
}
.btn-connect:hover { opacity: .9; }

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-full { width: 100%; }

.btn-icon {
  background: none;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { background: var(--gray-100); }

/* ── 관리자 레이아웃 ────────────────────────────────── */
.admin-layout {
  display: flex;
  min-height: 100vh;
}

/* ── 사이드바 ───────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  font-size: 15px;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.nav-list {
  list-style: none;
  padding: 12px 8px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  color: rgba(255,255,255,.7);
  text-decoration: none;
  border-radius: 8px;
  font-size: 14px;
  transition: all .2s;
  margin-bottom: 2px;
}

.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.12); color: #fff; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.btn-logout {
  width: 100%;
  padding: 8px;
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.7);
  border: none;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all .2s;
}
.btn-logout:hover { background: rgba(255,255,255,.15); color: #fff; }

/* ── 메인 콘텐츠 ───────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 24px 32px;
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.content-header h2 {
  font-size: 22px;
  font-weight: 700;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* ── 통계 카드 ──────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--blue);
}

.stat-label {
  font-size: 13px;
  color: var(--gray-500);
  margin-top: 4px;
}

/* ── 검색 바 ────────────────────────────────────────── */
.search-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.search-bar input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}
.search-bar input:focus { border-color: var(--blue); }

.search-bar select {
  padding: 10px 14px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  min-width: 160px;
}

/* ── 그룹 섹션 (대시보드) ──────────────────────────── */
.group-section {
  margin-bottom: 32px;
}

.group-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.group-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
}

.group-device-count {
  font-size: 13px;
  color: var(--gray-500);
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.device-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s;
  border-left: 4px solid var(--blue);
}

.device-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.device-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.device-card-name {
  font-size: 15px;
  font-weight: 600;
}

.device-card-id {
  font-size: 13px;
  color: var(--gray-500);
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

.device-card-meta {
  font-size: 12px;
  color: var(--gray-400);
  margin-top: 4px;
}

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

/* ── 테이블 (장비관리) ──────────────────────────────── */
.page-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
}

.toolbar-left {
  display: flex;
  gap: 12px;
  flex: 1;
}

.toolbar-left input {
  flex: 1;
  max-width: 300px;
  padding: 10px 14px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}
.toolbar-left input:focus { border-color: var(--blue); }

.toolbar-left select {
  padding: 10px 14px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  min-width: 160px;
}

.data-table {
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

.data-table td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--gray-50); }

.table-group-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
}

.table-actions {
  display: flex;
  gap: 4px;
}

.mono {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 13px;
}

.text-muted { color: var(--gray-400); font-size: 13px; }
.text-center { text-align: center; }

.empty-state {
  text-align: center;
  padding: 48px;
  color: var(--gray-400);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.empty-state svg { margin-bottom: 12px; opacity: .5; }

/* ── 설정 ───────────────────────────────────────────── */
.settings-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.settings-section h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-100);
}

.group-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}

.group-form input[type="text"] {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}
.group-form input[type="text"]:focus { border-color: var(--blue); }

.group-form input[type="color"] {
  width: 40px;
  height: 40px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  cursor: pointer;
  padding: 2px;
}

.group-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-100);
}

.group-list-item:last-child { border-bottom: none; }

.group-list-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.group-color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.group-list-name {
  font-weight: 600;
  font-size: 14px;
}

.group-list-desc {
  font-size: 12px;
  color: var(--gray-400);
}

.group-list-actions {
  display: flex;
  gap: 4px;
}

.info-grid {
  display: grid;
  gap: 12px;
}

.info-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--gray-100);
}

.info-item:last-child { border-bottom: none; }

.info-label {
  font-size: 13px;
  color: var(--gray-500);
}

.info-value {
  font-size: 14px;
  font-weight: 500;
}

.info-value.mono {
  font-size: 11px;
  word-break: break-all;
  text-align: right;
  max-width: 60%;
}

/* ── 모달 ───────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--gray-100);
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--gray-400);
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--gray-700); }

.modal-body { padding: 24px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--gray-100);
}

/* ── 반응형 ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    width: 60px;
  }
  .sidebar-header span,
  .nav-item span:not(svg) { display: none; }
  .sidebar-header { justify-content: center; padding: 20px 8px; }
  .nav-item { justify-content: center; padding: 10px; }
  .main-content { margin-left: 60px; padding: 16px; }
  .stats-row { grid-template-columns: 1fr; }
  .device-grid { grid-template-columns: 1fr; }
  .search-bar { flex-direction: column; }
  .page-toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-left { flex-direction: column; }
  .group-form { flex-wrap: wrap; }
}
