/* =====================================================================
   오란다 판매관리 - 공통 스타일
   ===================================================================== */
:root {
  --brand:        #8a5a2b;
  --brand-dark:   #6d4520;
  --brand-light:  #f5ece2;
  --accent:       #c8873d;
  --bg:           #f6f5f3;
  --card:         #ffffff;
  --text:         #2b2521;
  --text-sub:     #6f6660;
  --line:         #e5e0da;
  --ok:           #2e7d4f;
  --warn:         #b7791f;
  --danger:       #c0392b;
  --info:         #2a6fb0;
  --radius:       12px;
  --shadow:       0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --safe-top:     env(safe-area-inset-top, 0px);
  --safe-bottom:  env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard",
               "Malgun Gothic", "맑은 고딕", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: 15px; }

/* ---------- 로그인 ---------- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  background: linear-gradient(160deg, #8a5a2b 0%, #c8873d 100%);
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--card); border-radius: 16px; padding: 32px 24px;
  box-shadow: 0 10px 40px rgba(0,0,0,.2);
  text-align: center;
}
.login-logo { font-size: 44px; line-height: 1; }
.login-card h1 { margin: 12px 0 2px; font-size: 20px; }
.login-sub { margin: 0 0 20px; color: var(--text-sub); font-size: 13px; }
.login-foot { margin: 16px 0 0; color: #b5aea8; font-size: 12px; }

/* ---------- 앱 레이아웃 ---------- */
.app-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--brand); color: #fff;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 1px 6px rgba(0,0,0,.15);
}
.app-header h1 { margin: 0; font-size: 16px; font-weight: 600; flex: 1; }
.app-header .header-user { font-size: 12px; opacity: .85; }
.app-header .icon-btn {
  background: rgba(255,255,255,.15); border: 0; color: #fff;
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 15px;
}

