/* 공통 — 색 · 글꼴 · 머리 메뉴 · 버튼 · 대화창. 화면별 모양은 static/<기능>/<화면>.css (규칙 9) */
:root {
  --color-background: #f6f7f4;
  --color-surface: #ffffff;
  --color-text: #1c2420;
  --color-muted: #66706a;
  --color-line: #dfe3dc;
  --color-accent: #2f6b4f;
  --color-accent-text: #ffffff;
  --color-online: #3c5fa8;
  --color-online-soft: #e6ecf8;
  --color-male: #dcebf7;
  --color-female: #f8e3ef;
  --color-danger: #b4432f;
  --radius: 10px;
  --gutter: max(16px, env(safe-area-inset-left, 0px));
  --font: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-background: #141916;
    --color-surface: #1d2420;
    --color-text: #e7ece8;
    --color-muted: #9aa59e;
    --color-line: #2f3833;
    --color-accent: #6fbf96;
    --color-accent-text: #0f1a14;
    --color-online: #8fb0f0;
    --color-online-soft: #22304a;
    --color-male: #1f3140;
    --color-female: #3a2232;
    --color-danger: #e58a76;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--color-background);
  color: var(--color-text);
  font: 15px/1.5 var(--font);
}

.page {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 var(--gutter) 48px;
}

/* ── 머리 메뉴 ── */
.app-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-line);
}

.app-header-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 10px var(--gutter);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}

.app-title {
  font-weight: 700;
  color: var(--color-text);
  text-decoration: none;
}

.app-menu {
  display: flex;
  gap: 4px;
  flex: 1;
}

.app-menu a {
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--color-muted);
  text-decoration: none;
  white-space: nowrap;
}

.app-logout { margin-left: 0; }

/* 접속자 — 동그라미 첫 글자 + 이름 (폰은 동그라미만) */
.app-me {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding: 2px 8px 2px 2px;
  border: 1px solid var(--color-line);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.app-me-avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--color-accent);
  color: var(--color-accent-text);
  font-size: 13px;
  font-weight: 700;
}

.app-header-inner:not(:has(.app-me)) .app-logout { margin-left: auto; }

@media (max-width: 720px) {
  .app-me { padding: 2px; }
  .app-me-name { display: none; }
}

/* 폰: 위는 [제목 · 부서 · 로그아웃] 한 줄, 메뉴는 화면 맨 아래 탭 (같은 너비로 나눠 스크롤 없음) */
@media (max-width: 720px) {
  .app-menu {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    gap: 0;
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid var(--color-line);
    background: var(--color-surface);
  }
  .app-menu a {
    flex: 1;
    min-width: 0;
    padding: 14px 1px 12px;
    border-top: 2px solid transparent;
    border-radius: 0;
    font-size: 12px;
    letter-spacing: -0.02em;
    text-align: center;
  }
  .app-menu a[aria-current="page"] {
    border-top-color: var(--color-text);
    background: none;
  }
  /* 아래 탭에 내용이 가려지지 않게 */
  body { padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
  body .ui-toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
}

/* 아이폰은 16px 보다 작은 입력칸을 누르면 화면을 확대한다 */
@media (max-width: 900px) {
  input, select, textarea { font-size: 16px; }
}

.app-menu a[aria-current="page"] {
  background: var(--color-background);
  color: var(--color-text);
  font-weight: 600;
}

.app-link-button {
  border: 0;
  background: none;
  color: var(--color-muted);
  font: inherit;
  cursor: pointer;
}

/* ── 공용 요소 ── */
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 24px 0 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--color-muted);
}

.empty-state {
  padding: 16px;
  text-align: center;
  color: var(--color-muted);
}

input, select, button { font: inherit; color: inherit; }

input, select {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--color-line);
  border-radius: 8px;
  background: var(--color-surface);
}

:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

.button-primary {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--color-accent);
  color: var(--color-accent-text);
  font-weight: 600;
  cursor: pointer;
}

.button-ghost {
  display: inline-block;
  border: 1px solid var(--color-line);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--color-surface);
  color: var(--color-text);
  text-decoration: none;
  cursor: pointer;
}

.button-small { padding: 2px 10px; font-size: 13px; }

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--color-line);
  border-radius: 8px;
  background: var(--color-background);
  cursor: pointer;
}

.icon-button:disabled { opacity: .4; cursor: default; }

/* ── 알림 (uiToast) · 대화창 (uiAlert) — 브라우저 alert 대신 (규칙 21) ── */
.ui-toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--color-text);
  color: var(--color-background);
  z-index: 30;
}

.ui-dialog {
  max-width: min(360px, calc(100vw - 32px));
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
}

.ui-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* 줄바꿈(
)을 그대로 보여 준다 — 중복 명단 같은 여러 줄 안내 */
.ui-dialog-text {
  margin: 0 0 8px;
  max-height: 50vh;
  overflow-y: auto;
  white-space: pre-line;
}

