/* ============================================
   Ask Adjust – Global Styles
   ============================================ */

:root {
  /* Brand colours – DO NOT CHANGE */
  --bg: #EFF4FF;
  --fg: #293142;
  --primary: #2563EB;
  --card: #D3D3D3;
  --border: #DBDDE1;
  --shadow-soft: 0 10px 30px rgba(15, 23, 42, 0.06);

  /* Safe area */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  /* Dynamic viewport */
  --app-height: 100dvh;
  --keyboard-offset: 0px;

  /* Feedback colours */
  --success-bg: #ECFDF3;
  --success-fg: #166534;
  --error-bg: #FEF2F2;
  --error-fg: #B91C1C;
  --info-bg: #EFF6FF;
  --info-fg: #1D4ED8;

  /* Surfaces */
  --surface: #FFFFFF;
  --surface-hover: #F8FAFC;
  --surface-muted: #F3F4F6;

  /* Spacing */
  --header-height: 56px;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--fg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Prevent FOUT – enforce consistent font everywhere */
input, textarea, select, button {
  font-family: inherit;
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

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

/* ---- Utility classes ---- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.container {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---- Global Header ---- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  padding-top: var(--safe-top);
  height: calc(var(--header-height) + var(--safe-top));
  display: flex;
  align-items: center;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.app-header-inner {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-height);
}

.header-back-btn {
  border: none;
  background: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg);
  transition: background 0.15s;
}
.header-back-btn:hover {
  background: var(--surface-muted);
}
.header-back-btn svg {
  width: 20px;
  height: 20px;
}

.header-logo {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.header-logo img {
  height: 42px;
  width: auto;
  object-fit: contain;
  border-radius: 8px;
}

.header-title-group {
  flex: 1;
  min-width: 0;
}
.header-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-subtitle {
  margin: 0;
  font-size: 11px;
  opacity: 0.6;
  line-height: 1.3;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.header-icon-btn {
  border: none;
  background: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg);
  transition: background 0.15s;
  position: relative;
}
.header-icon-btn:hover {
  background: var(--surface-muted);
}
.header-icon-btn svg {
  width: 20px;
  height: 20px;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  text-decoration: none;
  line-height: 1.4;
}
.btn:active {
  transform: scale(0.98);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: #1d4ed8;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
  background: var(--surface-muted);
  color: var(--fg);
}
.btn-secondary:hover:not(:disabled) {
  background: #e5e7eb;
}

.btn-outline {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
}
.btn-outline:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: #94a3b8;
}

.btn-sm {
  padding: 7px 14px;
  font-size: 13px;
  border-radius: 8px;
}

.btn-pill {
  border-radius: 999px;
}

.btn-icon {
  padding: 8px;
  border-radius: 8px;
}

/* Inline SVG icons inside buttons */
.btn > svg, .btn > span > svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow-soft);
  transition: transform 0.15s, box-shadow 0.15s;
}
.card-interactive {
  cursor: pointer;
}
.card-interactive:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 36px rgba(15, 23, 42, 0.1);
}

/* ---- Form inputs ---- */
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--fg);
}
.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: var(--surface);
  color: var(--fg);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.form-input::placeholder {
  color: #9ca3af;
}
/* Prevent iOS zoom on focus */
@media (max-width: 600px) {
  .form-input, textarea.form-input {
    font-size: 16px;
  }
}

textarea.form-input {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

select.form-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-hint {
  font-size: 12px;
  color: #6b7280;
  margin-top: 4px;
}
.form-error {
  font-size: 12px;
  color: var(--error-fg);
  margin-top: 4px;
}

/* ---- Toast ---- */
.toast-container {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.toast {
  background: #1f2937;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: auto;
  max-width: 90vw;
  text-align: center;
}
.toast.visible {
  opacity: 1;
  transform: translateY(0);
}
.toast.toast-error {
  background: #991b1b;
}
.toast.toast-success {
  background: #166534;
}

/* ---- Overlay / Modal ---- */
.overlay-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.overlay-backdrop.visible {
  opacity: 1;
  visibility: visible;
}

.overlay-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(15, 23, 42, 0.25);
  max-width: 640px;
  width: 100%;
  max-height: calc(100% - 32px);
  display: flex;
  flex-direction: column;
  transform: translateY(8px);
  transition: transform 0.2s ease;
}
.overlay-backdrop.visible .overlay-card {
  transform: translateY(0);
}

.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.overlay-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
}
.overlay-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
  -webkit-overflow-scrolling: touch;
}
.overlay-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ---- Loading spinner ---- */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- Skeleton loading ---- */
.skeleton {
  background: linear-gradient(90deg, #e5e7eb 25%, #f3f4f6 50%, #e5e7eb 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---- Empty / Error states ---- */
.state-box {
  text-align: center;
  padding: 48px 24px;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-soft);
}
.state-box-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}
.state-box-title {
  font-size: 16px;
  font-weight: 500;
  margin: 0 0 8px;
}
.state-box-text {
  font-size: 13px;
  opacity: 0.7;
  margin: 0;
}

.error-box {
  text-align: center;
  padding: 24px;
  background: var(--error-bg);
  border-radius: 16px;
  border: 1px solid #FECACA;
}
.error-box-title {
  font-size: 14px;
  font-weight: 500;
  color: #DC2626;
  margin: 0 0 8px;
}
.error-box-text {
  font-size: 13px;
  color: #7F1D1D;
  margin: 0;
}

/* ---- Badge / Pills ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge-blue {
  background: #DBEAFE;
  color: #1E40AF;
}
.badge-purple {
  background: #E0E7FF;
  color: #3730A3;
}
.badge-green {
  background: var(--success-bg);
  color: var(--success-fg);
}
.badge-red {
  background: var(--error-bg);
  color: var(--error-fg);
}
.badge-gray {
  background: var(--surface-muted);
  color: #4b5563;
}

/* ---- Tab bar ---- */
.tab-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.tab-btn {
  border: 1px solid rgba(148, 163, 184, 0.5);
  background: var(--surface);
  color: #4b5563;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.tab-btn:hover {
  background: var(--surface-hover);
}
.tab-btn.active {
  background: #EEF2FF;
  border-color: #818CF8;
  color: #3730A3;
}
.tab-count {
  background: rgba(0, 0, 0, 0.08);
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 11px;
  margin-left: 6px;
}
.tab-btn.active .tab-count {
  background: rgba(79, 70, 229, 0.15);
}

/* ---- Page layout helpers ---- */
.page {
  min-height: calc(100dvh - var(--header-height) - var(--safe-top));
  padding-bottom: calc(24px + var(--safe-bottom));
}

.page-section {
  margin-bottom: 24px;
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
  .container {
    padding: 0 12px;
  }

  .card {
    padding: 16px;
    border-radius: 14px;
  }

  .header-title {
    font-size: 14px;
  }
  .header-subtitle {
    display: none;
  }
}

/* ---- Focus visible (accessibility) ---- */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ---- Animations ---- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

.fade-in {
  animation: fadeIn 0.3s ease forwards;
}

/* ---- Print styles ---- */
@media print {
  .app-header,
  .toast-container,
  .overlay-backdrop {
    display: none !important;
  }
}
