:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #dfe5ee;
  --text: #172033;
  --muted: #68758a;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --sidebar: #121826;
  --sidebar-soft: #1c2536;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  height: 100vh;
  overflow: hidden;
}

a {
  color: var(--primary);
  text-decoration: none;
}

.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 264px;
  height: 100vh;
  background: var(--sidebar);
  color: #d7deea;
  transition: width 180ms ease, flex-basis 180ms ease;
  overflow: hidden;
  z-index: 30;
}

.sidebar.is-collapsed {
  width: 76px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 64px;
  padding: 0 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
  background: #fff;
  flex: 0 0 36px;
}

.brand-name,
.menu-label,
.menu-caret {
  transition: opacity 160ms ease;
}

.sidebar.is-collapsed .brand-name,
.sidebar.is-collapsed .menu-label,
.sidebar.is-collapsed .menu-caret,
.sidebar.is-collapsed .menu-empty {
  opacity: 0;
  pointer-events: none;
}

.menu {
  height: calc(100vh - 64px);
  overflow-y: auto;
  padding: 12px 10px;
}

.menu-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.menu-list .menu-list {
  display: none;
  padding-left: 14px;
}

.menu-item.is-open > .menu-list {
  display: block;
}

.menu-item.is-open > .menu-link .menu-caret {
  transform: rotate(90deg);
}

.menu-link {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 42px;
  margin: 3px 0;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #d7deea;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.menu-link:hover {
  background: var(--sidebar-soft);
  color: #fff;
}

.menu-link.is-active,
.menu-link[aria-current="page"],
.menu-item.is-active > .menu-link {
  background: var(--sidebar-soft);
  color: #fff;
  font-weight: 600;
}

.menu-item.is-open > .menu-link,
.menu-toggle.is-active {
  color: #fff;
}

.menu-item.is-open > .menu-link:not(.is-active) {
  background: rgba(255, 255, 255, 0.06);
}

.menu-link[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 9px;
  bottom: 9px;
  width: 4px;
  border-radius: 999px;
  background: #60a5fa;
}

.menu-link[aria-current="page"] .menu-label {
  padding-left: 10px;
}

.menu-empty {
  padding: 12px;
  color: #8f9bb0;
  font-size: 14px;
}

.main {
  min-width: 0;
  flex: 1 1 auto;
  margin-left: 264px;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  transition: margin-left 180ms ease;
}

.sidebar.is-collapsed + .main {
  margin-left: 76px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.topbar p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 10px;
  cursor: pointer;
}

.icon-button span {
  display: block;
  height: 2px;
  border-radius: 2px;
  background: var(--text);
}

.user-box {
  display: flex;
  align-items: center;
  margin-left: auto;
  color: var(--muted);
}

.user-menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 4px 10px 4px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #334155;
  font-size: 13px;
  cursor: pointer;
}

.user-menu-toggle:hover,
.user-menu-toggle.show {
  border-color: #bfdbfe;
  background: #f8fbff;
  color: #1d4ed8;
}

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 700;
}

.user-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu {
  min-width: 148px;
  border-color: var(--line);
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.14);
  font-size: 13px;
}

.user-menu form {
  margin: 0;
}

.topbar-lock-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  margin-left: auto;
  padding: 0 12px;
  border: 1px solid #f3d08b;
  border-radius: 999px;
  background: #fff8e8;
  color: #9a6700;
  font-size: 13px;
  white-space: nowrap;
}

.topbar-lock-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59e0b;
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.15);
}

.topbar-lock-meta {
  color: #b45309;
}