.ui-dialog-field {
  display: grid;
  gap: 2px;
  width: min(320px, calc(100vw - 64px));
  margin-bottom: 8px;
  color: var(--color-muted);
  font-size: 12px;
}

/* 비고 창은 넓게 */
.ui-dialog:has(.ui-dialog-textarea) { max-width: min(600px, calc(100vw - 32px)); }

.ui-dialog-textarea {
  width: min(560px, calc(100vw - 64px));
  min-height: 12em;
  padding: 8px 10px;
  border: 1px solid var(--color-line);
  border-radius: 8px;
  background: var(--color-surface);
  font: inherit;
  resize: vertical;
}

/* 표가 넓은 화면(명단 관리 · 계정)은 폭을 넓게 */
.page-wide { max-width: 1080px; }

.app-department {
  padding: 4px 8px;
  font-weight: 600;
}

/* 휴지통 버튼 (명단 · 계정). 아이콘만이라 aria-label 을 꼭 붙인다 */
.roster-delete {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--color-danger);
  cursor: pointer;
}

.roster-delete:hover { border-color: var(--color-danger); }

/* 비밀번호 칸 + [보기] 버튼 (common.js addPasswordToggle) */
.password-wrap {
  position: relative;
  display: block;
  min-width: 0;
}

.password-wrap > input {
  width: 100%;
  padding-right: 44px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 4px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  transform: translateY(-50%);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--color-muted);
  cursor: pointer;
}

.password-toggle:hover,
.password-toggle[aria-pressed="true"] { color: var(--color-accent); background: var(--color-background); }

/* 명단에서 사람 고르기 창 (common.js uiPickMembers) */
.ui-pick-search { width: min(320px, calc(100vw - 64px)); margin-bottom: 8px; }

.ui-pick-list {
  display: grid;
  gap: 4px;
  width: min(320px, calc(100vw - 64px));
  max-height: 50vh;
  overflow-y: auto;
}

.ui-pick-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--color-line);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.ui-pick-row[hidden] { display: none; }
.ui-pick-male { background: var(--color-male); }
.ui-pick-female { background: var(--color-female); }

/* 상태 색 — 출석자 초록 · 장기결석자 빨강 · 방문자 파랑 (명단 고르기 칸 · 요약 배지) */
.status-attending { color: #1f7a4d; font-weight: 600; }
.status-long-absent { color: #b4432f; font-weight: 600; }
.status-visitor { color: #2f5fb3; font-weight: 600; }

.status-badge {
  display: inline-block;
  margin-right: 6px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.6;
}

.status-badge.status-attending { background: #dff3e8; }
.status-badge.status-long-absent { background: #fbe3dd; }
.status-badge.status-visitor { background: #e1eafa; }

@media (prefers-color-scheme: dark) {
  .status-attending { color: #7fd3a5; }
  .status-long-absent { color: #f0a08f; }
  .status-visitor { color: #9dbcf0; }
  .status-badge.status-attending { background: #1d3a2b; }
  .status-badge.status-long-absent { background: #43231c; }
  .status-badge.status-visitor { background: #1f2c45; }
}

/* 여러 명 고르기 — 아래 '추가될 사람' 목록 */
.ui-pick-chosen {
  width: min(320px, calc(100vw - 64px));
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--color-line);
}

.ui-pick-chosen-title { margin: 0 0 6px; font-size: 13px; font-weight: 700; }

.ui-pick-chosen-list {
  display: grid;
  gap: 4px;
  max-height: 25vh;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.ui-pick-chip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 4px 0 10px;
  border: 1px solid var(--color-accent);
  border-radius: 8px;
  background: var(--color-surface);
  font-size: 14px;
  font-weight: 600;
}

.ui-pick-chip button {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--color-muted);
  font-size: 18px;
  cursor: pointer;
}

.ui-pick-chosen-empty { color: var(--color-muted); font-size: 13px; }

/* 날짜 칸 — 아이패드 · 아이폰(사파리)은 날짜 칸을 글자 칸처럼 그리고 높이 · 정렬이 달라진다.
   모양을 직접 맞추고, 사파리에는 달력 아이콘을 그려 날짜 칸인 걸 알게 한다 (누르면 사파리 날짜 고르기가 뜬다) */
input[type="date"] {
  min-height: 38px;
  min-width: 0;
  line-height: 1.4;
  text-align: left;
}

input[type="date"]::-webkit-date-and-time-value { min-height: 1.4em; text-align: left; }

@supports (-webkit-touch-callout: none) {
  input[type="date"] {
    -webkit-appearance: none;
    appearance: none;
    display: block;
    width: 100%;
    padding-right: 34px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round'%3E%3Crect x='3' y='5' width='18' height='16' rx='2'/%3E%3Cpath d='M3 10h18M8 3v4M16 3v4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 18px;
  }
}
