/* =============================================================
   pages.css — Shared page-level components (Phase 2)
   Card, StatStrip, Seg, Form, Modal, Toast, Dashboard, Login
   ============================================================= */

/* ----- Page header ----- */
.pg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.pg-header h2 { margin: 0; }
.pg-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ----- Card ----- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
}
.card-pad { padding: 20px; }
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: 15.5px; white-space: nowrap; }
.card-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.card-pad.flex h3 { white-space: nowrap; }

/* chip (status pill without dot) */
.chip {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 20px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}

/* ===== Stat Strip ===== */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
}
.stat-strip > div {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
  display: grid; gap: 5px; box-shadow: var(--shadow-xs);
}
.stat-strip span { font-size: 12.5px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.stat-strip b { font-size: 22px; color: var(--ink); font-weight: 700; letter-spacing: -0.01em; }

/* ===== Segmented tabs ===== */
.seg {
  display: inline-flex; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 11px; padding: 3px;
}
.seg-btn {
  border: 0; background: transparent; color: var(--muted);
  font-family: var(--font); font-size: 13.5px; font-weight: 600;
  padding: 7px 13px; border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; gap: 7px; white-space: nowrap;
  transition: background .14s, color .14s;
  min-height: 0;
  box-shadow: none;
}
.seg-btn:hover { color: var(--ink); box-shadow: none !important; transform: none !important; background: transparent !important; border-color: transparent !important; }
.seg-btn.active { background: var(--surface) !important; color: var(--ink) !important; box-shadow: var(--shadow-xs) !important; border-color: transparent !important; transform: none !important; }
.seg-count {
  font-size: 11.5px; font-weight: 700;
  background: var(--border); color: var(--muted);
  padding: 0 6px; border-radius: 20px; min-width: 18px; text-align: center;
}
.seg-btn.active .seg-count { background: var(--brand-50); color: var(--brand); }

/* ===== Page header row ===== */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 4px; }
.page-head h2 { font-size: 21px; }
.page-head p { color: var(--muted); margin-top: 4px; font-size: 14px; }

/* ===== Inline search box (inside toolbar) ===== */
.sc-search-sm {
  display: flex; align-items: center; gap: 9px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 10px; padding: 8px 13px; width: 220px; color: var(--muted);
  transition: border-color .14s, box-shadow .14s;
}
.sc-search-sm:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); background: #fff; }
.sc-search-sm input { border: 0; background: transparent; outline: 0; font-family: var(--font); font-size: 14px; color: var(--ink); width: 100%; min-height: 0; padding: 0; }
.sc-search-sm input::placeholder { color: var(--faint); }

/* customer name cell */
.cust-cell { display: flex; align-items: center; gap: 10px; }
.cust-cell .name { font-weight: 600; color: var(--ink); font-size: 14px; white-space: nowrap; }
.cust-cell .sub { font-size: 12px; color: var(--faint); margin-top: 2px; }

/* ===== Pager ===== */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.pager-info { font-size: 13px; color: var(--muted); }
.pager-btns { display: flex; gap: 4px; }

/* ===== Form layouts ===== */
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--gap); align-items: start; }
.form-side { position: sticky; top: 0; }
.form-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-full { grid-column: 1 / -1; }

/* document items table */
.items-tbl { table-layout: fixed; width: 100%; }
.items-tbl td { padding: 7px 10px; }
.items-tbl th { padding: 10px; }
.cell-input {
  width: 100%; border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; padding: 8px 10px;
  font-family: var(--font); font-size: 14px; color: var(--ink);
  outline: 0; transition: border-color .12s, background .12s, box-shadow .12s;
  min-height: 0;
}
.cell-input:hover { border-color: var(--border-strong); background: var(--surface-2); }
.cell-input:focus { border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px var(--brand-50); }
.cell-input[readonly] { border-color: transparent; background: var(--surface-2); color: var(--ink); cursor: default; }

