:root {
  --bg: #0f1419;
  --bg-card: #1a2332;
  --bg-card-hover: #1f2a3c;
  --border: #2a3648;
  --text: #e8eef7;
  --text-muted: #8b9bb4;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 16px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

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

.logo-icon {
  font-size: 28px;
}

.logo-text {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-open {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.badge-closed {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.badge-unknown {
  background: rgba(139, 155, 180, 0.15);
  color: var(--text-muted);
}

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

.last-update {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

.btn-icon.spinning svg {
  animation: spin 0.8s linear infinite;
}

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

/* Error */
.error-banner {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  padding: 14px 18px;
  border-radius: 12px;
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.error-banner.hidden {
  display: none;
}

.btn-text {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.btn-text:hover {
  background: var(--accent-soft);
}

/* Dashboard grid */
.dashboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 24px;
  flex: 1;
}

.card-revenue {
  grid-column: 1 / -1;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.card-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.muted {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Revenue */
.revenue-value {
  font-size: 3.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: 20px;
  background: none;
  
  color: #e8eef7;
  
}

.revenue-details {
  display: flex;
  gap: 32px;
  margin-bottom: 16px;
}

.detail {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail .label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.detail .value {
  font-size: 1.25rem;
  font-weight: 600;
}

.period-info {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* Top items */
.top-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.top-item {
  display: grid;
  grid-template-columns: 36px 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  transition: background 0.15s;
}

.top-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.top-item .rank {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.85rem;
  background: var(--accent-soft);
  color: var(--accent);
}

.top-item:nth-child(1) .rank { background: rgba(234, 179, 8, 0.2); color: #facc15; }
.top-item:nth-child(2) .rank { background: rgba(156, 163, 175, 0.2); color: #d1d5db; }
.top-item:nth-child(3) .rank { background: rgba(180, 83, 9, 0.2); color: #fb923c; }

.top-item .name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-item .qty {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: right;
}

.top-item .amount {
  font-weight: 600;
  text-align: right;
  min-width: 90px;
}

.skeleton-row {
  height: 48px;
  background: linear-gradient(90deg, rgba(255,255,255,0.03) 25%, rgba(255,255,255,0.06) 50%, rgba(255,255,255,0.03) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 10px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Payments */
.payments-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: center;
}

.chart-wrapper {
  position: relative;
  max-width: 260px;
  margin: 0 auto;
}

.payment-legend {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.legend-item {
  display: grid;
  grid-template-columns: 12px 1fr auto auto;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.legend-name {
  font-weight: 500;
}

.legend-amount {
  font-weight: 600;
  text-align: right;
}

.legend-pct {
  color: var(--text-muted);
  font-size: 0.85rem;
  min-width: 48px;
  text-align: right;
}

/* Footer */
.footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.separator {
  opacity: 0.5;
}

/* Responsive */
@media (max-width: 900px) {
  .dashboard {
    grid-template-columns: 1fr;
  }

  .card-revenue {
    grid-column: 1;
  }

  .revenue-value {
    font-size: 2.6rem;
  }

  .payments-layout {
    grid-template-columns: 1fr;
  }

  .chart-wrapper {
    max-width: 220px;
  }
}

@media (max-width: 500px) {
  .app {
    padding: 16px;
  }

  .revenue-value {
    font-size: 2.2rem;
  }

  .top-item {
    grid-template-columns: 32px 1fr auto;
  }

  .top-item .qty {
    display: none;
  }
}

/* ServiQ PWA extras */
.logo-img {
  border-radius: 8px;
  display: block;
}

.btn-install {
  background: var(--accent);
  color: #fff;
  border: none;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
}

.btn-install:hover {
  filter: brightness(1.1);
}

.btn-install.hidden {
  display: none;
}

/* Safe area for notched phones when installed */
@supports (padding: env(safe-area-inset-top)) {
  .app {
    padding-top: max(24px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
  }
}
