/* Cards & Surfaces */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-card);
  min-width: 0;
  max-width: 100%;
}

.card-elevated {
  background: var(--surface-elevated);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.card-header > div {
  min-width: 0;
}

.card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
}

.kpi-card {
  background: linear-gradient(180deg, var(--surface-elevated), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.kpi-value {
  font-size: clamp(17px, 4.5vw, 21px);
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kpi-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-blue { color: var(--blue); }
.text-amber { color: var(--amber); }
.text-muted { color: var(--text-secondary); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
  text-decoration: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }

.btn-sm { min-height: 34px; padding: 6px 11px; font-size: 12px; }
.btn-block { width: 100%; }

.btn-primary {
  background: var(--blue);
  color: #08090C;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-secondary {
  background: var(--surface-elevated);
  border-color: var(--border);
  color: var(--text-primary);
}
.btn-secondary:hover:not(:disabled) { border-color: #3A414E; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-elevated);
  color: var(--text-primary);
}

.btn-danger-outline {
  background: var(--red-soft);
  border-color: rgba(255, 92, 112, 0.35);
  color: var(--red);
}

.btn-icon {
  min-height: 36px;
  width: 36px;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
}
.btn-icon:hover { color: var(--text-primary); border-color: #3B424F; }

/* Collapsible Filter Sections */
.collapse-icon {
  display: inline-block;
  font-size: 9px;
  line-height: 1;
  margin-right: 2px;
}
.collapsible-body {
  transition: opacity 0.2s ease;
}
.collapsible-body.collapsed {
  display: none !important;
}

@media (max-width: 767px) {
  .btn {
    min-height: 32px;
    padding: 5px 10px;
    font-size: 11.5px;
    gap: 4px;
    border-radius: 6px;
  }
  .btn-sm {
    min-height: 26px;
    padding: 3px 8px;
    font-size: 10.5px;
  }
  .btn-icon {
    min-height: 30px;
    width: 30px;
  }
  .btn-primary {
    font-weight: 500;
  }
  .filter-bar > .btn {
    min-height: 32px;
  }
  .tab-btn {
    padding: 4px 9px;
    font-size: 11px;
  }
}

/* Inputs & Filters */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 175px), 1fr));
  gap: 10px;
  align-items: end;
  width: 100%;
}
.filter-bar > .btn {
  min-height: 38px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.field label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
}

.input, .select, .textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 38px;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-neutral { background: rgba(146, 153, 165, 0.14); color: var(--text-secondary); }

/* Charts */
.chart-wrap {
  position: relative;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 240px;
  overflow: hidden;
}
@media (min-width: 900px) {
  .chart-wrap {
    height: 270px;
  }
}

/* Tables (Desktop) + Mobile Card Lists */
.table-desktop-only {
  display: none;
  min-width: 0;
  max-width: 100%;
}
.mobile-card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.tx-mobile-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  min-width: 0;
  max-width: 100%;
}

.tx-mobile-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.tx-mobile-title {
  font-weight: 600;
  font-size: 13px;
  word-break: break-word;
}

.tx-mobile-bottom {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
}

@media (min-width: 768px) {
  .table-desktop-only {
    display: block;
    width: 100%;
    overflow-x: auto;
  }
  .mobile-card-list {
    display: none;
  }
}

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

.data-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  word-break: break-word;
}
.data-table td.tabular {
  white-space: nowrap;
  word-break: normal;
}

.data-table tbody tr {
  transition: background 0.12s;
}
.data-table tbody tr.clickable:hover {
  background: var(--surface-elevated);
  cursor: pointer;
}

.text-right { text-align: right !important; }

/* Auth Shell */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
  background:
    radial-gradient(600px 300px at 50% 0%, rgba(100, 140, 255, 0.14), transparent 70%),
    var(--bg-primary);
}

.auth-card {
  width: 100%;
  max-width: 410px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 22px;
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-panel {
  width: 100%;
  max-width: 680px;
  max-height: 85vh;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: auto;
}

@media (min-width: 640px) {
  .modal-backdrop {
    padding: 24px;
  }
  .modal-panel {
    padding: 22px;
  }
}

/* Bottom Sheets (Mobile More Menu) */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.sheet-panel {
  width: 100%;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 12px 16px calc(22px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 99px;
  background: var(--border);
  margin: 0 auto;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sheet-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.sheet-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 8px;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  text-decoration: none;
  font-size: 12px;
  text-align: center;
}

/* Empty State & Skeleton */
.empty-state {
  padding: 36px 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
}

.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-elevated) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Toasts */
.toast-root {
  position: fixed;
  top: 14px;
  right: 14px;
  left: 14px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
@media (min-width: 640px) {
  .toast-root {
    left: auto;
    width: 360px;
  }
}

.toast {
  pointer-events: auto;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--blue);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  box-shadow: var(--shadow-modal);
  font-size: 13px;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }

.tabs-row {
  display: flex;
  gap: 6px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}
.tabs-row::-webkit-scrollbar {
  display: none;
}
@media (min-width: 900px) {
  .tabs-row {
    flex-wrap: wrap;
    overflow-x: visible;
  }
}

.tab-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 7px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.tab-btn.active {
  background: var(--blue-soft);
  border-color: var(--blue);
  color: var(--text-primary);
}

.code-block {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  max-width: 100%;
  overflow-x: auto;
  overflow-wrap: anywhere;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}
