/* ============================================
   KikiPaw Design System
   ============================================ */

/* ---------- CSS Variables (Tokens) ---------- */
:root {
  /* Colors */
  --bg: #f8fafc;
  --bg-gradient: radial-gradient(circle at 12% 10%, rgba(8, 145, 178, 0.08), transparent 30%),
                 radial-gradient(circle at 82% 0%, rgba(16, 185, 129, 0.08), transparent 28%),
                 var(--bg);
  --panel: #ffffff;
  --panel-alt: #f1f5f9;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;

  /* Primary – Medical Teal (Cyan-600) */
  --primary: #0891b2;
  --primary-hover: #0e7490;
  --primary-light: #ecfeff;

  /* Success – Emerald */
  --success: #10b981;
  --success-light: #ecfdf5;

  /* Warning – Amber */
  --warning: #f59e0b;
  --warning-light: #fffbeb;

  /* Danger – Red */
  --danger: #ef4444;
  --danger-light: #fef2f2;

  /* Spacing Scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;

  /* Border Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 999px;

  /* Font Sizes */
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 16px;
  --text-md: 16px;
  --text-lg: 18px;
  --text-xl: 20px;
  --text-2xl: 24px;

  /* Shadows */
  --shadow-sm: 0 4px 12px rgba(30, 41, 59, 0.04);
  --shadow-md: 0 10px 30px rgba(30, 41, 59, 0.06);
  --shadow-lg: 0 14px 40px rgba(30, 41, 59, 0.08);
  --shadow-primary: 0 8px 24px rgba(8, 145, 178, 0.18);
}

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

body {
  margin: 0;
  font-family: 'Manrope', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: var(--text-base);
  background: var(--bg-gradient);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Typography ---------- */
h1, h2, h3, h4 {
  margin: 0 0 var(--space-2) 0;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

h1 { font-size: clamp(var(--text-xl), 4vw, var(--text-2xl)); }
h2 { font-size: clamp(var(--text-lg), 3vw, var(--text-xl)); }
h3 { font-size: var(--text-md); }
p { margin: 0 0 var(--space-3) 0; }

.muted { color: var(--muted); font-size: var(--text-sm); }
.small { font-size: var(--text-xs); }

a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.15s ease;
}
a:hover { color: var(--primary-hover); }

/* ---------- Header / Nav ---------- */
header {
  padding: var(--space-3) var(--space-4);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  backdrop-filter: blur(12px);
  z-index: 100;
  gap: var(--space-2);
}

header .brand {
  color: var(--text);
  font-weight: 800;
  font-size: var(--text-md);
  letter-spacing: -0.01em;
}

header a { color: var(--text); text-decoration: none; font-weight: 800; }

header nav {
  display: flex;
  gap: var(--space-3);
  align-items: center;
}

header nav a {
  color: var(--muted);
  font-weight: 700;
  font-size: var(--text-sm);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background 0.15s ease;
}

header nav a:hover {
  color: var(--primary);
  background: var(--primary-light);
}

header nav a.active,
header nav a[aria-current="page"] {
  color: var(--primary);
  background: var(--primary-light);
}

/* Disabled button */
button:disabled, .action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Mobile menu toggle */
.menu-toggle {
  display: none;
  background: transparent;
  border: none;
  padding: var(--space-2);
  cursor: pointer;
  color: var(--text);
  border-radius: var(--radius-sm);
}

.menu-toggle:hover { background: var(--panel-alt); }
.menu-toggle svg { width: 24px; height: 24px; display: block; }

/* Language selector wrapper */
.lang-select {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.lang-select label {
  font-size: var(--text-sm);
  color: var(--muted);
  font-weight: 700;
}

.lang-select select {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--panel-alt);
  font-family: inherit;
  font-size: var(--text-sm);
  color: var(--text);
  cursor: pointer;
  min-height: 36px;
}

.btn-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--panel-alt);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 36px;
  min-width: 36px;
}

