/* Revolta WebView — mobile-first, touch-friendly */

:root {
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-text: #0f172a;
  --color-text-muted: #64748b;
  --color-border: #e2e8f0;
  --color-primary: #0ea5e9;
  --color-primary-hover: #0284c7;
  --color-error: #dc2626;
  --color-error-bg: #fef2f2;
  --color-success: #16a34a;
  --min-touch: 44px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --header-h: 52px;
}

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  min-height: 100dvh;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--header-h);
  padding: 0 12px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.back-btn {
  position: absolute;
  left: 12px;
  width: var(--min-touch);
  height: var(--min-touch);
  min-width: var(--min-touch);
  min-height: var(--min-touch);
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-primary);
  font-size: 24px;
  border-radius: var(--radius);
}

.back-btn-icon {
  display: block;
  line-height: 1;
  font-weight: 700;
}

.back-btn:hover,
.back-btn:focus-visible {
  background: var(--color-bg);
}

.back-btn[hidden] {
  display: none !important;
}

.app-title {
  font-size: 1.125rem;
  font-weight: 600;
}

/* Main content */
.main {
  flex: 1;
  overflow: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

#content {
  min-height: 200px;
}

/* Cards grid (providers, categories, subcategories, products) */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

@media (min-width: 480px) {
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
  }
}

.card {
  display: block;
  min-height: var(--min-touch);
  padding: 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  text-align: center;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.card:active,
.card:hover,
.card:focus-visible {
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(14, 165, 233, 0.15);
}

.card-thumb {
  width: 48px;
  height: 48px;
  margin: 0 auto 8px;
  border-radius: var(--radius);
  object-fit: cover;
  background: var(--color-bg);
}

.card-title {
  font-size: 0.9375rem;
  font-weight: 500;
  margin-bottom: 4px;
}

.card-meta {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.card-price {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--color-primary);
}

/* Provider sections (homepage) */
.provider-section {
  margin-bottom: 24px;
}

.provider-section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 12px;
  padding-bottom: 4px;
}

.provider-section-view-all {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.875rem;
  color: var(--color-primary);
  text-decoration: none;
}

.provider-section-view-all:hover,
.provider-section-view-all:focus-visible {
  text-decoration: underline;
}

.provider-section-error {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin: 0;
  padding: 8px 0;
}

/* Loading */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  gap: 12px;
  color: var(--color-text-muted);
  animation: loadingFadeIn 0.25s ease-out;
}

@keyframes loadingFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1.2s ease-in-out infinite;
}

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

.skeleton {
  background: linear-gradient(90deg, var(--color-border) 25%, var(--color-bg) 50%, var(--color-border) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.5s ease-in-out infinite;
  border-radius: var(--radius);
}

.skeleton-card {
  height: 120px;
}

.provider-section-categories .skeleton-card {
  height: 10px;
}

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

/* Error */
.error-banner {
  padding: 12px 16px;
  background: var(--color-error-bg);
  border: 1px solid var(--color-error);
  border-radius: var(--radius);
  color: var(--color-error);
  margin-bottom: 16px;
}

.error-banner p {
  margin-bottom: 8px;
}

.error-banner button {
  min-height: var(--min-touch);
  padding: 0 16px;
  background: var(--color-error);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  padding: 24px;
  text-align: center;
  color: var(--color-text-muted);
}

.empty-state p {
  font-size: 0.9375rem;
  margin-top: 8px;
}

/* Product detail */
.detail-section {
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  padding: 16px;
  margin-bottom: 16px;
}

.detail-section h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--color-text-muted);
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9375rem;
}

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

.detail-label {
  color: var(--color-text-muted);
}

.detail-value {
  font-weight: 500;
}

.detail-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--min-touch);
  padding: 0 20px;
  font-size: 1rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

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

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

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover,
.btn-secondary:focus-visible {
  background: var(--color-bg);
}

.btn-block {
  width: 100%;
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--color-text);
}

.form-group input,
.form-group select {
  width: 100%;
  min-height: var(--min-touch);
  padding: 0 12px;
  font-size: 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
}

.form-group .hint,
.form-group .error-msg {
  font-size: 0.8125rem;
  margin-top: 4px;
}

.form-group .error-msg {
  color: var(--color-error);
}

/* Receipt / confirmation */
.receipt-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.receipt-card.success {
  border-color: var(--color-success);
  background: #f0fdf4;
}

.receipt-ref {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.receipt-ref strong {
  color: var(--color-text);
}

/* Transaction history list */
.transaction-list {
  list-style: none;
}

.transaction-item {
  display: block;
  padding: 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s;
}

.transaction-item:hover,
.transaction-item:focus-visible {
  border-color: var(--color-primary);
}

.transaction-item .row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 4px;
}

.transaction-item .product-name {
  font-weight: 500;
}

.transaction-item .date {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

/* Breadcrumb / nav */
.breadcrumb {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin-bottom: 16px;
}

.breadcrumb a {
  color: var(--color-primary);
  text-decoration: none;
}

/* Date range (history) */
.date-range {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

@media (min-width: 480px) {
  .date-range {
    grid-template-columns: 1fr 1fr;
  }
}

/* Activation code display */
.activation-code {
  word-break: break-all;
  font-family: ui-monospace, monospace;
  font-size: 0.875rem;
  padding: 12px;
  background: var(--color-bg);
  border-radius: var(--radius);
  margin-top: 8px;
}

.qr-placeholder {
  width: 160px;
  height: 160px;
  margin: 12px auto;
  background: var(--color-bg);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: 0.875rem;
}
