.app-shell {
  display: flex;
  min-height: 100vh;
}

:root {
  --sidebar-width: 224px;
  --sidebar-scale: 1;
}

html[data-feishu-client="1"] {
  --sidebar-width: 208px;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  width: var(--sidebar-width);
  height: 100vh;
  flex: 0 0 var(--sidebar-width);
  display: flex;
  flex-direction: column;
  padding: calc(18px * var(--sidebar-scale)) calc(14px * var(--sidebar-scale)) calc(16px * var(--sidebar-scale));
  background: #fff;
  border-right: 1px solid var(--line);
  z-index: 30;
  overflow: hidden;
  pointer-events: auto;
}

.sidebar-brand {
  min-height: calc(64px * var(--sidebar-scale));
  margin: 0 calc(4px * var(--sidebar-scale)) calc(22px * var(--sidebar-scale));
  padding: calc(7px * var(--sidebar-scale)) calc(9px * var(--sidebar-scale));
  border-radius: calc(12px * var(--sidebar-scale));
}

.sidebar-brand:hover {
  background: var(--surface-soft);
}

.sidebar-brand .logo {
  width: calc(38px * var(--sidebar-scale));
  height: calc(38px * var(--sidebar-scale));
  border-radius: calc(12px * var(--sidebar-scale));
  font-size: calc(14px * var(--sidebar-scale));
}

.sidebar-brand strong {
  font-size: calc(14px * var(--sidebar-scale));
  line-height: 1.35;
}

.sidebar-brand small {
  letter-spacing: .13em;
  font-size: calc(9px * var(--sidebar-scale));
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: calc(8px * var(--sidebar-scale));
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.nav-label {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav a {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: calc(10px * var(--sidebar-scale));
  min-height: calc(44px * var(--sidebar-scale));
  padding: calc(8px * var(--sidebar-scale)) calc(10px * var(--sidebar-scale));
  color: #59647a;
  border-radius: calc(11px * var(--sidebar-scale));
  font-size: calc(14px * var(--sidebar-scale));
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background .16s ease, color .16s ease;
  overflow: hidden;
}

.sidebar-nav a:hover {
  color: var(--blue);
  background: #f2f6ff;
}

.sidebar-nav a.active {
  color: var(--blue);
  background: #eaf1ff;
  box-shadow: inset 3px 0 0 var(--blue);
}

.nav-icon {
  width: calc(29px * var(--sidebar-scale));
  height: calc(29px * var(--sidebar-scale));
  flex: 0 0 calc(29px * var(--sidebar-scale));
  display: grid;
  place-items: center;
  border-radius: calc(8px * var(--sidebar-scale));
  background: #f0f3f8;
  color: #69758c;
  font-size: calc(12px * var(--sidebar-scale));
  font-weight: 700;
}

.sidebar-nav a.active .nav-icon {
  color: #fff;
  background: var(--blue);
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: calc(10px * var(--sidebar-scale));
  color: var(--muted);
  font-size: calc(11px * var(--sidebar-scale));
  flex-shrink: 0;
  min-width: 0;
}

.service-status {
  display: flex;
  align-items: center;
  gap: calc(9px * var(--sidebar-scale));
  padding: calc(11px * var(--sidebar-scale)) calc(12px * var(--sidebar-scale));
  border: 1px solid var(--line);
  border-radius: calc(11px * var(--sidebar-scale));
  background: var(--surface-soft);
}

.service-status > span:last-child {
  display: flex;
  flex-direction: column;
}

.service-status strong {
  color: var(--ink);
  font-size: calc(12px * var(--sidebar-scale));
}

.service-status small {
  color: var(--muted);
  font-size: calc(10px * var(--sidebar-scale));
}

.status-dot {
  width: calc(8px * var(--sidebar-scale));
  height: calc(8px * var(--sidebar-scale));
  flex: 0 0 calc(8px * var(--sidebar-scale));
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--green) 16%, transparent);
}

.version-row {
  display: flex;
  justify-content: space-between;
  padding: 0 4px;
}

.version-row strong {
  color: var(--muted);
  font-weight: 600;
}

