:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --sidebar: #ffffff;
  --line: #d9d9d9;
  --text: #2e2e2e;
  --muted: #7f7f7f;
  --primary: #de3a34;
  --primary-dark: #ba2c27;
  --secondary: #4f545b;
  --white: #ffffff;
  /* Bootstrap-like typography scale */
  --fs-base: 16px;
  --fs-sm: 14px;
  --fs-lg: 18px;
  --fs-h1: 1rem;
  --fs-nav: 0.83rem;
  --fs-label: 1.125rem;
  --fs-input: 1rem;
  --fs-table-head: 1rem;
  --fs-table-body: 0.92rem;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: var(--fs-base);
  line-height: 1.5;
}

a {
  text-decoration: none;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
  background: #ededed;
}

.sidebar {
  width: 150px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  z-index: 30;
}

.mobile-topbar {
  display: none;
}

.mobile-sidebar-backdrop {
  display: none;
}

.mobile-sidebar-header {
  display: none;
}

.mobile-menu-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  padding: 0;
}

.mobile-menu-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: #333333;
  border-radius: 1px;
}

.mobile-topbar-title,
.mobile-brand-title {
  font-size: 1rem;
  font-weight: 700;
  color: #303030;
}

.mobile-topbar-logout {
  color: #333333;
  font-size: 0.95rem;
}

.brand {
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
}

.brand img {
  width: 72px;
  height: 72px;
  object-fit: contain;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.nav-menu a {
  color: #3f3f3f;
  font-size: var(--fs-nav);
  line-height: 1.3;
  padding: 14px 20px;
  border-left: 3px solid transparent;
  display: block;
  text-align: center;
}

.nav-menu a.active {
  background: var(--primary);
  color: var(--white);
  border-left-color: var(--primary-dark);
  font-weight: 700;
}

.sidebar-bottom {
  margin-top: auto;
  padding: 18px 20px 24px;
}

.sidebar-user {
  font-size: 1.1rem;
  color: #3a3a3a;
  margin-bottom: 10px;
  line-height: 1.2;
  word-break: break-all;
}

.logout-link {
  font-size: 1rem;
  color: #222;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: #ededed;
}

.page-wrap {
  padding: 26px 40px 20px;
  overflow: auto;
  flex: 1;
  min-height: 0;
  background: #ededed;
}

.table-head-sticky {
  position: sticky;
  top: 0;
  z-index: 60;
  background: #ededed;
  padding: 6px 0 10px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08);
}

