/* 에이전트 현황판 — Montage 디자인 시스템 기반, MIT */
:root {
  --bg: #F7F8FA;
  --surface: #FFFFFF;
  --surface-2: #F1F2F4;
  --line: #E3E5E9;
  --line-soft: #EFF0F3;
  --text: #16171B;
  --text-2: #43474D;
  --text-3: #5F646B;
  --point: #2B49E0;
  --point-soft: #EEF1FF;
  --ok: #067A54;
  --ok-soft: #E7F7F1;
  --warn: #A85F00;
  --warn-soft: #FFF6E5;
  --danger: #C0271B;
  --danger-soft: #FEECEA;
  --idle: #666C74;
  --idle-soft: #F0F1F3;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 26px;
  --shadow: 0 1px 2px rgba(16, 18, 24, .04), 0 6px 18px rgba(16, 18, 24, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101114;
    --surface: #191B1F;
    --surface-2: #232529;
    --line: #2E3136;
    --line-soft: #26282D;
    --text: #F2F3F5;
    --text-2: #C3C7CE;
    --text-3: #9AA0A8;
    --point: #8FA2FF;
    --point-soft: #202643;
    --ok: #4ADE9E;
    --ok-soft: #12291F;
    --warn: #F3B25B;
    --warn-soft: #2B2314;
    --danger: #FF8A80;
    --danger-soft: #2C1917;
    --idle: #9AA0A8;
    --idle-soft: #232529;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard",
    "Malgun Gothic", system-ui, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -0.01em;
  padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid var(--point);
  outline-offset: 2px;
  border-radius: 6px;
}

/* App bar */
.appbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: rgba(247, 248, 250, .88);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line-soft);
}
@media (min-width: 620px) {
  .appbar { padding-left: max(16px, calc((100vw - 560px) / 2)); padding-right: max(16px, calc((100vw - 560px) / 2)); }
}
.appbar-title { display: flex; align-items: center; gap: 9px; min-width: 0; }
.app-icon {
  width: 30px; height: 30px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 16px; box-shadow: var(--shadow); object-fit: cover;
}
.appbar h1 { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }

