/* JS Contract System — Professional ERP redesign */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@300;400;500;600;700&family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --bg: #F6F7F9;
  --surface: #FFFFFF;
  --surface-2: #F9FAFB;
  --border: #E5E7EB;
  --border-strong: #D1D5DB;
  --text: #0F172A;
  --text-2: #475569;
  --text-3: #94A3B8;
  --brand: #2563EB;
  --brand-700: #1D4ED8;
  --brand-50: #EFF6FF;
  --brand-100: #DBEAFE;
  --success: #16A34A;
  --success-50: #F0FDF4;
  --warn: #D97706;
  --warn-50: #FFFBEB;
  --danger: #DC2626;
  --danger-50: #FEF2F2;
  --side: #0B1220;
  --side-2: #111A2E;
  --side-border: #1E293B;
  --side-text: #CBD5E1;
  --side-text-dim: #64748B;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'IBM Plex Sans Thai', 'IBM Plex Sans', system-ui, sans-serif;
  font-feature-settings: 'tnum';
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; font-feature-settings: 'tnum'; }
.num { font-variant-numeric: tabular-nums; }

#root { height: 100%; }

/* ---------- App shell ---------- */
.shell { display: flex; height: 100%; }
.shell.topnav { flex-direction: column; }

.side {
  width: 248px;
  background: var(--side);
  color: var(--side-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid var(--side-border);
}
.side-brand {
  padding: 18px 18px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--side-border);
}
.side-brand .mark {
  width: 32px; height: 32px; border-radius: 7px;
  background: linear-gradient(135deg, #2563EB 0%, #1D4ED8 100%);
  display: grid; place-items: center;
  color: white; font-weight: 700; font-size: 14px;
  font-family: 'IBM Plex Sans', sans-serif;
  letter-spacing: -0.02em;
}
.side-brand .name { font-weight: 600; color: #fff; font-size: 14px; line-height: 1.2; }
.side-brand .sub { color: var(--side-text-dim); font-size: 11px; }

.side-section { padding: 14px 12px 4px; color: var(--side-text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 500; }
.side-nav { padding: 4px 8px; display: flex; flex-direction: column; gap: 2px; }
.side-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 6px;
  color: var(--side-text);
  font-size: 13.5px;
  cursor: pointer;
  border: 1px solid transparent;
  text-align: left;
  background: transparent;
}
.side-item:hover { background: var(--side-2); color: #fff; }
.side-item.active { background: rgba(37,99,235,0.15); color: #fff; border-color: rgba(37,99,235,0.4); }
.side-item .ico { width: 18px; text-align: center; opacity: 0.85; }
.side-item .badge { margin-left: auto; background: var(--side-2); color: var(--side-text); font-size: 11px; padding: 1px 7px; border-radius: 10px; }
.side-item.active .badge { background: var(--brand); color: #fff; }

.side-foot { margin-top: auto; padding: 12px; border-top: 1px solid var(--side-border); }
.side-user { display: flex; align-items: center; gap: 10px; padding: 6px 4px; }
.side-user .avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, #3B82F6, #2563EB); display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 13px; }
.side-user .meta { flex: 1; min-width: 0; }
.side-user .meta .n { color: #fff; font-size: 13px; font-weight: 500; }
.side-user .meta .r { color: var(--side-text-dim); font-size: 11px; }
.side-user .out { color: var(--side-text-dim); background: transparent; border: 1px solid var(--side-border); border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 12px; }
.side-user .out:hover { color: #fff; background: var(--side-2); }

/* topnav variant */
.topbar {
  height: 56px; flex-shrink: 0;
  background: var(--side); color: var(--side-text);
  display: flex; align-items: center; padding: 0 16px; gap: 16px;
  border-bottom: 1px solid var(--side-border);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; padding-right: 16px; border-right: 1px solid var(--side-border); }
.topbar .brand .name { color: #fff; font-weight: 600; }
.topbar .nav { display: flex; gap: 4px; }
.topbar .nav .side-item { padding: 7px 12px; }
.topbar .spacer { flex: 1; }

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.crumb {
  height: 52px; flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 14px;
}
.crumb .path { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px; }
.crumb .path .sep { color: var(--text-3); }
.crumb .path .here { color: var(--text); font-weight: 500; }
.crumb .search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px;
  padding: 6px 10px; min-width: 280px; color: var(--text-3);
}
.crumb .search input { border: 0; outline: 0; background: transparent; flex: 1; font: inherit; color: var(--text); }
.crumb .search kbd { font-family: 'IBM Plex Mono', monospace; font-size: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; color: var(--text-3); }
.crumb .spacer { flex: 1; }
.crumb .ico-btn { width: 34px; height: 34px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface); display: grid; place-items: center; color: var(--text-2); cursor: pointer; }
.crumb .ico-btn:hover { background: var(--surface-2); color: var(--text); }
.crumb .ico-btn .dot { position: absolute; }

.scroll { flex: 1; overflow: auto; }

/* ---------- Page ---------- */
.page { padding: 22px 24px 32px; max-width: 1480px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-title { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 4px; }
.page-sub { color: var(--text-2); font-size: 13px; margin: 0; }
.page-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.card-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.card-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.card-head .sub { color: var(--text-2); font-size: 12px; }
.card-body { padding: 16px 18px; }
.card-flush > .card-body { padding: 0; }

/* ---------- Stat tiles ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  position: relative;
}
.stat .label { color: var(--text-2); font-size: 12px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; margin-top: 6px; font-family: 'IBM Plex Sans', sans-serif; font-variant-numeric: tabular-nums; }
.stat .delta { font-size: 12px; margin-top: 6px; display: inline-flex; align-items: center; gap: 4px; }
.stat .delta.up { color: var(--success); }
.stat .delta.down { color: var(--danger); }
.stat .accent { position: absolute; top: 16px; right: 16px; width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; color: var(--brand); background: var(--brand-50); }
.stat.accent-green .accent { color: var(--success); background: var(--success-50); }
.stat.accent-warn .accent { color: var(--warn); background: var(--warn-50); }
.stat.accent-red .accent { color: var(--danger); background: var(--danger-50); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 7px;
  font: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; border: 1px solid transparent;
  background: var(--surface); color: var(--text);
  border-color: var(--border);
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-700); border-color: var(--brand-700); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: var(--danger-50); border-color: #FECACA; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn.lg { padding: 10px 16px; font-size: 14px; }
.btn .ico { font-size: 12px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.ico-btn {
  width: 30px; height: 30px; border-radius: 6px;
  background: transparent; border: 1px solid transparent;
  display: inline-grid; place-items: center;
  color: var(--text-2); cursor: pointer; font-size: 13px;
}
.ico-btn:hover { background: var(--surface-2); color: var(--text); }
.ico-btn.danger:hover { background: var(--danger-50); color: var(--danger); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--text-2); font-weight: 500; }
.input, .select, textarea.input {
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: 13.5px;
  outline: 0;
  transition: border-color 0.12s, box-shadow 0.12s;
  width: 100%;
}
.input:focus, .select:focus, textarea.input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.input::placeholder { color: var(--text-3); }
.select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2.5'><polyline points='6 9 12 15 18 9'/></svg>"); background-repeat: no-repeat; background-position: right 11px center; padding-right: 32px; }
textarea.input { resize: vertical; min-height: 90px; font-family: 'IBM Plex Mono', monospace; font-size: 12.5px; }

.file-drop {
  border: 1.5px dashed var(--border-strong); border-radius: 8px;
  padding: 14px; background: var(--surface-2);
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; transition: all 0.15s;
}
.file-drop:hover { border-color: var(--brand); background: var(--brand-50); }
.file-drop .ico { width: 36px; height: 36px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); display: grid; place-items: center; color: var(--brand); }
.file-drop .t { font-size: 13px; font-weight: 500; }
.file-drop .s { font-size: 11px; color: var(--text-3); }

/* ---------- Table ---------- */
.tbl-wrap { overflow: auto; }
table.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.tbl thead th {
  text-align: left; font-weight: 500;
  color: var(--text-2); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em;
  background: var(--surface-2);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  border-top: 1px solid var(--border);
  white-space: nowrap;
}
.tbl thead th:first-child { padding-left: 18px; }
.tbl thead th:last-child { padding-right: 18px; }
.tbl thead th.r { text-align: right; }
.tbl thead th.c { text-align: center; }
.tbl tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody td:first-child { padding-left: 18px; }
.tbl tbody td:last-child { padding-right: 18px; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr.selected { background: var(--brand-50); }
.tbl tbody tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--brand); }
.tbl .r { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .c { text-align: center; }
.tbl .dim { color: var(--text-2); }
.tbl .num { font-family: 'IBM Plex Sans', sans-serif; font-variant-numeric: tabular-nums; font-weight: 500; }
.tbl .strong { font-weight: 600; }
.tbl .row-actions { display: flex; gap: 2px; justify-content: flex-end; }

/* ---------- Pills / Tags ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 500;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.pill.brand { background: var(--brand-50); color: var(--brand-700); border-color: #BFDBFE; }
.pill.success { background: var(--success-50); color: #15803D; border-color: #BBF7D0; }
.pill.warn { background: var(--warn-50); color: #B45309; border-color: #FDE68A; }
.pill.danger { background: var(--danger-50); color: var(--danger); border-color: #FECACA; }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- Progress ---------- */
.prog { display: flex; flex-direction: column; gap: 4px; min-width: 120px; }
.prog-bar { height: 6px; background: #E5E7EB; border-radius: 3px; overflow: hidden; }
.prog-fill { height: 100%; background: var(--brand); border-radius: 3px; transition: width 0.4s ease; }
.prog-fill.success { background: var(--success); }
.prog-fill.warn { background: var(--warn); }
.prog-meta { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ---------- Detail panel ---------- */
.dual { display: grid; grid-template-columns: 1fr 420px; gap: 18px; align-items: start; }
.dual.collapsed { grid-template-columns: 1fr; }
.detail-panel { position: sticky; top: 18px; }
.detail-empty { padding: 40px 24px; text-align: center; color: var(--text-3); }
.detail-empty .ico { font-size: 32px; margin-bottom: 8px; opacity: 0.4; }

.kv { display: grid; grid-template-columns: 100px 1fr; gap: 8px 14px; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; color: var(--text); font-weight: 500; }

/* ---------- Activity feed ---------- */
.feed { display: flex; flex-direction: column; }
.feed-item { padding: 12px 18px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; }
.feed-item:last-child { border-bottom: 0; }
.feed-item .av { width: 28px; height: 28px; border-radius: 50%; background: var(--brand-50); color: var(--brand-700); display: grid; place-items: center; font-size: 12px; font-weight: 600; flex-shrink: 0; }
.feed-item .content { flex: 1; font-size: 13px; }
.feed-item .meta { color: var(--text-3); font-size: 11.5px; margin-top: 2px; }
.feed-item .amt { color: var(--success); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  z-index: 50; display: grid; place-items: center;
  padding: 20px; animation: fade 0.15s;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface); border-radius: 12px;
  width: 100%; max-width: 560px;
  max-height: 92vh; overflow: auto;
  box-shadow: 0 24px 60px -12px rgba(15,23,42,0.4);
  animation: pop 0.18s;
}
.modal.lg { max-width: 800px; }
.modal.xl { max-width: 1000px; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 14px; }
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 600; flex: 1; }
.modal-head .ico { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand); }
.modal-body { padding: 20px 22px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); border-radius: 0 0 12px 12px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100%; display: grid; grid-template-columns: 1fr 1fr; }
.login-side { background: var(--side); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-side::before { content: ''; position: absolute; inset: 0; background: radial-gradient(800px 400px at 20% 0%, rgba(37,99,235,0.2), transparent 60%), radial-gradient(600px 400px at 80% 100%, rgba(37,99,235,0.15), transparent 60%); }
.login-side > * { position: relative; }
.login-side .brand { display: flex; align-items: center; gap: 10px; }
.login-side .brand .name { font-weight: 600; font-size: 15px; }
.login-side .pitch { max-width: 420px; }
.login-side .pitch h1 { font-size: 32px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; margin: 0 0 12px; }
.login-side .pitch p { color: rgba(203,213,225,0.85); font-size: 15px; line-height: 1.55; margin: 0; }
.login-side .quote { background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); border-radius: 10px; padding: 16px 18px; font-size: 13px; color: rgba(203,213,225,0.95); }
.login-side .quote .who { color: rgba(203,213,225,0.6); margin-top: 6px; font-size: 12px; }

.login-form { padding: 48px; display: flex; flex-direction: column; justify-content: center; max-width: 480px; margin: 0 auto; width: 100%; }
.login-form h2 { font-size: 24px; font-weight: 600; margin: 0 0 6px; }
.login-form .sub { color: var(--text-2); margin: 0 0 28px; }
.login-form .form-grid { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skel { background: linear-gradient(90deg, #F1F5F9 0%, #E2E8F0 50%, #F1F5F9 100%); background-size: 200% 100%; border-radius: 4px; animation: skel 1.4s infinite; }
@keyframes skel { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.hstack { display: flex; align-items: center; gap: 8px; }
.vstack { display: flex; flex-direction: column; gap: 8px; }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.mt-6 { margin-top: 6px; } .mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; }

/* ---------- Toast ---------- */
.toast-stack { position: fixed; top: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; min-width: 280px; box-shadow: 0 8px 24px -8px rgba(15,23,42,0.2); display: flex; gap: 10px; align-items: flex-start; animation: pop 0.18s; }
.toast .ico { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; flex-shrink: 0; }
.toast.success .ico { background: var(--success-50); color: var(--success); }
.toast.err .ico { background: var(--danger-50); color: var(--danger); }
.toast .t { font-weight: 500; font-size: 13px; }
.toast .s { font-size: 12px; color: var(--text-2); margin-top: 2px; }

/* ---------- Progress modal (for fixing report-loading pain) ---------- */
.prog-modal-bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin: 14px 0 4px; }
.prog-modal-fill { height: 100%; background: linear-gradient(90deg, var(--brand) 0%, #60A5FA 100%); border-radius: 4px; transition: width 0.4s ease; }
.prog-steps { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.prog-step { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }
.prog-step .dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); display: grid; place-items: center; flex-shrink: 0; font-size: 9px; }
.prog-step.done .dot { background: var(--success); border-color: var(--success); color: #fff; }
.prog-step.active .dot { border-color: var(--brand); color: var(--brand); }
.prog-step.active { color: var(--text); font-weight: 500; }
.prog-step.done { color: var(--text); }

/* responsive collapse */
@media (max-width: 1100px) {
  .dual { grid-template-columns: 1fr; }
  .detail-panel { position: static; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
