/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Pretendard GOV', 'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  height: 100%;
  display: flex;
  flex-direction: column;
  transition: background 0.3s, color 0.3s;
  overflow-x: hidden; /* 모바일 수평 스크롤 방지 */
}

/* Black Han Sans: 페이지 타이틀 전용 */
.title-font {
  font-family: 'Black Han Sans', sans-serif;
}

a {
  text-decoration: none;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  font-size: inherit;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

/* ===== Header ===== */
#app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--header-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 5px 10px;
  border-radius: 10px;
  transition: background 0.2s;
  flex-shrink: 1;
  min-width: 0;
  max-width: 55vw;
}

.header-brand:hover {
  background: var(--hover);
}

.header-back-arrow {
  font-size: 1.1rem;
  color: var(--primary);
  flex-shrink: 0;
  align-items: center;
}

.header-title {
  font-family: 'Black Han Sans', sans-serif;
  font-size: 1.3rem;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: transparent;
  border: none;
  padding: 0;
  line-height: 1.2;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  position: relative;
  z-index: 2;
}

.header-selects {
  display: flex;
  gap: 6px;
}

.header-select {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-bg);
  color: var(--text);
  padding: 6px 10px;
  font-size: 0.8rem;
  font-weight: 600;
}

.theme-picker-wrap,
.backup-picker-wrap {
  position: relative;
}

.theme-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.2);
  display: inline-block;
}

.theme-menu,
.backup-menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 18px var(--shadow);
  padding: 8px;
  z-index: 180;
  display: none;
}

.theme-menu.open,
.backup-menu-dropdown.open {
  display: flex;
}

.theme-menu {
  gap: 8px;
}

.theme-color-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.15);
}

.chip-blue { background: #A8D8EA; }
.chip-green { background: #B5E8C3; }
.chip-pink { background: #F4B6C2; }
.chip-yellow { background: #FDE68A; }

.backup-menu-dropdown {
  min-width: 180px;
  flex-direction: column;
  gap: 6px;
}

.dropdown-item {
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
}

.dropdown-item:hover {
  background: var(--hover);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  transition: background 0.2s;
  color: var(--text);
}

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

/* ===== Main Content ===== */
#app-content {
  flex: 1;
  padding: 40px 24px 100px;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* ===== Dashboard ===== */
.dashboard-header {
  text-align: center;
  margin-bottom: 36px;
  padding-top: 16px;
}

.dashboard-header h1 {
  font-family: 'Black Han Sans', sans-serif; /* 대시보드 메인 타이틀 */
  font-size: 2rem;
  color: var(--primary);
  margin-bottom: 8px;
}

.dashboard-header p {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  align-content: start;
}

.module-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 24px 20px;
  text-align: center;
  cursor: pointer;
  width: 100%;
  transition: transform 0.2s, box-shadow 0.2s;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.module-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px var(--shadow);
}

button.module-card {
  appearance: none;
}

.module-card .material-icons {
  font-size: 48px;
  color: var(--primary);
  margin-bottom: 12px;
  display: block;
}

.module-card h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.module-card p {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.card-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--primary);
  color: white;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  min-width: 20px;
  text-align: center;
  line-height: 1.4;
}

/* ===== Module Page ===== */
.module-page {
  animation: fadeIn 0.3s ease;
}

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

.module-title {
  font-family: 'Black Han Sans', sans-serif; /* 모듈 페이지 타이틀 */
  font-size: 1.6rem;
  color: var(--primary);
  margin-bottom: 20px;
  text-align: center;
}

.work-area {
  background: var(--card-bg);
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 24px;
  min-height: 400px;
  position: relative;
}

/* ===== FAB ===== */
#fab-container {
  position: fixed;
  bottom: 60px;
  right: 20px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.fab-main {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px var(--shadow);
  transition: transform 0.3s, background 0.3s;
}

.fab-main:hover {
  transform: scale(1.1);
}

.fab-main.open {
  transform: rotate(45deg);
  background: var(--text-secondary);
}

.fab-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
}

.fab-menu.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.fab-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--card-bg);
  border-radius: 28px;
  box-shadow: 0 2px 8px var(--shadow);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  transition: transform 0.2s;
  border: 1px solid var(--border);
}

.fab-item:hover {
  transform: scale(1.05);
}

.fab-item .material-icons {
  font-size: 20px;
  color: var(--primary);
}

/* ===== Footer ===== */
#app-footer {
  text-align: center;
  padding: 16px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  background: var(--header-bg);
}