.list-page {
  height: 100%;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.page-title {
  margin: 0 0 20px;
  font-size: var(--fs-h1);
  font-weight: 600;
  color: #434343;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.toolbar .spacer {
  margin-left: auto;
}

.btn-main,
.btn-danger,
.btn-secondary,
.btn-linkish,
.btn-primary {
  border: none;
  border-radius: 10px;
  padding: 10px 20px;
  font-size: 1rem;
  line-height: 1.2;
}

.btn-main,
.btn-primary {
  background: var(--primary);
  color: var(--white);
}

.btn-main:hover,
.btn-primary:hover {
  background: var(--primary-dark);
  color: var(--white);
}

.btn-danger {
  background: #d73545;
  color: var(--white);
}

.btn-danger:hover {
  background: #bd2535;
  color: var(--white);
}

.btn-secondary {
  background: #2f6de1;
  color: var(--white);
}

.btn-secondary:hover {
  background: #2458ba;
  color: var(--white);
}

.btn-linkish {
  color: #2f6de1;
  background: transparent;
  padding-left: 0;
  padding-right: 0;
}

.form-control,
.form-select {
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid #bfc5ca;
  font-size: var(--fs-input);
  background: #f7f7f7;
}

.form-label {
  font-size: var(--fs-label);
  font-weight: 500;
  margin-bottom: 8px;
  color: #343434;
}

.table-wrap {
  border: 1px solid #cfd3d7;
  background: #ffffff;
  border-radius: 18px;
  overflow: hidden;
}

.table {
  margin-bottom: 0;
  border-collapse: separate;
  border-spacing: 0;
}

.table thead th {
  border-bottom: 2px solid #1f1f1f;
  font-size: var(--fs-table-head);
  font-weight: 600;
  padding: 9px 12px;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 20;
  background: #ffffff;
}

.table thead th:first-child {
  border-top-left-radius: 18px;
}

.table thead th:last-child {
  border-top-right-radius: 18px;
}

.table tbody tr:last-child td:first-child {
  border-bottom-left-radius: 18px;
}

.table tbody tr:last-child td:last-child {
  border-bottom-right-radius: 18px;
}

.table-wrap.sticky-with-controls .table thead th {
  top: 0;
  z-index: 71;
  background: #ffffff;
  box-shadow: inset 0 -1px 0 #c7c7c7;
}

.table-wrap.sticky-with-controls {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  overflow-x: hidden;
  z-index: 1;
  border-radius: 18px;
}

.table-wrap.sticky-with-controls .table {
  position: relative;
  z-index: 1;
  border-collapse: separate;
  border-spacing: 0;
}

.table-wrap.sticky-with-controls .table thead {
  position: sticky;
  top: 0;
  z-index: 70;
}

.table-wrap.sticky-with-controls .table tbody td {
  position: relative;
  z-index: 1;
}

.table tbody td {
  font-size: var(--fs-table-body);
  padding: 8px 12px;
  border-color: #cfd3d7;
  vertical-align: middle;
}

.table .btn.btn-sm {
  padding: 4px 12px;
  font-size: 0.9rem;
  border-radius: 8px;
}

.action-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mobile-record-list {
  display: none;
}

.mobile-record-card {
  border: 1px solid #d7dbe0;
  border-radius: 14px;
  background: #ffffff;
  padding: 14px 14px 16px;
  display: grid;
  gap: 12px;
  box-shadow: 0 8px 20px rgba(30, 37, 48, 0.05);
}

.mobile-record-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.mobile-record-check {
  margin-top: 4px;
  width: 18px;
  height: 18px;
}

.mobile-record-title {
  font-size: 1.02rem;
  font-weight: 700;
  color: #2f2f2f;
  line-height: 1.35;
}

.mobile-record-subtitle {
  font-size: 0.86rem;
  color: #717171;
  line-height: 1.4;
  margin-top: 4px;
  word-break: break-all;
}

.mobile-record-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
}

.mobile-record-item {
  min-width: 0;
}

.mobile-record-label {
  display: block;
  font-size: 0.78rem;
  color: #888888;
  margin-bottom: 4px;
}

.mobile-record-value {
  display: block;
  font-size: 0.92rem;
  color: #2f2f2f;
  word-break: break-word;
}

.mobile-record-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 2px;
  justify-content: flex-end;
}

.mobile-record-actions form {
  margin: 0;
}

.mobile-icon-action {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 12px;
  background: #eef4ff;
  color: #2f6de1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgba(47, 109, 225, 0.08);
}

.mobile-icon-action:hover {
  background: #e1ecff;
  color: #2458ba;
}

.mobile-icon-danger {
  background: #fff0f2;
  color: #d73545;
  box-shadow: inset 0 0 0 1px rgba(215, 53, 69, 0.08);
}

.mobile-icon-danger:hover {
  background: #ffe3e8;
  color: #bd2535;
}

.mobile-record-actions .btn,
.mobile-record-actions form .btn {
  min-width: 84px;
}

.action-group form {
  margin: 0;
}

.responsive-form .row {
  margin-left: 0;
  margin-right: 0;
}

.alert {
  border-radius: 10px;
  font-size: var(--fs-sm);
}

.footer-note {
  margin-top: auto;
  padding: 8px 28px 16px;
  color: #858585;
  font-size: 0.9rem;
  background: #ededed;
}

.search-box {
  display: flex;
  gap: 10px;
  min-width: 420px;
}

.search-box .form-control {
  min-height: 44px;
  font-size: 1rem;
}

.search-box .btn-main {
  min-width: 92px;
}

.page-section {
  max-width: 100%;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 44% 56%;
}

.login-left {
  background: #ffffff;
  padding: 56px 70px 36px;
  display: flex;
  flex-direction: column;
}