.btn-logout:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

.btn-settings {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--panel-alt);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 36px;
  min-width: 36px;
  text-decoration: none;
}

.btn-settings:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* ---------- Main Content ---------- */
main {
  padding: var(--space-4);
  display: grid;
  gap: var(--space-4);
  max-width: 1180px;
  margin: 0 auto;
}

/* ---------- Cards ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-md);
}

.card > p.muted { margin: 0 0 var(--space-3) 0; }

.card-body { display: grid; gap: var(--space-3); }
.card.collapsed .card-body { display: none; }

/* ---------- Row / List Items ---------- */
.row {
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--panel-alt);
  border: 1px solid var(--border);
}

.list { display: grid; gap: var(--space-3); }

/* ---------- Grid Layouts ---------- */
.grid-2 {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: 1fr;
}

/* ---------- Buttons ---------- */
button, .btn {
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

/* ── .btn base (shared by btn-primary, btn-secondary, etc.) ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: var(--space-2) var(--space-4);
  border: none;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: var(--text-sm);
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--success));
  color: #ffffff;
  box-shadow: var(--shadow-primary);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(8, 145, 178, 0.24);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--panel);
  color: var(--primary);
  border: 1.5px solid var(--primary);
  box-shadow: none;
}
.btn-secondary:hover {
  background: var(--primary-light);
  border-color: var(--primary-hover);
}

.btn-ghost {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}
.btn-ghost:hover {
  background: var(--panel-alt);
  border-color: var(--muted);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
  background: #dc2626;
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(239, 68, 68, 0.35);
}
.btn-danger:active { transform: translateY(0); }

.action, button.action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: var(--space-2) var(--space-4);
  background: linear-gradient(135deg, var(--primary), var(--success));
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  font-weight: 800;
  font-size: var(--text-sm);
  box-shadow: var(--shadow-primary);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.action:focus, button.action:focus {
  background: linear-gradient(135deg, var(--primary), var(--success));
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.action:hover, button.action:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(8, 145, 178, 0.24);
}

.action:active, button.action:active { transform: translateY(0); }

/* Ghost button variant */
.ghost {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: none;
  -webkit-tap-highlight-color: transparent;
}

.ghost:focus {
  background: var(--panel);
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.ghost:hover {
  background: var(--panel-alt);
  border-color: var(--muted);
  transform: none;
  box-shadow: none;
}

/* Text/link button variant - minimal styling like a link */
.action.text {
  background: transparent;
  border: none;
  color: var(--muted);
  box-shadow: none;
  padding: var(--space-2);
  min-height: auto;
}

.action.text:hover {
  color: var(--primary);
  background: transparent;
  transform: none;
  box-shadow: none;
}

/* Pet row hover and active states */
.pet-row:hover {
  background: var(--panel);
  border-color: var(--primary);
}

.pet-row.active {
  background: var(--primary-light);
  border-color: var(--primary);
}

.actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
}

/* ---------- Pills / Badges ---------- */
.pill {
  display: inline-block;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  font-size: var(--text-xs);
}

.pill.green { background: var(--success-light); color: #15803d; }
.pill.red { background: var(--danger-light); color: #b91c1c; }
.pill.amber { background: var(--warning-light); color: #92400e; }

/* ---------- Tags / Chips ---------- */
.tags { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.tag {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--panel-alt);
  font-weight: 700;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tag:hover { border-color: var(--muted); }
.tag.complete { border-color: #15803d; background: var(--success-light); color: #15803d; }
.tag.partial { border-color: #92400e; background: var(--warning-light); color: #92400e; }
.tag.pending, .tag.missing { border-color: var(--border); background: var(--panel-alt); color: var(--muted); }
.tag.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }

.chip {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  font-size: var(--text-xs);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s ease;
}

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

.chip:disabled {
  opacity: 0.6;
  cursor: default;
  pointer-events: none;
}

.chip:disabled.active {
  opacity: 0.85;
}

/* ---------- Confirmed "none" state (shared by wizard & profile) ---------- */
.wiz-none-confirmed {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: #e8f5e9;
  border: 1px solid #c8e6c9;
  border-radius: var(--radius-md, 8px);
  margin-bottom: 8px;
}

.wiz-none-confirmed .wiz-none-text {
  flex: 1;
  font-weight: 600;
  color: #2e7d32;
  font-size: var(--text-sm, 0.9em);
}

.wiz-undo-active {
  color: #1565c0 !important;
  border-color: #1565c0 !important;
  background: #e3f2fd !important;
}

.chip:hover {
  opacity: 0.85;
}

.chip button {
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  padding: 0;
  line-height: 1;
}

.chip-row {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
  margin-top: var(--space-2);
}

/* ---------- Unified Modal System ---------- */
.ui-modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay-bg, rgba(0, 0, 0, 0.5));
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--modal-z-index, 1000);
  padding: var(--modal-overlay-padding, var(--space-3));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.ui-modal-overlay.open,
.ui-modal-overlay.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.ui-modal {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: var(--modal-padding, var(--space-6));
  width: var(--modal-width, 100%);
  max-width: var(--modal-max-width, 480px);
  max-height: var(--modal-max-height, 90vh);
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform 0.2s ease;
}

.ui-modal-overlay.open .ui-modal,
.ui-modal-overlay.visible .ui-modal {
  transform: translateY(0);
}

.ui-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.ui-modal-btn-cancel {
  padding: var(--space-2) var(--space-4);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text);
  font-size: var(--text-sm);
  transition: background 0.15s ease;
}

.ui-modal-btn-cancel:hover {
  background: var(--panel-alt);
}

.ui-modal-btn-confirm {
  padding: var(--space-2) var(--space-4);
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 700;
  font-size: var(--text-sm);
  transition: background 0.15s ease;
}

.ui-modal-btn-confirm:hover {
  background: var(--primary-hover);
}

.ui-modal-btn-confirm:disabled {
  background: var(--muted);
  cursor: not-allowed;
}

.ui-modal-btn-confirm--danger { background: var(--danger); }
.ui-modal-btn-confirm--danger:hover { background: #dc2626; }
.ui-modal-btn-confirm--success { background: var(--success); }
.ui-modal-btn-confirm--success:hover { background: #16a34a; }

.ui-modal-error {
  color: var(--danger);
  font-size: var(--text-xs);
  margin-top: var(--space-2);
  display: none;
}

dialog.ui-dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: var(--dialog-padding, var(--space-4));
  width: min(var(--dialog-width, 90vw), var(--dialog-max-width, 480px));
  max-width: var(--dialog-max-width, 480px);
  max-height: var(--dialog-max-height, 90vh);
  overflow: auto;
  box-shadow: var(--shadow-lg);
  background: var(--panel);
}

dialog.ui-dialog::backdrop {
  background: var(--dialog-backdrop, rgba(0, 0, 0, 0.45));
}

dialog.ui-dialog.ui-dialog--sheet {
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: var(--dialog-max-width, 400px);
  margin: auto auto 0 auto;
}

@media (max-width: 639px) {
  .ui-modal-overlay:not(.ui-modal-overlay--center-mobile) {
    align-items: flex-end;
  }

  .ui-modal {
    max-width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: var(--modal-mobile-padding, var(--space-4));
    max-height: var(--modal-mobile-max-height, 85vh);
  }

  dialog.ui-dialog.ui-dialog--mobile-sheet {
    width: 100%;
    max-width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    margin: 0;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 88vh;
  }
}

/* ---------- Forms ---------- */
input, select, textarea {
  font-family: inherit;
  font-size: var(--text-base);
  color: var(--text);
}

input, select {
  width: 100%;
  min-height: 44px;
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--panel-alt);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
  width: 100%;
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--panel-alt);
  resize: vertical;
  min-height: 80px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

input:disabled, select:disabled, textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

label {
  display: block;
  font-size: var(--text-sm);
  color: var(--muted);
  font-weight: 700;
  margin-bottom: var(--space-1);
}

form.inline { display: grid; gap: var(--space-3); }
form.inline label { display: grid; gap: var(--space-1); }
form.inline label input,
form.inline label select,
form.inline label textarea { margin-top: 0; }

/* ---------- Status Indicators ---------- */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  display: inline-block;
  margin-right: var(--space-2);
}

.status-dot.ok, .ok { background: var(--success); }
.status-dot.warn, .warn { background: var(--warning); }
.status-dot.bad, .bad { background: var(--danger); }

/* ---------- Progress Bar ---------- */
.progress {
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--border);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--success));
  transition: width 0.3s ease;
}

