:root {
  --blue-900: #0f3d8c;
  --blue-800: #1650b0;
  --blue-700: #1e5fc8;
  --blue-600: #2a6fd6;
  --blue-500: #3b82e8;
  --blue-400: #5b9aef;
  --blue-300: #8bb8f5;
  --blue-200: #c5daf9;
  --blue-150: #d9e8fb;
  --blue-100: #e8f1fc;
  --blue-50: #f3f8fe;
  --gray-900: #1f2933;
  --gray-700: #3d4a57;
  --gray-600: #52606d;
  --gray-500: #7b8794;
  --gray-400: #9aa5b1;
  --gray-300: #cbd2d9;
  --gray-200: #e4e7eb;
  --gray-100: #f0f2f5;
  --gray-50: #f7f8fa;
  --white: #ffffff;
  --danger: #d64545;
  --danger-bg: #fde8e8;
  --warn: #c47d0e;
  --warn-bg: #fff4db;
  --ok: #1f8a4c;
  --ok-bg: #e3f6eb;
  --sum-bg: #eef6e8;
  --sidebar-w: 280px;
  --header-h: 48px;
  --font: "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 13px;
  color: var(--gray-900);
  background: var(--gray-100);
  -webkit-font-smoothing: antialiased;
}

button, input, select {
  font: inherit;
  color: inherit;
}

.app {
  display: grid;
  grid-template-rows: var(--header-h) 1fr;
  height: 100vh;
  min-height: 640px;
}

/* —— Top bar (WEHAGO blue) —— */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: linear-gradient(180deg, var(--blue-600), var(--blue-700));
  color: var(--white);
  box-shadow: 0 1px 0 rgba(0,0,0,.12);
  user-select: none;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 15px;
}
.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: rgba(255,255,255,.2);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
}
.top-tabs {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}
.top-tab {
  border: 0;
  background: transparent;
  color: rgba(255,255,255,.88);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.top-tab:hover { background: rgba(255,255,255,.12); }
.top-tab:active { background: rgba(0,0,0,.14); }
.top-tab.is-active {
  background: rgba(0,0,0,.18);
  color: #fff;
  font-weight: 600;
}
.top-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
  align-items: center;
}
.icon-btn {
  border: 0;
  background: rgba(255,255,255,.12);
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 4px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .12s ease;
}
.icon-btn:hover { background: rgba(255,255,255,.2); }
.icon-btn:active { background: rgba(0,0,0,.18); }

/* —— Body —— */
.body {
  display: grid;
  grid-template-columns: 1fr var(--sidebar-w);
  min-height: 0;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--white);
  border-right: 1px solid var(--gray-200);
}

/* pills / filters */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 14px;
  background: var(--blue-50);
  border-bottom: 1px solid var(--blue-200);
}
.pill-row { display: flex; gap: 4px; flex-wrap: wrap; }
.pill {
  border: 1px solid var(--blue-200);
  background: var(--white);
  color: var(--blue-800);
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.pill:hover { background: var(--blue-100); }
.pill:active { background: var(--blue-200); }
.pill.is-active {
  background: var(--blue-700);
  border-color: var(--blue-700);
  color: #fff;
}
.pill.is-active:hover { background: var(--blue-800); }
.pill.is-active:active { background: var(--blue-900); }

.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--gray-600);
}
.filter-group label { white-space: nowrap; font-size: 12px; }
.filter-group input,
.filter-group select {
  height: 28px;
  border: 1px solid var(--gray-300);
  border-radius: 3px;
  padding: 0 8px;
  background: var(--white);
  min-width: 110px;
}
.filter-group input:focus,
.filter-group select:focus {
  outline: 2px solid var(--blue-300);
  outline-offset: 0;
  border-color: var(--blue-500);
}

