/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #0f1117;
  --bg-card:      #161b25;
  --bg-card2:     #1c2233;
  --border:       rgba(255,255,255,0.08);
  --border-light: rgba(255,255,255,0.05);
  --text:         #e8e6e1;
  --text-secondary: #8b8a85;
  --text-tertiary:  #5a5957;
  --blue:         #378ADD;
  --blue-dim:     rgba(55,138,221,0.15);
  --green:        #1D9E75;
  --amber:        #BA7517;
  --red:          #E24B4A;
  --purple:       #7F77DD;
  --radius:       10px;
  --radius-lg:    14px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

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

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-icon {
  font-size: 36px;
  color: var(--blue);
  margin-bottom: .5rem;
}

.login-brand {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.login-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 3px;
}

.login-error {
  background: rgba(226,75,74,0.15);
  border: 1px solid rgba(226,75,74,0.3);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  color: #F09595;
  margin-bottom: 1rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.form-group input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}

.form-group input:focus {
  border-color: var(--blue);
}

.login-btn {
  width: 100%;
  padding: 12px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}

.login-btn:hover { background: #185FA5; }
.login-btn:disabled { opacity: .6; cursor: default; }

/* ── Header ──────────────────────────────────────────────────────────────── */
.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 10;
}

.dash-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dash-icon {
  font-size: 22px;
  color: var(--blue);
}

.dash-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.dash-sub {
  font-size: 11px;
  color: var(--text-tertiary);
}

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

.data-date {
  font-size: 12px;
  color: var(--text-tertiary);
}

.sign-out-btn {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.sign-out-btn:hover { background: var(--bg-card2); }

/* ── Banners ─────────────────────────────────────────────────────────────── */
.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 1.5rem;
  font-size: 13px;
  border-bottom: 1px solid transparent;
}

.banner-danger {
  background: rgba(226,75,74,0.12);
  border-bottom-color: rgba(226,75,74,0.2);
  color: #F09595;
}

.banner-warning {
  background: rgba(186,117,23,0.12);
  border-bottom-color: rgba(186,117,23,0.2);
  color: #FAC775;
}

.banner-info {
  background: rgba(55,138,221,0.1);
  border-bottom-color: rgba(55,138,221,0.2);
  color: #85B7EB;
}

.banner-success {
  background: rgba(29,158,117,0.1);
  border-bottom-color: rgba(29,158,117,0.2);
  color: #6DD4B0;
}

.banner-action {
  margin-left: auto;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  cursor: pointer;
  opacity: .8;
  white-space: nowrap;
}

.banner-action:hover { opacity: 1; }

/* ── Controls ────────────────────────────────────────────────────────────── */
.controls-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: .75rem 1.5rem;
  border-bottom: 1px solid var(--border-light);
  flex-wrap: wrap;
}

.range-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.controls-bar select,
.controls-bar input[type=date] {
  font-size: 13px;
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  outline: none;
}

.yoy-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  margin-left: auto;
}

.toggle-track {
  width: 32px;
  height: 18px;
  border-radius: 9px;
  background: var(--border);
  position: relative;
  transition: background .2s;
  flex-shrink: 0;
}

.toggle-track.on { background: var(--blue); }

.toggle-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: left .2s;
}

.toggle-track.on .toggle-thumb { left: 14px; }

/* ── Main layout ─────────────────────────────────────────────────────────── */
.dash-main {
  padding: 1.25rem 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
}

.section-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin: 1.5rem 0 .6rem;
}

.section-label:first-child { margin-top: 0; }

/* ── Metric cards ────────────────────────────────────────────────────────── */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 1.25rem;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
}

.metric-card.loading { opacity: .5; }

.metric-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.metric-value {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.metric-delta {
  font-size: 11px;
  margin-top: 3px;
}

.delta-up   { color: #3B9E5F; }
.delta-down { color: #E24B4A; }
.delta-flat { color: var(--text-tertiary); }

/* ── Chart cards ─────────────────────────────────────────────────────────── */
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.chart-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: .75rem;
  flex-wrap: wrap;
  gap: 8px;
}

.chart-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}

.chart-legend span {
  display: flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: 220px;
}

.chart-wrap-sm {
  height: 160px;
}

.chart-footer {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 8px;
}

.two-col {
  display: grid;
  grid-template-columns: minmax(0,1fr) minmax(0,1fr);
  gap: 10px;
  margin-bottom: 1.25rem;
}

@media (max-width: 640px) {
  .two-col { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Bar lists ───────────────────────────────────────────────────────────── */
.bar-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: .5rem;
}

.bar-row { }

.bar-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 3px;
  color: var(--text-secondary);
}

.bar-track {
  height: 6px;
  background: var(--bg-card2);
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .6s ease;
}

/* ── Manager alerts ──────────────────────────────────────────────────────── */
.mgr-alerts {
  margin-top: 10px;
  border-top: 1px solid var(--border-light);
  padding-top: 8px;
}

.mgr-alert-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
}

.mgr-alert-row:last-child { border-bottom: none; }

.mgr-alert-name { font-weight: 500; color: var(--text); }

.tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 8px;
  margin-left: 5px;
}

.tag-flag    { background: rgba(226,75,74,0.15); color: #F09595; }
.tag-manager { background: rgba(186,117,23,0.15); color: #FAC775; }
.tag-work    { background: rgba(55,138,221,0.15); color: #85B7EB; }
.tag-personal{ background: rgba(29,158,117,0.15); color: #6DD4B0; }

/* ── Machine list ────────────────────────────────────────────────────────── */
.machine-list {
  display: flex;
  flex-direction: column;
}

.machine-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
}

.machine-row:last-child { border-bottom: none; }

.machine-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-ok      { background: #3B9E5F; }
.dot-warning { background: #BA7517; }
.dot-error   { background: #E24B4A; }

.machine-name {
  font-weight: 500;
  color: var(--text);
  flex: 1;
}

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

.machine-uptime {
  font-size: 11px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}

/* ── Loading states ──────────────────────────────────────────────────────── */
.loading-text {
  font-size: 13px;
  color: var(--text-tertiary);
  padding: .5rem 0;
  text-align: center;
}

@keyframes pulse {
  0%, 100% { opacity: .5; }
  50%       { opacity: 1; }
}

.loading { animation: pulse 1.5s ease-in-out infinite; }
