/* ==========================================================================
   Portad Dashboard – Professional design system
   ========================================================================== */

:root {
  --pro-bg: #f1f5f9;
  --pro-bg-elevated: #ffffff;
  --pro-bg-muted: #e2e8f0;
  --pro-border: #cbd5e1;
  --pro-border-subtle: #e2e8f0;
  --pro-text: #0f172a;
  --pro-text-secondary: #334155;
  --pro-text-muted: #64748b;

  --pro-primary: #1d4ed8;
  --pro-primary-hover: #1e40af;
  --pro-primary-muted: #dbeafe;

  --pro-success: #047857;
  --pro-success-bg: #d1fae5;
  --pro-error: #b91c1c;
  --pro-error-bg: #fef2f2;
  --pro-warning: #d97706;
  --pro-warning-bg: #fef3c7;
  --pro-info: #0369a1;

  --pro-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --pro-shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --pro-shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.04);

  --pro-radius: 8px;
  --pro-radius-lg: 12px;
  --pro-space: 1.5rem;
  --pro-space-lg: 2rem;
}

/* Dark mode */
[data-theme="dark"] {
  --pro-bg: #0f172a;
  --pro-bg-elevated: #1e293b;
  --pro-bg-muted: #334155;
  --pro-border: #475569;
  --pro-border-subtle: #334155;
  --pro-text: #f1f5f9;
  --pro-text-secondary: #cbd5e1;
  --pro-text-muted: #94a3b8;
  --pro-primary-muted: rgba(29, 78, 216, 0.2);
  --pro-success-bg: rgba(4, 120, 87, 0.15);
  --pro-error-bg: rgba(185, 28, 28, 0.15);
  --pro-warning-bg: rgba(217, 119, 6, 0.15);
  --pro-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --pro-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --pro-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .logo-img { filter: brightness(0) invert(1) brightness(0.9); }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--pro-text);
  background: var(--pro-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 0.25s ease, color 0.25s ease;
}

.dashboard {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--pro-space-lg);
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem var(--pro-space-lg);
  margin: 0 calc(-1 * var(--pro-space-lg)) var(--pro-space-lg);
  background: var(--pro-bg-elevated);
  border-bottom: 1px solid var(--pro-border);
  min-height: 64px;
  gap: 0.75rem;
}

.header-left {
  display: flex;
  align-items: center;
  min-width: 0;
}

.logo-link {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  text-decoration: none;
}

.logo-img {
  display: block;
  height: 36px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.header-badge {
  flex-shrink: 0;
  padding: 0.35rem 0.7rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--pro-primary);
  background: var(--pro-primary-muted);
  border: 1px solid rgba(29, 78, 216, 0.2);
  border-radius: 6px;
}

.header-badge.prod {
  color: var(--pro-success);
  background: var(--pro-success-bg);
  border-color: rgba(4, 120, 87, 0.2);
}

.control-select {
  padding: 0.4rem 0.6rem;
  font-size: 0.8125rem;
  font-family: inherit;
  color: var(--pro-text);
  background: var(--pro-bg);
  border: 1px solid var(--pro-border);
  border-radius: 6px;
  cursor: pointer;
  outline: none;
}

.control-select:focus { border-color: var(--pro-primary); }

.control-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: var(--pro-bg);
  border: 1px solid var(--pro-border);
  border-radius: 6px;
  color: var(--pro-text-muted);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.control-btn:hover { color: var(--pro-primary); border-color: var(--pro-primary); }
.control-btn.spinning svg { animation: spin 0.8s linear infinite; }

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

/* --------------------------------------------------------------------------
   Tabs
   -------------------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: var(--pro-space-lg);
  border-bottom: 1px solid var(--pro-border);
  margin-left: calc(-1 * var(--pro-space-lg));
  margin-right: calc(-1 * var(--pro-space-lg));
  padding-left: var(--pro-space-lg);
  overflow-x: auto;
}

.tab {
  padding: 0.75rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--pro-text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
  white-space: nowrap;
}

.tab:hover { color: var(--pro-text); }

.tab.active {
  color: var(--pro-primary);
  border-bottom-color: var(--pro-primary);
}

.panel { display: block; }
.panel.hidden { display: none; }

/* --------------------------------------------------------------------------
   KPI cards
   -------------------------------------------------------------------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--pro-space);
  margin-bottom: var(--pro-space-lg);
}

.kpi-card {
  background: var(--pro-bg-elevated);
  border-radius: var(--pro-radius-lg);
  padding: 1.25rem;
  box-shadow: var(--pro-shadow);
  border: 1px solid var(--pro-border-subtle);
  position: relative;
  overflow: hidden;
  transition: background 0.25s, border-color 0.25s;
}

.kpi-card .label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--pro-text-muted);
  margin-bottom: 0.5rem;
}

.kpi-card .value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--pro-text);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.kpi-card.success .value { color: var(--pro-success); }
.kpi-card.error .value { color: var(--pro-error); }
.kpi-card.warning .value { color: var(--pro-warning); }
.kpi-card.accent {
  border-left: 4px solid var(--pro-primary);
}
.kpi-card.accent .value {
  font-size: 2.5rem;
  color: var(--pro-primary);
}

/* --------------------------------------------------------------------------
   Loading skeletons
   -------------------------------------------------------------------------- */
.kpi-skeleton {
  position: relative;
  overflow: hidden;
}

.kpi-skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 25%, var(--pro-bg-muted) 50%, transparent 75%);
  animation: shimmer 1.5s infinite;
  border-radius: inherit;
  pointer-events: none;
}