.content {
  padding: 24px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stat-card {
  padding: 18px;
}

.stat-card span,
.stat-card small,
.panel p {
  color: var(--muted);
}

.stat-card strong {
  display: block;
  margin: 10px 0 6px;
  font-size: 30px;
}

.panel {
  padding: 22px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel h2,
.panel p {
  margin: 0;
}

.panel h2 {
  margin-bottom: 6px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  padding: 0 16px;
  font-weight: 600;
  cursor: pointer;
}

.button:hover {
  background: var(--primary-dark);
  color: #fff;
}

.button-secondary {
  background: #edf2ff;
  color: var(--primary);
}

.button-secondary:hover {
  background: #dbe7ff;
  color: var(--primary-dark);
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.quick-grid > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 13px 10px;
  text-align: left;
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
}

.status {
  display: inline-flex;
  border-radius: 999px;
  background: #e8f3ee;
  color: #0f7a4c;
  padding: 4px 10px;
  font-size: 13px;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  background: var(--bg);
}

.login-card {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 28px;
}

.login-card h1 {
  margin: 0 0 8px;
}

.login-card p {
  margin: 0 0 22px;
  color: var(--muted);
}

.login-card label {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--muted);
}

.login-card input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  font: inherit;
}

.login-card .button {
  width: 100%;
  margin-top: 8px;
}

.message-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

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

.message-success {
  border-color: #b7e4c7;
  background: #eefbf2;
  color: #146c43;
}

.message-warning {
  border-color: #f3d08b;
  background: #fff8e8;
  color: #9a6700;
}

.action-row,
.filter-actions,
.upload-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

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

.filter-form label {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.filter-form input,
.filter-form select,
.upload-form input[type="file"] {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 12px;
  font: inherit;
}

.filter-actions {
  align-items: end;
}

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

.cell-wrap {
  min-width: 320px;
  white-space: normal;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  margin-top: 16px;
  color: var(--muted);
}

.source-list {
  margin: 0 0 18px;
  padding-left: 18px;
  color: var(--muted);
}

.sales-stats {
  margin-bottom: 20px;
}

.bootstrap-table .fixed-table-toolbar,
.bootstrap-table .fixed-table-pagination {
  padding-bottom: 12px;
}

.bootstrap-table .fixed-table-toolbar {
  padding-top: 0;
}

.bootstrap-table .search input {
  min-height: 38px;
  border-color: var(--line);
}

.bootstrap-table .columns .btn,
.bootstrap-table .search .form-control,
.bootstrap-table .search .btn,
.bootstrap-table .pagination-detail,
.bootstrap-table .page-list {
  font-size: 12px;
}

.bootstrap-table .table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: #475569;
  white-space: nowrap;
}

.bootstrap-table .table tbody td {
  vertical-align: middle;
}

.bootstrap-table-like {
  margin-bottom: 0;
  table-layout: auto;
  width: max-content;
  min-width: 100%;
}

.bootstrap-table .table {
  margin-bottom: 0;
  font-size: 12px;
}

.bootstrap-table .table > :not(caption) > * > * {
  padding: 0.5rem 0.6rem;
}

.bootstrap-table .btn,
.bootstrap-select .btn,
.datepicker {
  font-size: 12px;
}

.bootstrap-select > .dropdown-toggle,
.bootstrap-select > .dropdown-toggle:focus,
.bootstrap-select > .dropdown-toggle.show {
  min-height: 38px;
  border-color: var(--line);
  background: #fff;
}

.bootstrap-select .dropdown-menu {
  border-color: var(--line);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
}

.datepicker-dropdown {
  border-color: var(--line);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
}

.sales-table-responsive {
  position: relative;
  overflow: auto;
  max-height: calc(100vh - 280px);
}

.sales-table-responsive .table {
  font-size: 12px;
}

.sales-filter-card .card-header {
  min-height: auto;
}

.sales-filter-card .card-body {
  padding-top: 0.75rem !important;
  padding-bottom: 0.9rem !important;
}

.sales-filter-card .form-label {
  color: var(--muted);
  font-size: 12px;
}

.sales-filter-card .form-control-sm,
.sales-filter-card .bootstrap-select > .dropdown-toggle {
  min-height: 34px;
}

.sales-filter-card .bootstrap-select .dropdown-toggle .filter-option-inner-inner {
  font-size: 13px;
}

.sales-filter-card .btn {
  min-height: 34px;
}

.sales-table-responsive .bootstrap-table,
.sales-table-responsive .fixed-table-container,
.sales-table-responsive .fixed-table-body {
  overflow: visible !important;
}