/* summary rows */
.sum-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; color: var(--text); }
.sum-row > span { white-space: nowrap; }
.sum-row b { color: var(--ink); font-weight: 700; }
.sum-divider { height: 1px; background: var(--border); margin: 6px 0; }
.sum-row.total { font-size: 15px; }
.sum-row.total > span { font-weight: 700; color: var(--ink); }
.sum-row.total b { font-size: 22px; color: var(--brand); }

/* ===== Progress bar ===== */
.bar { height: 8px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; }
.bar-fill.pos { background: var(--pos); }
.bar-fill.warn { background: var(--warn); }
.bar-fill.muted { background: var(--faint); }
.bar-fill.neg { background: var(--neg); }

/* ===== Toggle switch ===== */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 8px; border-bottom: 1px solid var(--border); }
.toggle-row:last-child { border-bottom: 0; }
.switch { width: 40px; height: 23px; border-radius: 20px; background: var(--border-strong); position: relative; flex: none; transition: background .16s; cursor: pointer; border: 0; padding: 0; min-height: 0; box-shadow: none; }
.switch.on { background: var(--brand); }
.switch:hover { background: var(--faint) !important; box-shadow: none !important; transform: none !important; border-color: transparent !important; }
.switch.on:hover { background: var(--brand-700) !important; }
.switch .knob { position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: left .16s; }
.switch.on .knob { left: 19px; }

/* ===== Upload slot ===== */
.upload-slot {
  border: 1.5px dashed var(--border-strong); border-radius: 10px;
  padding: 18px; text-align: center; color: var(--muted);
  font-size: 13px; display: flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer; transition: border-color .14s, color .14s;
}
.upload-slot:hover { border-color: var(--brand); color: var(--brand); }

