.contracts-shell {
  display: flex;
  flex: 1;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.contracts-nav {
  width: 156px;
  flex: 0 0 156px;
  padding: 16px 10px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.contracts-nav-title {
  padding: 2px 10px 10px;
  color: #94A3B8;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .12em;
}

.contracts-nav-btn {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font: 600 12px 'Noto Sans KR', sans-serif;
  text-align: left;
  cursor: pointer;
  transition: .15s ease;
}

.contracts-nav-btn:hover { background: var(--surface2); color: var(--text); }
.contracts-nav-btn.is-active {
  color: #3730A3;
  background: #EEF2FF;
  border-color: #A5B4FC;
  box-shadow: inset 3px 0 0 #4F46E5;
  font-weight: 800;
}

.contracts-view {
  display: none;
  flex: 1;
  min-width: 0;
  min-height: 0;
}
.contracts-view.is-active { display: flex; }

.contracts-main {
  width: 0;
  max-width: 100%;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.contracts-main::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 130px;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(79,70,229,.065), rgba(255,255,255,0) 48%, rgba(16,185,129,.035));
}

.contracts-head,
.contracts-kpis,
.contracts-toolbar,
.contracts-table-frame,
.contracts-status { position: relative; z-index: 1; }

.contracts-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 12px;
}

.contracts-title h2 { margin: 0 0 4px; font-size: 18px; color: var(--text); }
.contracts-title p { margin: 0; font-size: 12px; color: var(--text-muted); }

.contracts-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  min-width: 0;
  gap: 10px;
  padding: 0 22px 14px;
}

