/* ============================================================
   Warrantify — Global Stylesheet
   Pure vanilla CSS with custom properties + responsive breakpoints
   ============================================================ */

/* --- CSS Custom Properties (Design Tokens) ------------------ */
:root {
  /* Colors */
  --color-bg:        #f8f9fa;
  --color-surface:   #ffffff;
  --color-text:      #1a1a2e;
  --color-text-secondary: #6b7280;
  --color-border:    #e5e7eb;
  --color-border-light: #f3f4f6;
  --color-primary:   #1a1a2e;
  --color-primary-hover: #374151;
  --color-success-text:  #166534;
  --color-success-bg:    #dcfce7;
  --color-success-border:#bbf7d0;
  --color-warning-text:  #92400e;
  --color-warning-bg:    #fffbeb;
  --color-warning-border:#fde68a;
  --color-error-text:    #991b1b;
  --color-error-bg:      #fef2f2;
  --color-error-border:  #fecaca;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 9999px;

  /* Shadows */
  --shadow-card: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-card-hover: 0 2px 8px rgba(0,0,0,0.10);
  --shadow-button: 0 1px 2px rgba(0,0,0,0.05);

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: SF Mono, 'Fira Code', 'Cascadia Code', monospace;
  --font-size-sm: 13px;
  --font-size-base: 15px;
  --font-size-lg: 18px;
  --font-size-xl: 22px;
  --font-size-2xl: 32px;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.2s ease;

  /* Layout */
  --content-max-width: 640px;
  --dashboard-max-width: 960px;
  --button-height: 48px;
}

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { opacity: 0.7; }

img { max-width: 100%; height: auto; display: block; }

code, pre, .mono {
  font-family: var(--font-mono);
  font-size: 11px;
}

/* --- Layout ------------------------------------------------- */
.container {
  width: 100%;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-md);
}

.container--narrow {
  max-width: var(--content-max-width);
}

.container--wide {
  max-width: var(--dashboard-max-width);
}

/* --- Header / Nav ------------------------------------------ */
.header {
  text-align: center;
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--color-border-light);
  margin-bottom: var(--space-lg);
}

.header__title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
  letter-spacing: -0.3px;
}

.header__subtitle {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-top: var(--space-xs);
}

.header__nav {
  display: flex;
  justify-content: center;
  gap: var(--space-lg);
  margin-top: var(--space-md);
}

.header__nav a {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.header__nav a:hover { color: var(--color-primary); background: var(--color-bg); }
.header__nav a.active { color: var(--color-primary); background: var(--color-bg); font-weight: var(--font-weight-semibold); }

/* --- Cards ------------------------------------------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-card);
  transition: box-shadow var(--transition-base);
  margin-bottom: var(--space-md);
}

.card:hover {
  box-shadow: var(--shadow-card-hover);
}

.card__label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin-bottom: var(--space-sm);
}

/* --- Buttons ----------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--button-height);
  padding: 0 var(--space-lg);
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  transition: all var(--transition-base);
  text-align: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--color-primary);
  color: #ffffff;
  box-shadow: var(--shadow-button);
}

.btn--primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.btn--primary:active:not(:disabled) {
  transform: scale(0.98);
}

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

.btn--secondary:hover:not(:disabled) {
  background: var(--color-bg);
}

.btn--secondary:active:not(:disabled) {
  transform: scale(0.98);
}

.btn--full {
  width: 100%;
}

.btn--group {
  display: flex;
  gap: var(--space-sm);
}

.btn--group .btn {
  flex: 1;
}

/* --- Forms ------------------------------------------------- */
.select,
.input {
  width: 100%;
  height: var(--button-height);
  padding: 0 var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  appearance: none;
  -webkit-appearance: none;
}

.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%236b7280'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

.select:focus,
.input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(26,26,46,0.1);
}

.form-group {
  margin-bottom: var(--space-md);
}

.form-group__label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-sm);
  color: var(--color-text);
}

/* --- Badges ------------------------------------------------ */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0.2px;
  line-height: 1.8;
  white-space: nowrap;
}

