/* 모바일 우선 설계: 주 사용 기기가 스마트폰(아이폰/갤럭시 폴드)이고
   노트북에서도 쓰이므로, 기본 스타일은 좁은 화면 기준으로 작성하고
   넓은 화면에서 여백만 넓혀줍니다. 시스템 다크모드도 자동으로 따라갑니다. */

:root {
  --color-bg: #f4f5f8;
  --color-surface: #ffffff;
  --color-surface-raised: #ffffff;
  --color-text: #14161c;
  --color-muted: #6b7280;
  --color-faint: #9aa1af;
  --color-primary: #3457e8;
  --color-primary-dark: #2540bf;
  --color-primary-tint: #eaefff;
  --color-border: #e6e8ee;
  --color-danger: #dc2626;
  --color-danger-tint: #fef2f2;
  --color-success-tint: #ecfdf5;
  --color-success-text: #065f46;
  --shadow-sm: 0 1px 2px rgba(20, 22, 28, 0.04), 0 1px 1px rgba(20, 22, 28, 0.03);
  --shadow-md: 0 8px 24px rgba(20, 22, 28, 0.08), 0 2px 6px rgba(20, 22, 28, 0.04);
  --shadow-fab: 0 10px 24px rgba(52, 87, 232, 0.35);
  --radius: 16px;
  --radius-sm: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #101217;
    --color-surface: #1a1d24;
    --color-surface-raised: #20242c;
    --color-text: #eef0f4;
    --color-muted: #9aa1af;
    --color-faint: #6b7280;
    --color-primary: #6d87ff;
    --color-primary-dark: #8ba0ff;
    --color-primary-tint: #232a4d;
    --color-border: #2b2f3a;
    --color-danger: #f87171;
    --color-danger-tint: #3a1f22;
    --color-success-tint: #10241d;
    --color-success-text: #6ee7b7;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
    --shadow-fab: 0 10px 24px rgba(109, 135, 255, 0.35);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(32px + var(--safe-bottom));
}

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px;
}

header.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--color-surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--color-border);
  padding: calc(12px + var(--safe-top)) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--color-text);
  text-decoration: none;
  letter-spacing: -0.01em;
}

header.topbar .brand .logo-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--color-primary);
  flex: none;
}

header.topbar nav {
  display: flex;
  align-items: center;
  gap: 14px;
}

header.topbar nav .whoami {
  color: var(--color-muted);
  font-size: 0.82rem;
}

header.topbar nav a {
  color: var(--color-muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
}
header.topbar nav a:hover {
  color: var(--color-text);
}

.logout-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--color-muted);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  min-height: auto;
}
.logout-btn:hover {
  color: var(--color-text);
}

main {
  padding: 18px 0 40px;
}

h1 {
  letter-spacing: -0.015em;
}

.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  margin-bottom: 12px;
}

/* ---------------- 고객 목록 ---------------- */

.list-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.list-header h1 {
  font-size: 1.35rem;
  margin: 0;
}

.result-count {
  color: var(--color-muted);
  font-size: 0.85rem;
}

a.customer-item {
  display: block;
  text-decoration: none;
  color: inherit;
}

.customer-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
  margin-bottom: 10px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

a.customer-item:active .customer-card {
  transform: scale(0.98);
}

@media (hover: hover) {
  a.customer-item:hover .customer-card {
    box-shadow: var(--shadow-md);
    border-color: color-mix(in srgb, var(--color-primary) 35%, var(--color-border));
  }
}

.avatar {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--color-primary-tint);
  color: var(--color-primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.05rem;
}

.customer-card-body {
  min-width: 0;
  flex: 1;
}

.customer-name {
  font-size: 1.02rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.customer-phone {
  color: var(--color-muted);
  font-size: 0.87rem;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}

.chevron {
  flex: none;
  color: var(--color-faint);
}

/* ---------------- 버튼 ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.98rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  text-decoration: none;
  min-height: 46px;
  transition: transform 0.08s ease, opacity 0.12s ease, background 0.12s ease;
  font-family: inherit;
}

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

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:active {
  background: var(--color-primary-dark);
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-danger {
  background: var(--color-danger-tint);
  color: var(--color-danger);
  border: 1px solid transparent;
}

.btn-icon {
  width: 20px;
  height: 20px;
  flex: none;
}

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(24px + var(--safe-bottom));
  z-index: 20;
  box-shadow: var(--shadow-fab);
  padding: 14px 20px;
}

/* ---------------- 폼 ---------------- */

form .field {
  margin-bottom: 18px;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.88rem;
  color: var(--color-text);
}

input,
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

input::placeholder,
textarea::placeholder {
  color: var(--color-faint);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 18%, transparent);
}

textarea {
  resize: vertical;
}

input[type="checkbox"] {
  width: 20px;
  height: 20px;
  padding: 0;
  vertical-align: middle;
  margin-right: 8px;
  accent-color: var(--color-primary);
}

/* ---------------- 검색창 ---------------- */

.search-bar {
  position: relative;
  margin-bottom: 18px;
}

.search-bar .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-faint);
  pointer-events: none;
}

.search-bar input {
  width: 100%;
  padding-left: 42px;
  padding-right: 14px;
}

.search-spinner {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.search-spinner.is-active {
  opacity: 1;
}

@keyframes spin {
  to {
    transform: translateY(-50%) rotate(360deg);
  }
}

/* ---------------- 고객 상세 / 이력 타임라인 ---------------- */

.detail-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 4px;
}

.detail-header .avatar {
  width: 56px;
  height: 56px;
  font-size: 1.3rem;
}

.detail-header h1 {
  font-size: 1.3rem;
  margin: 0;
}

.meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--color-muted);
  font-size: 0.9rem;
}

.info-block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--color-border);
}

.info-block label {
  color: var(--color-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.action-row {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}
.action-row form {
  flex: 1;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 24px 0 12px;
  color: var(--color-text);
}

.timeline {
  position: relative;
  padding-left: 4px;
}

.history-item {
  position: relative;
  padding-left: 20px;
  padding-bottom: 20px;
  border-left: 2px solid var(--color-border);
  margin-left: 6px;
}

.history-item:last-child {
  border-left-color: transparent;
  padding-bottom: 0;
}

.history-item::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 2px solid var(--color-surface);
}

.history-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: 12px 14px;
}

.history-date {
  font-size: 0.82rem;
  color: var(--color-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-content {
  white-space: pre-wrap;
  margin: 8px 0 6px;
  line-height: 1.55;
}

.history-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--color-faint);
}

.history-footer a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 600;
}

.history-type {
  display: inline-flex;
  align-items: center;
  background: var(--color-primary-tint);
  color: var(--color-primary-dark);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.72rem;
  font-weight: 700;
}

/* ---------------- 메시지 / 빈 상태 ---------------- */

.messages {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
}

.messages li {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--color-success-tint);
  color: var(--color-success-text);
  margin-bottom: 8px;
  font-size: 0.9rem;
  font-weight: 500;
}

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

.empty-state .empty-icon {
  color: var(--color-faint);
  margin-bottom: 12px;
}

.empty-state p {
  margin: 0;
  line-height: 1.6;
}

.helptext {
  color: var(--color-muted);
  font-size: 0.8rem;
  margin-top: 4px;
}

.errorlist {
  color: var(--color-danger);
  font-size: 0.85rem;
  padding-left: 0;
  list-style: none;
  margin: 4px 0;
}

/* 노트북 등 넓은 화면 */
@media (min-width: 768px) {
  body {
    font-size: 15px;
  }
  .container {
    padding: 0 24px;
  }
}