#app-footer a {
  color: var(--text-secondary);
  transition: color 0.2s;
}

#app-footer a:hover {
  color: var(--primary);
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s;
}

.modal-content {
  background: var(--card-bg);
  border-radius: 16px;
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

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

.modal-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
}

.modal-body {
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text);
}

.modal-body h3 {
  font-weight: 700;
  color: var(--primary);
  margin: 16px 0 8px;
  font-size: 1.05rem;
}

.modal-body ul {
  padding-left: 20px;
  margin-bottom: 12px;
}

.modal-body li {
  margin-bottom: 4px;
}

.backup-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ===== Form Elements ===== */
.form-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.form-input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus {
  border-color: var(--primary);
}

.btn {
  padding: 10px 20px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  transition: transform 0.2s, opacity 0.2s;
}

.btn:active {
  transform: scale(0.97);
}

button:focus-visible,
.icon-btn:focus-visible,
.module-card:focus-visible,
.chip:focus-visible,
.toggle-switch:focus-visible,
.form-input:focus-visible,
.header-select:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  opacity: 0.9;
}

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

.btn-danger {
  background: #f87171;
  color: white;
}

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

/* ===== List Items ===== */
.list-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  transition: transform 0.2s;
}

.list-item:hover {
  transform: translateX(4px);
}

.list-item-content {
  flex: 1;
  min-width: 0;
}

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

.list-item-actions .icon-btn {
  width: 32px;
  height: 32px;
}

.list-item-actions .material-icons {
  font-size: 18px;
}

/* ===== Toast Notification ===== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 300;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Chip / Tag ===== */
.chip {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  user-select: none;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
}

button.chip {
  appearance: none;
}

.chip:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 8px var(--shadow);
}

.chip.selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ===== Toggle Switch ===== */
.toggle-container {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.toggle-switch {
  position: relative;
  width: 48px;
  height: 26px;
  background: var(--border);
  border-radius: 13px;
  cursor: pointer;
  transition: background 0.3s;
  border: none;
  padding: 0;
}

.toggle-switch.active {
  background: var(--primary);
}

.toggle-switch::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: white;
  top: 2px;
  left: 2px;
  transition: transform 0.3s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch.active::after {
  transform: translateX(22px);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ===== Responsive ===== */

/* 중간 화면 (태블릿) */
@media (max-width: 768px) {
  #app-content {
    padding: 28px 16px 90px;
  }

  .module-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
  }
}

/* 모바일 */
@media (max-width: 600px) {
  /* 헤더 */
  #app-header {
    padding: 8px 10px;
    gap: 6px;
  }

  .header-brand {
    max-width: 48vw;
  }

  .header-title {
    font-size: 0.95rem;
  }

  .header-selects {
    flex-direction: column;
    gap: 4px;
  }

  .header-select {
    padding: 4px 8px;
    font-size: 0.72rem;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
  }

  /* 컨텐츠 */
  #app-content {
    padding: 20px 12px 90px;
  }

  /* 대시보드 */
  .dashboard-header {
    margin-bottom: 24px;
    padding-top: 8px;
  }

  .dashboard-header h1 {
    font-size: 1.5rem;
  }

  .dashboard-header p {
    font-size: 0.85rem;
  }

  .module-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .module-card {
    padding: 16px 10px;
  }

  .module-card .material-icons {
    font-size: 36px;
    margin-bottom: 8px;
  }

  .module-card h3 {
    font-size: 0.95rem;
  }

  .module-card p {
    font-size: 0.75rem;
  }

  /* 모듈 페이지 */
  .module-title {
    font-size: 1.3rem;
    margin-bottom: 14px;
  }

  .work-area {
    padding: 14px;
    min-height: 300px;
  }

  /* 폼 */
  .form-row {
    flex-direction: column;
  }

  .form-input {
    font-size: 16px; /* iOS 자동 줌 방지 */
  }

  /* FAB */
  #fab-container {
    bottom: 50px;
    right: 14px;
  }

  .fab-main {
    width: 50px;
    height: 50px;
  }

  .fab-item {
    padding: 7px 12px;
    font-size: 0.8rem;
  }

  /* 토글 */
  .toggle-container {
    justify-content: center;
  }
}

/* 매우 작은 화면 */
@media (max-width: 380px) {
  .header-right {
    gap: 4px;
  }

  .header-select {
    padding: 4px 6px;
  }

  .module-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
}