.sales-table-responsive .fixed-table-body table tfoot,
.sales-table-responsive .bootstrap-table .table tfoot,
.sales-table-responsive > table tfoot {
  display: table-footer-group !important;
}

.sales-table-responsive .fixed-table-body table tfoot tr,
.sales-table-responsive .bootstrap-table .table tfoot tr,
.sales-table-responsive > table tfoot tr {
  display: table-row !important;
}

.sales-table-responsive .fixed-table-body table tfoot td,
.sales-table-responsive .bootstrap-table .table tfoot td,
.sales-table-responsive > table tfoot td {
  display: table-cell !important;
}

.sales-product-cell {
  width: 26%;
}

.sales-table-responsive .table tbody tr {
  height: 38px;
}

.sales-table-responsive .table:not(.db-result-table):not(.sales-table-footer-table) {
  table-layout: auto !important;
  width: max-content !important;
  min-width: 100%;
}

.sales-table-responsive .table:not(.db-result-table):not(.sales-table-footer-table) th,
.sales-table-responsive .table:not(.db-result-table):not(.sales-table-footer-table) td {
  min-width: 112px;
  max-width: 320px;
  white-space: nowrap;
}

.sales-table-responsive .table:not(.db-result-table):not(.sales-table-footer-table) .sales-product-cell {
  min-width: 240px;
}

.sales-table-responsive .table > :not(caption) > * > * {
  padding: 0.5rem 0.6rem;
}

.sales-cell-ellipsis {
  display: block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sales-cell-ellipsis-wide {
  max-width: 100%;
}

.table-sort-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #475569;
  font-weight: 600;
  text-decoration: none;
}

.table-sort-button {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
  cursor: pointer;
}

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

.sort-form {
  margin: 0;
}

.sales-table-responsive table thead th {
  position: sticky !important;
  top: 0;
  z-index: 5;
  background: #f8fafc !important;
  box-shadow: inset 0 -1px 0 var(--line);
}

.sales-table-footer-table {
  width: 100%;
  table-layout: fixed;
  margin-top: 0.5rem;
}

.sales-table-footer-table td {
  background: #f8fafc !important;
  box-shadow: inset 0 1px 0 var(--line);
}

.is-loading {
  position: relative;
  pointer-events: none;
}

.is-loading::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(245, 247, 251, 0.72);
  backdrop-filter: blur(1px);
}

.is-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 21;
  width: 38px;
  height: 38px;
  margin: -19px 0 0 -19px;
  border: 3px solid rgba(37, 99, 235, 0.16);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: sales-spin 0.75s linear infinite;
}

@keyframes sales-spin {
  to {
    transform: rotate(360deg);
  }
}

.sort-indicator {
  font-size: 11px;
  color: var(--primary);
}

.page-jump-input {
  width: 84px;
}

#database-manage-page {
  height: calc(100vh - 112px);
  overflow: hidden;
}

.db-console-shell {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  min-height: 0;
  color: #334155;
  font-size: 12px;
}

.db-console-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
}

.db-console-switch-form {
  display: flex;
  align-items: end;
  gap: 12px;
  min-width: 0;
}

.db-console-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.db-console-field .form-label {
  margin: 0;
  color: #64748b;
  font-size: 11px;
}

.db-console-field .form-select-sm {
  min-height: 30px;
  min-width: 132px;
  font-size: 12px;
}

.db-console-table-status {
  min-width: 220px;
}

.db-console-current-table {
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  color: #0f172a;
  line-height: 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.db-console-hint {
  color: #64748b;
  font-size: 12px;
  white-space: nowrap;
}

.db-console-layout {
  display: grid;
  grid-template-columns: minmax(190px, 240px) minmax(0, 1fr);
  gap: 12px;
  height: 100%;
  min-height: 0;
}

#database-workspace {
  flex: 1 1 auto;
  min-height: 0;
}

.db-console-main {
  display: grid;
  grid-template-rows: minmax(220px, 34%) minmax(0, 1fr);
  gap: 12px;
  min-width: 0;
  min-height: 0;
}

