:root {
  --bg-primary: #f8fafc;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --border: #e2e8f0;
  --danger: #ef4444;
  --success: #10b981;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Malgun Gothic', sans-serif;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

.app-container {
  display: flex;
  height: 100vh;
}

/* 사이드바 및 트리 메뉴 */
.sidebar {
  width: 340px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

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

.logo {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
}

.search-box {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.search-box input {
  width: 100%;
  border: none;
  outline: none;
  font-size: 0.9rem;
  background: transparent;
}

.tree-menu {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
}

/* 트리 구조 노드 스타일 */
.tree-category {
  margin-bottom: 8px;
}

.category-header {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
  color: var(--text-main);
}

.category-header:hover {
  background-color: #f1f5f9;
}

.category-header .arrow {
  margin-right: 8px;
  font-size: 0.75rem;
  transition: transform 0.2s;
}

.category-header.expanded .arrow {
  transform: rotate(90deg);
}

.tree-children {
  margin-left: 20px;
  border-left: 2px solid #e2e8f0;
  padding-left: 6px;
  display: none;
}

.tree-children.show {
  display: block;
}

/* 루틴 아이템 스타일 & 호버 효과 */
.routine-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  margin: 2px 0;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
}

.routine-item:hover {
  background-color: #eff6ff;
  color: var(--primary);
  transform: translateX(3px);
}

.routine-item .item-title {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.type-badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
}

.type-badge.python { background: #e0f2fe; color: #0284c7; }
.type-badge.ahk { background: #dcfce7; color: #16a34a; }
.type-badge.url { background: #f3e8ff; color: #9333ea; }
.type-badge.cmd { background: #f1f5f9; color: #475569; }

.item-actions {
  display: none;
  gap: 4px;
}

.routine-item:hover .item-actions {
  display: flex;
}

/* 하단 푸터 */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}
.status-dot.online { background-color: var(--success); }

/* 메인 대시보드 영역 */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}

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

.subtitle {
  color: var(--text-muted);
  margin-top: 6px;
  font-size: 0.95rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--bg-card);
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}
.bg-blue { background: #eff6ff; color: #3b82f6; }
.bg-green { background: #f0fdf4; color: #22c55e; }
.bg-purple { background: #faf5ff; color: #a855f7; }

.stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: block;
}

.stat-val {
  font-size: 1.15rem;
  font-weight: 700;
}

.log-card {
  min-height: 250px;
}

.logs-container {
  margin-top: 12px;
  background: #0f172a;
  color: #38bdf8;
  padding: 16px;
  border-radius: 8px;
  font-family: 'Consolas', monospace;
  font-size: 0.85rem;
  height: 220px;
  overflow-y: auto;
}

.log-entry {
  margin-bottom: 6px;
  line-height: 1.4;
}

/* 플로팅 호버 툴팁 */
.floating-tooltip {
  position: fixed;
  background-color: #1e293b;
  color: #ffffff;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.85rem;
  max-width: 280px;
  line-height: 1.4;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  z-index: 9999;
  transition: opacity 0.15s ease;
}

.floating-tooltip.hidden {
  opacity: 0;
  visibility: hidden;
}

/* 모달 스타일 */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.hidden {
  display: none;
}

.modal-box {
  background: white;
  width: 450px;
  border-radius: 12px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

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

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

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-main);
}

.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  font-size: 0.9rem;
}

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

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
}

.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #e2e8f0; color: #475569; }
.btn-danger { background: var(--danger); color: white; }

.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1rem;
  padding: 6px;
  border-radius: 4px;
}
.icon-btn:hover { background: #f1f5f9; color: var(--text-main); }


/* ------------------------------------------------------------------
   클라우드 모드 (이 PC 의 허브가 없는 주소): 로컬 전용 조작은 숨긴다. app.js initMode 가 body 에 cloud-mode 를 붙인다.
   루틴 편집·삭제·순서 변경·가져오기/내보내기·즉시 실행은 허브가 있어야 하므로 PC 의 앱/로컬 웹에서만 한다.
   ------------------------------------------------------------------ */
body.cloud-mode [onclick^="exportRoutinesData("],
body.cloud-mode [onclick^="triggerImportFile("],
body.cloud-mode [onclick^="openCategoryManageModal("],
body.cloud-mode [onclick^="openRoutineModal("],
body.cloud-mode [onclick^="openEditRoutineModal("],
body.cloud-mode [onclick^="deleteRoutine("],
body.cloud-mode [onclick^="moveRoutineOrder("],
body.cloud-mode [onclick^="executeRoutineDirectly("] {
  display: none !important;
}

/* ---- 어두운 테마에 맞춘 기본 요소 (docs/12 E6) ---- */
/* 스크롤바·select 목록 같은 브라우저 기본 요소를 어두운 색으로 (밝은 스크롤바가 튀지 않게) */
html.dark { color-scheme: dark; }

/* 폰에서 입력칸 글자가 16px 보다 작으면 iOS 가 입력할 때 화면을 자동 확대한다 → 폰 폭에서는 16px.
   (예전엔 확대 자체를 막았지만, 확대를 막으면 시력이 약한 사용자가 못 쓰므로 viewport 의 확대 금지를 없앴다) */
@media (max-width: 767px) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]),
  select,
  textarea {
    font-size: 16px !important;
  }
}