.badge--success { background: var(--color-success-bg); color: var(--color-success-text); }
.badge--warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.badge--error   { background: var(--color-error-bg);   color: var(--color-error-text); }
.badge--neutral { background: var(--color-bg);          color: var(--color-text-secondary); }

/* --- Stats Grid -------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-card);
  transition: box-shadow var(--transition-base);
}

.stat-card:hover {
  box-shadow: var(--shadow-card-hover);
}

.stat-card__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xs);
}

.stat-card__value {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  line-height: 1.2;
}

.stat-card__hint {
  font-size: 11px;
  color: var(--color-text-secondary);
  margin-top: var(--space-xs);
}

.stat-card__value--success { color: var(--color-success-text); }
.stat-card__value--warning { color: var(--color-warning-text); }
.stat-card__value--error   { color: var(--color-error-text); }

/* --- Banner ------------------------------------------------ */
.banner {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-base);
  margin-bottom: var(--space-lg);
  border: 1px solid transparent;
}

.banner--success { background: var(--color-success-bg); color: var(--color-success-text); border-color: var(--color-success-border); }
.banner--warning { background: var(--color-warning-bg); color: var(--color-warning-text); border-color: var(--color-warning-border); }
.banner--error   { background: var(--color-error-bg);   color: var(--color-error-text);   border-color: var(--color-error-border); }
.banner--info    { background: var(--color-bg);          color: var(--color-text-secondary); border-color: var(--color-border); }

/* --- Tabs -------------------------------------------------- */
.tabs {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
  flex-wrap: wrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font-family: var(--font-sans);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.tab:hover { background: var(--color-bg); }
.tab.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* --- Table ------------------------------------------------- */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-card);
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  font-size: var(--font-size-sm);
}

.table thead {
  background: #fafafa;
  border-bottom: 1px solid var(--color-border);
}

.table th {
  text-align: left;
  padding: 12px var(--space-md);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-secondary);
  font-weight: var(--font-weight-semibold);
  white-space: nowrap;
}

.table td {
  padding: 10px var(--space-md);
  border-bottom: 1px solid var(--color-border-light);
  color: var(--color-text);
}

.table tbody tr {
  transition: background var(--transition-fast);
}

