:root {
  --header-height: 56px;
  --sidebar-width: 240px;
  --sidebar-collapsed-width: 64px;
  --primary-color: #1e3a5f;
  --sidebar-bg: #1a2f4a;
  --sidebar-hover: #243d5c;
  --content-bg: #f4f6f9;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans KR', sans-serif;
  background: var(--content-bg);
  color: #212529;
}

/* Layout */
.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--primary-color);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: 1030;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .1);
}

.app-toast-container {
  top: calc(var(--header-height) + .75rem);
  right: 1rem;
  z-index: 1090;
  pointer-events: none;
}

.app-toast-container .toast {
  pointer-events: auto;
  min-width: min(360px, calc(100vw - 2rem));
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.header-bell,
.header-user,
.header-logout {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  color: #fff;
  text-decoration: none;
  line-height: 1;
  padding: .35rem .4rem;
  border-radius: .25rem;
  border: 0;
  background: transparent;
  flex-shrink: 0;
}

.header-bell:hover,
.header-user:hover,
.header-logout:hover {
  color: #e8eef5;
  background: rgba(255, 255, 255, .08);
}

.header-user-static {
  cursor: default;
  pointer-events: none;
}

.header-user-switcher {
  position: relative;
}

.header-user-switcher .header-user.dropdown-toggle::after {
  margin-left: .2rem;
  vertical-align: .15em;
  opacity: .85;
}

.header-user-switch-menu {
  min-width: 12rem;
  max-width: min(18rem, 80vw);
  max-height: 18rem;
  overflow-y: auto;
  padding: .35rem 0;
}

.header-user-switch-item {
  white-space: normal;
  line-height: 1.25;
}

.header-user-switch-current {
  display: block;
  padding: .4rem .9rem;
  font-size: .875rem;
}

.header-bell,
.header-logout {
  font-size: 1.15rem;
}

.header-logout-form {
  display: inline-flex;
  align-items: center;
}

.header-logout {
  cursor: pointer;
}

.header-bell-alert {
  position: absolute;
  top: -.05rem;
  right: -.1rem;
  width: .9rem;
  height: .9rem;
  border-radius: 50%;
  background: #dc3545;
  color: #fff;
  font-size: .55rem;
  font-weight: 700;
  line-height: .9rem;
  text-align: center;
  pointer-events: none;
}

.header-user {
  max-width: min(220px, 42vw);
  font-size: .9rem;
  min-width: 0;
}

.header-user .bi-person-circle {
  font-size: 1.15rem;
  flex-shrink: 0;
}

.header-user-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-sidebar {
  display: flex;
  flex-direction: column;
}

.app-sidebar .sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
}

.brand {
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
}

.brand:hover { color: #e8eef5; }

.env-badge {
  display: inline-block;
  margin-left: .5rem;
  padding: .1rem .4rem;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .02em;
  vertical-align: middle;
  border-radius: .25rem;
  background: rgba(255, 255, 255, .18);
  color: #fff;
}

body.env-dev {
  --primary-color: #6d4a4e;
  --sidebar-bg: #543c3f;
  --sidebar-hover: #65484b;
}

body.env-dev .app-sidebar .nav-link.active {
  border-left-color: #c9a3a6;
}

body.env-dev .brand:hover { color: #f3e8e9; }

body.env-dev.auth-body {
  background: linear-gradient(135deg, #6d4a4e 0%, #8a6266 100%);
}

.sidebar-toggle {
  color: #fff !important;
  font-size: 1.4rem;
  padding: .25rem .5rem;
  text-decoration: none;
}

.app-sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--header-height));
  background: var(--sidebar-bg);
  overflow: hidden;
  transition: width .25s ease, transform .25s ease;
  z-index: 1020;
}

.app-sidebar .nav-link {
  color: #c8d6e5;
  padding: .75rem 1.25rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s;
}

.app-sidebar .nav-link:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.app-sidebar .nav-link.active {
  background: var(--sidebar-hover);
  color: #fff;
  border-left-color: #4dabf7;
}

.app-sidebar .nav-link.disabled {
  opacity: .5;
  pointer-events: none;
}

.nav-section {
  display: block;
  padding: .5rem 1.25rem;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #7a8fa8;
}