/* ===== Dashboard ===== */
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap); }
.metric { display: grid; gap: 4px; }
.metric-ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; }
.metric-ico.pos { background: var(--pos-bg); color: var(--pos); }
.metric-ico.warn { background: var(--warn-bg); color: var(--warn); }
.metric-ico.brand { background: var(--brand-50); color: var(--brand); }
.metric-ico.info { background: var(--info-bg); color: var(--info); }
.metric-ico.neg { background: var(--neg-bg); color: var(--neg); }
.metric-value { font-size: 25px; font-weight: 700; color: var(--ink); letter-spacing: -0.02em; margin-top: 10px; }
.metric-label { font-size: 13.5px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.metric-sub { font-size: 12px; color: var(--faint); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-trend { display: inline-flex; align-items: center; gap: 3px; font-size: 12.5px; font-weight: 700; padding: 3px 8px; border-radius: 20px; }
.metric-trend.up { color: var(--pos); background: var(--pos-bg); }
.metric-trend.down { color: var(--neg); background: var(--neg-bg); }

.db-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: var(--gap); }
.chart-legend { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.kpi { display: grid; gap: 2px; }
.kpi span { font-size: 12px; color: var(--faint); font-weight: 600; white-space: nowrap; }
.kpi b { font-size: 16px; white-space: nowrap; }

.year-card { background: linear-gradient(155deg, #1d2b46, #111a2e); border: 0; padding: 22px; color: #fff; }
.year-amount { font-size: 32px; font-weight: 700; color: #fff; letter-spacing: -0.02em; margin-top: 4px; }
.year-rows { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 20px; padding-top: 18px; border-top: 1px solid rgba(255,255,255,.12); }
.year-rows div { display: grid; gap: 3px; }
.year-rows span { font-size: 12px; color: rgba(255,255,255,.6); font-weight: 600; white-space: nowrap; }
.year-rows b { font-size: 16px; color: #fff; }
.recent-row { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 10px; transition: background .12s; }
.recent-row:hover { background: var(--surface-2); }

/* ===== Login ===== */
.login-wrap { display: grid; grid-template-columns: 1.05fr 1fr; min-height: 100vh; }
.login-brand {
  background: linear-gradient(160deg, #16223a, #0b1220 70%);
  color: #fff; padding: 44px; display: flex; flex-direction: column;
  position: relative; overflow: hidden;
}
.login-brand::before {
  content: ""; position: absolute; width: 460px; height: 460px; border-radius: 50%;
  background: radial-gradient(circle, rgba(37,99,235,.4), transparent 65%);
  top: -120px; right: -120px; filter: blur(8px);
}
.login-brand::after {
  content: ""; position: absolute; width: 360px; height: 360px; border-radius: 50%;
  background: radial-gradient(circle, rgba(99,102,241,.22), transparent 65%);
  bottom: -100px; left: -80px;
}
.login-brand-top { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
.login-brand-mid { margin-top: auto; margin-bottom: auto; position: relative; z-index: 1; max-width: 440px; }
.login-brand-mid h2 { color: #fff; font-size: 34px; line-height: 1.25; font-weight: 700; letter-spacing: -0.02em; }
.login-brand-mid p { color: rgba(255,255,255,.7); font-size: 15px; line-height: 1.7; margin-top: 18px; }
.login-stats { display: flex; gap: 30px; margin-top: 36px; }
.login-stats div { display: grid; gap: 3px; }
.login-stats b { font-size: 26px; font-weight: 700; color: #fff; }
.login-stats span { font-size: 12.5px; color: rgba(255,255,255,.6); font-weight: 600; }
.login-brand-foot { position: relative; z-index: 1; font-size: 12.5px; color: rgba(255,255,255,.45); }
.login-form-side { display: grid; place-items: center; padding: 40px; background: var(--bg); }
.login-card { width: 100%; max-width: 400px; }
.login-card h1 { font-size: 27px; }
.login-divider { display: flex; align-items: center; gap: 14px; margin: 24px 0 18px; color: var(--faint); font-size: 12.5px; font-weight: 600; }
.login-divider::before, .login-divider::after { content: ""; height: 1px; background: var(--border); flex: 1; }

/* ===== Chat / LINE cases ===== */
.chat-grid { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: var(--gap); height: calc(100vh - 200px); min-height: 520px; }
.chat-grid > .card { height: 100%; overflow: hidden; display: flex; flex-direction: column; }
.case-item { width: 100%; display: flex; gap: 11px; align-items: flex-start; padding: 12px 16px; border: 0; border-bottom: 1px solid var(--border); background: transparent; cursor: pointer; text-align: left; transition: background .12s; min-height: 0; box-shadow: none; }
.case-item:hover { background: var(--surface-2); box-shadow: none !important; transform: none !important; }
.case-item.active { background: var(--brand-50); box-shadow: inset 3px 0 0 var(--brand) !important; }
.unread { background: var(--brand); color: #fff; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 20px; display: grid; place-items: center; padding: 0 5px; flex: none; }
.chat-body { flex: 1; overflow-y: auto; padding: 20px; background: var(--surface-2); display: flex; flex-direction: column; gap: 12px; }
.chat-day { text-align: center; font-size: 11.5px; color: var(--faint); font-weight: 600; margin: 4px 0; }
.bubble-row { display: flex; }
.bubble-row.me { justify-content: flex-end; }
.bubble { max-width: 78%; padding: 10px 14px; border-radius: 14px; font-size: 13.5px; line-height: 1.55; }
.bubble-them { background: var(--surface); border: 1px solid var(--border); border-top-left-radius: 4px; color: var(--text); }
.bubble-me { background: var(--brand); color: #fff; border-top-right-radius: 4px; }
.bubble-time { display: block; font-size: 10.5px; opacity: .6; margin-top: 4px; }
.chat-input { display: flex; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--border); flex: none; }
.chat-input .input { flex: 1; }
.chat-input .btn { width: 46px; padding: 0; }

/* ===== Service Map ===== */
.map-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--gap); height: calc(100vh - 200px); min-height: 520px; }
.map-grid > .card { height: 100%; overflow: hidden; }
.map-canvas { position: absolute; inset: 0; background:
  repeating-linear-gradient(0deg, transparent 0 39px, rgba(37,99,235,.05) 39px 40px),
  repeating-linear-gradient(90deg, transparent 0 39px, rgba(37,99,235,.05) 39px 40px),
  radial-gradient(circle at 50% 40%, #eef3fb, #e4ebf5); }
.map-note { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); font-family: var(--font-num); font-size: 12px; color: var(--faint); background: rgba(255,255,255,.8); padding: 5px 12px; border-radius: 20px; white-space: nowrap; }
.map-pin { position: absolute; transform: translate(-50%, -50%); width: 24px; height: 24px; border: 0; background: transparent; cursor: pointer; padding: 0; min-height: 0; box-shadow: none; }
.map-pin:hover { box-shadow: none !important; transform: translate(-50%,-50%) !important; }
.map-pin-dot { display: block; width: 18px; height: 18px; border-radius: 50%; background: var(--pc, var(--brand)); border: 3px solid #fff; box-shadow: 0 3px 8px rgba(0,0,0,.25); margin: 3px; transition: transform .15s; }
.map-pin.active .map-pin-dot { transform: scale(1.35); box-shadow: 0 0 0 6px rgba(37,99,235,.2), 0 3px 8px rgba(0,0,0,.25); }
.job-item { width: 100%; display: block; text-align: left; padding: 14px 16px; border: 0; border-bottom: 1px solid var(--border); background: transparent; cursor: pointer; transition: background .12s; box-shadow: none; min-height: 0; }
.job-item:hover { background: var(--surface-2); box-shadow: none !important; transform: none !important; }
.job-item.active { background: var(--brand-50); box-shadow: inset 3px 0 0 var(--brand) !important; }

/* ===== Settings ===== */
.settings-2col { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); align-items: start; }

/* ===== Expenses extra ===== */
.exp-grid { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: var(--gap); align-items: start; }

/* ===== Info card ===== */
.info-card { background: var(--info-bg); border-color: rgba(99,102,241,.25); }

/* ===== Placeholder ===== */
.placeholder { display: grid; place-items: center; gap: 14px; padding: 70px 20px; text-align: center; }
.placeholder .ph-ico { width: 64px; height: 64px; border-radius: 18px; background: var(--brand-50); color: var(--brand); display: grid; place-items: center; }
.placeholder h3 { font-size: 18px; }
.placeholder p { color: var(--muted); max-width: 360px; }

/* =============================================================
   Modal
   ============================================================= */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.50);
  display: grid; place-items: center;
  z-index: 2000; padding: 24px;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
@media (prefers-reduced-motion: no-preference) {
  .modal-box { animation: modalPop .18s cubic-bezier(.2,.7,.3,1.2); }
}
@keyframes modalPop { from { transform: translateY(12px) scale(.98); opacity:.8; } to { transform: none; opacity:1; } }
.modal-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 20px 22px; border-bottom: 1px solid var(--border); flex: none;
}
.modal-head h3 { font-size: 17px; margin: 0; }
.modal-head p { margin: 3px 0 0; font-size: 13px; color: var(--muted); }
.modal-head .row-act { margin-left: auto; }
.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 22px; border-top: 1px solid var(--border);
  background: var(--surface-2); flex: none;
}

/* =============================================================
   Toast
   ============================================================= */
.sc-toast-wrap {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  z-index: 3000; display: flex; flex-direction: column; align-items: center; gap: 10px;
  pointer-events: none;
}
.toast {
  background: var(--ink); color: #fff;
  font-size: 14px; font-weight: 600;
  padding: 12px 18px; border-radius: 12px;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 9px;
  white-space: nowrap; pointer-events: auto;
}
.toast.error { background: var(--neg); }
.toast.warn  { background: var(--warn); }
.toast svg { color: #4ade80; flex: none; }
.toast.error svg { color: #fff; }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toastUp .25s ease; }
}
@keyframes toastUp { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }

/* =============================================================
   Responsive
   ============================================================= */
@media (max-width: 1180px) {
  .metric-grid, .stat-strip { grid-template-columns: repeat(2, 1fr); }
  .db-grid, .form-grid { grid-template-columns: 1fr; }
  .form-side { position: static; }
  .exp-grid { grid-template-columns: 1fr; }
  .chat-grid, .map-grid { grid-template-columns: 1fr; height: auto; }
  .settings-2col { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .stat-strip { grid-template-columns: 1fr 1fr; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .form-2col { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .login-wrap { grid-template-columns: 1fr; }
}