.table tbody tr:hover {
  background: #fafbfc;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

/* Row status colors */
.table tr.row--success td { background: #f0fdf4; }
.table tr.row--warning td { background: #fffbeb; }
.table tr.row--error td   { background: #fef2f2; }
.table tr.row--success:hover td { background: #dcfce7; }
.table tr.row--warning:hover td { background: #fef3c7; }
.table tr.row--error:hover td   { background: #fee2e2; }

.table td code {
  font-family: var(--font-mono);
  font-size: 11px;
  word-break: break-all;
}

/* --- Preview ----------------------------------------------- */
.preview {
  max-width: 100%;
  max-height: 280px;
  border-radius: var(--radius-md);
  object-fit: contain;
  border: 1px solid var(--color-border);
  background: #fafafa;
}

.preview--hidden { display: none; }

.preview__name {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-sm);
}

/* --- Result ------------------------------------------------ */
.result {
  padding: var(--space-md);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  line-height: 1.6;
  word-break: break-word;
}

.result--hidden { display: none; }
.result--success { background: var(--color-success-bg); color: var(--color-success-text); }
.result--error   { background: var(--color-error-bg);   color: var(--color-error-text); }
.result--loading { background: var(--color-warning-bg); color: var(--color-warning-text); }

.result__title {
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-xs);
}

.result__field {
  margin-bottom: var(--space-xs);
}

.result__field strong {
  font-weight: var(--font-weight-semibold);
}

.result details {
  margin-top: var(--space-sm);
  font-size: var(--font-size-sm);
}

.result details summary {
  cursor: pointer;
  color: var(--color-text-secondary);
  font-weight: var(--font-weight-medium);
}

.result details pre {
  max-height: 140px;
  overflow: auto;
  background: var(--color-surface);
  padding: var(--space-sm);
  border-radius: var(--radius-sm);
  margin-top: var(--space-xs);
  font-family: var(--font-mono);
  font-size: 11px;
  border: 1px solid var(--color-border-light);
}

/* --- Spinner ----------------------------------------------- */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: var(--space-sm);
}

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

/* --- Loading State ----------------------------------------- */
.loading-hint {
  text-align: center;
  color: var(--color-text-secondary);
  padding: var(--space-xl) var(--space-md);
  font-size: var(--font-size-sm);
}

/* --- Camera ------------------------------------------------- */
.camera-view {
  max-width: 100%;
  max-height: 280px;
  border-radius: var(--radius-md);
  background: #000;
  display: none;
  margin-bottom: var(--space-md);
}

.camera-view--active { display: block; }

/* --- Utility ----------------------------------------------- */
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.text-center { text-align: center; }
.text-secondary { color: var(--color-text-secondary); }
.hidden { display: none !important; }

/* ============================================================
   Responsive — Mobile (< 640px)
   ============================================================ */
@media (max-width: 639px) {
  :root {
    --font-size-xl: 20px;
    --font-size-2xl: 26px;
  }

  .container {
    padding: var(--space-md) var(--space-md);
  }

  .card {
    padding: var(--space-md);
    border-radius: var(--radius-md);
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
  }

  .stat-card {
    padding: var(--space-md);
  }

  .stat-card__value {
    font-size: var(--font-size-xl);
  }

  .btn--group {
    flex-direction: column;
  }

  .header__nav {
    gap: var(--space-sm);
  }

  .table th,
  .table td {
    padding: 8px var(--space-sm);
    font-size: 12px;
  }

  .banner {
    font-size: var(--font-size-sm);
    padding: var(--space-sm) var(--space-md);
  }
}

/* ============================================================
   Responsive — Tablet (640px – 1024px)
   ============================================================ */
@media (min-width: 640px) and (max-width: 1024px) {
  .container {
    padding: var(--space-xl) var(--space-lg);
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .container--narrow {
    max-width: 640px;
  }
}

/* ============================================================
   Responsive — Desktop (> 1024px)
   ============================================================ */
@media (min-width: 1025px) {
  .container {
    padding: var(--space-xl) var(--space-lg);
  }

  .container--narrow {
    padding-top: 48px;
  }

  .container--wide {
    padding-top: 40px;
  }

  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* --- File input (hidden by default, triggered by button) --- */
.input--file {
  display: none;
}

/* --- Action button with icon ------------------------------- */
.btn__icon {
  font-size: 18px;
  line-height: 1;
}

/* --- Camera capture button --------------------------------- */
.btn--capture {
  background: #d97706;
  color: #fff;
}

.btn--capture:hover:not(:disabled) {
  background: #b45309;
}

/* --- Small buttons (table actions) ------------------------- */
.btn--sm {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: var(--font-weight-medium);
  font-family: var(--font-sans);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn--sm:hover {
  background: var(--color-bg);
}

/* --- Toolbar ----------------------------------------------- */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.toolbar .input,
.toolbar .select {
  width: auto;
  margin-bottom: 0;
}

/* --- Textarea override (don't force 48px height) ----------- */
textarea.input {
  height: auto;
  padding: var(--space-sm) var(--space-md);
  resize: vertical;
  min-height: 60px;
}

/* --- Form row (side-by-side fields) ------------------------ */
.form-row {
  display: flex;
  gap: var(--space-md);
}

.form-row .form-group {
  flex: 1;
}

@media (max-width: 639px) {
  .form-row {
    flex-direction: column;
    gap: 0;
  }
}

/* --- Modal ------------------------------------------------- */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
}

.modal__backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
}

.modal__content {
  position: relative;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
}

.modal__title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  margin-bottom: var(--space-lg);
  color: var(--color-text);
}

.modal__actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
  margin-top: var(--space-lg);
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-border-light);
}

.modal__actions .btn {
  min-width: 90px;
  height: auto;
  padding: 10px 20px;
  font-size: var(--font-size-sm);
}
