/* 테마: 색은 모두 이 변수로만 쓴다. 사용자가 고른 테마는 <html data-theme="...">로 들어오고,
   "시스템"을 고르면 data-theme 없이 운영체제 밝기 설정을 따른다.
   설정 화면의 견본도 같은 [data-theme] 블록으로 칠한다. 테마를 더하면 User.Theme에도 넣는다. */
:root, [data-theme="light"] {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #667085;
  --border: #e3e6eb;
  --primary: #1d5bd8;
  --primary-text: #ffffff;
  --danger: #c4320a;
  --danger-bg: #fef3f2;
  --ok-bg: #ecfdf3;
  --ok: #067647;
  --warn-bg: #fffaeb;
  --warn: #b54708;
  --info-bg: #eff4ff;
  --info: #1d4ed8;
  --neutral-bg: #f2f4f7;
  --radius: 8px;
  color-scheme: light;
}

/* 시스템이 다크일 때는 아래 [data-theme="dark"]와 같은 값. 고칠 때 둘 다 고친다 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #12151b;
    --surface: #1b2029;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --border: #2c3340;
    --primary: #5b8def;
    --primary-text: #0b1220;
    --danger: #f97066;
    --danger-bg: #3a1a17;
    --ok-bg: #12321f;
    --ok: #6ce9a6;
    --warn-bg: #3a2a0f;
    --warn: #fdb022;
    --info-bg: #172a52;
    --info: #9bb8ff;
    --neutral-bg: #262c37;
    color-scheme: dark;
  }
}

/* 소프트 그레이: 순백을 빼고 대비를 낮춘 밝은 화면 */
[data-theme="soft"] {
  --bg: #e9ebee;
  --surface: #f3f4f6;
  --text: #2a303b;
  --muted: #5f6878;
  --border: #d5d9df;
  --primary: #2f5fb8;
  --primary-text: #ffffff;
  --danger: #b42318;
  --danger-bg: #f6e3e0;
  --ok-bg: #dfeee4;
  --ok: #146c43;
  --warn-bg: #f4ead3;
  --warn: #8f4a0b;
  --info-bg: #e0e7f4;
  --info: #2948a8;
  --neutral-bg: #e2e5e9;
  color-scheme: light;
}

/* 종이: 누런 종이색의 따뜻한 밝은 화면 */
[data-theme="paper"] {
  --bg: #efe8da;
  --surface: #f8f3e8;
  --text: #3a3226;
  --muted: #665b4a;
  --border: #ddd3c0;
  --primary: #2f5d8a;
  --primary-text: #ffffff;
  --danger: #a63a1e;
  --danger-bg: #f3dfd3;
  --ok-bg: #e2e8d2;
  --ok: #4a6420;
  --warn-bg: #f3e3c1;
  --warn: #8a560c;
  --info-bg: #dde3e6;
  --info: #2f5d8a;
  --neutral-bg: #e8e0cf;
  color-scheme: light;
}

/* 세이지: 연녹색 바탕의 눈 보호 화면 */
[data-theme="sage"] {
  --bg: #dfe8dc;
  --surface: #eef3eb;
  --text: #26322a;
  --muted: #56655a;
  --border: #c9d6c5;
  --primary: #2a6a52;
  --primary-text: #ffffff;
  --danger: #a8321c;
  --danger-bg: #f1dcd5;
  --ok-bg: #d3e6d0;
  --ok: #2d6a2f;
  --warn-bg: #efe4c4;
  --warn: #85520c;
  --info-bg: #d6e2e8;
  --info: #2b5a85;
  --neutral-bg: #d7e1d3;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #12151b;
  --surface: #1b2029;
  --text: #e6e9ef;
  --muted: #98a2b3;
  --border: #2c3340;
  --primary: #5b8def;
  --primary-text: #0b1220;
  --danger: #f97066;
  --danger-bg: #3a1a17;
  --ok-bg: #12321f;
  --ok: #6ce9a6;
  --warn-bg: #3a2a0f;
  --warn: #fdb022;
  --info-bg: #172a52;
  --info: #9bb8ff;
  --neutral-bg: #262c37;
  color-scheme: dark;
}

