* {
  box-sizing: border-box;
}

:root {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --panel-soft: #f8faf9;
  --text: #17211f;
  --muted: #68736f;
  --line: #dfe7e3;
  --line-strong: #cbd8d2;
  --primary: #147d6f;
  --primary-dark: #0e6257;
  --primary-soft: #e7f4f1;
  --danger: #d64545;
  --warning: #b7791f;
  --sidebar: #17211f;
  --sidebar-soft: #22302c;
  --shadow: 0 18px 45px rgba(19, 34, 31, 0.08);
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  max-width: 100%;
  overflow-x: hidden !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font-family: inherit;
}

[hidden],
.is-hidden {
  display: none !important;
}

.layui-btn {
  border-radius: 6px;
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 5px 12px rgba(20, 125, 111, 0.14);
}

.layui-btn:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.layui-btn-primary {
  color: #24312e;
  background: #fff;
  border-color: var(--line-strong);
  box-shadow: none;
}

.layui-btn-primary:hover {
  color: var(--primary);
  background: #f7fbfa;
  border-color: var(--primary);
}

.layui-btn-danger {
  background: var(--danger);
  border-color: var(--danger);
}

.layui-btn-danger:hover {
  background: #b83232;
  border-color: #b83232;
}

.layui-btn-warm {
  background: var(--warning);
  border-color: var(--warning);
}

.layui-input,
.layui-select,
.layui-textarea {
  border-color: var(--line);
  border-radius: 6px;
}

.layui-input:focus,
.layui-textarea:focus {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px rgba(20, 125, 111, 0.1);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #edf7f4 0%, #f6f2ea 48%, #f3f6fa 100%);
}

.login-panel {
  width: min(420px, calc(100vw - 32px));
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(223, 231, 227, 0.9);
  border-radius: 14px;
  padding: 30px;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.login-mark,
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 10px;
  color: #fff;
  background: var(--primary);
  font-weight: 800;
  letter-spacing: 0;
}

.login-panel h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.login-panel p {
  margin: 4px 0 0;
  color: var(--muted);
}

.login-panel .layui-input {
  height: 44px;
}

.login-panel .layui-btn {
  height: 44px;
  margin-top: 4px;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 232px 1fr;
  grid-template-rows: 60px 1fr;
}

.topbar {
  grid-column: 1 / 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px 0 16px;
  color: var(--text);
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 6px 22px rgba(23, 33, 31, 0.05);
  z-index: 2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 17px;
  font-weight: 800;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex-basis: 34px;
  border-radius: 9px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-user {
  color: var(--muted);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar {
  padding: 14px 12px;
  background: var(--sidebar);
  overflow-y: auto;
}

.menu-section {
  margin: 14px 8px 7px;
  color: #91a49d;
  font-size: 12px;
  line-height: 1;
}

.menu-section:first-child {
  margin-top: 4px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  margin: 2px 0;
  padding: 0 10px;
  color: #dce6e2;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.menu-item .layui-icon {
  width: 18px;
  color: #9fb3ac;
  text-align: center;
  font-size: 16px;
}

.menu-item:hover {
  color: #fff;
  background: var(--sidebar-soft);
}

.menu-item.active {
  color: #fff;
  background: var(--primary);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.16);
}

.menu-item.active .layui-icon {
  color: #fff;
}

.content {
  min-width: 0;
  min-height: 0;
  padding: 0;
  background: var(--bg);
}

.content iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.page {
  min-height: 100vh;
  padding: 22px;
}

.page-title {
  margin: 0 0 16px;
  font-size: 20px;
  line-height: 1.25;
  font-weight: 800;
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 22px rgba(23, 33, 31, 0.04);
}

.toolbar .layui-input,
.toolbar .layui-select,
.toolbar select {
  width: 188px;
  height: 34px;
}

.page-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  box-shadow: 0 8px 22px rgba(23, 33, 31, 0.04);
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  margin: 0;
  background: #fff;
}

.data-table th {
  color: #40504b;
  background: #f5f8f7;
  font-weight: 700;
  white-space: nowrap;
  border-color: var(--line);
}

.data-table td {
  vertical-align: middle;
  border-color: var(--line);
}

.data-table tbody tr:hover {
  background: #f8fbfa;
}

.empty-cell {
  color: #93a19c;
  text-align: center;
  padding: 40px 0 !important;
}

.status-text {
  color: var(--muted);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status-pill.is-on {
  color: #047857;
  background: #ecfdf5;
  border-color: #a7f3d0;
}

.status-pill.is-off {
  color: #5d6a66;
  background: #f1f5f4;
  border-color: #cbd8d2;
}

.status-pill.is-pending {
  color: #a15c08;
  background: #fff7e6;
  border-color: #f7d998;
}

.status-pill.is-returned {
  color: #b42345;
  background: #fff1f3;
  border-color: #fac8d1;
}

.row-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 168px;
}

.row-actions .layui-btn {
  box-shadow: none;
}

.modal-body {
  padding: 18px 20px 6px;
  max-height: 78vh;
  overflow-y: auto;
  overflow-x: hidden !important;
  min-width: 0;
  max-width: 100%;
  background: #fff;
}

.layui-layer {
  border-radius: 10px !important;
  overflow: hidden;
}