.app-content {
  margin-top: var(--header-height);
  margin-left: var(--sidebar-width);
  min-height: calc(100vh - var(--header-height));
  display: flex;
  flex-direction: column;
  transition: margin-left .25s ease;
}

.content-inner {
  flex: 1;
  padding: 1.5rem;
}

.app-footer {
  padding: 1rem 1.5rem;
  font-size: .8rem;
  color: #6c757d;
  border-top: 1px solid #dee2e6;
  background: #fff;
}

/* Collapsed sidebar */
body.sidebar-collapsed .app-sidebar {
  width: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .app-sidebar .nav-link span,
body.sidebar-collapsed .app-sidebar .nav-section {
  display: none;
}

body.sidebar-collapsed .app-sidebar .nav-link {
  justify-content: center;
  padding: .75rem;
}

body.sidebar-collapsed .app-content {
  margin-left: var(--sidebar-collapsed-width);
}

/* Auth */
.auth-body {
  background: linear-gradient(135deg, #1e3a5f 0%, #2d5a87 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-body .app-toast-container {
  top: 1rem;
}

.auth-wrapper {
  width: 100%;
  padding: 1rem;
}

.auth-card {
  max-width: 420px;
  margin: 0 auto;
  border: none;
  border-radius: .75rem;
}

/* Components */
.page-title { font-weight: 600; }

.stat-card {
  border: none;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.stat-card .stat-label {
  font-size: .85rem;
  color: #6c757d;
}

.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary-color);
}

.card {
  border: none;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  border-radius: .5rem;
}

.table th {
  font-size: .85rem;
  font-weight: 600;
  white-space: nowrap;
}

/* 카드 관리 목록 */
.cards-index-table {
  table-layout: fixed;
  width: 100%;
}

.cards-index-table .col-card-name {
  width: 200px;
  max-width: 200px;
}

.cards-index-table .card-name-text {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cards-index-table .card-number-link {
  text-decoration: none;
}

.cards-index-table .card-number-link:hover code {
  text-decoration: underline;
}

.client-contacts-table .client-contacts-col-name { width: 12%; }
.client-contacts-table .client-contacts-col-position { width: 11%; }
.client-contacts-table .client-contacts-col-phone { width: 20%; }
.client-contacts-table .client-contacts-col-email { width: 26%; }
.client-contacts-table .client-contacts-col-actions { width: 1%; }

/* 거래처 정보 카드 — label/value 1행 compact */
.client-info-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.client-info-row {
  display: grid;
  grid-template-columns: 7.75rem minmax(0, 1fr);
  column-gap: 0.75rem;
  align-items: baseline;
}
.client-info-row-memo {
  grid-template-columns: 7.75rem minmax(0, 1fr) auto;
  align-items: start;
}
.client-info-label {
  color: var(--bs-secondary-color);
  font-size: 0.8125rem;
  line-height: 1.4;
  flex-shrink: 0;
}
.client-info-value {
  min-width: 0;
  font-size: 0.875rem;
  line-height: 1.4;
  word-break: break-word;
}

/* 거래처 문서 panel — Bootstrap row stretch + h-100 (운영 구조) / upload 1행 */
.client-doc-card {
  display: flex;
  flex-direction: column;
}
.client-doc-body {
  min-height: 0;
}
.client-doc-empty,
.client-doc-preview {
  flex: 1 1 auto;
  min-height: 280px;
}
.client-doc-preview {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.client-doc-preview-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}
.client-doc-preview-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.client-doc-upload-row {
  min-width: 0;
}
.client-doc-upload-row .client-doc-label {
  flex: 1 1 auto;
  min-width: 0;
}
/* desktop: h-100 유지 + viewport min-height로 하단 여백 축소 (height 고정 금지) */
@media (min-width: 992px) {
  .client-doc-card {
    min-height: calc(100vh - var(--header-height) - 15.5rem);
  }
}

/* 세금계산서 상세 — content-inner 폭 전체 사용 (sidebar 침범 금지) */
.tax-invoice-show {
  width: 100%;
  max-width: none;
}
.tax-inv-detail {
  width: 100%;
}
.tax-inv-metric {
  padding: 1rem 1.15rem;
  border-radius: .5rem;
  background: #f8f9fa;
  border: 1px solid #e9ecef;
}

.tax-inv-metric-total.tax-inv-metric-primary {
  background: rgba(13, 110, 253, .06);
  border-color: rgba(13, 110, 253, .18);
}

.tax-inv-metric-total.tax-inv-metric-danger {
  background: rgba(220, 53, 69, .06);
  border-color: rgba(220, 53, 69, .18);
}

.tax-inv-metric-label {
  font-size: .8rem;
  color: #6c757d;
  margin-bottom: .35rem;
}

.tax-inv-metric-value {
  font-size: 1.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}

.tax-inv-metric-total .tax-inv-metric-value {
  font-size: 1.45rem;
}

/* Permission Matrix UI — Role × Action table */
.rbac-role-tabs .nav-link {
  color: #495057;
}
.rbac-role-tabs .nav-link.active {
  font-weight: 600;
  color: #1e3a5f;
}
.rbac-role-panel {
  background: #fff;
}
.rbac-action-matrix {
  --rbac-resource-width: 38%;
  --rbac-action-width: 7.5%;
  min-width: 720px;
}
.rbac-action-matrix .rbac-col-resource { width: var(--rbac-resource-width); }
.rbac-action-matrix .rbac-col-action { width: var(--rbac-action-width); }
.rbac-action-matrix .rbac-col-special { width: 12%; min-width: 6.5rem; }
.rbac-action-matrix thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8f9fa;
  vertical-align: middle;
  padding: .45rem .35rem;
  font-size: .8rem;
  font-weight: 600;
  white-space: nowrap;
}
.rbac-action-matrix td {
  padding: .35rem .4rem;
  vertical-align: middle;
}
.rbac-resource-label {
  font-weight: 600;
  font-size: .875rem;
  white-space: nowrap;
}
.rbac-section-cell {
  background: #eef2f6 !important;
  color: #495057;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: .35rem .75rem !important;
}
.rbac-action-cell {
  cursor: pointer;
  min-width: 2.75rem;
}
.rbac-action-cell .form-check-input,
.rbac-special-cell .form-check-input {
  width: 1.1rem;
  height: 1.1rem;
  margin: 0;
  cursor: pointer;
}
.rbac-na {
  font-size: .85rem;
  user-select: none;
}
.rbac-cell-dirty {
  background: rgba(255, 193, 7, .14) !important;
}
.rbac-action-bar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, .04);
}

