:root {
  --navy: #26364f;
  --navy-2: #34486a;
  --navy-3: #4a6088;
  --bg: #e8ecf1;
  --panel: #ffffff;
  --line: #ccd4de;
  --line-soft: #e3e8ee;
  --text: #1f2a37;
  --muted: #6b7686;
  --th-bg: #4b5f80;
  --th-text: #ffffff;
  --row-alt: #f7f9fb;
  --row-hover: #eaf2fb;
  --row-sel: #d6e7fa;
  --accent: #2f7fc4;
  --accent-dark: #2368a3;
  --danger: #c0392b;
  --ok: #2e8b57;
  --warn-bg: #fff4b8;
  --readonly-bg: #f1f4f7;
  --radius: 4px;
  --font: "Pretendard Variable", Pretendard, -apple-system, "Malgun Gothic", "맑은 고딕", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 13px; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); font-weight: 400; }
.hidden { display: none !important; }

/* ---------- 버튼 / 입력 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  height: 28px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f2f5f8; }
.btn:disabled, .btn.is-disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { background: #fff; border-color: #e3b1ab; color: var(--danger); }
.btn-dark { background: var(--navy-2); border-color: var(--navy-2); color: #fff; }
.btn-dark:hover { background: var(--navy); }
.btn-block { width: 100%; height: 40px; font-size: 15px; }
.btn-sm { height: 24px; padding: 0 8px; font-size: 12px; }

.input, select.input, textarea.input {
  height: 28px; padding: 0 8px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; min-width: 0;
}
textarea.input { height: auto; padding: 6px 8px; resize: vertical; }
.input[readonly], .input.readonly { background: var(--readonly-bg); color: #3c4857; }
.input:focus { outline: 2px solid #9cc7ee; outline-offset: -1px; }
.input-auto { background: #eef5fc; }

/* ---------- 로그인 ---------- */
.login-body { display: grid; place-items: center; background: linear-gradient(160deg, #26364f 0%, #3b5378 100%); }
.login-card { width: 380px; background: #fff; border-radius: 10px; padding: 32px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-brand { text-align: center; margin-bottom: 22px; }
.login-logo { width: 54px; height: 54px; margin: 0 auto 10px; border-radius: 12px; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 800; letter-spacing: 1px; }
.login-brand h1 { margin: 0; font-size: 22px; }
.login-brand p { margin: 4px 0 0; color: var(--muted); }
.login-form { display: grid; gap: 12px; }
.login-form > label { display: grid; gap: 4px; font-weight: 600; }
.login-form input[type=text], .login-form input[type=password] { height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; font-size: 14px; }
.login-role { border: 1px solid var(--line-soft); border-radius: 6px; padding: 8px 12px; display: flex; gap: 18px; }
.login-role legend { font-size: 12px; padding: 0 4px; }
.login-note { margin: 0; font-size: 12px; color: var(--muted); text-align: center; }

/* ---------- 앱 레이아웃 ---------- */
.app-body { display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: 40px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; background: var(--navy); color: #fff;
}
.topbar-title { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.badge-demo { font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 3px; background: #f0b429; color: #3a2a00; }
.topbar-right { display: flex; align-items: center; gap: 4px; }
.topbar-user { font-weight: 600; margin: 0 8px; }
.topbar-link { background: transparent; border: 0; color: #dfe7f2; padding: 4px 8px; cursor: pointer; border-radius: 3px; }
.topbar-link:hover { background: rgba(255,255,255,.12); color: #fff; }
.demo-switch { font-size: 12px; color: #c9d4e3; display: inline-flex; align-items: center; gap: 4px; margin-right: 6px; }
.demo-switch select { height: 24px; border-radius: 3px; border: 0; padding: 0 4px; color: var(--text); }

.topbar-btn { height: 26px; padding: 0 10px; border: 1px solid rgba(255,255,255,.35); border-radius: 3px; background: transparent; color: #fff; cursor: pointer; margin-left: 4px; }
.topbar-btn:hover { background: rgba(255,255,255,.12); }
.login-error { margin: 12px 0 0; color: var(--danger); font-size: 13px; text-align: center; }

.tabstrip { height: 42px; flex: none; display: flex; align-items: flex-end; gap: 4px; padding: 0 10px; background: #dfe5ec; border-bottom: 2px solid var(--accent); }
.tab {
  display: flex; align-items: center; justify-content: center; height: 34px; min-width: 110px; padding: 0 18px;
  background: #f4f6f9; border: 1px solid var(--line); border-bottom: 0; border-radius: 4px 4px 0 0; cursor: pointer; color: #475468; font-weight: 600;
}
.tab:hover { background: #fff; }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tabpanes { flex: 1; min-height: 0; position: relative; }
.kpi-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.kpi-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi-card .lbl { color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi-card .val { font-size: 20px; font-weight: 800; margin-top: 4px; color: var(--navy); }
.stats-view, .repurchase-view { height: 100%; display: grid; gap: 8px; }
.stats-view { grid-template-rows: auto auto minmax(180px, 1fr) minmax(160px, 1fr); }
.repurchase-view { grid-template-rows: auto minmax(200px, 1fr); }
.postcode-box { height: 440px; border: 1px solid var(--line-soft); }
.tabpane { position: absolute; inset: 0; overflow: auto; padding: 8px; }
.tabpane:not(.active) { display: none; }
.empty-workspace { height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 14px; text-align: center; }

/* ---------- 패널 ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line-soft); min-height: 36px; }
.panel-title { font-weight: 700; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.panel-title::before { content: "■"; color: var(--navy-3); font-size: 10px; }
.panel-title .sub { font-weight: 400; color: var(--muted); font-size: 12px; }
.panel-body { padding: 8px 10px; min-height: 0; }
.panel-body.flush { padding: 0; }
.panel-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.panel-note { font-size: 12px; color: var(--muted); padding: 4px 10px 8px; }

/* ---------- 폼 그리드 ---------- */
.form-grid { display: grid; grid-template-columns: 80px 1fr 80px 1fr; gap: 6px 8px; align-items: center; }
.form-grid > label, .form-grid .lbl { color: #475468; font-weight: 600; font-size: 12px; }
.form-grid .span-3 { grid-column: span 3; }
.form-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.form-row .lbl { color: #475468; font-weight: 600; font-size: 12px; }
.req::after { content: " *"; color: var(--danger); }

/* ---------- 테이블 ---------- */
.table-wrap { overflow: auto; min-height: 0; flex: 1; }
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
table.grid th, table.grid td { border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); padding: 5px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; height: 30px; }
table.grid th { position: sticky; top: 0; z-index: 1; background: var(--th-bg); color: var(--th-text); font-weight: 600; font-size: 12px; user-select: none; }
table.grid th.num, table.grid td.num { text-align: right; }
table.grid th.center, table.grid td.center { text-align: center; }
table.grid tbody tr:nth-child(even) td { background: var(--row-alt); }
table.grid tbody tr:hover td { background: var(--row-hover); cursor: default; }
table.grid tbody tr.selected td { background: var(--row-sel); }
table.grid tbody tr.clickable td { cursor: pointer; }
table.grid td.cell-warn { background: var(--warn-bg) !important; }
table.grid td.empty { text-align: center; color: var(--muted); padding: 24px; height: auto; }
table.grid tr.row-locked td { color: var(--muted); font-style: italic; }
table.grid input[type=checkbox] { margin: 0; vertical-align: middle; }
table.grid.compact th, table.grid.compact td { height: 26px; padding: 3px 8px; }
.col-resizer { position: absolute; right: 0; top: 0; bottom: 0; width: 6px; cursor: col-resize; }
.col-resizer:hover { background: rgba(255,255,255,.35); }
table.grid th { position: sticky; }

.tag { display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 11px; font-weight: 600; background: #e8edf3; color: #3d4b5f; }
.tag.blue { background: #dcebfa; color: #1e5d97; }
.tag.green { background: #dcf3e5; color: #1f6e43; }
.tag.red { background: #fbe1de; color: #9b2c20; }
.tag.gray { background: #eceff3; color: #6b7686; }
.tag.yellow { background: var(--warn-bg); color: #6b5200; }

/* ---------- 합계 박스 ---------- */
.sum-row { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-top: 1px solid var(--line-soft); flex-wrap: wrap; }
.sum-item { display: flex; align-items: center; gap: 6px; }
.sum-item .lbl { color: #475468; font-weight: 600; font-size: 12px; }
.sum-item .val { min-width: 100px; height: 28px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: flex-end; border: 1px solid var(--line); border-radius: var(--radius); background: var(--readonly-bg); font-weight: 700; }
.money-big { font-size: 18px; font-weight: 800; color: var(--accent-dark); }

/* ---------- 판매관리 ---------- */
.sales-view { height: 100%; display: grid; grid-template-rows: 210px auto minmax(160px, 1fr) auto; gap: 8px; }
.sales-top { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; min-height: 0; }
.sales-summary { display: flex; align-items: center; gap: 24px; padding: 10px 14px; flex-wrap: wrap; }
.sales-summary .scope { display: flex; gap: 12px; }
.sales-summary .kpi { display: flex; align-items: baseline; gap: 8px; }
.sales-summary .kpi .lbl { font-weight: 600; color: #475468; }
.sales-summary .hint { font-size: 12px; color: var(--muted); flex-basis: 100%; }

/* ---------- 상담관리 ---------- */
.consult-view { height: 100%; display: grid; grid-template-rows: auto auto minmax(220px, 1fr); gap: 8px; min-height: 680px; }
.consult-top { display: grid; grid-template-columns: minmax(420px, 1fr) minmax(420px, 1.15fr); gap: 8px; }
.consult-left { display: grid; grid-template-rows: auto auto; gap: 8px; }
.memo-box { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 6px; }
.memo-box textarea { min-height: 70px; }
.memo-box .memo-actions { display: grid; gap: 6px; align-content: start; width: 118px; }
.memo-box .memo-actions .btn { padding: 0 6px; }
.edit-banner { font-size: 12px; color: #9a5b00; background: #fff6e0; border: 1px solid #f2d79b; border-radius: 3px; padding: 4px 8px; margin-top: 6px; display: flex; justify-content: space-between; align-items: center; }

/* ---------- 예약리스트 ---------- */
.rsv-view { height: 100%; display: grid; grid-template-rows: auto minmax(200px, 1fr); gap: 8px; }
.subtabs { display: flex; gap: 4px; }
.subtab { height: 28px; padding: 0 14px; border: 1px solid var(--line); background: #fff; border-radius: var(--radius); cursor: pointer; }
.subtab.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ---------- 설정 ---------- */
.settings-view { height: 100%; display: grid; grid-template-columns: 170px 1fr; gap: 8px; }
.settings-menu { display: flex; flex-direction: column; padding: 8px; gap: 4px; }
.settings-menu button { text-align: left; height: 34px; padding: 0 12px; border: 1px solid transparent; background: transparent; border-radius: var(--radius); cursor: pointer; font-weight: 600; color: #475468; }
.settings-menu button:hover { background: #f2f5f8; }
.settings-menu button.active { background: var(--row-sel); color: #1e5d97; border-color: #b9d5f2; }
.settings-main { display: grid; grid-template-rows: minmax(200px, 1fr) auto; gap: 8px; min-height: 0; }

/* ---------- 모달 ---------- */
.modal-layer { position: fixed; inset: 0; background: rgba(20, 30, 45, .38); display: grid; place-items: center; padding: 20px; }
.modal { background: #fff; border-radius: 6px; box-shadow: 0 18px 50px rgba(0,0,0,.3); display: flex; flex-direction: column; max-height: calc(100vh - 40px); max-width: 100%; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 0 12px; height: 38px; background: var(--navy-2); color: #fff; border-radius: 6px 6px 0 0; flex: none; }
.modal-title { font-weight: 700; }
.modal-close { background: transparent; border: 0; color: #fff; font-size: 18px; cursor: pointer; padding: 2px 6px; border-radius: 3px; }
.modal-close:hover { background: rgba(255,255,255,.15); }
.modal-body { padding: 12px; overflow: auto; display: grid; grid-auto-rows: max-content; gap: 10px; }
.modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--line-soft); flex: none; }
.modal-foot .foot-note { margin-right: auto; font-size: 12px; color: var(--muted); }
.modal .panel { border-color: var(--line-soft); }
.modal-msg { font-size: 14px; line-height: 1.6; }
.modal-msg .sub { color: var(--muted); font-size: 13px; }
.info-list { display: grid; grid-template-columns: 100px 1fr; gap: 6px 10px; align-items: center; }
.info-list .lbl { color: #475468; font-weight: 600; font-size: 12px; }
.notice { font-size: 12px; color: #5b6676; background: #f4f7fa; border: 1px solid var(--line-soft); border-radius: 4px; padding: 6px 10px; }
.notice.warn { background: #fff8e6; border-color: #f1dca5; color: #7a5a00; }

.order-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.money-line { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.alert-card { border: 1px solid #b9d5f2; background: #f2f8fe; border-radius: 6px; padding: 10px 12px; cursor: pointer; }
.alert-card:hover { background: #e6f1fc; }
.alert-time { font-size: 15px; font-weight: 700; color: var(--accent-dark); }

/* ---------- 토스트 ---------- */
.toast-root { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 6px; z-index: 9999; }
.toast { background: #263447; color: #fff; padding: 10px 14px; border-radius: 6px; box-shadow: 0 8px 20px rgba(0,0,0,.2); font-size: 13px; animation: toast-in .15s ease-out; }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ==========================================================================
   반응형: 태블릿·모바일 (PC 레이아웃은 그대로, 좁은 화면에서만 세로로 쌓는다)
   ========================================================================== */
@media (max-width: 1100px) {
  .sales-top, .consult-top, .order-grid { grid-template-columns: minmax(0, 1fr); }
  .sales-view > *, .consult-view > *, .consult-left > *, .settings-main > * { min-width: 0; }
  .consult-view { min-height: 0; }

  /* 고정 높이 그리드 대신 위에서 아래로 흐르는 레이아웃 */
  .sales-view, .consult-view, .rsv-view, .stats-view, .repurchase-view, .settings-main {
    display: flex; flex-direction: column; height: auto; gap: 8px;
  }
  .consult-left { display: flex; flex-direction: column; gap: 8px; }
  .panel > .panel-body .table-wrap { max-height: 60vh; }
  .sales-top .table-wrap, .consult-top .table-wrap { max-height: 260px; }

  /* 판매실적 누계는 스크롤해도 화면 하단에 고정 */
  .sales-view > .panel:last-child { position: sticky; bottom: 0; z-index: 5; box-shadow: 0 -4px 14px rgba(0,0,0,.08); }

  .settings-view { grid-template-columns: minmax(0, 1fr); height: auto; }
  .settings-menu { flex-direction: row; overflow-x: auto; }
  .settings-menu button { flex: none; }
}

@media (max-width: 768px) {
  body { font-size: 14px; }
  /* iOS 입력 시 화면 확대 방지(16px) + 터치 영역 확대 */
  .input, select.input, textarea.input { font-size: 16px; height: 38px; }
  textarea.input { height: auto; }
  .btn { height: 36px; padding: 0 12px; }
  .btn-sm { height: 30px; }
  /* 좁은 화면에서는 내용 폭에 맞춰 열을 잡고 표 안에서 가로 스크롤 */
  table.grid { table-layout: auto; width: max-content; min-width: 100% !important; }
  table.grid td { max-width: 240px; }
  table.grid th, table.grid td { height: 36px; }
  table.grid.compact th, table.grid.compact td { height: 32px; }

  /* 상단바 */
  .topbar { height: auto; min-height: 44px; padding: 6px 10px; flex-wrap: wrap; gap: 4px; }
  .topbar-title { font-size: 14px; }
  .topbar-user { margin: 0 4px 0 0; font-size: 12px; }
  .topbar-btn { height: 30px; padding: 0 8px; font-size: 12px; }

  /* 업무 탭: 가로로 밀어서 이동 */
  .tabstrip { height: 44px; overflow-x: auto; overflow-y: hidden; padding: 0 6px; scrollbar-width: none; }
  .tabstrip::-webkit-scrollbar { display: none; }
  .tab { flex: none; min-width: auto; padding: 0 14px; height: 36px; }
  .tabpane { padding: 6px; -webkit-overflow-scrolling: touch; }

  /* 패널·폼 */
  .panel-head { flex-wrap: wrap; }
  .panel-title { white-space: normal; }
  .panel-title .sub { display: none; }
  .panel-actions { width: 100%; }
  .panel-actions .btn { flex: 1 1 auto; }
  /* 입력 폼은 라벨을 위, 입력칸을 아래로 한 줄씩 */
  .form-grid { grid-template-columns: minmax(0, 1fr); gap: 2px 0; }
  .form-grid > label { margin-top: 8px; }
  .form-grid .span-3 { grid-column: auto; }
  .form-grid .form-row > .btn { flex: none; }
  .form-row { gap: 6px; }
  .form-row > .input, .form-row > select.input { flex: 1 1 140px; width: auto !important; }
  .form-row > .btn { flex: 1 1 auto; }
  .form-row .lbl { flex: 0 0 100%; margin: 4px 0 -2px !important; }
  .form-row > span[style*="flex: 1"] { display: none; }
  .memo-box { grid-template-columns: 1fr; }
  .memo-box .memo-actions { width: auto; grid-template-columns: 1fr 1fr; }
  .sum-row { gap: 6px; }
  .sum-item { flex: 1 1 45%; justify-content: space-between; }
  .sum-item .val { min-width: 0; flex: 1; }
  .info-list { grid-template-columns: 90px minmax(0, 1fr); }
  .subtabs { width: 100%; }
  .subtab { flex: 1; height: 36px; }

  /* 판매실적 누계 */
  .sales-summary { gap: 8px 14px; padding: 8px 10px; }
  .sales-summary > span[style*="flex: 1"] { display: none; }
  .sales-summary .kpi { flex: 1 1 100%; justify-content: space-between; }
  .money-big { font-size: 16px; }

  .kpi-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-card .val { font-size: 17px; }

  /* 팝업: 전체 화면 */
  .modal-layer { padding: 0; place-items: stretch; }
  .modal { width: 100% !important; max-height: 100dvh; height: 100dvh; border-radius: 0; }
  .modal-head { border-radius: 0; height: 46px; }
  .modal-close { font-size: 24px; padding: 4px 10px; }
  .modal-body { flex: 1; align-content: start; }
  .modal-foot { flex-wrap: wrap; }
  .modal-foot .foot-note { flex-basis: 100%; }
  .modal-foot .btn { flex: 1 1 auto; }
  .postcode-box { height: 60vh; }

  /* 로그인 */
  .login-card { width: calc(100% - 24px); padding: 24px 18px; }

  .toast-root { left: 10px; right: 10px; bottom: 10px; }
}
