@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --bg-app: #f4f6f8;
  --bg-surface: #ffffff;
  --bg-subtle: #f8fafc;
  --border: #e2e8f0;
  --border-focus: #1890ff;

  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;

  --primary: #1890ff;
  --primary-hover: #096dd9;
  --primary-tint: #e6f7ff;

  --success: #52c41a;
  --success-bg: #f6ffed;
  --success-border: #b7eb8f;

  --warning: #faad14;
  --warning-bg: #fffbe6;
  --warning-border: #ffe58f;

  --danger: #ff4d4f;
  --danger-bg: #fff2f0;
  --danger-border: #ffccc7;

  --sidebar-bg: #001529;
  --radius-sm: 4px;
  --radius-md: 4px;
  --radius-card: 6px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-dropdown: 0 6px 16px rgba(0, 0, 0, 0.12);

  --sidebar-w: 220px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.cn-text {
  font-size: 11px;
  opacity: 0.85;
  margin-left: 3px;
  font-weight: normal;
}

/* App Shell */
.app-container {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background-color: var(--sidebar-bg);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 30;
}

.sidebar-brand {
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #002140;
}

.brand-badge {
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.sidebar-title {
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  white-space: nowrap;
}

.sidebar-nav {
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.nav-section-label {
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 18px 4px 18px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  color: rgba(255, 255, 255, 0.65);
  text-decoration: none;
  font-size: 13px;
  font-weight: 400;
  transition: all 150ms ease;
  cursor: pointer;
  user-select: none;
}

.nav-item:hover {
  color: #ffffff;
}

.nav-item.active {
  background-color: var(--primary);
  color: #ffffff;
  font-weight: 500;
}

.nav-item svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

/* Main Area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: 50px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

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

/* Breadcrumb & Tabs bar */
.sub-header-bar {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  padding: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.breadcrumb-trail {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.tag-tabs-bar {
  display: flex;
  gap: 6px;
  padding: 8px 20px 0 20px;
}

.tag-tab {
  padding: 4px 10px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tag-tab.active {
  color: var(--primary);
  font-weight: 600;
  background: #ffffff;
  border-color: var(--border);
}

.tag-tab-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
}

.content-body {
  padding: 16px 20px;
  max-width: 1560px;
  width: 100%;
  margin: 0 auto;
}

/* Cowpay-Style Filter Query Box */
.query-box {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 16px 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.query-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px 20px;
}

.query-field {
  display: flex;
  align-items: center;
}

.query-label {
  width: 150px;
  flex-shrink: 0;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-main);
  text-align: right;
  padding-right: 12px;
  white-space: nowrap;
}

.query-input-wrap {
  flex: 1;
}

.query-input {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  font-size: 12.5px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  background: #ffffff;
  transition: border-color 150ms;
}

.query-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.15);
}

.query-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
}

/* Operation & Metrics Bar (Above Data Table) */
.table-toolbar {
  background: #ffffff;
  border: 1px solid var(--border);
  border-bottom: none;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  border-radius: var(--radius-card) var(--radius-card) 0 0;
}

.toolbar-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toolbar-metrics {
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 12.5px;
  color: var(--text-main);
}

.metric-item b {
  font-family: var(--font-mono);
  font-weight: 600;
  color: #1e293b;
}

/* Table Container */
.table-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius-card) var(--radius-card);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.table th {
  background-color: #fafafa;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text-main);
  vertical-align: middle;
}

.table tr:hover td {
  background-color: #f8fafc;
}

/* Standard Buttons */
.btn {
  height: 32px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 400;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 150ms ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
}

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

.btn-secondary, .btn-outline {
  background-color: #ffffff;
  border-color: var(--border);
  color: var(--text-main);
}

.btn-secondary:hover, .btn-outline:hover {
  background-color: var(--bg-subtle);
  border-color: #cbd5e1;
}

.btn-sm {
  height: 26px;
  padding: 0 8px;
  font-size: 11.5px;
}

.btn-warning-outline {
  background-color: #fffbe6;
  border-color: #ffe58f;
  color: #d46b08;
}

.btn-link-action {
  background-color: #e6f7ff;
  border-color: #91d5ff;
  color: #096dd9;
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 20px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #cbd5e1;
  transition: .2s;
  border-radius: 20px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .2s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary);
}

input:checked + .slider:before {
  transform: translateX(18px);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 4px;
  white-space: nowrap;
}

.badge-success {
  background-color: var(--success-bg);
  color: #389e0d;
  border: 1px solid var(--success-border);
}

.badge-warning {
  background-color: var(--warning-bg);
  color: #d46b08;
  border: 1px solid var(--warning-border);
}

.badge-danger {
  background-color: var(--danger-bg);
  color: #cf1322;
  border: 1px solid var(--danger-border);
}

.badge-info {
  background-color: var(--primary-tint);
  color: #096dd9;
  border: 1px solid #91d5ff;
}

.badge-gray {
  background-color: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  background: var(--bg-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

.modal-body {
  padding: 18px;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  background-color: #fafafa;
}

/* Tabs */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 999;
  padding: 8px 14px;
  background: #1e293b;
  color: #ffffff;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  box-shadow: var(--shadow-md);
}

@media (max-width: 768px) {
  .app-container { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; }
  .query-grid { grid-template-columns: 1fr; }
  .query-label { width: 110px; }
  .table-toolbar { flex-direction: column; align-items: flex-start; }
}