/* 원장가져오기 — 파일선택 + 업로드 단일행 */
.import-upload-row .import-upload-file {
  min-width: 0;
  min-height: calc(1.5em + .5rem + 2px);
  padding: .125rem .5rem;
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  background: #fff;
}
.import-upload-row .import-upload-file .btn {
  white-space: nowrap;
}
@media (min-width: 576px) {
  .import-upload-row {
    flex-wrap: nowrap;
  }
}

/* 신한은행 ①/② 2열 */
.shinhan-dual-cols > .shinhan-dual-col .import-upload-row {
  width: 100%;
}
@media (min-width: 768px) {
  .shinhan-dual-cols > .shinhan-dual-col + .shinhan-dual-col {
    border-left: 1px solid var(--bs-border-color);
    padding-left: 1rem;
  }
  .shinhan-dual-cols > .shinhan-dual-col:first-child {
    padding-right: .25rem;
  }
}

/* Person 문서 목록 — 내부 스크롤 + 컬럼 폭 (FIX-094) */
.person-document-list {
  max-height: 460px;
  overflow-y: auto;
}
.person-document-list table {
  table-layout: fixed;
  width: 100%;
}
.person-document-list thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background-color: var(--bs-table-bg, #f8f9fa);
  box-shadow: inset 0 -1px 0 var(--bs-border-color, #dee2e6);
}
.person-doc-col-type {
  width: 7.5rem;
}
.person-doc-col-size {
  width: 4.5rem;
}
.person-doc-col-actions {
  width: 13.5rem;
}
.person-doc-col-name {
  width: auto;
  min-width: 0;
}
.person-doc-filename {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.person-doc-actions {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
}

/* Mobile */
@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width);
  }

  body.sidebar-open .app-sidebar {
    transform: translateX(0);
  }

  .app-content {
    margin-left: 0;
  }

  body.sidebar-collapsed .app-content {
    margin-left: 0;
  }
}
