/* ==========================================================
   DrLab Order System - Base Style (Toss/Naver style clean UI)
   ========================================================== */
:root {
  --primary: #3182f6;
  --primary-dark: #1b64da;
  --primary-light: #e8f3ff;
  --bg: #f2f4f6;
  --card: #ffffff;
  --text: #191f28;
  --text-sub: #8b95a1;
  --text-muted: #b0b8c1;
  --border: #e5e8eb;
  --danger: #f04452;
  --danger-light: #ffecee;
  --success: #00c896;
  --warning: #ff9f43;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.10);
  --cart-item-height: 68px; /* 장바구니 한 줄 높이 (4줄만 보이게 하는 기준값) */
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo",
    "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ---------------- Layout ---------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .logo {
  font-size: 19px;
  font-weight: 800;
  color: var(--primary);
  padding: 0 8px 20px;
  letter-spacing: -0.5px;
}

.sidebar .user-box {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 18px;
}
.sidebar .user-box .name { font-weight: 700; font-size: 14.5px; }
.sidebar .user-box .role { color: var(--text-sub); font-size: 12.5px; margin-top: 2px; }

.nav-menu { flex: 1; }
.nav-menu li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 600;
  font-size: 14.5px;
  margin-bottom: 2px;
  transition: background .12s ease;
}
.nav-menu li a:hover { background: var(--bg); }
.nav-menu li a.active { background: var(--primary-light); color: var(--primary-dark); }
.nav-menu li a .ic { width: 20px; text-align: center; }

.logout-link {
  color: var(--text-sub);
  font-size: 13.5px;
  padding: 10px 12px;
  font-weight: 600;
}
.logout-link:hover { color: var(--danger); }

.main {
  flex: 1;
  min-width: 0;
  padding: 28px 32px 60px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}
.page-header h1 { font-size: 21px; font-weight: 800; margin: 0; }
.page-header .desc { color: var(--text-sub); font-size: 13.5px; margin-top: 4px; }

/* ---------------- Card / Panel ---------------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 700;
  background: var(--bg);
  color: var(--text);
  transition: transform .05s ease, opacity .12s ease;
}
.btn:hover { opacity: 0.88; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-outline { background: #fff; border: 1px solid var(--border); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------------- Form ---------------- */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-sub);
  margin-bottom: 6px;
}
.form-control {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color .12s ease;
}
.form-control:focus { border-color: var(--primary); }
textarea.form-control { resize: vertical; min-height: 70px; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }
.input-suffix { position: relative; }
.input-suffix span {
  position: absolute; right: 13px; top: 50%; transform: translateY(-50%);
  color: var(--text-sub); font-size: 13px; font-weight: 600;
}

/* Toggle switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border); border-radius: 24px;
  transition: background .15s ease;
}
.toggle .slider::before {
  content: ""; position: absolute; width: 18px; height: 18px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%;
  transition: transform .15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle input:checked + .slider { background: var(--primary); }
.toggle input:checked + .slider::before { transform: translateX(18px); }

/* ---------------- Table ---------------- */
table.grid { width: 100%; border-collapse: collapse; }
table.grid th {
  text-align: left; font-size: 12.5px; color: var(--text-sub);
  font-weight: 700; padding: 10px 12px; border-bottom: 1.5px solid var(--border);
  white-space: nowrap;
}
table.grid td {
  padding: 12px; border-bottom: 1px solid var(--border);
  font-size: 14px; vertical-align: middle;
}
table.grid tr:last-child td { border-bottom: none; }
table.grid tr.dragging { opacity: .4; background: var(--primary-light); }
.drag-handle { cursor: grab; color: var(--text-muted); font-size: 16px; padding: 0 4px; }
.drag-handle:active { cursor: grabbing; }