/* 딤: 회색빛으로 대비를 낮춘 어두운 화면 */
[data-theme="dim"] {
  --bg: #22272e;
  --surface: #2d333b;
  --text: #cdd5de;
  --muted: #a0aab6;
  --border: #444c56;
  --primary: #6d9ae0;
  --primary-text: #10161f;
  --danger: #f0837a;
  --danger-bg: #4a2a2a;
  --ok-bg: #233d2e;
  --ok: #79c99a;
  --warn-bg: #45381f;
  --warn: #e0ac5a;
  --info-bg: #263a5a;
  --info: #9fbaf0;
  --neutral-bg: #373e48;
  color-scheme: dark;
}

/* 야간: 파란빛을 줄인 따뜻한 어두운 화면 */
[data-theme="night"] {
  --bg: #1c1915;
  --surface: #26221d;
  --text: #dccfb9;
  --muted: #a89b86;
  --border: #3a342c;
  --primary: #e0a458;
  --primary-text: #1c1915;
  --danger: #ef8a72;
  --danger-bg: #43231b;
  --ok-bg: #2a3320;
  --ok: #b5cc85;
  --warn-bg: #43341a;
  --warn: #ecc66a;
  --info-bg: #253039;
  --info: #9fb6c9;
  --neutral-bg: #312c25;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.danger { color: var(--danger); }
.error { color: var(--danger); display: block; }

/* 상단바 */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem;
  padding: .75rem 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); }
.nav { display: flex; flex-wrap: wrap; gap: .25rem 1rem; flex: 1; }
.nav a { color: var(--text); }
.nav .nav-primary { color: var(--primary); font-weight: 600; }
.nav-user { display: flex; align-items: center; gap: .5rem; color: var(--muted); margin: 0; }
.nav-search { margin: 0; }
.nav-search input { width: 13rem; padding: .3rem .6rem; font-size: .9rem; }

/* 업무 화면이라 폭 제한 없이 화면을 다 쓴다. 양옆 여백만 화면 폭에 맞춰 16~32px */
.page { padding: 1.25rem clamp(16px, 2vw, 32px) 3rem; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }

.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li { padding: .6rem .9rem; border-radius: var(--radius); background: var(--ok-bg); color: var(--ok); }
.messages .msg-error { background: var(--danger-bg); color: var(--danger); }

.block { margin-bottom: 1.75rem; }
.count { color: var(--muted); font-weight: 400; margin-left: .25rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }

/* 버튼 */
.button {
  display: inline-block; padding: .5rem 1rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; cursor: pointer; text-align: center;
}
.button-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
.button-block { display: block; width: 100%; }
button.link { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; }

/* 배지 */
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .8rem; white-space: nowrap; background: var(--neutral-bg); color: var(--muted); }
.status-new { background: var(--info-bg); color: var(--info); }
.status-in_progress { background: var(--ok-bg); color: var(--ok); }
.status-waiting { background: var(--warn-bg); color: var(--warn); }
.prio-1, .prio-2 { background: var(--danger-bg); color: var(--danger); margin-right: .25rem; }