.sidebar[data-sidebar-collapsed="1"] .nav-label,
.sidebar[data-sidebar-collapsed="1"] .sidebar-brand > span:last-child,
.sidebar[data-sidebar-collapsed="1"] .service-status > span:last-child,
html[data-sidebar-collapsed="1"] .sidebar .nav-label,
html[data-sidebar-collapsed="1"] .sidebar .sidebar-brand > span:last-child,
html[data-sidebar-collapsed="1"] .sidebar .service-status > span:last-child {
  display: none !important;
}

.sidebar[data-sidebar-collapsed="1"] .sidebar-brand,
html[data-sidebar-collapsed="1"] .sidebar .sidebar-brand {
  justify-content: center;
  min-height: auto;
  margin-bottom: calc(12px * var(--sidebar-scale));
}

.sidebar[data-sidebar-collapsed="1"] .sidebar-nav a,
html[data-sidebar-collapsed="1"] .sidebar .sidebar-nav a {
  justify-content: center;
  padding-left: calc(8px * var(--sidebar-scale));
  padding-right: calc(8px * var(--sidebar-scale));
}

.sidebar[data-sidebar-collapsed="1"] .service-status,
html[data-sidebar-collapsed="1"] .sidebar .service-status {
  justify-content: center;
  padding-left: calc(8px * var(--sidebar-scale));
  padding-right: calc(8px * var(--sidebar-scale));
}

.sidebar-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-right: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
  font-family: inherit;
}

.sidebar-toggle:hover {
  color: var(--blue);
  border-color: color-mix(in srgb, var(--blue) 35%, var(--line));
  background: var(--hover-blue);
}

.sidebar-toggle-icon {
  font-size: 18px;
  line-height: 1;
}

.ledger-panel .table-wrap table {
  min-width: 960px;
}

.app-main {
  flex: 1;
  min-width: 0;
}

.app-topbar {
  justify-content: flex-end;
  gap: 12px;
  padding: 0 28px;
}

.app-content {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
}

.activity-panel {
  padding-top: 0;
}

.activity-head {
  display: grid;
  grid-template-columns: 180px 140px minmax(0, 1fr);
  gap: 10px;
  margin: 0 -20px;
  padding: 13px 20px;
  color: var(--muted);
  background: var(--surface-soft);
  border-bottom: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
  font-size: 12px;
  font-weight: 500;
}

.activity-panel .log {
  grid-template-columns: 180px 140px minmax(0, 1fr);
  padding: 13px 0;
}

.activity-panel .log span {
  overflow-wrap: anywhere;
}

.capacity-create-form {
  display: grid;
  grid-template-columns: minmax(200px, 1.4fr) minmax(100px, .65fr) minmax(140px, 1fr) auto;
  align-items: end;
  gap: 14px;
}

.capacity-create-actions {
  display: flex;
}

.capacity-create-actions button {
  white-space: nowrap;
}

.inventory-table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 15px;
}

.inventory-table-head h2 {
  margin-bottom: 0;
}

.inventory-table-head .muted {
  font-size: 12px;
}

.drag-cell {
  width: 34px;
  padding-left: 4px;
  padding-right: 4px;
  text-align: center;
}

.drag-handle {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 30px;
  color: var(--muted);
  border-radius: 6px;
  cursor: grab;
  user-select: none;
  font-weight: 700;
  letter-spacing: -3px;
}

.drag-handle:hover {
  color: var(--blue);
  background: var(--surface-soft);
}

.drag-handle:active {
  cursor: grabbing;
}

#platform-sortable tr {
  transition: opacity .15s ease, background .15s ease;
}

#platform-sortable tr.dragging {
  opacity: .45;
  background: var(--surface-soft);
}

.operation-status {
  margin: -4px 0 16px;
}