/* ---------- Tables / Data Grids ---------- */
.table {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-3);
}

/* ---------- Section Headers ---------- */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}

.section-header h2 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  margin: 0;
}

.section-header .chevron {
  font-size: var(--text-sm);
  color: var(--muted);
  transition: transform 0.2s ease;
}

.card.collapsed .section-header .chevron { transform: rotate(-90deg); }
.card.collapsed .actions[data-actions] { display: none; }

/* ---------- Inline Layout ---------- */
.inline {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
}

.inline-input {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.inline-input input {
  flex: 1;
  min-width: 120px;
}

/* ---------- Edit Actions ---------- */
.edit-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-top: var(--space-3);
}

/* ---------- Mobile Bottom Navigation ---------- */
.bottom-nav {
  display: none; /* hidden on desktop */
}

@media (max-width: 639px) {
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 800;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding: var(--space-1) 0;
    padding-bottom: calc(var(--space-1) + env(safe-area-inset-bottom, 0px));
    justify-content: space-around;
    align-items: center;
    height: 56px;
    box-sizing: border-box;
  }
  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    text-decoration: none;
    color: var(--muted);
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    transition: color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    line-height: 1;
  }
  .bottom-nav-item span {
    max-width: 56px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .bottom-nav-item svg {
    flex-shrink: 0;
  }
  .bottom-nav-item:hover,
  .bottom-nav-item.active {
    color: var(--primary);
  }
  .bottom-nav-item.active svg {
    stroke-width: 2.5;
  }

  /* Reserve space for bottom nav so content isn't hidden behind it */
  body {
    padding-bottom: 56px;
  }
}