.layui-layer-title {
  height: 48px !important;
  line-height: 48px !important;
  color: var(--text) !important;
  background: #f7faf9 !important;
  border-bottom: 1px solid var(--line) !important;
  font-weight: 700;
}

.layui-layer-content,
.modal-body .layui-form {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: visible;
}

.modal-body .layui-form-item {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: visible;
}

.modal-body .layui-form-label {
  width: 112px;
  max-width: 42%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-body .layui-input-block {
  margin-left: 142px;
  min-width: 0;
  width: auto;
  overflow: visible;
}

.modal-body .layui-input,
.modal-body .layui-textarea,
.modal-body select {
  max-width: 100%;
}

.form-tip {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

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

.preview-box {
  display: none;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.preview-box.is-visible {
  display: block;
}

.preview-box img {
  width: 128px;
  height: 128px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.resource-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 150px;
}

.resource-cell img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
}

.result-panel {
  margin-top: 14px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
}

.result-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.result-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.result-item strong {
  font-size: 20px;
}

.cashier-result {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 18px;
  align-items: start;
}

.cashier-result img {
  width: 180px;
  height: 180px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.detail-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 18px;
}

.detail-list div {
  min-width: 0;
}

.detail-list span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.detail-list strong {
  word-break: break-all;
}

.binding-list {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.binding-intro,
.binding-tip {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.binding-intro {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid #cfe8e1;
  border-radius: 8px;
  background: var(--primary-soft);
  color: #2d6259;
}

.binding-tip {
  margin-top: 10px;
}

.binding-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.binding-grid {
  display: grid;
  grid-template-columns: minmax(120px, 0.9fr) minmax(150px, 1.2fr) minmax(220px, 2fr) 110px;
  gap: 12px;
  align-items: center;
  min-width: 680px;
  padding: 11px 12px;
}

.binding-grid-head {
  color: #40504b;
  background: #f5f8f7;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
}

.binding-grid-row {
  min-height: 72px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.binding-grid-row:last-child {
  border-bottom: 0;
}

.binding-method strong,
.binding-method span,
.binding-current-name,
.binding-current-mode {
  display: block;
}

.binding-method strong {
  color: var(--text);
  font-size: 14px;
}

.binding-method span,
.binding-current-mode {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.binding-current-name {
  color: #2f3d39;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.binding-grid-row .layui-select {
  width: 100%;
  height: 36px;
}

.binding-submit-item {
  margin: 16px 0 4px;
}

.binding-empty,
.binding-loading,
.binding-error {
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

.binding-error {
  color: var(--danger);
}

.binding-row {
  display: grid;
  grid-template-columns: 24px 1fr 86px 86px 86px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.binding-row .layui-input {
  height: 32px;
}

.cleanup-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.cleanup-summary .result-item strong {
  font-size: 18px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

.dashboard-section {
  margin-top: 18px;
}

.section-title {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.4;
}

.stat-card,
.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 8px 22px rgba(23, 33, 31, 0.04);
}

.stat-card span {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}

.stat-card strong {
  display: block;
  color: #0f3f39;
  font-size: 24px;
}

.permission-form-item .layui-input-block {
  overflow: visible;
}

.permission-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

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

.permission-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  overflow: hidden;
}

.permission-group-title {
  padding: 9px 12px;
  color: #31413d;
  background: #eef5f2;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
  padding: 12px;
}

.permission-check {
  min-width: 0;
}

.permission-check .layui-form-checkbox[lay-skin="primary"] {
  max-width: 100%;
}

.permission-check .layui-form-checkbox[lay-skin="primary"] span {
  max-width: calc(100% - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 104px 1fr;
  }

  .brand span:last-child,
  .menu-section,
  .topbar-user {
    display: none;
  }

  .menu-item {
    justify-content: center;
    padding: 0 8px;
  }

  .menu-item span {
    display: none;
  }

  .stats-grid,
  .permission-groups {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .inline-fields,
  .detail-list,
  .result-grid,
  .cleanup-summary,
  .cashier-result {
    grid-template-columns: 1fr;
  }

  .modal-body .layui-form-label {
    width: 92px;
    max-width: 40%;
  }

  .modal-body .layui-input-block {
    margin-left: 112px;
  }

  .binding-row {
    grid-template-columns: 24px 1fr;
  }

  .binding-grid {
    min-width: 640px;
    grid-template-columns: 118px 150px minmax(200px, 1fr) 96px;
  }
}

@media (max-width: 680px) {
  .app-shell {
    grid-template-columns: 74px 1fr;
  }

  .topbar {
    padding: 0 10px;
  }

  .sidebar {
    padding: 10px 8px;
  }

  .page {
    padding: 14px;
  }

  .toolbar .layui-input,
  .toolbar .layui-select,
  .toolbar select {
    width: 100%;
  }

  .stats-grid,
  .permission-groups,
  .permission-grid {
    grid-template-columns: 1fr;
  }

  .layui-layer {
    max-width: calc(100vw - 12px) !important;
  }

  .layui-layer-content {
    max-width: 100%;
    overflow-x: hidden;
  }

  .modal-body {
    padding: 14px 12px 6px;
  }

  .modal-body .layui-form-label {
    width: 78px;
    max-width: 34%;
    padding-left: 0;
    padding-right: 8px;
  }

  .modal-body .layui-input-block {
    margin-left: 90px;
  }
}
