:root {
  --bg: #f4f6f9; --card: #fff; --line: #dde2ea; --text: #1d2433; --muted: #6b7486;
  --primary: #2f6fde; --danger: #d9534f; --warn: #fff5d6;
  --st0: #2f6fde; --st1: #2a9d5c; --st2: #e08a00; --st3: #8a93a6;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", "Hiragino Sans", "Noto Sans JP", sans-serif;
}
body.noscroll { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.05rem; margin: .2rem 0 .8rem; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
  background: #1f2a44; color: #fff; padding: .6rem 1rem; position: sticky; top: 0; z-index: 10;
}
.topbar .brand { color: #fff; font-weight: 700; font-size: 1.1rem; }
.topbar nav { display: flex; flex-wrap: wrap; gap: .2rem; align-items: center; }
.topbar nav a, .topbar .linkbtn {
  color: #cfd7ea; padding: .35rem .7rem; border-radius: 6px; background: none; border: 0; font: inherit; cursor: pointer;
}
.topbar nav a.on, .topbar nav a:hover, .topbar .linkbtn:hover { background: #33415f; color: #fff; text-decoration: none; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; margin-bottom: 1rem; }
.flash { background: #e8f1ff; border: 1px solid #b9d2fb; padding: .6rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.req { color: var(--danger); }
.preline { white-space: pre-line; }
.nowrap { white-space: nowrap; }
.r { text-align: right; }
.page-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; margin-bottom: .6rem; }
.page-head h1, .page-head h2 { margin: 0; }
.btn-row { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.btn {
  display: inline-block; padding: .45rem .9rem; border: 1px solid var(--line); border-radius: 7px; background: #fff;
  color: var(--text); font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f0f3f8; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #2459b8; }
.btn.danger { color: var(--danger); border-color: #efc4c3; }
.btn.small { padding: .2rem .55rem; font-size: .85rem; }
.btn.full { width: 100%; }
form.inline { display: inline; margin: 0; }
input, select, textarea {
  font: inherit; padding: .42rem .55rem; border: 1px solid #c9d0db; border-radius: 6px; background: #fff; width: 100%;
}
select.auto { width: auto; }
input[type=file] { padding: .3rem; }
label { display: block; font-size: .88rem; color: #3b4458; }
label > input, label > select, label > textarea { margin-top: .2rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem 1rem; }
.form-grid .span2 { grid-column: 1 / -1; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; }
.login-box { max-width: 360px; margin: 3rem auto; }
.login-box label { margin-bottom: .7rem; }

/* status badges */
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; color: #fff; vertical-align: middle; white-space: nowrap; }
.badge.st-0 { background: var(--st0); }
.badge.st-1 { background: var(--st1); }
.badge.st-2 { background: var(--st2); }
.badge.st-3 { background: var(--st3); }
.badge.warn { background: #fff; color: var(--st2); border: 1px solid var(--st2); }
.dday { display: inline-block; font-size: .8rem; font-weight: 700; padding: 0 .35rem; border-radius: 4px; color: var(--muted); background: #eef1f6; }
.dday.near { color: #9a5d00; background: #fff1d6; }
.dday.soon { color: #fff; background: var(--st2); }
.dday.over { color: #fff; background: var(--danger); }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.stat {
  display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--st0);
  border-radius: 10px; padding: .7rem 1rem; color: var(--text);
}
.stat:hover { text-decoration: none; background: #f8fafd; }
.stat span { font-size: .85rem; color: var(--muted); }
.stat b { font-size: 1.8rem; line-height: 1.2; }
.stat.st-1 { border-left-color: var(--st1); }
.stat.st-2 { border-left-color: var(--st2); }
.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li + li { border-top: 1px solid var(--line); }
.mini-list a { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .5rem .2rem; color: var(--text); }
.mini-list a:hover { background: #f5f8fc; text-decoration: none; }
.mini-list .ml-main { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-list .ml-side { white-space: nowrap; }

/* list */
.tabs { display: flex; gap: .3rem; overflow-x: auto; margin-bottom: .7rem; border-bottom: 1px solid var(--line); }
.tabs a { padding: .45rem .8rem; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--text); font-weight: 700; border-bottom-color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs .cnt { font-size: .78rem; background: #eef1f6; border-radius: 999px; padding: 0 .4rem; color: var(--muted); }
.search { display: flex; gap: .4rem; margin-bottom: .8rem; }
.search input[type=search] { flex: 1; }
.search select { width: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { padding: .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data thead th { background: #f0f3f8; text-align: left; white-space: nowrap; }
table.linkrows tbody tr { cursor: pointer; }
table.linkrows tbody tr:hover td { background: #f5f8fc; }
table.linkrows tr.expiring td { background: #fff8e8; }
table.linkrows tr.expiring td:first-child { box-shadow: inset 4px 0 0 var(--st2); }
table.linkrows tr.closed td { color: var(--muted); }
table.linkrows td.name a { font-weight: 700; }

/* condition badges (관리회사) */
.badge.ok-yes { background: var(--st1); }
.badge.ok-no { background: var(--danger); }
.badge.ok-cond { background: var(--st2); }
.badge.ok-unknown { background: #eef1f6; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .3rem; }
.chip { background: #eef4ff; border: 1px solid #c9dafb; border-radius: 6px; padding: 0 .45rem; font-size: .85rem; }
ul.doclist { margin: 0; padding-left: 1.1rem; }
ul.doclist li { margin: .05rem 0; }
.screening { background: #fff5d6; border: 1px solid #f2cf8d; border-radius: 8px; padding: .55rem .75rem; }
.screening b { display: block; font-size: .85rem; color: #9a5d00; }
.company-card { border-top: 4px solid var(--st2); }
.company-card .page-head h2 { margin: 0; }
.warn-card { border-color: #f2cf8d; background: #fffaf0; max-width: 720px; }
.detail-grid { align-items: start; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.flabel { font-size: .88rem; color: #3b4458; }
.radios { display: flex; flex-wrap: wrap; gap: .3rem 1rem; }
.radio { display: inline-flex; align-items: center; gap: .3rem; font-size: .95rem; color: var(--text); }
.radio input, label.check input { width: auto; margin: 0; }
label.check { display: flex; gap: .4rem; align-items: center; margin: .2rem 0; font-size: .95rem; color: var(--text); }
.doc-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 0 1rem; margin-bottom: .4rem; }
.input-group { display: flex; gap: .3rem; align-items: center; margin-bottom: .3rem; }
.input-group input { flex: 1; }
.form-grid h2 { margin: .6rem 0 0; border-top: 1px solid var(--line); padding-top: .8rem; }

/* detail */
dl.info { display: grid; grid-template-columns: 7rem 1fr; gap: .45rem 1rem; margin: 0 0 .8rem; }
dl.info dt { color: var(--muted); font-size: .9rem; }
dl.info dd { margin: 0; }
.upload { display: flex; gap: .5rem; align-items: center; }
.upload input[type=file] { flex: 1; }
.file-list { list-style: none; margin: .5rem 0 0; padding: 0; }
.file-list li { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; padding: .55rem 0; border-top: 1px solid var(--line); }
.file-open { display: flex; align-items: center; gap: .5rem; flex: 1; min-width: 12rem; background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; text-align: left; }
.file-open:hover .fname { text-decoration: underline; }
.ficon { font-size: .7rem; font-weight: 700; color: #fff; background: var(--danger); border-radius: 4px; padding: .15rem .35rem; }
.fname { word-break: break-all; }
.danger-zone { text-align: right; }

/* preview modal */
.modal { position: fixed; inset: 0; background: rgba(15, 20, 35, .7); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal[hidden] { display: none; }
.modal-box { background: #fff; border-radius: 10px; width: min(1000px, 100%); height: min(92vh, 100%); display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .5rem .8rem; border-bottom: 1px solid var(--line); }
.modal-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { flex: 1; min-height: 0; background: #525659; display: flex; align-items: center; justify-content: center; overflow: auto; }
.modal-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.modal-body > img { max-width: 100%; max-height: 100%; object-fit: contain; background: #fff; }
.pdf-pages { align-self: stretch; width: 100%; overflow: auto; padding: .5rem; -webkit-overflow-scrolling: touch; }
.pdf-pages img { display: block; width: 100%; max-width: 900px; height: auto; margin: 0 auto .5rem; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.preview-fail { color: #fff; padding: 1rem; text-align: center; }

/* mobile */
@media (max-width: 720px) {
  .wrap { padding: .6rem; }
  .grid2, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .stats { gap: .4rem; }
  .stat { padding: .5rem .6rem; }
  .stat b { font-size: 1.5rem; }
  .search { flex-wrap: wrap; }
  .search input[type=search] { flex-basis: 100%; }
  table.linkrows thead { display: none; }
  table.linkrows, table.linkrows tbody, table.linkrows tr, table.linkrows td { display: block; width: 100%; }
  table.linkrows tr { border: 1px solid var(--line); border-radius: 8px; margin-bottom: .5rem; padding: .4rem .6rem; }
  table.linkrows td { border: 0; padding: .12rem 0; text-align: left; }
  table.linkrows td[data-label]::before { content: attr(data-label); display: inline-block; width: 4.5rem; color: var(--muted); font-size: .8rem; }
  table.linkrows tr.expiring { background: #fff8e8; border-color: #f2cf8d; }
  table.linkrows tr.expiring td, table.linkrows tr.expiring td:first-child { background: none; box-shadow: none; }
  dl.info { grid-template-columns: 5.5rem 1fr; }
  .modal { padding: 0; }
  .modal-box { border-radius: 0; height: 100%; }
  .modal-head { padding: .4rem .5rem; }
  .modal-head .btn-row { flex-wrap: nowrap; gap: .25rem; }
  .modal-title { font-size: .9rem; }
}

/* candidates (후보 매물) */
.badge.cand-0 { background: #e8f1ff; color: var(--st0); border: 1px solid #b9d2fb; }
.badge.cand-1 { background: var(--st2); }
.badge.cand-2 { background: #eef1f6; color: var(--muted); }
.badge.cand-3 { background: var(--st1); }
.badge.cand-total { background: #fff; color: var(--text); border: 1px solid var(--line); }
.cand-sum { margin-top: .15rem; }
.cand-counts { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.cand-add { margin-bottom: .8rem; }
.cand-add > summary { list-style: none; display: inline-block; }
.cand-add > summary::-webkit-details-marker { display: none; }
.cand-add[open] > summary { margin-bottom: .6rem; }
.cand-form { background: #f8fafd; border: 1px dashed var(--line); border-radius: 8px; padding: .8rem; }
.cand-list { display: grid; gap: .7rem; }
.cand { border: 1px solid var(--line); border-left: 4px solid var(--st0); border-radius: 8px; padding: .7rem .8rem; display: flex; flex-direction: column; gap: .4rem; }
.cand.cand-st-1 { border-left-color: var(--st2); }
.cand.cand-st-2 { border-left-color: #c3c9d4; background: #fafbfc; }
.cand.cand-st-2 .cand-title b { color: var(--muted); text-decoration: line-through; }
.cand.cand-st-3 { border-left-color: var(--st1); background: #f3fbf6; }
.cand-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; flex-wrap: wrap; }
.cand-title { min-width: 0; word-break: break-word; }
.cand-meta { display: flex; flex-wrap: wrap; gap: .2rem 1rem; }
.cand-memo { background: #f5f7fa; border-radius: 6px; padding: .4rem .6rem; font-size: .9rem; }
.cond-compact { display: flex; flex-direction: column; gap: .3rem; border-top: 1px dashed var(--line); padding-top: .45rem; }
.cond-badges { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip.doc { background: #f3f5f8; border-color: var(--line); }
.cand-actions { justify-content: flex-end; }
.modal-box.dialog { height: auto; max-height: 92vh; overflow: auto; width: min(620px, 100%); padding: 1rem 1.1rem; display: block; }
.modal-box.dialog h2 { margin-top: 0; }
table.compare td, table.compare th { font-size: .9rem; }
table.compare tr.changed td { background: #fff5d6; font-weight: 600; }
@media (max-width: 720px) {
  .modal .modal-box.dialog { height: auto; border-radius: 10px; margin: .6rem; }
  .modal-box.dialog .btn-row .btn { flex: 1 1 100%; text-align: center; }
}

/* client contacts (연락처) */
.contact-rows { display: flex; flex-direction: column; gap: .4rem; }
.contact-row { display: grid; grid-template-columns: 11rem minmax(0, 1fr) minmax(0, 1fr) auto; gap: .35rem; align-items: center; }
.contact-row .contact-label { display: none; }
.contact-row.is-other { grid-template-columns: 11rem 9rem minmax(0, 1fr) minmax(0, 1fr) auto; }
.contact-row.is-other .contact-label { display: block; }
.contact-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .25rem; }
.contact-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .4rem; }
.contact-icon { min-width: 3em; flex: none; white-space: nowrap; }
.contact-kind-label { font-size: .8rem; color: var(--muted); background: #eef1f6; border-radius: 4px; padding: 0 .35rem; white-space: nowrap; }
.contact-val { font-weight: 600; word-break: break-all; }
.nowrap-ellipsis { max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.more { background: #eef1f6; border-radius: 999px; padding: 0 .35rem; font-size: .75rem; }
@media (max-width: 720px) {
  .contact-row, .contact-row.is-other { grid-template-columns: minmax(0, 1fr) auto; border: 1px solid var(--line); border-radius: 8px; padding: .4rem; }
  .contact-row .contact-kind { grid-column: 1; grid-row: 1; }
  .contact-row .contact-remove { grid-column: 2; grid-row: 1; }
  .contact-row .contact-label, .contact-row .contact-value, .contact-row .contact-memo { grid-column: 1 / -1; }
  .nowrap-ellipsis { max-width: 100%; }
}

/* 진행 히스토리 (timeline) */
ol.timeline { list-style: none; margin: 0; padding: 0 0 0 .2rem; position: relative; }
ol.timeline::before { content: ""; position: absolute; left: .55rem; top: .4rem; bottom: .4rem; width: 2px; background: var(--line); }
.act { position: relative; display: grid; grid-template-columns: 8.6rem 6.2rem minmax(0, 1fr); gap: .5rem; align-items: baseline; padding: .35rem 0 .35rem 1.5rem; }
.act::before { content: ""; position: absolute; left: .3rem; top: .75rem; width: .6rem; height: .6rem; border-radius: 50%; background: #fff; border: 2px solid var(--st0); }
.act time { font-size: .82rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.act-badge { font-size: .78rem; font-weight: 600; background: #eef1f6; border-radius: 999px; padding: 0 .5rem; white-space: nowrap; justify-self: start; }
.act-msg { word-break: break-word; }
.act-created::before { border-color: var(--st1); background: var(--st1); }
.act-status::before, .act-confirm::before { border-color: var(--st1); }
.act-confirm .act-badge { background: #e3f5ea; color: #1d7a45; }
.act-status .act-badge { background: #e8f1ff; color: var(--st0); }
.act-candidate::before, .act-candidate_status::before { border-color: var(--st2); }
.act-system::before { border-color: #c3c9d4; }
.act-system .act-msg { color: var(--muted); font-size: .9rem; }
.timeline-more > summary { list-style: none; display: inline-block; margin: .4rem 0 0 1.7rem; }
.timeline-more > summary::-webkit-details-marker { display: none; }
.timeline-more[open] > summary { display: none; }
.dates2 .dlabel { display: inline-block; font-size: .72rem; color: var(--muted); background: #eef1f6; border-radius: 3px; padding: 0 .25rem; }
@media (max-width: 720px) {
  .act { grid-template-columns: auto minmax(0, 1fr); gap: .1rem .5rem; }
  .act time { grid-column: 1; }
  .act-badge { grid-column: 2; }
  .act-msg { grid-column: 1 / -1; }
  .dates2 div { display: inline-block; margin-right: .7rem; }
}
