:root {
  --sidebar-width: 220px;
  --sidebar-bg: #001529;
  --sidebar-bg-sub: #000c17;
  --sidebar-text: rgba(255,255,255,0.65);
  --sidebar-text-hover: #fff;
  --primary: #1677ff;
  --primary-hover: #4096ff;
  --primary-bg: #e6f4ff;
  --primary-border: #91caff;
  --success: #52c41a;
  --success-bg: #f6ffed;
  --warning: #faad14;
  --warning-bg: #fffbe6;
  --danger: #ff4d4f;
  --danger-bg: #fff2f0;
  --text: #262626;
  --text-secondary: #8c8c8c;
  --text-tertiary: #bfbfbf;
  --border: #f0f0f0;
  --border-base: #d9d9d9;
  --bg-layout: #f5f7fa;
  --radius: 6px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.03);
  --header-height: 64px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-layout);
  overflow: hidden;
}

button { cursor: pointer; font-family: inherit; }
a { text-decoration: none; color: inherit; }

/* ================ Layout ================ */
.console-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100vh;
}

/* ================ Sidebar ================ */
.console-sidebar {
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.console-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--header-height);
  padding: 0 20px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  background: var(--sidebar-bg-sub);
  flex-shrink: 0;
}

.console-brand img {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  object-fit: contain;
  background: #fff;
  padding: 2px;
}

.console-sidebar .nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
  gap: 4px;
}

.console-sidebar .nav-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--sidebar-text);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  transition: all 0.2s;
}

.console-sidebar .nav-link:hover {
  color: var(--sidebar-text-hover);
  background: rgba(255,255,255,0.06);
}

.console-sidebar .nav-link.active {
  color: #fff;
  background: var(--primary);
}

.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  font-size: 14px;
}

/* ================ Main ================ */
.console-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.console-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: var(--header-height);
  padding: 0 24px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.page-title { font-size: 18px; font-weight: 600; margin: 0; line-height: 1.2; }
.page-summary { font-size: 13px; color: var(--text-secondary); margin: 4px 0 0; line-height: 1.2; }

.console-content {
  flex: 1;
  overflow: auto;
  padding: 20px 24px;
  min-height: 0;
}

.console-content > section {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ================ Split layout (sidebar + main area) ================ */
.split-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 16px;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.split-side, .split-main {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ================ Cards ================ */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-sm);
}

.card-full {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.card-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius) var(--radius) 0 0;
  flex-shrink: 0;
}

.card-header h2 { font-size: 14px; font-weight: 600; color: var(--text); }

.card-body { padding: 16px; }
.card-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: #fafafa;
  border-radius: 0 0 var(--radius) var(--radius);
}