.operation-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.operation-card {
  display: flex;
  min-height: 190px;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.operation-card h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.operation-card p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.operation-card small {
  display: block;
  color: var(--muted);
  line-height: 1.6;
}

.operation-card button {
  width: 100%;
}

td.missing-department {
  background: color-mix(in srgb, var(--orange) 12%, var(--surface));
  box-shadow: inset 3px 0 0 var(--orange);
}

.missing-department-label {
  display: inline-block;
  margin-left: 6px;
  color: var(--orange);
  font-size: 11px;
  font-weight: 700;
}

tr[id^="asset-"] {
  scroll-margin-top: 86px;
}

.table-sort {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: inherit;
  font-weight: inherit;
  text-decoration: none;
  white-space: nowrap;
}

.table-sort span {
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
}

.table-sort:hover {
  color: var(--blue);
}

.department-inventory {
  margin-top: 18px;
}

.department-filter {
  display: flex;
  align-items: end;
  gap: 12px;
  margin: 16px 0;
  padding: 14px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.department-filter label {
  min-width: 180px;
}

.department-filter-status {
  align-self: center;
  margin: 0 0 0 2px;
  color: var(--muted);
  font-size: 12px;
}

.department-filter-status.error {
  color: var(--red);
}

.department-inventory > :not(.department-filter) {
  transition: opacity .15s ease;
}

.department-inventory.is-loading > :not(.department-filter) {
  opacity: .55;
}

.department-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.department-summary > div {
  padding: 14px 16px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.department-summary span,
.department-table small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.department-summary strong {
  display: block;
  margin-top: 5px;
  font-size: 24px;
}

.department-table small {
  margin-top: 4px;
}

.department-inventory h3 {
  margin: 22px 0 10px;
  font-size: 15px;
}

.department-matrix-wrap {
  overflow-x: auto;
}

.department-matrix {
  min-width: max-content;
}

.department-matrix th,
.department-matrix td {
  min-width: 86px;
  text-align: center;
}

.department-matrix th:first-child,
.department-matrix td:first-child {
  position: sticky;
  left: 0;
  min-width: 180px;
  text-align: left;
  background: var(--surface);
  box-shadow: 1px 0 0 var(--line);
  z-index: 1;
}

.department-missing-row td {
  background: color-mix(in srgb, var(--orange) 12%, var(--surface));
}

.department-matrix .department-missing-row td:first-child {
  background: color-mix(in srgb, var(--orange) 12%, var(--surface));
  box-shadow: inset 3px 0 0 var(--orange), 1px 0 0 var(--line);
}

.detail-button {
  white-space: nowrap;
}

.usage-detail-dialog {
  width: min(1000px, calc(100vw - 40px));
  max-width: none;
  max-height: min(760px, calc(100vh - 40px));
  margin: auto;
  padding: 20px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 70px rgb(15 23 42 / 25%);
}

.usage-detail-dialog::backdrop {
  background: rgb(15 23 42 / 48%);
  backdrop-filter: blur(2px);
}

.usage-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.usage-detail-head h2,
.usage-detail-head p {
  margin: 0;
}

.usage-detail-head p {
  margin-top: 5px;
}

.dialog-close {
  width: 36px;
  height: 36px;
  padding: 0;
  flex: 0 0 auto;
  font-size: 24px;
  line-height: 1;
}

.usage-detail-dialog .table-wrap {
  max-height: calc(100vh - 170px);
  overflow: auto;
}

.usage-detail-dialog table {
  min-width: 760px;
}

@media (max-width: 800px) {
  .sidebar {
    width: var(--sidebar-width);
    flex-basis: var(--sidebar-width);
    max-width: var(--sidebar-width);
  }

  .app-topbar {
    padding: 0 14px;
  }

  .app-content {
    padding-left: 12px;
    padding-right: 12px;
  }

  .activity-head {
    display: none;
  }

  .activity-panel {
    padding-top: 18px;
  }

  .activity-panel .log {
    grid-template-columns: 1fr;
  }

  .capacity-create-form {
    grid-template-columns: 1fr;
  }

  .capacity-create-actions button {
    width: 100%;
  }

  .operation-grid {
    grid-template-columns: 1fr;
  }

  .operation-card {
    min-height: 0;
  }

  .department-filter {
    align-items: stretch;
    flex-direction: column;
  }

  .department-filter label {
    min-width: 0;
  }

  .department-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .usage-detail-dialog {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
    padding: 14px;
  }

  .usage-detail-dialog .table-wrap {
    max-height: calc(100vh - 135px);
  }
}