/* 티켓 목록 */
.tickets { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.tickets > li + li { border-top: 1px solid var(--border); }
.tickets .empty { padding: .75rem 1rem; color: var(--muted); }
.ticket-row {
  display: grid; grid-template-columns: 6.5rem minmax(0, 1fr) auto 8.5rem; grid-template-areas: "num title status due" "num meta status who";
  gap: 0 1rem; align-items: center; padding: .65rem 1rem; color: var(--text);
}
.ticket-row:hover { background: var(--bg); }
.ticket-row.is-overdue .t-due { color: var(--danger); font-weight: 600; }
.t-num { grid-area: num; color: var(--muted); font-variant-numeric: tabular-nums; }
.t-title { grid-area: title; font-weight: 600; }
.t-meta { grid-area: meta; color: var(--muted); font-size: .85rem; }
.t-meta .t-product::before { content: "· "; }
.t-status { grid-area: status; }
.t-due { grid-area: due; font-variant-numeric: tabular-nums; white-space: nowrap; }
.t-who { grid-area: who; min-width: 0; color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 통합 검색 (templates/tickets/search.html) */
.search-form { display: flex; gap: .5rem; max-width: 44rem; margin-bottom: 1rem; }
.search-form input { flex: 1; min-width: 0; font-size: 1rem; }
.search-section { margin-bottom: 1.5rem; }

@media (max-width: 720px) {
  .ticket-row {
    grid-template-columns: 1fr auto;
    grid-template-areas: "num status" "title title" "meta meta" "due who";
    gap: .15rem .5rem;
  }
  .t-status { justify-self: end; }
  .t-who { text-align: right; }
}

/* 탭 */
.tabs { display: flex; flex-wrap: wrap; gap: .5rem; }
.tabs a { padding: .3rem .8rem; border: 1px solid var(--border); border-radius: 999px; color: var(--text); background: var(--surface); }
.tabs a.active { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }

/* 폼 */
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .85rem; }
.field label { font-weight: 600; font-size: .9rem; }
input, select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit;
}
input[type="checkbox"] { width: auto; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.form-card { max-width: 640px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }

/* 상세 */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.5rem; align-items: start; }
@media (max-width: 900px) { .detail { grid-template-columns: minmax(0, 1fr); } }
@media (min-width: 1600px) { .detail { grid-template-columns: minmax(0, 1fr) 380px; } }
.summary { margin-bottom: 1.5rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .75rem 1.5rem; margin: 0; }
.facts dt { color: var(--muted); font-size: .8rem; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.description { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.ai-summary { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.email-subject { font-weight: 600; margin-top: .3rem; }
.email-body { max-height: 24rem; overflow-y: auto; overflow-wrap: anywhere; }
.description p:first-child { margin-top: 0; }

.timeline { list-style: none; margin: 0 0 1rem; padding: 0; }
.event { padding: .6rem .9rem; border-left: 3px solid var(--border); margin-bottom: .5rem; background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0; }
.event-head { display: flex; flex-wrap: wrap; gap: .5rem; align-items: baseline; }
.event-body { margin-top: .3rem; white-space: normal; }
.kind-note { border-left-color: var(--warn); }
.kind-email_in { border-left-color: var(--info); }
.kind-email_out { border-left-color: var(--ok); }
.kind-escalation, .kind-reminder { border-left-color: var(--danger); }
.changes { margin: .3rem 0 0; padding-left: 1.1rem; color: var(--muted); }
.changes strong { color: var(--text); }

/* 메일 패널: 전달·인용으로 한 통에 쌓인 메일을 한 통씩. 색은 타임라인의 고객 메일·답장과 같다 */
.mails { display: grid; gap: .5rem; }
.mail { min-width: 0; padding: .5rem .9rem; border-left: 3px solid var(--border); border-radius: 0 var(--radius) var(--radius) 0; }
.mail-customer { border-left-color: var(--info); }
.mail-staff { border-left-color: var(--ok); }
.mail-head { display: flex; flex-wrap: wrap; gap: .25rem .5rem; align-items: baseline; cursor: pointer; list-style: none; }
.mail-head::-webkit-details-marker { display: none; }
.mail-via { color: var(--muted); font-size: .8rem; }
.mail-snippet { flex: 1 1 12rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .85rem; }
.mail[open] .mail-snippet { display: none; }
.mail-to { margin: .2rem 0 0; color: var(--muted); font-size: .8rem; overflow-wrap: anywhere; }
.mail-body { margin-top: .5rem; overflow-wrap: anywhere; }
.mail > p.muted { margin: .4rem 0 0; font-size: .85rem; }
.mail-raw { margin-top: .4rem; }
.mail-raw > summary { cursor: pointer; color: var(--muted); font-size: .85rem; }

/* 패널: 상세 화면의 섹션. 제목 줄과 본문을 나눠 섹션끼리 확실히 구분한다 */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1.25rem; overflow: hidden; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .75rem; padding: .65rem 1rem; background: var(--neutral-bg); border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0; font-size: 1rem; }
.panel-meta { color: var(--muted); font-size: .85rem; }
.panel-aside { margin-left: auto; }
.panel-body { padding: 1rem; }
.panel-body > :last-child { margin-bottom: 0; }
.panel-body.flush { padding: 0; }
.panel-body.flush > .tickets { border: 0; border-radius: 0; }
.empty-row { margin: 0; padding: .75rem 1rem; color: var(--muted); }
.panel-foot { padding: .65rem 1rem; border-top: 1px solid var(--border); }
.panel-links { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; }
.panel-links > details[open] { flex-basis: 100%; }
.panel-links summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.panel-links form { margin-top: .75rem; }
.history-stage { margin: .75rem 0 .25rem; font-size: .95rem; }

/* 접는 패널: 닫혀 있으면 제목 줄 한 줄만 보인다 */
.fold > summary { cursor: pointer; list-style: none; flex-wrap: nowrap; }
.fold > summary::-webkit-details-marker { display: none; }
.fold:not([open]) > summary { border-bottom: 0; }
.fold > summary h2 { white-space: nowrap; }
.fold-latest { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .85rem; }
.fold-latest strong { color: var(--text); font-weight: 600; margin-right: .25rem; }
.fold-hint { margin-left: auto; }
.fold-hint::after { content: "펼치기"; color: var(--primary); font-size: .85rem; white-space: nowrap; }
.fold[open] .fold-hint::after { content: "접기"; }
.fold[open] .fold-latest { display: none; }

.note-form { display: flex; flex-wrap: wrap; align-items: flex-start; gap: .5rem; }
.note-form textarea { flex: 1 1 18rem; width: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* 업무 단계 */
.stage-chip { display: inline-block; padding: 0 .4rem; border-radius: 4px; background: var(--neutral-bg); color: var(--text); font-size: .8rem; margin-right: .25rem; }
.stage-chip.is-late { background: var(--danger-bg); color: var(--danger); }

.stepper { list-style: none; display: flex; flex-wrap: wrap; gap: .4rem .25rem; padding: 0; margin: 0 0 1rem; }
.step { display: flex; align-items: center; gap: .35rem; padding: .25rem .65rem .25rem .3rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); font-size: .85rem; }
.step-mark { display: inline-flex; align-items: center; justify-content: center; width: 1.4rem; height: 1.4rem; border-radius: 50%; background: var(--neutral-bg); font-size: .75rem; font-weight: 600; }
.step-done { color: var(--text); }
.step-done .step-mark { background: var(--ok-bg); color: var(--ok); }
.step-current { border-color: var(--primary); color: var(--text); font-weight: 600; }
.step-current .step-mark { background: var(--primary); color: var(--primary-text); }

.stage-card { margin-bottom: 1rem; }
.stage-block { margin-top: 1.25rem; padding-left: 1rem; border-left: 3px solid var(--primary); }
.panel-body > .stage-block:first-child { margin-top: 0; }
.stage-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem 1rem; }
.stage-head h3 { margin: 0; font-size: 1.1rem; }
.checklist { list-style: none; padding: 0; margin: .75rem 0 1rem; }
.check-item { display: flex; flex-direction: column; gap: .25rem; padding: .6rem 0; border-top: 1px solid var(--border); }
.check-item:first-child { border-top: 0; }
.check-item.is-done > label, .check-item.is-done .check-label span { color: var(--muted); }
.check-label { display: flex; gap: .6rem; align-items: flex-start; cursor: pointer; }
.check-label input { margin-top: .25rem; width: 1.1rem; height: 1.1rem; flex: none; }
.stage-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; }
.stage-extra, .stage-history { margin-top: .75rem; }
.stage-extra summary, .stage-history summary { cursor: pointer; color: var(--muted); }
.stage-extra form { margin-top: .75rem; }
.stage-history h4 { margin: .75rem 0 .25rem; font-size: .95rem; }
.history-list { margin: 0; padding-left: 1.1rem; }