.contracts-kpi {
  min-width: 0;
  min-height: 82px;
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,.94);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(15,23,42,.045);
  transition: transform .15s, border-color .15s, box-shadow .15s;
  font-family: 'Noto Sans KR', sans-serif;
}
.contracts-kpi:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(15,23,42,.07); }
.contracts-kpi.is-active { border-color: currentColor; box-shadow: 0 0 0 2px currentColor, 0 10px 24px rgba(15,23,42,.07); }
.contracts-kpi-label { display: block; margin-bottom: 5px; color: var(--text-muted); font-size: 11px; font-weight: 800; }
.contracts-kpi-value { color: var(--text); font-size: 23px; font-weight: 900; font-variant-numeric: tabular-nums; }
.contracts-kpi-unit { margin-left: 3px; color: var(--text-muted); font-size: 11px; font-weight: 600; }
.contracts-kpi-sub { display: block; margin-top: 2px; color: #94A3B8; font-size: 10px; }
.contracts-kpi.k6 { color: #2563EB; }
.contracts-kpi.k3 { color: #D97706; }
.contracts-kpi.k1 { color: #EA580C; }
.contracts-kpi.k0 { color: #DC2626; }

.contracts-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.contracts-sheet-tabs { display: flex; gap: 5px; flex-wrap: wrap; }
.contracts-sheet-btn {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text-muted);
  font: 700 11px 'Noto Sans KR', sans-serif;
  cursor: pointer;
}
.contracts-sheet-btn:hover { border-color: #A5B4FC; color: #4338CA; }
.contracts-sheet-btn.is-active { background: #EEF2FF; border-color: #818CF8; color: #3730A3; }

.contracts-toolbar-spacer { flex: 1; }
.contracts-add-row-btn {
  padding: 7px 11px;
  border: 1px solid #4F46E5;
  border-radius: 8px;
  background: #4F46E5;
  color: #fff;
  font: 800 11px 'Noto Sans KR', sans-serif;
  cursor: pointer;
}
.contracts-add-row-btn:hover { background: #4338CA; border-color: #4338CA; }
.contracts-add-row-btn:disabled { opacity: .55; cursor: wait; }
.contracts-search {
  width: 230px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  color: var(--text);
  background: #fff;
  font: 12px 'Noto Sans KR', sans-serif;
}
.contracts-search:focus { border-color: #818CF8; box-shadow: 0 0 0 3px rgba(99,102,241,.1); }
.contracts-refresh {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text-muted);
  font: 700 11px 'Noto Sans KR', sans-serif;
  cursor: pointer;
}
.contracts-refresh:hover { color: var(--text); border-color: #94A3B8; }

.contracts-status {
  display: flex;
  align-items: center;
  min-height: 30px;
  padding: 7px 22px 0;
  color: var(--text-muted);
  font-size: 11px;
}
.contracts-status.is-error { color: #B91C1C; }
.contracts-status.is-ok { color: #047857; }

.contracts-table-frame {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: auto;
  max-width: calc(100% - 44px);
  min-height: 0;
  margin: 8px 22px 20px;
  position: relative;
  overflow: hidden;
}

.contracts-table-card {
  flex: 1;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  background: var(--surface);
  overflow-x: auto;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(15,23,42,.045);
  scrollbar-width: none;
}

.contracts-table-card::-webkit-scrollbar { width: 12px; height: 0; }
.contracts-table-card::-webkit-scrollbar-track { background: #F1F5F9; border-radius: 999px; }
.contracts-table-card::-webkit-scrollbar-thumb { background: #94A3B8; border: 3px solid #F1F5F9; border-radius: 999px; }
.contracts-horizontal-scroll {
  flex: 0 0 17px;
  width: 100%;
  height: 17px;
  overflow-x: scroll;
  overflow-y: hidden;
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 10px 10px;
  background: #F1F5F9;
  scrollbar-color: #64748B #E2E8F0;
  scrollbar-width: auto;
}
.contracts-horizontal-scroll::-webkit-scrollbar { height: 16px; }
.contracts-horizontal-scroll::-webkit-scrollbar-track { background: #E2E8F0; border-radius: 0 0 10px 10px; }
.contracts-horizontal-scroll::-webkit-scrollbar-thumb {
  min-width: 48px;
  background: #64748B;
  border: 3px solid #E2E8F0;
  border-radius: 999px;
}
.contracts-horizontal-scroll-inner { height: 1px; }
.contracts-scroll-hint {
  position: absolute;
  z-index: 8;
  top: 1px;
  right: 1px;
  bottom: 18px;
  width: 104px;
  border-radius: 0 11px 0 0;
  background: linear-gradient(90deg, rgba(248,250,252,0), rgba(248,250,252,.78) 42%, rgba(248,250,252,.98) 82%, #F8FAFC);
  box-shadow: 14px 0 18px rgba(248,250,252,.96);
  opacity: 0;
  pointer-events: none;
}
.contracts-table-frame.has-overflow:not(.is-at-end) .contracts-scroll-hint { opacity: 1; }

.contracts-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.contracts-table th {
  position: sticky;
  top: 0;
  z-index: 3;
  min-width: 112px;
  padding: 9px 10px;
  border-right: 1px solid #E5E7EB;
  border-bottom: 1px solid var(--border);
  background: #F8FAFC;
  color: #64748B;
  font-size: 11px;
  font-weight: 800;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}
.contracts-table th:first-child { left: 0; z-index: 5; min-width: 62px; text-align: center; }
.contracts-table th:last-child { min-width: 170px; }
.contracts-table th:hover { color: #3730A3; background: #F1F5F9; }
.contracts-draggable-header { cursor: grab !important; user-select: none; }
.contracts-draggable-header:active { cursor: grabbing !important; }
.contracts-draggable-header.is-dragging { opacity: .45; }
.contracts-draggable-header.is-drag-over-before { box-shadow: inset 3px 0 #4F46E5; }
.contracts-draggable-header.is-drag-over-after { box-shadow: inset -3px 0 #4F46E5; }
.contracts-drag-hint { float: right; margin-left: 8px; color: #A5B4FC; font-size: 12px; letter-spacing: -3px; }
.contracts-filter-actions { display: inline-flex; align-items: center; gap: 8px; }
.contracts-sort { margin-left: 4px; color: #A5B4FC; }
.contracts-filter-header { cursor: default !important; padding: 0 !important; }
.contracts-filter-header.is-open { z-index: 9; }
.contracts-filter-header.is-filtered { background: #EEF2FF; color: #3730A3; }
.contracts-filter-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 35px;
  padding: 9px 10px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.contracts-filter-trigger:hover { color: #3730A3; background: #F1F5F9; }
.contracts-filter-arrow { color: #64748B; font-size: 8px; transition: transform .15s ease; }
.contracts-filter-header.is-open .contracts-filter-arrow { transform: rotate(180deg); color: #4F46E5; }
.contracts-filter-header.is-filtered .contracts-filter-arrow { color: #4F46E5; }
.contracts-filter-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% - 1px);
  left: 4px;
  width: 230px;
  padding: 8px;
  border: 1px solid #CBD5E1;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 16px 36px rgba(15,23,42,.18);
  color: #0F172A;
  text-align: left;
}
.contracts-filter-options {
  max-height: 220px;
  margin: 4px 0 8px;
  overflow-y: auto;
  border-top: 1px solid #E2E8F0;
  border-bottom: 1px solid #E2E8F0;
}
.contracts-filter-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 8px;
  border-radius: 6px;
  color: #334155;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.contracts-filter-option:hover { background: #F8FAFC; color: #3730A3; }
.contracts-filter-option input { width: 15px; height: 15px; margin: 0; accent-color: #4F46E5; cursor: pointer; }
.contracts-filter-all { color: #0F172A; font-weight: 800; }
.contracts-filter-empty { padding: 18px 8px; color: #94A3B8; text-align: center; font-size: 11px; }
.contracts-filter-clear {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid #C7D2FE;
  border-radius: 7px;
  background: #EEF2FF;
  color: #4338CA;
  font: 800 11px 'Noto Sans KR', sans-serif;
  cursor: pointer;
}
.contracts-filter-clear:hover { background: #E0E7FF; }
.contracts-filter-clear:disabled { border-color: #E2E8F0; background: #F8FAFC; color: #94A3B8; cursor: default; }

.contracts-table td {
  min-width: 112px;
  max-width: 260px;
  padding: 8px 10px;
  border-right: 1px solid #F1F5F9;
  border-bottom: 1px solid #E5E7EB;
  background: #fff;
  color: #0F172A;
  font-size: 11px;
  line-height: 1.45;
  vertical-align: middle;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.contracts-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 62px;
  color: #94A3B8;
  background: #FAFBFC;
  text-align: center;
  font-weight: 700;
}
.contracts-table tr:hover td { background: #F8FAFC; }
.contracts-table tr:hover td:first-child { background: #F1F5F9; }
.contracts-table tr.is-expired td { background: #FFF7F7; }
.contracts-table tr.is-expired:hover td { background: #FEF2F2; }
.contracts-table tr.is-selected td {
  background: #EEF6FF !important;
  box-shadow: inset 0 1px 0 #93C5FD, inset 0 -1px 0 #93C5FD;
}
.contracts-table tr.is-selected td:first-child {
  color: #1D4ED8;
  background: #DBEAFE !important;
  box-shadow: inset 3px 0 0 #3B82F6, inset 0 1px 0 #93C5FD, inset 0 -1px 0 #93C5FD;
}

.contracts-owner-cell { font-weight: 900; letter-spacing: .01em; }
.contracts-owner-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  padding: 3px 10px;
  border-radius: 999px;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: inset 0 0 0 1px rgba(15,23,42,.06);
}
.contracts-owner-chip.contracts-owner-ccc { color: #166534; background: #DCFCE7; }
.contracts-owner-chip.contracts-owner-cc { color: #92400E; background: #FEF3C7; }
.contracts-owner-chip.contracts-owner-c { color: #B91C1C; background: #FEE2E2; }
.contracts-owner-chip.contracts-owner-seonhada { color: #075985; background: #E0F2FE; }
.contracts-owner-chip.contracts-owner-other { color: #475569; background: #F1F5F9; }

.contracts-cell[contenteditable="true"] {
  outline: none;
  cursor: text;
  transition: box-shadow .12s, background .12s;
}
.contracts-cell[contenteditable="true"]:hover { box-shadow: inset 0 0 0 1px #C7D2FE; }
.contracts-cell[contenteditable="true"]:focus { background: #EEF2FF !important; box-shadow: inset 0 0 0 2px #6366F1; }
.contracts-cell.is-dirty { background: #FFF7ED !important; }
.contracts-cell.is-saving { background: #FFFBEB !important; }
.contracts-cell.is-saved { animation: contractsSaved .9s ease; }
.contracts-cell.is-conflict { background: #FEF2F2 !important; box-shadow: inset 0 0 0 2px #EF4444; }
@keyframes contractsSaved { 0%,100%{background:#fff} 35%{background:#ECFDF5} }


.contracts-file-cell {
  min-width: 220px !important;
  max-width: 280px !important;
}
.contracts-file-wrap { display: flex; align-items: center; gap: 8px; width: 100%; }
.contracts-file-main { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; flex: 1; }
.contracts-file-link { color: #4338CA; font-weight: 700; text-decoration: none; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contracts-file-link:hover { text-decoration: underline; }
.contracts-upload-btn,
.contracts-delete-btn,
.contracts-row-delete-btn {
  padding: 4px 7px;
  border-radius: 6px;
  font: 700 10px 'Noto Sans KR', sans-serif;
  cursor: pointer;
}
.contracts-upload-btn { border: 1px solid #86EFAC; background: #ECFDF5; color: #047857; }
.contracts-delete-btn { border: 1px solid #FCA5A5; background: #FEF2F2; color: #B91C1C; }
.contracts-row-delete-btn {
  flex: 0 0 auto;
  margin-left: auto;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: #94A3B8;
  font-size: 17px;
  line-height: 1;
  opacity: .35;
}
.contracts-file-cell:hover .contracts-row-delete-btn,
.contracts-table tr.is-selected .contracts-row-delete-btn,
.contracts-row-delete-btn:focus-visible { opacity: 1; }
.contracts-row-delete-btn:hover { border-color: #FDA4AF; background: #FFF1F2; color: #BE123C; }
.contracts-file-drop { outline: 2px dashed #6366F1; outline-offset: -4px; background: #EEF2FF !important; }

.contracts-upload-dialog { position: fixed; inset: 0; z-index: 4000; display: grid; place-items: center; padding: 20px; }
.contracts-upload-dialog[hidden] { display: none !important; }
.contracts-upload-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.52); backdrop-filter: blur(2px); }
.contracts-upload-panel {
  position: relative;
  z-index: 1;
  width: min(440px, 100%);
  padding: 24px;
  border: 1px solid #E2E8F0;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15,23,42,.25);
}
.contracts-upload-panel h3 { margin: 0 36px 4px 0; color: #0F172A; font-size: 18px; }
.contracts-upload-panel > p { margin: 0 0 16px; color: #64748B; font-size: 12px; }
.contracts-upload-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 999px;
  background: #F1F5F9;
  color: #64748B;
  font-size: 20px;
  cursor: pointer;
}
.contracts-upload-dropzone {
  display: flex;
  min-height: 150px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 22px;
  border: 2px dashed #A5B4FC;
  border-radius: 14px;
  background: #F8FAFF;
  color: #64748B;
  text-align: center;
  cursor: pointer;
  outline: none;
  transition: border-color .15s, background .15s, transform .15s;
}
.contracts-upload-dropzone strong { color: #4338CA; font-size: 15px; }
.contracts-upload-dropzone span { font-size: 12px; }
.contracts-upload-dropzone:hover,
.contracts-upload-dropzone:focus-visible,
.contracts-upload-dropzone.is-dragging { border-color: #4F46E5; background: #EEF2FF; transform: translateY(-1px); }
.contracts-upload-dialog.is-uploading .contracts-upload-dropzone { pointer-events: none; opacity: .6; }
.contracts-upload-dialog-status { min-height: 22px; padding-top: 10px; color: #475569; font-size: 11px; text-align: center; }

.contracts-empty,
.contracts-loading {
  padding: 56px 24px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
}
.contracts-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 7px;
  border: 2px solid #C7D2FE;
  border-top-color: #4F46E5;
  border-radius: 50%;
  vertical-align: -3px;
  animation: spin .75s linear infinite;
}

.contracts-library { overflow: auto; padding: 20px; }
.contracts-library .rv-panel { max-width: 1100px; width: 100%; margin: 0 auto; min-height: 0; }

@media (max-width: 980px) {
  .contracts-nav { width: 126px; flex-basis: 126px; }
  .contracts-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .contracts-kpi { padding: 10px 8px; min-height: 76px; }
  .contracts-kpi-sub { font-size: 9px; }
  .contracts-head { padding: 16px 14px 10px; }
  .contracts-kpis, .contracts-toolbar { padding-left: 14px; padding-right: 14px; }
  .contracts-table-frame { max-width: calc(100% - 28px); margin-left: 14px; margin-right: 14px; }
}
