/* Layout: 좌측 고정 내비 + 우측 작업 영역. 모바일에서는 상단 가로 탭으로 접힘 */
:root {
  --bg: #f3f6f7;
  --surface: #ffffff;
  --sunken: #eaeff1;
  --fg: #13222c;
  --muted: #5a6b76;
  --line: #d9e1e5;
  --accent: #0d5f78;
  --accent-fg: #ffffff;
  --accent-weak: #e1eff3;
  --pre: #8a5d00;
  --pre-bg: #fbf0d4;
  --bid: #1d4ea3;
  --bid-bg: #e4ecfb;
  --danger: #b0222b;
  --danger-bg: #fbe5e6;
  --ok: #1f7a49;
  --ok-bg: #e0f3e8;
  --shadow: 0 1px 2px rgba(19,34,44,.06), 0 8px 24px rgba(19,34,44,.08);
  --font-ui: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --font-num: "IBM Plex Mono", ui-monospace, "Consolas", monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e151a; --surface: #152027; --sunken: #111b21; --fg: #e1e9ed; --muted: #92a3ad; --line: #26343d;
    --accent: #5db4d1; --accent-fg: #06222c; --accent-weak: #16323d;
    --pre: #e8b94f; --pre-bg: #382c10; --bid: #8eb0f3; --bid-bg: #1a2947;
    --danger: #f0898f; --danger-bg: #3b191c; --ok: #6ccf97; --ok-bg: #143223;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e151a; --surface: #152027; --sunken: #111b21; --fg: #e1e9ed; --muted: #92a3ad; --line: #26343d;
  --accent: #5db4d1; --accent-fg: #06222c; --accent-weak: #16323d;
  --pre: #e8b94f; --pre-bg: #382c10; --bid: #8eb0f3; --bid-bg: #1a2947;
  --danger: #f0898f; --danger-bg: #3b191c; --ok: #6ccf97; --ok-bg: #143223;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* .drawer 등 display를 지정한 요소도 hidden 속성으로 숨긴다 */
body { background: var(--bg); color: var(--fg); font-family: var(--font-ui); font-size: 14px; line-height: 1.5; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

.app { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 24px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; font-weight: 700; font-size: 15px; }
.brand b { font-size: 16px; letter-spacing: -.01em; }
.brand small { display: block; color: var(--muted); font-size: 11px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 10px; border-radius: 8px; text-decoration: none; color: var(--fg); font-weight: 500; }
.nav a:hover { background: var(--sunken); }
.nav a[aria-current="page"] { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.nav .count { font-family: var(--font-num); font-size: 12px; color: var(--muted); }
.sync { margin-top: auto; border-top: 1px solid var(--line); padding: 14px 6px 0; font-size: 12px; color: var(--muted); display: grid; gap: 4px; }
.sync .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-right: 6px; vertical-align: 1px; }
.mock-tag { font-size: 11px; color: var(--muted); padding: 0 6px; }

main { min-width: 0; padding-block: 28px 48px; padding-left: max(28px, env(safe-area-inset-left, 0px)); padding-right: max(28px, env(safe-area-inset-right, 0px)); }
.wrap { max-width: 1180px; margin: 0 auto; display: grid; gap: 20px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.head h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; text-wrap: balance; }
.head p { margin: 4px 0 0; color: var(--muted); }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--sunken); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.panel-h { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.panel-h h2 { margin: 0; font-size: 15px; }
.panel-b { padding: 18px; }

/* 요약 */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 2px; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-family: var(--font-num); font-size: 26px; font-weight: 500; letter-spacing: -.02em; }
.stat .sub { font-size: 12px; color: var(--muted); }
.stat.warn .value { color: var(--danger); }

/* 필터 */
.filters { display: grid; gap: 12px; padding: 16px 18px; }
.filter-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filter-row > .lbl { width: 64px; flex: none; font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.chip .n { font-family: var(--font-num); font-size: 11px; opacity: .75; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 5px 12px; cursor: pointer; font-size: 13px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.input { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0; }
.search { flex: 1 1 220px; }

/* 테이블 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--sunken); white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--sunken); }
tbody tr:last-child td { border-bottom: 0; }
td.title { min-width: 300px; }
td.title b { font-weight: 600; display: block; }
td.title .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
td.r, th.r { text-align: right; }
.nowrap { white-space: nowrap; }
.badge { display: inline-block; border-radius: 5px; padding: 1px 7px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.pre { background: var(--pre-bg); color: var(--pre); }
.badge.bid { background: var(--bid-bg); color: var(--bid); }
.badge.new { background: var(--ok-bg); color: var(--ok); }
.badge.chg { background: var(--pre-bg); color: var(--pre); }
.badge.cxl { background: var(--danger-bg); color: var(--danger); }
.dday { font-family: var(--font-num); font-weight: 500; }
.dday.hot { color: var(--danger); }
.dday.past { color: var(--muted); }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.result-n { color: var(--muted); font-size: 13px; }

/* 상세 패널 */
.scrim { position: fixed; inset: 0; background: rgba(8,16,22,.38); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100%); background: var(--surface); z-index: 21; box-shadow: var(--shadow); display: flex; flex-direction: column; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); padding-right: env(safe-area-inset-right, 0px); }
.drawer-h { padding: 18px 20px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.drawer-h h3 { margin: 0; font-size: 17px; line-height: 1.4; text-wrap: balance; }
.drawer-b { padding: 6px 20px 20px; overflow-y: auto; }
dl.kv { display: grid; grid-template-columns: 110px minmax(0,1fr); margin: 0; }
dl.kv dt, dl.kv dd { padding: 10px 0; border-bottom: 1px solid var(--line); margin: 0; }
dl.kv dt { color: var(--muted); font-size: 13px; }
.linked { margin-top: 16px; background: var(--sunken); border-radius: 10px; padding: 12px 14px; font-size: 13px; display: grid; gap: 4px; }
.drawer-f { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* 기관 관리 */
.two { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 20px; align-items: start; }
.search-results { display: grid; }
.sr { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.sr:last-child { border-bottom: 0; }
.sr .nm { font-weight: 600; }
.sr .sub { font-size: 12px; color: var(--muted); }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.select { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 4px 6px; font-size: 13px; }
.hint { font-size: 12px; color: var(--muted); }

/* 알림 설정 */
.form { display: grid; gap: 0; }
.field { display: grid; grid-template-columns: 180px minmax(0,1fr); gap: 16px; padding: 18px; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; }
.field > .l b { display: block; font-weight: 600; }
.field > .l span { font-size: 12px; color: var(--muted); }
.field > .c { display: grid; gap: 10px; min-width: 0; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag { background: var(--sunken); border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
.tag button { border: 0; background: none; padding: 0; cursor: pointer; color: var(--muted); line-height: 1; }
.check { display: inline-flex; gap: 6px; align-items: center; margin-right: 14px; cursor: pointer; }
.radio-card { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.radio-card label { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer; display: grid; gap: 2px; }
.radio-card label:has(input:checked) { border-color: var(--accent); background: var(--accent-weak); }
.radio-card input { margin: 0 6px 0 0; }
.radio-card small { color: var(--muted); }
.form-f { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); background: var(--sunken); border-radius: 0 0 12px 12px; }

/* 메일 미리보기 */
.mail { max-width: 680px; }
.mail-meta { padding: 14px 18px; border-bottom: 1px solid var(--line); display: grid; gap: 4px; font-size: 13px; }
.mail-meta span { color: var(--muted); display: inline-block; width: 56px; }
.mail-body { padding: 24px; display: grid; gap: 20px; }
.mail-body h4 { margin: 0; font-size: 14px; display: flex; gap: 8px; align-items: baseline; }
.mail-body h4 small { color: var(--muted); font-weight: 400; }
.mail-item { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; display: grid; gap: 6px; }
.mail-item .t { font-weight: 600; }
.mail-item .m { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; }
.mail-foot { font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 14px; }

.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 30; }

@media (max-width: 960px) {
  .two { grid-template-columns: minmax(0,1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0,1fr); }
  .side { position: static; height: auto; flex-direction: row; align-items: center; gap: 12px; padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .brand small, .sync, .mock-tag { display: none; }
  .nav { flex-direction: row; }
  .nav a { white-space: nowrap; padding: 7px 10px; }
  .nav .count { display: none; }
  main { padding-block: 20px 40px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .field { grid-template-columns: minmax(0,1fr); gap: 10px; }
  .radio-card { grid-template-columns: minmax(0,1fr); }
  .filter-row > .lbl { width: 100%; }
  .mail-body { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* 앱 전용 */
.flash { background: var(--accent-weak); color: var(--accent); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; font-weight: 500; }
.flash.err { background: var(--danger-bg); color: var(--danger); }
.sync .err { color: var(--danger); }
.sync form { margin-top: 6px; }
.side-foot { display: flex; gap: 8px; padding: 0 6px; }
textarea.input { width: 100%; min-height: 72px; resize: vertical; }
.login { min-height: 100vh; display: grid; place-items: center; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.login form { width: min(360px, 100%); display: grid; gap: 14px; padding: 28px; }
.inline { display: inline; margin: 0; }

/* ── 모바일 ─────────────────────────────────────────────── */
.m-sync, .m-lbl { display: none; }
.side-foot .user { align-self: center; }
.unit { display: none; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-right: 6px; vertical-align: 1px; }

@media (max-width: 760px) {
  body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface); }
  .side {
    position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10; height: auto;
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; overflow: visible;
    padding: 10px max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px));
  }
  .side .brand { padding: 0; }
  .side .brand-mark { width: 26px; height: 26px; font-size: 13px; }
  .side .sync { display: none; }
  .side-foot { grid-column: 2; grid-row: 1; padding: 0; align-items: center; }
  .side-foot .user { display: none; }
  .side .nav { grid-column: 1 / -1; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; gap: 4px; }
  .side .nav::-webkit-scrollbar { display: none; }
  .side .nav a { border-radius: 0; border-bottom: 2px solid transparent; padding: 8px 10px 10px; }
  .side .nav a[aria-current="page"] { background: none; border-bottom-color: var(--accent); }

  .m-sync { display: flex; align-items: center; gap: 6px 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
  .m-sync .err { color: var(--danger); font-weight: 600; }
  .m-sync form { margin-left: auto; }

  input, select, textarea { font-size: 16px; }   /* iOS 확대 방지 */
  .head h1 { font-size: 20px; }
  .stat { padding: 12px; }
  .stat .value { font-size: 22px; }
  .filters { padding: 14px; }
  .seg { max-width: 100%; overflow-x: auto; }
  .seg button { white-space: nowrap; }
  #fAgency { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; padding-bottom: 2px; }
  .chip { white-space: nowrap; }
  .filter-row > .lbl { width: 100%; }
  .panel-h { padding: 12px 14px; }

  /* 표 → 카드 */
  table.cards thead { display: none; }
  table.cards, table.cards tbody { display: block; }
  table.cards td { display: block; padding: 0; border: 0; min-width: 0; }
  table.cards tr { display: grid; gap: 6px 8px; padding: 14px; border-bottom: 1px solid var(--line); }
  table.cards tbody tr:last-child { border-bottom: 0; }
  table.cards td.empty { padding: 32px 8px; }

  .notice-cards tr {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    grid-template-areas: "kind biz . status" "title title title title" "org org posted posted" "close close amt amt";
    align-items: center;
  }
  .notice-cards .c-kind { grid-area: kind; }
  .notice-cards .c-biz { grid-area: biz; font-size: 12px; color: var(--muted); }
  .notice-cards .c-status { grid-area: status; }
  .notice-cards .c-title { grid-area: title; }
  .notice-cards .c-title b { font-size: 15px; line-height: 1.4; }
  .notice-cards .c-org { grid-area: org; font-size: 13px; color: var(--muted); white-space: normal; }
  .notice-cards .c-posted { grid-area: posted; font-size: 12px; color: var(--muted); text-align: right; }
  .notice-cards .c-close { grid-area: close; }
  .notice-cards .c-close .meta { display: inline; margin-left: 6px; }
  .notice-cards .c-amt { grid-area: amt; font-weight: 500; }
  .notice-cards .unit { display: inline; font-size: 12px; color: var(--muted); margin-left: 2px; }

  .agency-cards tr {
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas: "name name del" "match count notify";
    align-items: center;
  }
  .agency-cards .a-name { grid-area: name; }
  .agency-cards .a-match { grid-area: match; }
  .agency-cards .a-count { grid-area: count; font-size: 13px; color: var(--muted); }
  .agency-cards .a-notify { grid-area: notify; }
  .agency-cards .a-del { grid-area: del; }
  .m-lbl { display: inline; }

  .sr { flex-wrap: wrap; }
  .panel-b { padding: 14px; }
  .form-f { flex-wrap: wrap; }
  .form-f .btn { flex: 1 1 auto; }
  .drawer-f .btn { flex: 1 1 auto; text-align: center; }
  dl.kv { grid-template-columns: 96px minmax(0, 1fr); }
  .mail iframe { height: 75vh; }
}