/* 업무 보드: 단계마다 한 줄씩 쌓고 접었다 펼 수 있다 (카드가 있는 단계만 펼친 채로 시작). 카드는 줄 너비만큼 줄바꿈하며 나열 */
.board { display: flex; flex-direction: column; gap: .5rem; }
.board-lane { min-width: 0; background: var(--neutral-bg); border-radius: var(--radius); }
.board-lane-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .75rem; padding: .6rem .75rem; cursor: pointer; list-style: none; border-radius: var(--radius); }
.board-lane-head::-webkit-details-marker { display: none; }
.board-lane-head::before { content: ""; align-self: center; width: .4rem; height: .4rem; margin: 0 .1rem 0 .15rem; border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(-45deg); transition: transform .15s; }
.board-lane[open] > .board-lane-head::before { transform: rotate(45deg); }
.board-lane-head:hover h2 { color: var(--primary); }
.board-lane-head h2 { font-size: .95rem; margin: 0; }
.board-lane-head .muted { font-size: .8rem; word-break: keep-all; }
.board-lane-body { padding: 0 .75rem .75rem; }
.board-cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: .5rem; }
.board-card { display: flex; flex-direction: column; gap: .25rem; height: 100%; padding: .6rem .75rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: .9rem; word-break: keep-all; overflow-wrap: anywhere; }
.board-card:hover { border-color: var(--primary); text-decoration: none; }
.board-card.is-late { border-left: 3px solid var(--danger); }
.board-card-top { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .4rem; font-size: .8rem; }
.board-card-top .badge { margin: 0; }
.board-title { font-weight: 600; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.board-meta { display: flex; gap: .5rem; font-size: .8rem; color: var(--muted); }
.board-customer { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-meta > :last-child { flex-shrink: 0; }
.board-empty { margin: 0; color: var(--muted); font-size: .85rem; }

/* 현황 */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; }
.tile-label { color: var(--muted); font-size: .9rem; }
.tile-value { font-size: 2rem; font-weight: 600; line-height: 1.2; margin: .25rem 0; }
.tile-unit { font-size: 1rem; font-weight: 400; color: var(--muted); margin-left: .2rem; }
.tile-note { font-size: .85rem; color: var(--muted); }
.flag { color: var(--danger); font-weight: 600; }
.empty-note { color: var(--muted); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .55rem .9rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table th { color: var(--muted); font-weight: 600; font-size: .85rem; white-space: nowrap; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

/* 로그인 */
.login { max-width: 380px; margin: 4rem auto; text-align: center; }
.login-admin { margin-top: 2rem; text-align: left; }
.login-admin summary { color: var(--muted); cursor: pointer; }
.login-admin label { display: block; margin: .75rem 0; }

/* 설정: 테마 고르기. 견본은 data-theme로 그 테마의 색 변수를 받아 칠한다 */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(210px, 100%), 1fr)); gap: .75rem; max-width: 960px; }
.theme-option { display: flex; flex-direction: column; gap: .2rem; padding: .6rem .6rem .75rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.theme-option:hover { border-color: var(--primary); }
.theme-option.is-current { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.theme-swatch { display: flex; height: 5rem; margin-bottom: .4rem; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.theme-sample { flex: 1; display: flex; padding: .6rem; background: var(--bg); }
.sample-card { flex: 1; display: flex; flex-direction: column; gap: .3rem; padding: .45rem .55rem; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; }
.sample-line { width: 75%; height: .4rem; border-radius: 2px; background: var(--text); }
.sample-muted { width: 50%; background: var(--muted); }
.sample-pill { width: 2.5rem; height: .65rem; margin-top: auto; border-radius: 999px; background: var(--primary); }
.theme-name { font-weight: 600; }
.theme-note { color: var(--muted); font-size: .85rem; word-break: keep-all; }

/* 장비 */
.state-new { background: var(--info-bg); color: var(--info); }
.state-check { background: var(--warn-bg); color: var(--warn); }
.state-ready, .result-pass { background: var(--ok-bg); color: var(--ok); }
.state-failed, .result-fail { background: var(--danger-bg); color: var(--danger); }
.badge-lg { font-size: .95rem; padding: .2rem .8rem; }
.sn { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; overflow-wrap: anywhere; }
h1.sn { font-size: 1.3rem; }
.tab-count { opacity: .75; margin-left: .15rem; }
.block-tight { margin-bottom: .75rem; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.filters select { width: auto; max-width: 100%; }
.filters input[type="search"] { flex: 1 1 16rem; width: auto; }
.units-table td { font-size: .9rem; }
.check-section { margin: 1rem 0 0; font-size: .9rem; color: var(--muted); }
.check-section + .checklist { margin-top: .25rem; }
.inspection { padding: .65rem 1rem; }
.inspection + .inspection { border-top: 1px solid var(--border); }
.inspection > summary { cursor: pointer; }
.inspection-items { list-style: none; margin: .75rem 0 1rem; padding: 0; font-size: .9rem; }
.inspection-items li { display: flex; gap: .5rem; padding: .15rem 0; }
.inspection-items .mark { flex: none; width: 1rem; font-weight: 700; }
.inspection-items .is-ok .mark { color: var(--ok); }
.inspection-items .is-ng .mark { color: var(--danger); }
.unit-list { list-style: none; margin: .5rem 0; padding: 0; }
.unit-list li { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .75rem; padding: .4rem 0; border-top: 1px solid var(--border); }
.unit-list li:first-child { border-top: 0; }
.unit-list form { margin: 0 0 0 auto; }
.inline-add { display: flex; gap: .5rem; margin: .75rem 0 .25rem; }
.inline-add input { flex: 1; min-width: 0; }

/* 첨부 사진: 링크에 올리면 미리보기, 누르면 크게 (static/js/image-viewer.js) */
.image-peek { position: fixed; z-index: 30; max-width: calc(100vw - 16px); padding: .25rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0, 0, 0, .25); pointer-events: none; }
.image-peek img { display: block; max-width: min(320px, 100%); max-height: 320px; border-radius: calc(var(--radius) - 2px); }
.image-viewer { padding: 0; border: 0; border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: 94vw; max-height: 94vh; overflow: hidden; }
.image-viewer::backdrop { background: rgba(0, 0, 0, .65); }
.image-viewer img { display: block; max-width: 94vw; max-height: calc(94vh - 3rem); object-fit: contain; }
.image-viewer-bar { display: flex; align-items: center; gap: .75rem; padding: .6rem .85rem; font-size: .9rem; }
.image-viewer-bar .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

/* 작업지시서: 확정한 내용, 로봇 구성 표 */
.wo-fields { display: grid; gap: .5rem; margin: 0 0 1rem; }
.wo-fields > div { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: .75rem; padding-bottom: .5rem; border-bottom: 1px solid var(--border); }
.wo-fields dt { color: var(--muted); font-size: .85rem; }
.wo-fields dd { margin: 0; overflow-wrap: anywhere; }
.wo-subhead { margin: 1rem 0 .5rem; font-size: .95rem; }
.parts-table td { font-size: .9rem; }
.parts-table form { margin: 0; }
.part-add { display: grid; grid-template-columns: 7rem minmax(0, 1.4fr) 4.5rem 7rem minmax(0, 1fr) auto; gap: .4rem; margin-top: .5rem; }
@media (max-width: 720px) {
  .wo-fields > div { grid-template-columns: 1fr; gap: .1rem; }
  .part-add { grid-template-columns: 1fr 1fr; }
  .part-add button { grid-column: span 2; }
}

/* 값 기록 항목: 종이 양식처럼 이름은 왼쪽, 칸은 오른쪽. 좁은 화면에서는 위아래 */
.check-item.check-field { display: grid; grid-template-columns: 10rem minmax(0, 1fr); column-gap: 1rem; row-gap: .2rem; align-items: start; padding: .45rem 0; }
.check-field > label { grid-column: 1; padding-top: .45rem; font-size: .9rem; font-weight: 600; overflow-wrap: anywhere; }
.check-field > input, .check-field > textarea, .check-field > small { grid-column: 2; }
@media (max-width: 600px) {
  .check-item.check-field { grid-template-columns: minmax(0, 1fr); }
  .check-field > label, .check-field > input, .check-field > textarea, .check-field > small { grid-column: 1; }
  .check-field > label { padding-top: 0; }
}
/* 값 기록 칸이 섞인 체크리스트는 체크 항목도 오른쪽 칸 줄에 맞춘다. 체크 항목만 있으면 그대로 */
form:has(.check-field) .checklist > .check-item:not(.check-field) { display: grid; grid-template-columns: 10rem minmax(0, 1fr); column-gap: 1rem; row-gap: .2rem; padding: .45rem 0; }
form:has(.check-field) .checklist > .check-item:not(.check-field) > * { grid-column: 2; }
@media (max-width: 600px) {
  form:has(.check-field) .checklist > .check-item:not(.check-field) { grid-template-columns: minmax(0, 1fr); }
  form:has(.check-field) .checklist > .check-item:not(.check-field) > * { grid-column: 1; }
}

/* 넓은 화면의 티켓 목록: 업무 단계·고객·제품을 따로 열로 빼서 제목과 상태·기한 사이를 채운다 */
@media (min-width: 1400px) {
  .ticket-row {
    grid-template-columns: 6.5rem minmax(0, 1fr) minmax(10rem, 16rem) minmax(8rem, 14rem) 8.5rem 8.5rem;  /* 상태 열도 고정해야 줄마다 열이 맞는다 */
    grid-template-areas: "num title stage customer status due" "num product stage customer status who";
  }
  .t-meta { display: contents; }
  .t-stage { grid-area: stage; justify-self: start; }
  .t-customer { grid-area: customer; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-size: .9rem; }
  .t-product { grid-area: product; color: var(--muted); font-size: .85rem; }
  .t-meta .t-product::before { content: none; }
  .t-status { justify-self: end; }
}

/* 상세 화면 1열·2열. 1열은 slot 번호 순서로 위아래로 쌓고, 2열(넓은 화면)은 보기 섹션 왼쪽·입력 섹션 오른쪽.
   오른쪽 '처리' 패널(detail-side)은 어느 쪽이든 그대로 옆에 둔다. */
.detail-main { display: flex; flex-direction: column; min-width: 0; }
.detail-view, .detail-work { display: contents; }
.slot { min-width: 0; }
.slot-1 { order: 1; } .slot-2 { order: 2; } .slot-3 { order: 3; } .slot-4 { order: 4; }
.slot-5 { order: 5; } .slot-6 { order: 6; } .slot-7 { order: 7; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; }
.layout-toggle { display: none; gap: 2px; margin: 0; padding: 2px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.icon-button { display: inline-flex; align-items: center; justify-content: center; width: 2rem; height: 1.8rem; padding: 0; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; }
.icon-button svg { fill: currentColor; }
.icon-button:hover { color: var(--text); }
.icon-button.is-current { background: var(--neutral-bg); color: var(--primary); }
@media (min-width: 1400px) {
  .layout-toggle { display: inline-flex; }
  .detail-main.is-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 1.25rem; align-items: start; }
  .detail-main.is-split > .detail-view, .detail-main.is-split > .detail-work { display: block; min-width: 0; }
}

/* 왼쪽 사이드바 (업무 보드·팀 큐·장비): 목록, 지금 상태(누르면 그것만), 필터·보기. 좁은 화면에서는 본문 위로 */
.with-side { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.side-main { min-width: 0; }
.side-panel { display: grid; gap: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.side-scroll { max-height: 16rem; overflow-y: auto; }
.side-range { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: .3rem .4rem; color: var(--muted); }
.side-range input { width: 100%; min-width: 0; padding: .3rem .35rem; font-size: .85rem; }
.list-note { margin: 0 0 .5rem; }
.side-section h2 { margin: 0 0 .4rem; font-size: .8rem; color: var(--muted); font-weight: 600; }
.side-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.side-list a { display: flex; justify-content: space-between; gap: .5rem; padding: .35rem .55rem; border-radius: 6px; color: var(--text); font-size: .9rem; }
.side-list a:hover { background: var(--neutral-bg); text-decoration: none; }
.side-list a.active { background: var(--primary); color: var(--primary-text); }
.side-list a.active .side-count, .side-list a.active .flag { color: var(--primary-text); }
.side-list a.is-zero { color: var(--muted); }
.side-count { font-variant-numeric: tabular-nums; white-space: nowrap; }
.side-clear { display: inline-block; margin-top: .35rem; font-size: .85rem; }
.side-filters { display: grid; gap: .55rem; }
.side-filters h2:not(:first-child) { margin-top: .5rem; }
.side-filters label { display: grid; gap: .2rem; font-size: .85rem; color: var(--muted); }
.side-filters .side-check { display: flex; align-items: center; gap: .45rem; color: var(--text); }
.side-filters select, .side-filters input[type="search"] { padding: .35rem .5rem; font-size: .9rem; }
.side-actions { display: flex; align-items: center; gap: .75rem; font-size: .9rem; }
.board-filter-note { margin: 0; }
.board-age { margin-left: auto; color: var(--muted); font-size: .75rem; white-space: nowrap; }
@media (min-width: 1100px) {
  .with-side { grid-template-columns: 17rem minmax(0, 1fr); }
  .side-panel { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; }
}

/* 고객용 웹 수리 신청서 (templates/public). 로그인 없이 휴대폰으로도 쓴다 */
.public { max-width: 720px; margin: 0 auto; }
.public .form-card { max-width: none; }
.public-intro p { margin: 0 0 .6rem; }
.public-note { padding: .75rem 1rem; margin: 1rem 0; border-radius: var(--radius); background: var(--info-bg); color: var(--text); }
.public-note p { margin: 0 0 .5rem; }
.public-note .facts { margin: .5rem 0; }
.public-form fieldset { border: 0; padding: 0; margin: 0 0 1.25rem; min-width: 0; }
.public-form legend { font-weight: 700; font-size: 1.05rem; padding: 0; margin-bottom: .6rem; }
.public-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 1rem; }
.public-grid .field-wide { grid-column: 1 / -1; }
@media (max-width: 560px) { .public-grid { grid-template-columns: minmax(0, 1fr); } }
.public-privacy { margin: 0 0 .75rem; padding-left: 1.1rem; font-size: .9rem; }
.public-error { padding: .6rem .9rem; border-radius: var(--radius); background: var(--danger-bg); }
.public-trap { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.public-number { font-size: 1.15rem; }
.public-number strong { font-size: 1.4rem; font-variant-numeric: tabular-nums; }

/* 고객에게 보낼 신청서 링크 (티켓 상세·새 티켓) */
.share-link { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .6rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.share-link input { flex: 1 1 18rem; min-width: 0; font-size: .85rem; color: var(--muted); }
.form-card.share-link { margin: 0 0 1rem; padding: 1rem 1.25rem; }

/* 조직도 (templates/accounts/org.html): 회사 → 본부 → 팀 → 사람. 가로로 넓어지면 좌우로 스크롤한다.
   연결선은 li의 ::before(왼쪽 가로선)·::after(오른쪽 가로선 + 세로선)와 ul의 ::before(부모에서 내려오는 세로선)로 그린다 */
.org-wrap { overflow-x: auto; padding: .25rem 0 1rem; margin-bottom: 1.5rem; }
.org-tree, .org-children { list-style: none; margin: 0; padding: 0; display: flex; justify-content: center; align-items: flex-start; }
.org-children { position: relative; padding-top: 1.25rem; }
.org-tree > li, .org-children > li { position: relative; padding: 1.25rem .4rem 0; text-align: center; }
.org-children > li::before, .org-children > li::after { content: ""; position: absolute; top: 0; right: 50%; width: 50%; height: 1.25rem; border-top: 1px solid var(--border); }
.org-children > li::after { right: auto; left: 50%; border-left: 1px solid var(--border); }
.org-tree > li:only-child, .org-children > li:only-child { padding-top: 0; }
.org-children > li:only-child::before, .org-children > li:only-child::after { display: none; }
.org-children > li:first-child::before, .org-children > li:last-child::after { border-top: 0; }
.org-children > li:last-child::before { border-right: 1px solid var(--border); border-radius: 0 6px 0 0; }
.org-children > li:first-child::after { border-radius: 6px 0 0 0; }
.org-children::before { content: ""; position: absolute; top: 0; left: 50%; height: 1.25rem; border-left: 1px solid var(--border); }
.org-node { display: inline-block; width: 13.5rem; text-align: left; vertical-align: top; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .75rem .7rem; }
.org-root { width: auto; min-width: 11rem; text-align: center; border-color: var(--primary); }
.org-root strong { font-size: 1.05rem; }
.org-node-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.org-node-head strong { font-size: 1rem; }
.org-count { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.org-sub { margin: .15rem 0 0; font-size: .8rem; color: var(--muted); word-break: keep-all; }
.org-people { list-style: none; margin: .5rem 0 0; padding: .5rem 0 0; border-top: 1px solid var(--border); display: grid; gap: .35rem; }
.org-person { font-size: .9rem; line-height: 1.35; }
.org-person.is-lead .org-name { font-weight: 600; }
.org-name a { color: var(--text); }
.org-contact { display: block; color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.badge-lead { background: var(--info-bg); color: var(--info); }
.org-people-wide { margin: 0; padding: .75rem 1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); grid-template-columns: repeat(auto-fill, minmax(min(16rem, 100%), 1fr)); gap: .5rem 1rem; }
.org-edit > summary { cursor: pointer; color: var(--muted); font-size: .8rem; }
.org-form { display: grid; gap: .4rem; margin: .4rem 0 .5rem; }
.org-form label { display: grid; gap: .15rem; font-size: .8rem; color: var(--muted); }
.org-form input, .org-form select { padding: .3rem .4rem; font-size: .85rem; }
.org-form .side-check { display: flex; align-items: center; gap: .4rem; color: var(--text); }
.org-form .button { padding: .3rem .75rem; font-size: .85rem; justify-self: start; }
.org-note { margin: .2rem 0 0; font-size: .8rem; }
.org-tools { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; margin-bottom: 1rem; }
.org-tools > details[open] { flex-basis: 100%; }
.org-tools summary { cursor: pointer; color: var(--primary); font-weight: 600; }
.org-tools .form-card { margin-top: .75rem; max-width: 520px; }
.org-tools .org-form { margin: 0; }
.org-tools .org-form .button { justify-self: start; }