.scroll-y {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

/* ================ Buttons ================ */
.btn {
  border-radius: var(--radius);
  font-size: 14px;
  padding: 5px 15px;
  line-height: 1.5;
  transition: all 0.2s;
  border: 1px solid transparent;
}
.btn-sm { padding: 2px 10px; font-size: 13px; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #fff;
}
.btn-outline-primary {
  border-color: var(--primary);
  color: var(--primary);
  background: #fff;
}
.btn-outline-primary:hover:not(:disabled) {
  background: var(--primary-bg);
  color: var(--primary);
}
.btn-outline-secondary {
  border-color: var(--border-base);
  color: var(--text);
  background: #fff;
}
.btn-outline-secondary:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}
.btn-outline-danger {
  border-color: var(--danger);
  color: var(--danger);
  background: #fff;
}
.btn-outline-danger:hover:not(:disabled) {
  background: var(--danger-bg);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ================ Forms ================ */
.form-control, .form-select {
  border-radius: var(--radius);
  border: 1px solid var(--border-base);
  font-size: 14px;
  padding: 5px 11px;
  line-height: 1.5;
  transition: all 0.2s;
  background: #fff;
  color: var(--text);
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  outline: 0;
  box-shadow: 0 0 0 2px rgba(22,119,255,0.1);
}
.form-control:disabled {
  background: #f5f5f5;
  color: var(--text-secondary);
  cursor: not-allowed;
}
.form-label {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 6px;
  font-weight: 400;
}

/* ================ Tables ================ */
.table {
  margin: 0;
  font-size: 14px;
  color: var(--text);
  width: 100%;
  border-collapse: collapse;
}
.table th {
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 13px;
  background: #fafafa;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table-hover tbody tr:hover td { background: #fafafa; }
.table-responsive { overflow-x: auto; }
.align-middle th, .align-middle td { vertical-align: middle; }
.text-center { text-align: center; }
.text-end { text-align: right; }
.text-secondary { color: var(--text-secondary) !important; }
.text-danger { color: var(--danger) !important; }

/* ================ Badges ================ */
.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
  border-radius: 4px;
  border: 1px solid transparent;
}
.bg-success-subtle { background: var(--success-bg) !important; border-color: #b7eb8f; }
.text-success { color: var(--success) !important; }
.bg-secondary-subtle { background: #f5f5f5 !important; border-color: var(--border); }

/* ================ Status badges (feedback) ================ */
.status-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
  border: 1px solid transparent;
}
.status-badge-lg { padding: 4px 14px; font-size: 13px; }
.status-open { background: var(--warning-bg); color: #d48806; border-color: #ffe58f; }
.status-reviewing { background: var(--primary-bg); color: var(--primary); border-color: var(--primary-border); }
.status-fixed { background: var(--success-bg); color: #389e0d; border-color: #b7eb8f; }
.status-closed { background: #f5f5f5; color: var(--text-secondary); border-color: var(--border); }

/* ================ Feedback ================ */
.ticket-row { cursor: pointer; transition: background 0.2s; }
.ticket-row.active td { background: var(--primary-bg) !important; }
.title-main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
.title-sub { margin-top: 2px; color: var(--text-secondary); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }

.ticket-detail { min-height: 400px; }
.detail-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.detail-title-row h2 { min-width: 0; line-height: 1.4; word-break: break-word; font-size: 16px; font-weight: 600; }
.detail-meta { display: grid; gap: 8px; margin: 0 0 12px; }
.detail-meta > div { display: grid; grid-template-columns: 72px 1fr; gap: 8px; font-size: 13px; }
.detail-meta dt { color: var(--text-secondary); font-weight: 400; }
.detail-meta dd { margin: 0; word-break: break-word; }
.detail-content-box { padding: 12px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.detail-content-box h3 { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin: 0 0 8px; }
.detail-content { line-height: 1.7; white-space: pre-wrap; font-size: 14px; }

/* ================ List group ================ */
.list-group { list-style: none; padding: 0; margin: 0; }
.list-group-flush { border-radius: 0; }
.list-group-flush .list-group-item {
  border: 0;
  border-bottom: 1px solid var(--border);
}
.list-group-flush .list-group-item:last-child { border-bottom: 0; }
.list-group-item {
  display: block;
  padding: 12px 16px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
  border: 0;
  width: 100%;
  text-align: left;
  font-size: 14px;
  transition: background 0.2s;
}
.list-group-item-action { cursor: pointer; }
.list-group-item-action:hover { background: #fafafa; }
.list-group-item.active {
  background: var(--primary-bg);
  color: var(--primary);
  border-right: 2px solid var(--primary);
}
.list-group-item.active .text-secondary { color: var(--primary) !important; opacity: 0.7; }

/* ================ Dictionary ================ */
.dictionary-item-row { cursor: pointer; }
.dictionary-item-row.active td { background: var(--primary-bg) !important; }
.dictionary-item-row code { background: #f5f5f5; padding: 1px 6px; border-radius: 3px; font-size: 12px; color: #d4380d; font-family: "SFMono-Regular", Consolas, monospace; }

/* ================ Config groupings ================ */
.config-group-heading {
  margin-top: 4px;
}
.config-group-heading h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 8px;
}
.config-group-heading hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 0;
  opacity: 1;
}
.config-image-preview {
  width: 100%;
  max-height: 160px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  object-fit: cover;
}

/* ================ Auth overlay ================ */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1080;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0,0,0,0.45);
}
.auth-panel {
  width: min(360px, 100%);
  border-radius: var(--radius);
  padding: 32px 24px;
  background: #fff;
  box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}
.auth-panel img {
  display: block;
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  border-radius: 8px;
}

/* ================ Toast ================ */
.console-toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1090;
  max-width: 320px;
  border-radius: var(--radius);
  background: #1f1f1f;
  color: #fff;
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.25);
}

/* ================ Utilities (Bootstrap-like minimum) ================ */
.d-none { display: none !important; }
.d-flex { display: flex !important; }
.d-grid { display: grid !important; }
.flex-column { flex-direction: column !important; }
.flex-1 { flex: 1 !important; }
.align-items-center { align-items: center !important; }
.align-items-end { align-items: flex-end !important; }
.justify-content-between { justify-content: space-between !important; }
.justify-content-end { justify-content: flex-end !important; }
.gap-1 { gap: 4px !important; }
.gap-2 { gap: 8px !important; }
.gap-3 { gap: 16px !important; }
.mt-1 { margin-top: 4px !important; }
.mt-2 { margin-top: 8px !important; }
.mt-3 { margin-top: 16px !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 4px !important; }
.mb-2 { margin-bottom: 8px !important; }
.mb-3 { margin-bottom: 16px !important; }
.mb-4 { margin-bottom: 24px !important; }
.py-3 { padding-top: 16px !important; padding-bottom: 16px !important; }
.py-4 { padding-top: 24px !important; padding-bottom: 24px !important; }
.py-5 { padding-top: 40px !important; padding-bottom: 40px !important; }
.fw-semibold { font-weight: 600 !important; }
.small { font-size: 13px; }
.text-nowrap { white-space: nowrap !important; }
.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ================ Responsive ================ */
@media (max-width: 992px) {
  .console-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .console-sidebar { flex-direction: row; height: auto; }
  .console-brand { height: auto; padding: 12px 16px; }
  .console-sidebar .nav { flex-direction: row !important; padding: 8px; overflow-x: auto; }
  .split-layout { grid-template-columns: 1fr; }
}