.db-console-sidebar {
  min-width: 0;
  min-height: 0;
}

.db-console-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
  overflow: hidden;
}

.db-console-panel-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 38px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.db-console-panel-header h2 {
  margin: 0;
  color: #0f172a;
  font-size: 13px;
  font-weight: 650;
}

.db-console-panel-header span {
  color: #64748b;
  font-size: 11px;
}

.db-console-panel-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 10px 12px;
}

.db-console-sidebar .db-console-panel-body {
  overflow: auto;
}

.db-table-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.db-table-form {
  margin: 0;
}

.db-table-button {
  display: block;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #334155;
  font-size: 12px;
  line-height: 1.25;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.db-table-button:hover {
  background: #eef2ff;
  color: #1d4ed8;
}

.db-table-button.active {
  background: #2563eb;
  color: #fff;
}

.db-query-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
  min-height: 0;
}

.db-sql-editor {
  flex: 1 1 auto;
  min-height: 168px;
  border-color: #cbd5e1;
  border-radius: 6px;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 12px;
  line-height: 1.55;
  resize: vertical;
}

.db-sql-editor:focus {
  background: #0f172a;
  color: #f8fafc;
  border-color: #60a5fa;
  box-shadow: 0 0 0 0.16rem rgba(37, 99, 235, 0.18);
}

.db-sql-editor::placeholder {
  color: #94a3b8;
}

.db-query-actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.db-query-actions .btn {
  min-height: 30px;
  padding: 0.25rem 0.8rem;
  font-size: 12px;
}

.db-result-panel {
  min-height: 0;
}

.db-result-panel .db-console-panel-body {
  padding: 0;
}

.db-result-table {
  table-layout: auto;
  width: max-content;
  min-width: 100%;
  margin: 0;
  font-size: 12px;
}

.db-result-table th {
  min-width: 128px;
  max-width: none;
  padding: 7px 9px !important;
  color: #475569;
  white-space: nowrap;
}

.db-result-table td {
  min-width: 116px;
  max-width: 380px;
  padding: 6px 9px !important;
}

.db-result-wrap {
  height: 100%;
  max-height: none;
  overflow: auto;
}

.db-empty-result {
  padding: 18px 12px;
  color: #64748b;
  font-size: 12px;
}

.db-console-alert {
  margin: 10px 12px;
  padding: 8px 10px;
  font-size: 12px;
}

.db-col-resizer {
  position: absolute;
  top: 0;
  right: -3px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
}

.db-col-resizer::after {
  content: "";
  position: absolute;
  top: 20%;
  bottom: 20%;
  left: 3px;
  width: 2px;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.35);
}

body.db-resizing {
  cursor: col-resize;
  user-select: none;
}

@media (max-width: 860px) {
  body {
    overflow: auto;
    height: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    width: 264px;
    flex-basis: 264px;
  }

  .sidebar.is-collapsed {
    transform: translateX(0);
    width: 264px;
  }

  .sidebar.is-collapsed .brand-name,
  .sidebar.is-collapsed .menu-label,
  .sidebar.is-collapsed .menu-caret,
  .sidebar.is-collapsed .menu-empty {
    opacity: 1;
    pointer-events: auto;
  }

  .stats-grid,
  .quick-grid,
  .filter-form {
    grid-template-columns: 1fr;
  }

  .topbar {
    padding: 0 16px;
    position: static;
  }

  .content {
    padding: 16px;
  }

  .main {
    margin-left: 0;
    height: auto;
    overflow: visible;
  }

  .sales-table-responsive {
    max-height: none;
  }

  #database-manage-page {
    height: auto;
    overflow: visible;
  }

  .db-console-toolbar,
  .db-console-switch-form {
    align-items: stretch;
    flex-direction: column;
  }

  .db-console-hint {
    white-space: normal;
  }

  .db-console-layout {
    grid-template-columns: 1fr;
  }

  .db-console-sidebar .db-console-panel-body,
  .db-result-panel .db-console-panel-body {
    height: auto;
    max-height: 420px;
  }

}