.chart-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--pro-bg-elevated);
  border-radius: var(--pro-radius);
  z-index: 2;
  overflow: hidden;
}

.chart-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 25%, var(--pro-bg-muted) 50%, transparent 75%);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* --------------------------------------------------------------------------
   Cards & grids
   -------------------------------------------------------------------------- */
.section-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--pro-text);
  margin: 0 0 1rem 0;
  padding-bottom: 0.625rem;
  border-bottom: 1px solid var(--pro-border-subtle);
  letter-spacing: -0.01em;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: var(--pro-space-lg);
  margin-bottom: var(--pro-space-lg);
}

.card {
  background: var(--pro-bg-elevated);
  border-radius: var(--pro-radius-lg);
  padding: 1.5rem;
  box-shadow: var(--pro-shadow);
  border: 1px solid var(--pro-border-subtle);
  margin-bottom: var(--pro-space-lg);
  transition: background 0.25s, border-color 0.25s;
}

.grid-2 > .card { margin-bottom: 0; }

.card.chart-container { min-height: 300px; }

.chart-wrapper {
  position: relative;
  height: 260px;
  width: 100%;
}

.chart-wrapper canvas { max-height: 260px; }

.chart-wrapper-tall {
  height: 320px;
}

.chart-wrapper-tall canvas { max-height: 320px; }

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--pro-radius);
  border: 1px solid var(--pro-border-subtle);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--pro-border-subtle);
}

th {
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--pro-text-secondary);
  background: var(--pro-bg-muted);
}

tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--pro-bg); }

.status-badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 4px;
}

.status-badge.success { background: var(--pro-success-bg); color: var(--pro-success); }
.status-badge.error { background: var(--pro-error-bg); color: var(--pro-error); }
.status-badge.running { background: var(--pro-primary-muted); color: var(--pro-primary); }
.status-badge.warning { background: var(--pro-warning-bg); color: var(--pro-warning); }

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.footer {
  margin-top: auto;
  padding-top: var(--pro-space);
  padding-bottom: var(--pro-space);
  border-top: 1px solid var(--pro-border-subtle);
  font-size: 0.8125rem;
  color: var(--pro-text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.footer-refresh { font-size: 0.75rem; color: var(--pro-text-muted); }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .dashboard { padding: 1rem; }
  .header, .tabs {
    margin-left: -1rem;
    margin-right: -1rem;
    padding-left: 1rem;
    padding-right: 1rem;
  }
  .logo-img { height: 32px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .header-controls { width: 100%; justify-content: flex-end; }
  .header { flex-wrap: wrap; }
}

/* --------------------------------------------------------------------------
   Login screen
   -------------------------------------------------------------------------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--pro-bg);
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--pro-bg-elevated);
  border-radius: var(--pro-radius-lg);
  box-shadow: var(--pro-shadow-md);
  border: 1px solid var(--pro-border-subtle);
  padding: 2.5rem 2rem 2rem;
  text-align: center;
}

.login-logo { margin-bottom: 1.25rem; }
.login-logo img { height: 44px; width: auto; }

[data-theme="dark"] .login-logo img { filter: brightness(0) invert(1) brightness(0.9); }

.login-title {
  margin: 0 0 1.5rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--pro-text);
  letter-spacing: -0.02em;
}

.login-field {
  margin-bottom: 1rem;
  text-align: left;
}

.login-field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--pro-text-secondary);
  margin-bottom: 0.35rem;
}

.login-field input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 0.9375rem;
  font-family: inherit;
  color: var(--pro-text);
  background: var(--pro-bg);
  border: 1px solid var(--pro-border);
  border-radius: 6px;
  outline: none;
  transition: border-color 0.2s;
}

.login-field input:focus { border-color: var(--pro-primary); }

.login-error {
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--pro-error);
  background: var(--pro-error-bg);
  border-radius: 6px;
}

.login-btn {
  width: 100%;
  padding: 0.65rem;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--pro-primary);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.login-btn:hover { background: var(--pro-primary-hover); }
.login-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* --------------------------------------------------------------------------
   DataTables overrides – match dashboard design system
   -------------------------------------------------------------------------- */
.dataTables_wrapper {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.875rem;
  color: var(--pro-text);
}

.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
  padding: 0.35rem 0.6rem;
  font-size: 0.8125rem;
  font-family: inherit;
  color: var(--pro-text);
  background: var(--pro-bg);
  border: 1px solid var(--pro-border);
  border-radius: 6px;
  outline: none;
}

.dataTables_wrapper .dataTables_filter input:focus {
  border-color: var(--pro-primary);
}

.dataTables_wrapper .dataTables_info {
  font-size: 0.8125rem;
  color: var(--pro-text-muted);
  padding-top: 0.75rem;
}

.dataTables_wrapper .dataTables_paginate {
  padding-top: 0.75rem;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
  padding: 0.3rem 0.65rem;
  margin: 0 2px;
  font-size: 0.8125rem;
  border-radius: 4px;
  border: 1px solid var(--pro-border) !important;
  background: var(--pro-bg-elevated) !important;
  color: var(--pro-text) !important;
  cursor: pointer;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: var(--pro-bg-muted) !important;
  border-color: var(--pro-primary) !important;
  color: var(--pro-primary) !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: var(--pro-primary) !important;
  border-color: var(--pro-primary) !important;
  color: #fff !important;
  font-weight: 600;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
  opacity: 0.4;
  cursor: default;
}

table.dataTable thead th {
  border-bottom: 2px solid var(--pro-border) !important;
}

table.dataTable.no-footer {
  border-bottom: 1px solid var(--pro-border-subtle);
}
