:root {
  /* Windows 11 다크 테마 톤(#202020 배경 / #2b2b2b 서피스) + 보라색 강조색 */
  color-scheme: dark;
  --bg: #202020;
  --surface: #2b2b2b;
  --surface-raised: #323232;
  --border: #3f3f3f;
  --text: #f3f3f3;
  --text-muted: #a0a0a0;
  --primary: #8b5cf6;
  --primary-dark: #7c3aed;
  --danger: #f87171;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Malgun Gothic", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- 로그인 ---------- */
#view-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 20px;
  padding-right: 20px;
}
.login-box {
  width: 100%;
  max-width: 360px;
}
.app-title {
  text-align: center;
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 24px;
}
.app-title-small {
  font-weight: 700;
  color: var(--primary);
  font-size: 17px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-muted);
}
.field input,
.field select {
  font-size: 16px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
.field input:read-only,
.field input[readonly] {
  background: var(--bg);
  color: var(--text-muted);
  border-color: transparent;
}

/* 수정 모드일 때 입력칸 테두리/배경을 다르게 줘서 "지금 수정 중"임을 눈으로 바로 알 수 있게 한다. */
#detail-form.editing input:not(:read-only) {
  background: var(--surface-raised);
  border-color: var(--primary);
}

.checkbox-row {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.checkbox-row label { display: flex; align-items: center; gap: 6px; }

.field-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.btn-primary {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary {
  width: 100%;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}
.btn-link {
  display: block;
  width: 100%;
  margin-top: 10px;
  background: none;
  border: none;
  color: var(--primary);
  font-size: 14px;
  padding: 8px;
  cursor: pointer;
}
.error-text { color: var(--danger); font-size: 13px; margin: 4px 0 12px; }
.empty-text { color: var(--text-muted); text-align: center; padding: 32px 0; }

/* ---------- 모달 공통 ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  background: var(--surface);
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  max-height: 85dvh;
  overflow-y: auto;
  border-radius: var(--radius);
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
}
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }
.modal-actions .btn-primary, .modal-actions .btn-secondary { flex: 1; }

.input-with-action { display: flex; align-items: center; gap: 8px; }
.input-with-action input { flex: 1; min-width: 0; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--primary);
  text-decoration: none;
}
.icon-btn:active { background: var(--primary); color: #fff; }

/* ---------- 메인 셸 ---------- */
.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-title-small { flex-shrink: 0; }
#user-name-label {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.logout-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  padding: 6px 4px;
  cursor: pointer;
  white-space: nowrap;
}
.logout-btn:active { color: var(--primary); }

.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 45px;
  z-index: 9;
}
.tab-btn {
  flex: 1;
  padding: 12px 8px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.tabview { padding: 16px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

/* ---------- 검색 ---------- */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.search-input-wrap { position: relative; flex: 1; }
.search-input-wrap input {
  width: 100%;
  font-size: 16px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.search-bar .btn-primary { width: auto; padding: 11px 18px; }

.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  list-style: none;
  margin: 0;
  padding: 4px;
  max-height: 260px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.suggestions li {
  padding: 10px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.suggestions li:active, .suggestions li:hover { background: var(--surface-raised); }
.suggestions li small { display: block; color: var(--text-muted); font-size: 12px; margin-top: 2px; }

/* ---------- 카드 리스트 ---------- */
.card-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.customer-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
}
.customer-card:active { background: var(--surface-raised); }
.customer-card .row1 { display: flex; justify-content: space-between; font-weight: 600; font-size: 15px; }
.customer-card .row1 .dept { color: var(--text-muted); font-weight: 400; font-size: 13px; }
.customer-card .row2 { margin-top: 6px; color: var(--text-muted); font-size: 13px; }

/* ---------- 사용자 관리 테이블 ---------- */
.list-toolbar { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 12px; }
.btn-small {
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--primary);
  color: var(--primary);
  background: none;
  cursor: pointer;
}
.btn-small:active { background: var(--primary); color: #fff; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; }
td select { font-size: 13px; padding: 4px; }
tbody tr { cursor: pointer; }
tbody tr:active { background: var(--surface-raised); }
tbody tr.selected { background: color-mix(in srgb, var(--primary) 18%, var(--surface)); }

/* ---------- 토스트 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--primary-dark);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
}

[hidden] { display: none !important; }