.btn {
  height: 28px;
  padding: 0 14px;
  border-radius: 3px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.btn-primary {
  background: var(--blue-700);
  color: #fff;
}
.btn-primary:hover { background: var(--blue-800); }
.btn-primary:active { background: var(--blue-900); }
.btn-muted {
  background: #5a6672;
  color: #fff;
}
.btn-muted:hover { background: #48535d; }
.btn-muted:active { background: #364049; }
.btn-ghost {
  background: var(--white);
  border-color: var(--gray-300);
  color: var(--gray-700);
}
.btn-ghost:hover { background: var(--gray-100); }
.btn-ghost:active { background: var(--gray-200); }

/* KPI strip */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  border-bottom: 1px solid var(--gray-200);
}
.kpi {
  padding: 12px 14px;
  border-right: 1px solid var(--gray-200);
  background: var(--white);
  cursor: pointer;
  transition: background .12s ease;
}
.kpi:last-child { border-right: 0; }
.kpi:hover { background: var(--blue-50); }
.kpi:active { background: var(--blue-100); }
.kpi.is-active { background: var(--blue-100); box-shadow: inset 0 -2px 0 var(--blue-700); }
.kpi-label {
  font-size: 11px;
  color: var(--gray-500);
  margin-bottom: 4px;
}
.kpi-value {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.kpi-sub {
  margin-top: 2px;
  font-size: 11px;
  color: var(--gray-500);
}
.kpi.danger .kpi-value { color: var(--danger); }
.kpi.warn .kpi-value { color: var(--warn); }

/* content split: table + charts */
.content {
  display: grid;
  grid-template-rows: minmax(0, 1fr) 220px;
  min-height: 0;
  flex: 1;
}

.table-wrap {
  overflow: auto;
  min-height: 0;
  position: relative;
}

table.grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}
table.grid thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #eef2f6;
  color: var(--gray-700);
  font-weight: 600;
  font-size: 12px;
  text-align: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--gray-300);
  border-right: 1px solid var(--gray-200);
  white-space: nowrap;
}
table.grid thead tr.group th {
  background: var(--blue-100);
  color: var(--blue-900);
  border-bottom: 1px solid var(--blue-200);
}
table.grid tbody td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--gray-200);
  border-right: 1px solid var(--gray-100);
  white-space: nowrap;
  background: var(--white);
}
table.grid tbody tr:nth-child(even) td { background: var(--gray-50); }
table.grid tbody tr:hover td { background: var(--blue-50); }
table.grid tbody tr.is-selected td {
  background: var(--blue-150) !important;
  color: var(--blue-900);
}
table.grid tbody tr.is-selected:active td {
  background: var(--blue-200) !important;
}
table.grid tbody tr { cursor: pointer; }
table.grid .num { text-align: right; }
table.grid .center { text-align: center; }
table.grid tfoot td {
  background: var(--sum-bg);
  font-weight: 700;
  padding: 8px 10px;
  border-top: 1px solid var(--gray-300);
  position: sticky;
  bottom: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
}
.badge-high { background: var(--danger-bg); color: var(--danger); }
.badge-mid { background: var(--warn-bg); color: var(--warn); }
.badge-low { background: var(--ok-bg); color: var(--ok); }
.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.charts {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 0;
  border-top: 1px solid var(--gray-200);
  background: var(--gray-50);
  min-height: 0;
}
.chart-card {
  padding: 10px 12px;
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chart-card:last-child { border-right: 0; }
.chart-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chart-box {
  flex: 1;
  min-height: 0;
  position: relative;
}
.chart-box canvas { width: 100% !important; height: 100% !important; }

/* —— Right sidebar —— */
.sidebar {
  background: #f5f7fa;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--gray-200);
}
.side-head {
  padding: 12px 14px;
  background: var(--blue-700);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.side-head button {
  border: 0;
  background: rgba(255,255,255,.15);
  color: #fff;
  width: 24px;
  height: 24px;
  border-radius: 3px;
  cursor: pointer;
}
.side-head button:hover { background: rgba(255,255,255,.25); }
.side-head button:active { background: rgba(0,0,0,.2); }
.side-body {
  padding: 12px 14px;
  overflow: auto;
  flex: 1;
}
.side-section {
  margin-bottom: 16px;
}
.side-section h4 {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--blue-800);
  font-weight: 700;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--blue-200);
}
.kv {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 6px 8px;
  font-size: 12px;
}
.kv dt { color: var(--gray-500); }
.kv dd { margin: 0; color: var(--gray-900); word-break: break-all; }

.risk-meter {
  height: 8px;
  background: var(--gray-200);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0 4px;
}
.risk-meter > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  transition: width .25s ease;
}
.risk-note {
  font-size: 12px;
  line-height: 1.5;
  color: var(--gray-700);
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  padding: 10px;
}
.risk-note li { margin: 0 0 6px; }
.risk-note li:last-child { margin: 0; }

.due-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.due-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  margin-bottom: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: background .12s ease;
}
.due-list li:hover { background: var(--blue-50); }
.due-list li:active { background: var(--blue-100); }
.due-list .overdue {
  border-color: #f0b4b4;
  background: var(--danger-bg);
}
.due-amt { font-weight: 700; font-variant-numeric: tabular-nums; }

.import-box {
  border: 1px dashed var(--blue-300);
  background: var(--white);
  border-radius: 6px;
  padding: 14px;
  text-align: center;
  color: var(--gray-600);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.import-box:hover { background: var(--blue-50); border-color: var(--blue-500); }
.import-box:active { background: var(--blue-100); }
.import-box strong { display: block; color: var(--blue-800); margin-bottom: 4px; }
.import-box input { display: none; }

.status-bar {
  display: flex;
  gap: 16px;
  padding: 4px 12px;
  background: #e8edf3;
  border-top: 1px solid var(--gray-300);
  font-size: 11px;
  color: var(--gray-600);
}

/* detail panel overlay tabs inside main */
.view-tabs {
  display: flex;
  gap: 0;
  padding: 0 14px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
}
.view-tab {
  border: 0;
  background: transparent;
  padding: 10px 14px;
  color: var(--gray-600);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .12s ease, background .12s ease, border-color .12s ease;
}
.view-tab:hover { background: var(--blue-50); color: var(--blue-800); }
.view-tab:active { background: var(--blue-100); }
.view-tab.is-active {
  color: var(--blue-800);
  font-weight: 700;
  border-bottom-color: var(--blue-700);
}

.hidden { display: none !important; }

@media (max-width: 1100px) {
  .body { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sidebar.is-open-mobile {
    display: flex;
    position: fixed;
    right: 0; top: var(--header-h); bottom: 0;
    width: min(320px, 90vw);
    z-index: 20;
    box-shadow: -8px 0 24px rgba(0,0,0,.15);
  }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .charts { grid-template-columns: 1fr; height: auto; }
  .chart-card { height: 180px; border-right: 0; border-bottom: 1px solid var(--gray-200); }
}