.live {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  background: var(--ok-soft); color: #067647;
  font-size: 12px; font-weight: 700; letter-spacing: .02em;
  border: 1px solid #C6EEDB;
}
.live-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 0 rgba(14, 159, 110, .55);
  animation: pulse 2.4s infinite;
}
.live.stale { background: var(--warn-soft); color: var(--warn); border-color: #F6DDAE; }
.live.stale .live-dot { background: var(--warn); animation: none; }
.live.error { background: var(--danger-soft); color: var(--danger); border-color: #F7C9C4; }
.live.error .live-dot { background: var(--danger); animation: none; }
.live-time { font-weight: 600; color: inherit; opacity: .78; font-variant-numeric: tabular-nums; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(14, 159, 110, .5); }
  70% { box-shadow: 0 0 0 6px rgba(14, 159, 110, 0); }
  100% { box-shadow: 0 0 0 0 rgba(14, 159, 110, 0); }
}

.view { max-width: 560px; margin: 0 auto; padding: 14px 16px 28px; }

/* Error banner */
.banner-error {
  display: flex; flex-direction: column; gap: 4px;
  margin-bottom: 12px; padding: 12px 14px; border-radius: var(--r-md);
  background: var(--danger-soft); border: 1px solid #F7C9C4; color: #8A1F14;
  font-size: 13px;
}
.banner-error strong { font-size: 13.5px; font-weight: 750; }
.banner-error button {
  align-self: flex-start; margin-top: 6px; min-height: 36px; padding: 0 14px;
  border-radius: 999px; border: 1px solid #F0B3AB; background: rgba(255, 255, 255, .7);
  color: #8A1F14; font-family: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer;
}
@media (prefers-color-scheme: dark) {
  .banner-error { background: #2C1917; border-color: #5A2A25; color: #FFB4A9; }
  .banner-error button { background: rgba(255, 255, 255, .06); border-color: #5A2A25; color: #FFB4A9; }
}

/* Hero */
.hero {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 12px;
  min-height: 132px; padding: 18px;
  border-radius: var(--r-xl);
  background: linear-gradient(135deg, #1B1E2B 0%, #2B3355 55%, #3A4A8F 100%);
  color: #fff; box-shadow: var(--shadow);
}
.hero-art {
  position: absolute; right: -6px; bottom: -8px;
  width: 148px; height: 148px; opacity: .96; pointer-events: none;
}
.hero-copy { position: relative; z-index: 1; max-width: 66%; }
.hero-eyebrow {
  font-size: 12px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: rgba(255, 255, 255, .68); margin-bottom: 6px;
}
.hero h2 { font-size: 20px; line-height: 1.34; font-weight: 800; letter-spacing: -0.02em; }
.hero-sub { margin-top: 7px; font-size: 13px; color: rgba(255, 255, 255, .78); }

/* Summary */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.summary-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 12px 12px 10px;
  display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow);
}
.summary-label { font-size: 12.5px; font-weight: 600; color: var(--text-3); }
.summary-value { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.summary-foot { font-size: 12px; color: var(--text-3); font-weight: 500; }
.summary-card.ok .summary-value { color: var(--ok); }
.summary-card.warn .summary-value { color: var(--warn); }
.summary-card.danger .summary-value { color: var(--danger); }

/* Chips */
.chips {
  display: flex; gap: 7px; overflow-x: auto; margin: 16px 0 12px;
  padding-bottom: 2px; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface);
  color: var(--text-2); font-size: 13.5px; font-weight: 600;
  padding: 0 15px; min-height: 44px; border-radius: 999px; cursor: pointer;
  font-family: inherit; transition: all .15s ease; display: inline-flex; align-items: center;
}
.chip:active { transform: scale(.97); }
.chip.active { background: var(--text); color: #fff; border-color: var(--text); }

/* Agent cards */
.agent-list { display: flex; flex-direction: column; gap: 10px; }
.agent-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 14px; box-shadow: var(--shadow);
}
.agent-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.agent-name-row { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.agent-name { font-size: 15.5px; font-weight: 750; letter-spacing: -0.02em; }
.agent-sub { margin-top: 3px; font-size: 13px; color: var(--text-3); }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  border: 1px solid transparent; white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: #067647; border-color: #C6EEDB; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: #F6DDAE; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: #F7C9C4; }
.badge.idle { background: var(--idle-soft); color: var(--idle); border-color: var(--line); }
.badge.todo { background: var(--point-soft); color: var(--point); border-color: #DCE2FF; }

.agent-stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  margin: 12px 0 0; padding: 9px 0; border-radius: var(--r-md);
  background: var(--surface-2);
}
.agent-stat { text-align: center; border-right: 1px solid var(--line); }
.agent-stat:last-child { border-right: 0; }
.agent-stat span { display: block; font-size: 12px; color: var(--text-3); font-weight: 600; }
.agent-stat strong { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.agent-stat.ok strong { color: var(--ok); }
.agent-stat.warn strong { color: var(--warn); }
.agent-stat.idle strong { color: var(--idle); }

.agent-tasks { list-style: none; margin-top: 11px; display: flex; flex-direction: column; gap: 7px; }
.agent-task { display: flex; gap: 8px; align-items: baseline; font-size: 13.5px; }
.agent-task .t-time {
  flex: 0 0 auto; font-size: 12px; color: var(--text-3);
  font-variant-numeric: tabular-nums; padding-top: 1px;
}
.agent-task .t-id { flex: 0 0 auto; font-size: 12px; font-weight: 700; color: var(--text-2); }
.agent-task .t-text { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.agent-task.is-miss .t-text { color: var(--idle); }

.detail-toggle {
  margin-top: 11px; width: 100%; border: 0; background: none;
  color: var(--point); font-size: 13.5px; font-weight: 700; font-family: inherit;
  min-height: 44px; cursor: pointer; text-align: left; display: flex; align-items: center;
}
.detail { margin-top: 8px; border-top: 1px solid var(--line-soft); padding-top: 8px; display: none; }
.detail.open { display: block; }
.detail-row { display: flex; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line-soft); font-size: 12.5px; }
.detail-row:last-child { border-bottom: 0; }
.detail-row .d-left { flex: 0 0 88px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.detail-row .d-body { color: var(--text-2); }
.detail-row .d-reason { display: block; color: var(--text-3); margin-top: 2px; }

.copy-btn {
  margin: 16px 0 4px; width: 100%; min-height: 50px; padding: 14px;
  border-radius: var(--r-md); border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-family: inherit;
  font-size: 13.5px; font-weight: 700; cursor: pointer; box-shadow: var(--shadow);
}
.copy-btn:active { transform: scale(.99); background: var(--surface-2); }

/* Blocks */
.block {
  margin-top: 22px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 14px; box-shadow: var(--shadow);
}
.block-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.block-head h3 { font-size: 14px; font-weight: 750; letter-spacing: -0.02em; }
.block-meta { font-size: 12.5px; color: var(--text-3); }

/* Timeline */
.timeline { list-style: none; position: relative; padding-left: 16px; }
.timeline::before {
  content: ""; position: absolute; left: 4.5px; top: 6px; bottom: 6px;
  width: 1px; background: var(--line);
}
.tl-item { position: relative; padding: 6px 0 6px 12px; font-size: 13.5px; }
.tl-item::before {
  content: ""; position: absolute; left: -16px; top: 12px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--idle);
}
.tl-item.ok::before { border-color: var(--ok); }
.tl-item.warn::before { border-color: var(--warn); }
.tl-item.danger::before { border-color: var(--danger); }
.tl-time { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; display: block; }
.tl-body { color: var(--text-2); }
.tl-agent { font-weight: 700; color: var(--text); margin-right: 4px; }
.tl-empty { color: var(--text-3); font-size: 12.5px; padding: 6px 0; }

/* Flow */
.flow { display: flex; flex-direction: column; align-items: center; gap: 0; }
.flow-node {
  width: 100%; max-width: 260px; text-align: center;
  border-radius: var(--r-md); padding: 9px 12px; font-size: 13px; font-weight: 700;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
}
.flow-node.root { background: var(--text); color: #fff; border-color: var(--text); }
.flow-node.mid { background: var(--point-soft); color: var(--point); border-color: #DCE2FF; }
.flow-arrow { width: 1px; height: 16px; background: var(--line); position: relative; }
.flow-arrow::after {
  content: ""; position: absolute; left: -2.5px; bottom: 0;
  border-left: 3px solid transparent; border-right: 3px solid transparent;
  border-top: 5px solid var(--line);
}
.flow-agents { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.flow-agent {
  font-size: 12.5px; font-weight: 600; padding: 6px 11px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line);
}

/* Chart */
.chart { display: flex; align-items: flex-end; gap: 8px; height: 132px; padding-top: 8px; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart-stack {
  width: 100%; max-width: 26px; display: flex; flex-direction: column;
  justify-content: flex-end; gap: 2px; flex: 1;
}
.bar { width: 100%; border-radius: 4px; min-height: 2px; transition: height .3s ease; }
.bar.ok { background: var(--ok); }
.bar.warn { background: var(--warn); }
.bar.danger {
  background: repeating-linear-gradient(135deg, var(--danger) 0 3px, rgba(0, 0, 0, .15) 3px 6px);
}
.chart-day { font-size: 12px; color: var(--text-3); font-weight: 600; }
.chart-legend { display: flex; gap: 12px; margin-top: 10px; font-size: 12px; color: var(--text-3); }
.chart-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; }

/* Office */
.office-art { width: 100%; border-radius: var(--r-md); display: block; background: var(--surface-2); }
.office-caption { margin-top: 9px; font-size: 13px; color: var(--text-3); line-height: 1.6; }

/* Roles */
.role-note { font-size: 13px; color: var(--text-3); margin-bottom: 12px; }
.role-group { margin-bottom: 16px; }
.role-group h4 { font-size: 12.5px; font-weight: 700; color: var(--text-3); letter-spacing: .04em; margin-bottom: 6px; }
.role-item { padding: 9px 0; border-bottom: 1px solid var(--line-soft); }
.role-item:last-child { border-bottom: 0; }
.role-item strong { font-size: 14.5px; font-weight: 700; }
.role-item p { font-size: 13.5px; color: var(--text-2); margin-top: 2px; }

.credit { text-align: center; font-size: 11.5px; color: var(--text-3); margin: 22px 0 6px; letter-spacing: 0; }

/* Bottom tabs */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; gap: 4px; justify-content: center;
  max-width: 560px; margin: 0 auto;
  padding: 6px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
  border-radius: 0;
}
@media (prefers-color-scheme: dark) {
  .tabbar { background: rgba(25, 27, 31, .94); }
  .appbar { background: rgba(16, 17, 20, .88); }
}
.tab {
  flex: 1; max-width: 180px; border: 0; background: none; font-family: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 8px 0; min-height: 48px; font-size: 12px; font-weight: 600; color: var(--text-3); cursor: pointer;
}
.tab svg { width: 22px; height: 22px; display: block; }
.tab.active { color: var(--text); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  background: rgba(22, 23, 27, .94); color: #fff; font-size: 12.5px; font-weight: 600;
  padding: 9px 14px; border-radius: 999px; transition: all .22s ease; z-index: 60;
  max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 480px) {
  .hero h2 { font-size: 22px; }
}
