:root {
  --ap-primary: #2563eb;
  --ap-primary-soft: #eaf1ff;
  --ap-sidebar-bg: #061a2f;
  --ap-sidebar-bg-2: #09223d;
  --ap-sidebar-text: #c9d6e4;
  --ap-sidebar-muted: #7890a8;
  --ap-body-bg: #f5f7fb;
  --ap-card-bg: #ffffff;
  --ap-border: #e5e7eb;
  --ap-border-soft: #eef2f7;
  --ap-text: #111827;
  --ap-text-muted: #6b7280;
  --ap-heading: #0f172a;
  --ap-success: #16a34a;
  --ap-success-bg: #dcfce7;
  --ap-warning: #f59e0b;
  --ap-warning-bg: #fef3c7;
  --ap-danger: #dc2626;
  --ap-danger-bg: #fee2e2;
  --ap-info-bg: #dbeafe;
  --ap-purple: #7c3aed;
  --ap-purple-bg: #ede9fe;
  --ap-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
}

body.app-body,
body.auth-body {
  margin: 0;
  color: var(--ap-text);
  font-family: "Noto Sans Thai", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

.app-body {
  background: var(--ap-body-bg);
}

.app-sidebar {
  width: 260px;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--ap-sidebar-bg), var(--ap-sidebar-bg-2));
  color: var(--ap-sidebar-text);
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1030;
  padding: 18px;
}

.sidebar-brand,
.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--ap-primary);
  color: #fff;
  font-weight: 800;
}

.brand-title {
  color: #fff;
  font-weight: 800;
  line-height: 1.1;
}

.brand-subtitle,
.sidebar-user-role,
.page-subtitle {
  color: var(--ap-text-muted);
  font-size: 12px;
}

.text-muted-2 {
  color: var(--ap-text-muted) !important;
}

.sidebar-user {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 16px 0;
  margin: 16px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ap-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-weight: 800;
}

.sidebar-user-name {
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.sidebar-heading {
  color: var(--ap-sidebar-muted);
  font-size: 11px;
  font-weight: 800;
  margin: 16px 0 6px;
  text-transform: uppercase;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--ap-sidebar-text);
  text-decoration: none;
  font-size: 13px;
}

.sidebar-link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.sidebar-link.active {
  background: linear-gradient(135deg, #1f6fff, #2563eb);
  color: #fff;
}

.app-main {
  margin-left: 260px;
  min-height: 100vh;
  background: var(--ap-body-bg);
}

.app-topbar {
  height: 64px;
  background: #fff;
  border-bottom: 1px solid var(--ap-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 1020;
}

.app-content {
  padding: 24px;
}

.page-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--ap-heading);
  margin: 0;
}

.section-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--ap-heading);
  margin: 0;
}

.ap-card,
.metric-card {
  background: var(--ap-card-bg);
  border: 1px solid var(--ap-border-soft);
  border-radius: 14px;
  box-shadow: var(--ap-shadow-sm);
}

.ap-card-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--ap-border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ap-card-body {
  padding: 18px;
}

.metric-card {
  min-height: 136px;
  padding: 18px;
}

.metric-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-bottom: 14px;
}

.metric-title {
  color: var(--ap-text-muted);
  font-size: 13px;
  font-weight: 700;
}

.metric-value {
  color: var(--ap-heading);
  font-size: 28px;
  font-weight: 800;
  line-height: 1.1;
}

.ap-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}

.ap-table thead th {
  background: #f8fafc;
  color: #334155;
  font-weight: 800;
  border-bottom: 1px solid var(--ap-border);
  padding: 12px;
  white-space: nowrap;
}

.ap-table tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--ap-border-soft);
  vertical-align: middle;
  color: #334155;
}

.badge-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.badge-success { background: var(--ap-success-bg); color: var(--ap-success); }
.badge-pending { background: var(--ap-warning-bg); color: var(--ap-warning); }
.badge-update { background: var(--ap-info-bg); color: var(--ap-primary); }
.badge-inactive { background: #f1f5f9; color: #64748b; }
.badge-danger-soft { background: var(--ap-danger-bg); color: var(--ap-danger); }

.bg-primary-soft { background: var(--ap-primary-soft) !important; }
.bg-success-soft { background: var(--ap-success-bg) !important; }
.bg-warning-soft { background: var(--ap-warning-bg) !important; }
.bg-info-soft { background: var(--ap-info-bg) !important; }

.btn,
.form-control {
  border-radius: 10px;
  font-size: 13px;
}

.btn {
  font-weight: 700;
}

.btn-icon {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.form-label {
  color: #475569;
  font-size: 12px;
  font-weight: 800;
}

.code-box {
  background: #f8fafc;
  border: 1px solid var(--ap-border);
  border-radius: 12px;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  white-space: pre-line;
}

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--ap-text-muted);
}

.empty-state h6 {
  margin-bottom: 6px;
  color: var(--ap-heading);
}

.empty-state p {
  margin: 0;
}

.compact-empty {
  padding: 28px 12px;
}

.log-detail-cell details {
  min-width: 220px;
}

.log-detail-cell summary {
  cursor: pointer;
  color: var(--ap-primary);
  font-weight: 700;
}

.detail-grid {
  display: grid;
  gap: 10px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--ap-border-soft);
}

.detail-row span {
  color: var(--ap-text-muted);
  font-weight: 700;
}

.detail-row strong {
  color: var(--ap-heading);
  text-align: right;
  word-break: break-word;
}

.json-box {
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 340px;
  overflow: auto;
}

.upload-slip-textarea {
  min-height: 180px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.upload-slip-preview-wrap {
  min-height: 280px;
  border: 1px dashed var(--ap-border);
  border-radius: 12px;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.upload-slip-preview {
  max-width: 100%;
  max-height: 420px;
  display: block;
  object-fit: contain;
}

.auth-body {
  min-height: 100vh;
  background: var(--ap-body-bg);
}

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-panel {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--ap-border-soft);
  border-radius: 16px;
  box-shadow: var(--ap-shadow-sm);
  padding: 28px;
}

.auth-brand {
  margin-bottom: 28px;
}

.auth-brand h1 {
  font-size: 22px;
  font-weight: 800;
  margin: 0;
}

.auth-brand p {
  color: var(--ap-text-muted);
  margin: 0;
}

@media (max-width: 767.98px) {
  .app-sidebar {
    position: static;
    width: 100%;
    min-height: auto;
  }

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

  .app-topbar {
    height: auto;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
  }
}