/* ---------------- Badge / Chip ---------------- */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 100px;
  font-size: 11.5px; font-weight: 700;
}
.badge-on { background: #e6f9f3; color: #00a67c; }
.badge-off { background: #f2f2f2; color: var(--text-sub); }
.badge-role-super { background: #fdeeee; color: #e0384c; }
.badge-role-hospital { background: var(--primary-light); color: var(--primary-dark); }
.badge-role-sub { background: #fff4e0; color: #d98200; }

/* Category chips (order page) */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.chip {
  padding: 9px 16px; border-radius: 100px; background: #fff;
  border: 1.5px solid var(--border); font-weight: 700; font-size: 13.5px;
  color: var(--text-sub);
}
.chip.active { background: var(--text); color: #fff; border-color: var(--text); }

/* ---------------- Search box ---------------- */
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1.5px solid var(--border); border-radius: 10px;
  padding: 9px 14px; width: 260px;
}
.search-box input { border: none; outline: none; flex: 1; font-size: 14px; }
.search-box .ic { color: var(--text-muted); }

/* ---------------- Order page ---------------- */
.order-layout { display: flex; gap: 22px; align-items: flex-start; }
.order-left { flex: 1; min-width: 0; }
.order-right {
  width: 360px; flex-shrink: 0; position: sticky; top: 28px;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.product-card {
  background: #fff; border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 16px; cursor: pointer; transition: border-color .12s ease, transform .08s ease;
}
.product-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.product-card .cat { font-size: 11.5px; color: var(--primary); font-weight: 700; margin-bottom: 6px; }
.product-card .name { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.product-card .desc {
  font-size: 12.5px; color: var(--text-sub); margin-bottom: 12px;
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; min-height: 32px;
}
.product-card .price-row { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.product-card .final-price { font-weight: 800; font-size: 16px; }
.product-card .origin-price { font-size: 12px; color: var(--text-muted); text-decoration: line-through; }
.product-card .discount-tag { font-size: 12px; color: var(--danger); font-weight: 700; }

.cart-box { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 20px; }
.cart-box h3 { margin: 0 0 14px; font-size: 16px; font-weight: 800; }
.cart-empty { text-align: center; color: var(--text-muted); padding: 40px 0; font-size: 13.5px; }
.cart-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.cart-item .info { flex: 1; min-width: 0; }
.cart-item .info .name { font-weight: 700; font-size: 13.8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-item .info .unit { font-size: 12px; color: var(--text-sub); margin-top: 2px; }
.cart-item .qty { display: flex; align-items: center; gap: 8px; }
.cart-item .qty button {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; font-weight: 700; font-size: 16px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.cart-item .qty span { min-width: 20px; text-align: center; font-weight: 700; font-size: 14px; }
.cart-item .remove {
  color: var(--text-muted); font-size: 20px; padding: 8px;
  display: flex; align-items: center; justify-content: center;
}
.cart-item .remove:hover { color: var(--danger); }

.cart-summary { margin-top: 14px; padding-top: 14px; border-top: 1.5px dashed var(--border); }
.cart-summary .row { display: flex; justify-content: space-between; font-size: 13.5px; margin-bottom: 8px; color: var(--text-sub); }
.cart-summary .row.total { font-size: 17px; font-weight: 800; color: var(--text); margin-top: 10px; }
.cart-summary .row.total span:last-child { color: var(--primary); }

/* ---------------- Modal ---------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 20, 25, .45);
  display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.show { display: flex; }
.modal-box {
  background: #fff; border-radius: 18px; width: 460px; max-width: 92vw;
  max-height: 88vh; overflow-y: auto; padding: 26px;
  box-shadow: var(--shadow-lg);
}
.modal-box h2 { margin: 0 0 18px; font-size: 18px; font-weight: 800; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ---------------- Toast ---------------- */
#toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: #fff; padding: 13px 22px; border-radius: 10px;
  font-size: 13.5px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: all .2s ease; z-index: 200;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- Login ---------------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #eef4ff 0%, var(--bg) 60%);
}
.login-card {
  width: 380px; background: #fff; border-radius: 20px; box-shadow: var(--shadow-lg);
  padding: 44px 36px;
}
.login-card .logo { font-size: 24px; font-weight: 800; color: var(--primary); margin-bottom: 6px; text-align: center; }
.login-card .sub { text-align: center; color: var(--text-sub); font-size: 13px; margin-bottom: 28px; }
.login-card .btn-primary { margin-top: 8px; padding: 13px; font-size: 15px; }
.login-error {
  background: var(--danger-light); color: var(--danger); font-size: 13px;
  padding: 11px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 600;
}

.text-sub { color: var(--text-sub); }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }

/* ---------------- Pagination ---------------- */
.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: 4px; margin-top: 20px; flex-wrap: wrap;
}
.pagination .page-nav, .pagination .page-num {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; padding: 0 6px;
  border-radius: 8px; font-size: 13px; font-weight: 700;
  color: var(--text-sub); background: #fff; border: 1px solid var(--border);
}
.pagination a.page-nav:hover, .pagination a.page-num:hover { border-color: var(--primary); color: var(--primary); }
.pagination .page-num.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination .page-nav.disabled { color: var(--text-muted); opacity: .5; }

/* ---------------- Product list (order page, 한 줄에 3개) ---------------- */
.product-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.product-row {
  display: flex; flex-direction: column; align-items: stretch; justify-content: space-between; gap: 10px;
  min-width: 0;
  background: #fff; border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 16px; cursor: pointer; transition: border-color .12s ease, background .12s ease;
}
.product-row:hover { border-color: var(--primary); }
.product-row.selected { background: var(--primary-light); border-color: var(--primary); }
.product-row .prod-info { min-width: 0; }
.product-row .cat { font-size: 11.5px; color: var(--primary); font-weight: 700; margin-bottom: 4px; }
.product-row .name { font-weight: 700; font-size: 15px; margin-bottom: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: break-word; word-break: break-word; }
.product-row .desc { font-size: 12.5px; color: var(--text-sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-row .prod-price { flex-shrink: 0; text-align: left; }
.product-row .final-price { font-weight: 800; font-size: 16px; }
.product-row .origin-price { font-size: 12px; color: var(--text-muted); text-decoration: line-through; margin-right: 4px; }
.product-row .discount-tag { font-size: 12px; color: var(--danger); font-weight: 700; display: block; margin-bottom: 2px; }

/* ---------------- Cart (하단 고정 요약) ---------------- */
.cart-box { display: flex; flex-direction: column; max-height: calc(100vh - 56px); }
.cart-box h3 { flex-shrink: 0; }
/* 스크롤 없이도 항목 4개 정도만 보이는 높이로 고정 (그 이상은 스크롤) */
.cart-items-scroll {
  flex: 0 1 auto;
  max-height: calc(var(--cart-item-height) * 4);
  overflow-y: auto;
}
.cart-fixed-bottom { flex-shrink: 0; }
.discount-box { background: var(--bg); border-radius: var(--radius-sm); padding: 12px; margin-top: 12px; }
.discount-box .form-group { margin-bottom: 8px; }
.discount-box .form-group:last-child { margin-bottom: 0; }
.discount-box label { font-size: 12px; }

/* ---------------- Order list (확정 오더 리스트) ---------------- */
.detail-list { border-top: 1px solid var(--border); margin-top: 10px; }
.detail-list .row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.detail-list .row:last-child { border-bottom: none; }
.empty-state { text-align: center; padding: 60px 0; color: var(--text-muted); }

/* ---------------- 채팅관리 (병원 내부 직원 공용 채팅방) ---------------- */
.team-chat-box {
  display: flex; flex-direction: column;
  height: calc(100vh - 220px); min-height: 480px;
  padding: 0; overflow: hidden;
}
.team-chat-header { padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.team-chat-header h3 { margin: 0; font-size: 16px; font-weight: 800; }
.team-chat-header .text-sub { font-size: 12.5px; margin-top: 2px; }

.team-chat-scroll { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.team-chat-row { display: flex; flex-direction: column; max-width: 68%; }
.team-chat-row.me { align-items: flex-end; align-self: flex-end; }
.team-chat-row.other { align-items: flex-start; align-self: flex-start; }
.team-chat-sender { font-size: 12px; color: var(--text-sub); font-weight: 700; margin-bottom: 3px; }
.team-chat-bubble {
  padding: 11px 14px; border-radius: 14px; font-size: 14px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}
.team-chat-row.other .team-chat-bubble { background: #fff; border: 1.5px solid var(--border); border-top-left-radius: 4px; }
.team-chat-row.me .team-chat-bubble { background: var(--primary-light); color: var(--text); border-top-right-radius: 4px; }
.team-chat-time { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.team-chat-mention-tag { color: var(--primary); font-weight: 700; }
.team-chat-row.mentioned-me .team-chat-bubble { border: 1.5px solid var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

.team-chat-order-card {
  background: #fff; border: 1.5px solid var(--border); border-radius: 12px;
  padding: 12px 14px; font-size: 13px; width: 260px; max-width: 100%;
}
.team-chat-order-card-head { font-weight: 800; margin-bottom: 6px; }
.team-chat-order-card-row {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 4px 0; color: var(--text-sub);
}
.team-chat-order-card-row b { color: var(--text); font-weight: 700; text-align: right; }
.team-chat-order-card-link {
  display: block; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border);
  color: var(--primary); font-weight: 700; font-size: 12.5px; text-align: right;
}

.team-chat-input-row { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); flex-shrink: 0; }
.team-chat-input-row .btn { align-self: flex-end; }
.team-chat-compose { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.team-chat-input-wrap { position: relative; }
.team-chat-input-wrap textarea { width: 100%; resize: none; }

.team-chat-attach-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--primary-light); color: var(--primary-dark);
  border-radius: var(--radius-sm); padding: 8px 12px; font-size: 12.5px; font-weight: 700;
}
.team-chat-attach-remove { cursor: pointer; font-size: 16px; font-weight: 800; color: var(--text-sub); }
.team-chat-attach-remove:hover { color: var(--danger); }

.team-chat-mention-dropdown {
  /* .team-chat-box가 overflow:hidden이라 position:fixed로 띄우고, 위치는 JS에서 계산해 지정한다 */
  position: fixed;
  background: #fff; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); max-height: 240px; overflow-y: auto; z-index: 50;
}
.team-chat-mention-item { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border); }
.team-chat-mention-item:last-child { border-bottom: none; }
.team-chat-mention-item:hover, .team-chat-mention-item.active { background: var(--bg); }
.team-chat-mention-item .name { font-weight: 700; font-size: 13.5px; }
.team-chat-mention-item .meta { font-size: 12px; color: var(--text-sub); margin-top: 2px; }
.team-chat-mention-empty { padding: 14px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ==========================================================
   태블릿 반응형 (병원 데스크 태블릿에서 오더 페이지를 주로 사용)
   ========================================================== */

/* 가로가 좁은 태블릿(가로모드 포함) : 여백/카트 폭만 축소 */
@media (max-width: 1180px) {
  .main { padding: 22px 20px 48px; }
  .order-layout { gap: 16px; }
  .order-right { width: 300px; }
  .product-list { grid-template-columns: repeat(2, 1fr); }
}

/* 세로형 태블릿(portrait) : 카트를 상품 목록 아래로 내려서 1열로 쌓음 */
@media (max-width: 900px) {
  .sidebar { width: 84px; padding: 20px 8px; }
  .sidebar .user-box { padding: 10px 4px; text-align: center; overflow: hidden; }
  .sidebar .user-box .name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sidebar .user-box .role { font-size: 0; }
  .sidebar .user-box .role .badge { font-size: 10px; }
  .nav-menu li a { justify-content: center; padding: 12px 4px; gap: 0; font-size: 0; }
  .nav-menu li a .ic { font-size: 18px; width: auto; }
  .logout-link { text-align: center; font-size: 0; }

  .main { padding: 18px 16px 40px; }

  .order-layout { flex-direction: column; }
  .order-right { width: 100%; position: static; top: auto; }
  .cart-box { max-height: none; }
  .cart-items-scroll { max-height: calc(var(--cart-item-height) * 4); }

  .team-chat-box { height: 70vh; min-height: 380px; }

  .product-list { grid-template-columns: repeat(2, 1fr); }
  .product-row .desc { white-space: normal; }

  .search-box { width: 100%; }
  .chip { padding: 10px 16px; font-size: 14px; }
}

/* 터치 조작 대상 크기 보강 (탭하기 쉬운 최소 크기 확보) */
.btn { min-height: 40px; }
.btn-sm { min-height: 34px; }
.toggle { width: 46px; height: 26px; }
.toggle .slider::before { width: 20px; height: 20px; }
.toggle input:checked + .slider::before { transform: translateX(20px); }