.login-brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.login-brand-mark {
  width: 112px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-brand-mark img {
  display: block;
  max-width: 100%;
  height: auto;
}

.login-en {
  margin-top: 10px;
  color: #8e8e8e;
  font-size: 0.82rem;
  letter-spacing: 1px;
  line-height: 1.35;
  font-weight: 700;
}

.login-title {
  color: #b91f1f;
  font-size: clamp(2rem, 3.4vw, 3.2rem);
  line-height: 1.15;
  font-weight: 800;
  margin: 130px 0 38px;
}

.login-form .form-control {
  min-height: 54px;
  font-size: 1.25rem;
  border-radius: 20px;
  background: #ffffff;
}

.login-form .btn-main {
  min-width: 190px;
  font-size: 1.8rem;
  border-radius: 22px;
  margin-top: 14px;
}

.login-org {
  margin-top: auto;
  color: #3d3d3d;
  font-size: 1rem;
  font-weight: 700;
}

.login-right {
  background-image: url('/static/bg.png');
  background-position: right center;
  background-size: cover;
  position: relative;
}

.login-copyright {
  position: absolute;
  right: 24px;
  bottom: 20px;
  color: #f7f7f7;
  text-align: right;
  font-size: 0.9rem;
  line-height: 1.5;
}

.preview-card h3 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.preview-card .text-muted {
  font-size: 0.95rem;
}

.dashboard-card {
  border: 1px solid var(--line);
  background: #f5f5f5;
  padding: 22px 26px;
  display: flex;
  align-items: center;
  gap: 18px;
  color: #2f2f2f;
  min-height: 120px;
  transition: border-color .18s ease, background-color .18s ease;
}

.dashboard-card:hover {
  border-color: #b9bcc1;
  background: #f9f9f9;
}

.dashboard-card h3 {
  margin: 0 0 4px;
  font-size: 2rem;
  font-weight: 700;
  color: #2f2f2f;
}

.dashboard-card p {
  margin: 0;
  font-size: 0.95rem;
  color: #58606a;
}

.dashboard-icon {
  width: 60px;
  height: 60px;
  flex: 0 0 60px;
  display: grid;
  place-items: center;
  color: #111;
}

.dashboard-icon svg {
  width: 44px;
  height: 44px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.two-col {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 22px;
}

.preview-card {
  border: 1px solid var(--line);
  background: #ffffff;
  padding: 18px;
  text-align: center;
}

.preview-card img {
  max-width: 100%;
  max-height: min(56vh, 520px);
  object-fit: contain;
}

.cert-preview-img {
  max-height: min(58vh, 540px) !important;
}

.cert-preview-modal-img {
  max-height: 82vh;
  width: auto;
  display: block;
  margin: 0 auto;
}

@media (max-width: 1200px) {
  .nav-menu a {
    font-size: 0.67rem;
  }

  .logout-link {
    font-size: 1rem;
  }

  .page-title {
    font-size: 1rem;
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .search-box {
    min-width: 100%;
  }

  .dashboard-card h3 {
    font-size: 1.75rem;
  }
}

@media (max-width: 991.98px) {
  .app-shell {
    min-height: 100vh;
    height: auto;
    overflow: visible;
    display: block;
  }

  .sidebar {
    width: min(280px, 82vw);
    border-right: 1px solid var(--line);
    height: 100%;
    max-height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    transition: transform .24s ease;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.18);
    background: #ffffff;
    z-index: 160;
    overflow-y: auto;
  }

  body.mobile-sidebar-open .sidebar {
    transform: translateX(0);
  }

  .mobile-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 8px;
    border-bottom: 1px solid var(--line);
    background: #ffffff;
    position: sticky;
    top: 0;
    z-index: 2;
  }

  .mobile-sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.28);
    z-index: 150;
  }

  body.mobile-sidebar-open .mobile-sidebar-backdrop {
    display: block;
  }

  .brand {
    height: 96px;
    padding-top: 0;
  }

  .nav-menu {
    flex-direction: column;
    padding: 8px 0 0;
  }

  .nav-menu a {
    font-size: 0.95rem;
    padding: 12px 18px;
    border-left: 3px solid transparent;
    border-radius: 0;
    text-align: left;
  }

  .sidebar-bottom {
    padding: 14px 18px 18px;
  }

  .sidebar-user {
    font-size: 0.95rem;
    margin-bottom: 8px;
  }

  .main-area {
    min-height: 100vh;
    height: auto;
    overflow: visible;
    width: 100%;
  }

  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: space-between;
    padding: 12px 14px;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 140;
  }

  .logout-link {
    font-size: 1rem;
  }

  .page-wrap {
    padding: 14px 12px 14px;
    overflow: visible;
    width: 100%;
  }

  .login-shell {
    grid-template-columns: 1fr;
    min-height: 100vh;
    background: linear-gradient(180deg, #ffffff 0%, #f5f6f8 100%);
  }

  .login-left {
    min-height: 100vh;
    padding: 28px 18px 22px;
    justify-content: flex-start;
  }

  .login-title {
    font-size: clamp(2rem, 8vw, 2.5rem);
    margin: 72px 0 24px;
  }

  .login-right {
    display: none;
  }

  .login-brand-row {
    gap: 10px;
  }

  .login-brand-mark {
    width: 86px;
  }

  .login-en {
    margin-top: 0;
    font-size: 0.72rem;
    letter-spacing: 1.2px;
  }

  .login-form {
    margin-top: 8px;
  }

  .login-form .form-control {
    min-height: 48px;
    font-size: 1rem;
    border-radius: 18px;
    padding-left: 14px;
    padding-right: 14px;
  }

  .login-form .btn-main {
    width: 100%;
    min-width: 0;
    min-height: 50px;
    font-size: 1.18rem;
    border-radius: 18px;
    margin-top: 6px;
  }

  .login-org {
    margin-top: 26px;
    font-size: 0.9rem;
    line-height: 1.6;
  }

  .login-org span {
    font-size: 0.78rem !important;
    letter-spacing: 0.8px !important;
    line-height: 1.5;
  }

  .dashboard-card {
    min-height: 96px;
    padding: 16px 14px;
    gap: 12px;
  }

  .dashboard-icon {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
  }

  .dashboard-icon svg {
    width: 30px;
    height: 30px;
  }

  .dashboard-card h3 {
    font-size: 1.5rem;
  }

  .dashboard-card p {
    font-size: 0.9rem;
  }

  .footer-note {
    padding: 10px 12px 14px;
    font-size: 0.82rem;
    line-height: 1.5;
  }
}