/* 상단 메뉴 — 위: 그룹, 아래: 그 그룹의 탭. 둘 다 가로 스크롤 */
.app-nav {
  position: sticky; top: calc(52px + var(--safe-top)); z-index: 40;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.nav-groups, .nav-tabs {
  display: flex; gap: 2px; overflow-x: auto; padding: 0 6px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.nav-groups::-webkit-scrollbar, .nav-tabs::-webkit-scrollbar { display: none; }

.nav-groups {
  background: var(--brand); padding: 5px 6px; gap: 4px;
}
.nav-groups button {
  flex: 0 0 auto; border: 0; cursor: pointer; font-family: inherit;
  padding: 7px 16px; font-size: 14px; font-weight: 600; white-space: nowrap;
  border-radius: 8px; background: transparent; color: rgba(255,255,255,.72);
}
.nav-groups button:hover { background: rgba(255,255,255,.14); color: #fff; }
.nav-groups button.active { background: var(--card); color: var(--brand); font-weight: 700; }

.nav-tabs { border-top: 0; }
.nav-tabs button {
  flex: 0 0 auto; border: 0; background: none; cursor: pointer; font-family: inherit;
  padding: 11px 14px; font-size: 14px; color: var(--text-sub);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.nav-tabs button:hover { color: var(--brand); }
.nav-tabs button.active { color: var(--brand); font-weight: 700; border-bottom-color: var(--brand); }

.app-main { padding: 14px 14px calc(28px + var(--safe-bottom)); max-width: 1200px; margin: 0 auto; }

/* ---------- 카드 / 섹션 ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card-head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: -2px 0 12px;
}
.card-head h2 { margin: 0; font-size: 15px; flex: 1; }
.card-head .spacer { flex: 1; }

.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px; margin-bottom: 14px;
}
.stat {
  background: var(--card); border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow);
}
.stat .label { font-size: 12px; color: var(--text-sub); margin-bottom: 6px; }
.stat .value { font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.stat .value.sm { font-size: 17px; }
.stat.accent { background: var(--brand-light); }

/* ---------- 툴바 ---------- */
.toolbar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px;
}
.toolbar .grow { flex: 1 1 180px; min-width: 140px; }

/* ---------- 폼 ---------- */
.field { display: block; text-align: left; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; color: var(--text-sub); margin-bottom: 4px; }
.field > span .req { color: var(--danger); }

input[type=text], input[type=password], input[type=number], input[type=date],
input[type=email], input[type=tel], input[type=search], select, textarea {
  width: 100%; padding: 10px 11px; border: 1px solid var(--line);
  border-radius: 9px; background: #fff; color: var(--text); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(200,135,61,.15); }
input[readonly] { background: #f3f1ee; color: var(--text-sub); }
textarea { min-height: 72px; resize: vertical; }
select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path d='M1 1l5 5 5-5' fill='none' stroke='%236f6660' stroke-width='2'/></svg>");
  background-repeat: no-repeat; background-position: right 11px center; padding-right: 30px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 12px; }
.form-grid .full { grid-column: 1 / -1; }

.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 14px; }
.check input { width: 17px; height: 17px; accent-color: var(--brand); }

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  padding: 9px 15px; border: 1px solid var(--line); border-radius: 9px;
  background: #fff; color: var(--text); cursor: pointer; font-size: 14px;
  white-space: nowrap; transition: .12s;
}
.btn:hover { background: #f6f3ef; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger  { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: #fdeeec; }
.btn-ghost   { border-color: transparent; background: transparent; color: var(--text-sub); }
.btn-sm      { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn-block   { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 테이블 ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 560px; }
table.grid th, table.grid td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; }
table.grid th {
  background: #faf8f6; color: var(--text-sub); font-weight: 600; font-size: 12px;
  white-space: nowrap; position: sticky; top: 0;
}
table.grid tbody tr:hover { background: #fbf8f4; }
table.grid tbody tr.clickable { cursor: pointer; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid td.ctr, table.grid th.ctr { text-align: center; }
table.grid .muted { color: var(--text-sub); font-size: 12px; }

.empty { padding: 36px 12px; text-align: center; color: var(--text-sub); font-size: 14px; }

/* ---------- 배지 ---------- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
  background: #eee; color: #555;
}
.badge.b-ok      { background: #e4f3ea; color: var(--ok); }
.badge.b-warn    { background: #fdf1dc; color: var(--warn); }
.badge.b-danger  { background: #fbe6e3; color: var(--danger); }
.badge.b-info    { background: #e4eefa; color: var(--info); }
.badge.b-brand   { background: var(--brand-light); color: var(--brand); }
.badge.b-mute    { background: #eeebe7; color: var(--text-sub); }

/* ---------- 알림 ---------- */
.alert { padding: 10px 12px; border-radius: 9px; font-size: 13px; margin-bottom: 12px; text-align: left; }
.alert-error { background: #fbe6e3; color: var(--danger); }
.alert-info  { background: #e4eefa; color: var(--info); }
.alert-warn  { background: #fdf1dc; color: var(--warn); }

#toast {
  position: fixed; left: 50%; bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: rgba(35,28,23,.94); color: #fff; padding: 11px 18px;
  border-radius: 24px; font-size: 14px; z-index: 300;
  opacity: 0; pointer-events: none; transition: .25s; max-width: 88vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 모달 ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(30,24,20,.45);
  display: none; align-items: center; justify-content: center;
  z-index: 200; padding: 16px;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--card); border-radius: 16px; width: 100%; max-width: 560px;
  max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 16px 50px rgba(0,0,0,.28);
}
.modal.wide { max-width: 780px; }
.modal-head {
  padding: 15px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px;
}
.modal-head h3 { margin: 0; font-size: 16px; flex: 1; }
.modal-body { padding: 16px 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-foot {
  padding: 12px 18px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
}
.modal-foot .left { margin-right: auto; }

/* ---------- 로딩 ---------- */
.loading { padding: 32px; text-align: center; color: var(--text-sub); font-size: 14px; }
.spinner {
  width: 22px; height: 22px; border: 2px solid var(--line); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 유틸 ---------- */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.muted { color: var(--text-sub); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.text-ok { color: var(--ok); } .text-danger { color: var(--danger); } .text-warn { color: var(--warn); }

/* ---------- 달력 (배달) ---------- */
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
}
.cal-head { margin-bottom: 4px; }
.cal-dow {
  text-align: center; font-size: 12px; font-weight: 600; color: var(--text-sub);
  padding: 4px 0;
}
.cal-dow.sun { color: var(--danger); }
.cal-dow.sat { color: var(--info); }

.cal-cell {
  min-height: 92px; border: 1px solid var(--line); border-radius: 9px;
  padding: 5px 6px; background: #fff; position: relative;
  display: flex; flex-direction: column; gap: 3px;
}
.cal-cell.empty { border: 0; background: transparent; }
.cal-cell.has { cursor: pointer; }
.cal-cell.has:hover { background: #fbf8f4; border-color: var(--accent); }
.cal-cell.today { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(138,90,43,.18); }

.cal-day { font-size: 13px; font-weight: 700; color: var(--text); }
.cal-cell.sun .cal-day { color: var(--danger); }
.cal-cell.sat .cal-day { color: var(--info); }
.cal-cell.today .cal-day { color: var(--brand); }

.cal-body { display: flex; flex-direction: column; gap: 3px; }
.cal-cnt { font-size: 12px; font-weight: 700; color: var(--brand); }
.cal-dots { display: flex; flex-wrap: wrap; gap: 2px; }
.cal-dots .badge { font-size: 10px; padding: 1px 5px; }
.cal-amt { font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  .cal-grid { gap: 2px; }
  .cal-cell { min-height: 68px; padding: 3px 4px; border-radius: 7px; }
  .cal-day { font-size: 11px; }
  .cal-cnt { font-size: 11px; }
  .cal-dots .badge { font-size: 9px; padding: 0 3px; }
  .cal-amt { font-size: 10px; }
}

/* ---------- 인쇄 (배달표) ---------- */
@media print {
  .app-header, .app-nav, .nav-groups, .nav-tabs, .modal-head button, .modal-foot,
  #toast, .no-print, .toolbar { display: none !important; }
  body, .modal-backdrop { background: #fff !important; }
  .app-main { padding: 0; max-width: 100%; }

  /* 모달이 열려 있으면 모달만, 아니면 본문만 인쇄 */
  body.modal-open .app-main { display: none !important; }
  body:not(.modal-open) .modal-backdrop { display: none !important; }

  .modal-backdrop.show {
    position: static; display: block !important; padding: 0; background: #fff;
  }
  .modal { max-width: 100%; max-height: none; box-shadow: none; border-radius: 0; }
  .modal-body { overflow: visible; max-height: none; padding: 0; }

  .card {
    break-inside: avoid; page-break-inside: avoid;
    box-shadow: none; border: 1px solid #ddd; margin-bottom: 10px;
  }
  .table-wrap { overflow: visible !important; }
  table.grid { min-width: 0 !important; font-size: 11px; }
  table.grid th { background: #f2f2f2 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .stat { border: 1px solid #ddd; box-shadow: none; }
  .stat-grid { grid-template-columns: repeat(4, 1fr) !important; }
  .badge { border: 1px solid #999; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { margin: 12mm; }
}

/* ---------- 모바일 ---------- */
@media (max-width: 640px) {
  body { font-size: 14px; }
  .nav-groups button { padding: 7px 13px; font-size: 13.5px; }
  .nav-tabs button { padding: 10px 12px; font-size: 13.5px; }
  .app-main { padding: 12px 10px calc(24px + var(--safe-bottom)); }
  .card { padding: 13px; border-radius: 10px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat .value { font-size: 17px; }
  .modal { max-height: 94vh; border-radius: 14px; }
  table.grid { font-size: 13px; }
  table.grid th, table.grid td { padding: 8px 7px; }
  .toolbar .grow { flex: 1 1 100%; }
  /* iOS 입력 시 확대 방지 */
  input, select, textarea { font-size: 16px; }
}

/* ---------- 서브 탭 (낱개/박스, 환경설정 내부 메뉴) ---------- */
.seg-tabs {
  display: flex; flex-wrap: wrap; gap: 6px;
  background: #fff; border: 1px solid var(--line);
  border-radius: 11px; padding: 5px;
}
.seg-tabs .seg {
  flex: 0 0 auto; padding: 8px 14px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text-mute, #7a6f65);
  font-size: 14px; font-weight: 600; cursor: pointer;
  font-family: inherit; white-space: nowrap;
}
.seg-tabs .seg:hover { background: var(--brand-light); }
.seg-tabs .seg.active { background: var(--brand, #8a5a2b); color: #fff; }

.settings-sub { margin-top: 14px; }
.perm-grid td.perm-cell { text-align: center; }
.perm-grid input[type=checkbox] { width: 18px; height: 18px; }
.perm-grid tr.grp td {
  background: var(--brand-light); font-weight: 700; font-size: 13px;
}

@media (max-width: 640px) {
  .seg-tabs { overflow-x: auto; flex-wrap: nowrap; }
  .seg-tabs .seg { padding: 8px 11px; font-size: 13px; }
}

/* ---------- 숫자 링크 (건수 클릭 → 상세 이동) ---------- */
a.link-num {
  color: var(--brand, #8a5a2b); font-weight: 700;
  text-decoration: none; border-bottom: 1px dashed currentColor;
}
a.link-num:hover { color: var(--accent, #c8873d); }

/* ---------- 모달: 배경을 눌렀을 때 살짝 흔들어 알려 준다 ---------- */
@keyframes modal-shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}
.modal.shake { animation: modal-shake .28s ease; }
@media (prefers-reduced-motion: reduce) {
  .modal.shake { animation: none; }
}