/* ---------- Utility Classes ---------- */
.hidden { display: none !important; }

/* ---------- Responsive: Tablet+ ---------- */
@media (min-width: 640px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  main { padding: var(--space-6); gap: var(--space-4); }
  header { padding: var(--space-4) var(--space-6); }
}

/* ---------- Responsive: Desktop ---------- */
@media (min-width: 1024px) {
  main { padding: var(--space-8) var(--space-6); }
  .card { padding: var(--space-6); }
}

/* ---------- Responsive: Mobile ---------- */
@media (max-width: 639px) {
  header { flex-wrap: wrap; gap: var(--space-2); }

  /* Show mobile menu toggle */
  .menu-toggle { display: flex; order: 1; }
  header .brand, header > a:first-child { order: 0; flex: 1; }
  header .lang-select { order: 2; flex-shrink: 0; }
  header .lang-select label { display: none; }

  header nav {
    order: 3;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
  }

  header nav.open {
    max-height: 500px;
    padding-top: var(--space-2);
    border-top: 1px solid var(--border);
    margin-top: var(--space-2);
  }

  header nav a {
    padding: var(--space-3);
    border-radius: var(--radius-sm);
    text-align: center;
  }

  /* Full-width buttons on mobile */
  .actions { flex-direction: column; }
  .actions .action, .actions .ghost { width: 100%; justify-content: center; }

  /* Keep inline actions horizontal when specified */
  .actions.inline-actions { flex-direction: row; }
  .actions.inline-actions .action, .actions.inline-actions .ghost { width: auto; }
}