@media (max-width: 767.98px) {
  .login-left {
    padding: 22px 18px 18px;
  }

  .login-brand-mark {
    width: 74px;
  }

  .login-title {
    margin: 56px 0 20px;
    line-height: 1.08;
  }

  .login-form .form-control {
    font-size: 0.96rem;
  }

  .login-org {
    margin-top: 22px;
    font-size: 0.84rem;
  }
}

@media (min-width: 992px) {
  .sidebar {
    transform: none !important;
    box-shadow: none;
  }
}

@media (max-width: 767.98px) {
  .toolbar,
  .toolbar-actions,
  .search-box {
    width: 100%;
  }

  .toolbar-actions {
    flex-wrap: wrap;
  }

  .search-box {
    min-width: 0;
    flex-direction: column;
  }

  .btn-main,
  .btn-danger,
  .btn-secondary,
  .btn-primary {
    width: 100%;
  }

  .table-wrap.sticky-with-controls {
    overflow-x: auto;
  }

  .table-wrap {
    overflow-x: auto;
  }

  .table-wrap .table {
    min-width: 640px;
  }

  .table-wrap.sticky-with-controls .table {
    min-width: 860px;
  }

  .mobile-record-list {
    display: grid;
    gap: 12px;
  }

  .desktop-record-table {
    display: none;
  }

  .mobile-record-grid {
    grid-template-columns: 1fr;
  }

  .mobile-record-actions .btn,
  .mobile-record-actions form,
  .mobile-record-actions form .btn {
    width: 100%;
  }

  .mobile-record-actions form {
    width: auto;
  }

  .mobile-icon-action,
  .mobile-icon-danger {
    width: 46px;
    height: 46px;
  }

  .mobile-record-card {
    border-radius: 16px;
    padding: 14px 14px 16px;
  }

  .mobile-record-title {
    font-size: 0.98rem;
  }

  .mobile-record-value {
    font-size: 0.96rem;
    line-height: 1.45;
  }

  .table-head-sticky {
    position: static;
  }

  .responsive-form .row {
    display: block;
  }

  .responsive-form .row > [class*='col-'] {
    width: 100%;
    max-width: 100%;
    padding-left: 0;
    padding-right: 0;
    margin-left: 0;
  }

  .responsive-form .text-end {
    text-align: left !important;
  }

  .responsive-form .btn-main,
  .responsive-form .btn-secondary,
  .responsive-form .btn-primary,
  .responsive-form .btn-danger {
    width: 100%;
  }

  .action-group {
    gap: 6px;
  }

  .action-group .btn,
  .action-group form,
  .action-group form .btn {
    width: auto;
  }

  .pagination {
    flex-wrap: wrap;
    gap: 6px;
  }

  .page-item .page-link {
    border-radius: 8px;
  }
}
