/* ═══════════════════════════════════════════════════════════════════════════
   Pawmory Ops Workbench — Stylesheet
   Stone/natural palette, all styles self-contained, mobile-first.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── 1. CSS Reset + Variables ─────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f5f4;
  --card-bg: #ffffff;
  --border: #e7e5e4;
  --text-primary: #1c1917;
  --text-secondary: #78716c;
  --text-muted: #a8a29e;
  --accent: #1c1917;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.08);
  --max-width: 1400px;
  --header-h: 56px;
}

html { font-size: 16px; }

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { cursor: pointer; font: inherit; }
input, select, textarea, button { font: inherit; }

/* ── 2. Login Page ─────────────────────────────────────────────────────── */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
}

.login-header { margin-bottom: 28px; }

.login-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.login-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.login-desc {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.login-card .form-group { margin-bottom: 18px; }

.login-card .form-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.login-card .form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text-primary);
  font-size: 0.9375rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.login-card .form-group input:focus {
  outline: none;
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px rgba(28,25,23,0.12);
}

.login-card .form-group input::placeholder { color: var(--text-muted); }

.form-error {
  font-size: 0.8125rem;
  color: var(--danger);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-bottom: 14px;
  display: none;
}

.login-card .btn-full { width: 100%; margin-top: 4px; }

/* ── 3. Layout Styles ──────────────────────────────────────────────────── */

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
}

.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
}

.app-header h1 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.app-header nav { display: flex; align-items: center; gap: 12px; }

.main-container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.customer-nav {
  min-height: 56px;
  margin-bottom: 20px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.customer-nav__left,
.customer-tabs,
.customer-upload-row,
.customer-import-actions,
.customer-pagination {
  display: flex;
  align-items: center;
  gap: 12px;
}

.customer-nav__left a { color: var(--text-secondary); padding: 8px 18px; text-decoration: none; }
.customer-nav__left a.is-active { color: var(--text-primary); background: #f5f5f4; border-radius: 999px; }
.customer-nav__brand { color: var(--text-secondary); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.2em; }
.customer-tabs { margin-bottom: 20px; }
.customer-filters,
.customer-detail,
.customer-import-summary { margin-bottom: 20px; }
.customer-filter-grid { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 12px; margin-bottom: 14px; }
.customer-link { padding: 0; border: 0; color: var(--accent); background: transparent; font-weight: 600; text-align: left; }
.customer-empty { padding: 40px 16px; color: var(--text-muted); text-align: center; }
.customer-pagination { justify-content: flex-end; margin-top: 16px; }
.customer-pet-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-bottom: 16px; }
.customer-pet-card,
.customer-import-item,
.customer-review-pet { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fafaf9; }
.customer-import-list { display: grid; gap: 12px; margin-top: 18px; }
.customer-conflicts { color: var(--danger); }
.customer-resolution { display: grid; gap: 12px; margin-top: 12px; }
.customer-review-pet { display: grid; gap: 10px; }
.customer-review-pet label { display: grid; gap: 4px; color: var(--text-secondary); font-size: 0.8125rem; }
.customer-check-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.customer-review-pet .customer-check { display: flex; align-items: center; gap: 5px; }
.customer-date-row { display: grid; grid-template-columns: 1.2fr repeat(3, minmax(80px, .7fr)) 1.5fr; gap: 8px; }
.customer-error { margin-bottom: 16px; padding: 12px 16px; color: #991b1b; background: #fef2f2; border: 1px solid #fecaca; border-radius: var(--radius-sm); }
.text-muted { color: var(--text-muted); font-size: 0.8125rem; }

@media (max-width: 800px) {
  .customer-filter-grid,
  .customer-date-row { grid-template-columns: 1fr; }
  .customer-nav { align-items: flex-start; padding: 14px; }
  .customer-nav__left { flex-wrap: wrap; }
}

/* ── 4. Card Component ─────────────────────────────────────────────────── */

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 24px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.card-footer {
  border-top: 1px solid var(--border);
  margin: 16px -20px -20px;
  padding: 14px 20px;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  background: #fafaf9;
}

/* ── 5. Button Styles ──────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 22px;
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background 0.15s, opacity 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  line-height: 1.4;
}

.btn:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: #292524; }
.btn-primary:active { background: #44403c; }

.btn-secondary {
  background: var(--card-bg);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover { background: #f5f5f4; }
.btn-secondary:active { background: #e7e5e4; }

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover { background: #b91c1c; }
.btn-danger:active { background: #991b1b; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover { background: #f5f5f4; color: var(--text-primary); }

.btn-sm { padding: 8px 18px; font-size: 0.875rem; }
.btn-xs { padding: 3px 8px; font-size: 0.75rem; border-radius: 6px; }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── 6. Form Input Styles ──────────────────────────────────────────────── */

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text-primary);
  font-size: 0.9375rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px rgba(28,25,23,0.12);
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-muted); }

.form-textarea { min-height: 80px; resize: vertical; }

.form-select {
  appearance: none;
  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 fill='%2378716c' d='M6 8.825a.5.5 0 0 1-.354-.146l-4-4a.5.5 0 0 1 .708-.708L6 7.617l3.646-3.646a.5.5 0 0 1 .708.708l-4 4A.5.5 0 0 1 6 8.825z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.form-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.form-error-text {
  font-size: 0.75rem;
  color: var(--danger);
  margin-top: 3px;
}

/* ── 7. Table Styles ───────────────────────────────────────────────────── */

.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

thead th {
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr { transition: background 0.1s; }
tbody tr:hover { background: #fafaf9; }
tbody tr:last-child td { border-bottom: none; }

.table-cell-link {
  color: var(--accent);
  font-weight: 500;
  cursor: pointer;
}
.table-cell-link:hover { text-decoration: underline; }

/* ── 8. Badge / Tag Styles ─────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 999px;
  white-space: nowrap;
  line-height: 1.5;
}

.badge-pending      { background: #fef9c3; color: #854d0e; }
.badge-processing   { background: #dbeafe; color: #1e40af; }
.badge-completed    { background: #dcfce7; color: #166534; }
.badge-failed       { background: #fee2e2; color: #991b1b; }
.badge-cancelled    { background: #f5f5f4; color: #78716c; }
.badge-idle         { background: #f5f5f4; color: #78716c; }
.badge-running      { background: #dbeafe; color: #1e40af; }
.badge-success      { background: #dcfce7; color: #166534; }
.badge-warning      { background: #fef9c3; color: #854d0e; }
.badge-error        { background: #fee2e2; color: #991b1b; }

/* ── 9. Grid Styles (Order Detail Layout) ──────────────────────────────── */

.order-detail-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

@media (min-width: 900px) {
  .order-detail-grid {
    grid-template-columns: 1fr 1fr;
  }
  .order-detail-grid .detail-span-2 { grid-column: 1 / -1; }
}

.info-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.info-item-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.info-item-value {
  font-size: 0.875rem;
  color: var(--text-primary);
  word-break: break-word;
}

.item-cards { display: flex; flex-direction: column; gap: 16px; }

.item-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.item-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 0;
  flex-wrap: wrap;
}

.item-card-body { padding: 12px 20px 16px; }

.item-card-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: #fafaf9;
}

.item-card-title {
  font-size: 0.9375rem;
  font-weight: 600;
}

.item-card-subtitle {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.item-images {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.item-image-thumb {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: box-shadow 0.15s;
}
.item-image-thumb:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.12); }

.item-attributes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
  margin-top: 8px;
  font-size: 0.8125rem;
}

.item-attribute label {
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 0.75rem;
}

/* ── 10. Modal / Dialog Styles ────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.15s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.modal {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 48px rgba(0,0,0,0.18);
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease-out;
}

.modal-sm  { max-width: 400px; }
.modal-md  { max-width: 560px; }
.modal-lg  { max-width: 720px; }
.modal-xl  { max-width: 960px; }
.modal-full { max-width: 100%; margin: 0 16px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.modal-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.25rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s;
}
.modal-close:hover { background: #f5f5f4; color: var(--text-primary); }

.modal-body { padding: 16px 24px 24px; }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 24px 20px;
  border-top: 1px solid var(--border);
}

/* Lightbox modal */
.lightbox-overlay {
  background: rgba(0,0,0,0.85);
}

.lightbox-content {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  max-height: 90vh;
}

.lightbox-content img {
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

/* Crop modal */
.crop-container {
  position: relative;
  width: 100%;
  min-height: 320px;
  background: #1c1917;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.crop-container canvas {
  display: block;
  width: 100%;
}

.crop-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* ── 11. Utility Classes ───────────────────────────────────────────────── */

/* Flex */
.flex           { display: flex; }
.flex-col       { flex-direction: column; }
.flex-wrap      { flex-wrap: wrap; }
.items-center   { align-items: center; }
.items-start    { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end    { justify-content: flex-end; }
.gap-xs         { gap: 4px; }
.gap-sm         { gap: 8px; }
.gap-md         { gap: 12px; }
.gap-lg         { gap: 16px; }
.gap-xl         { gap: 24px; }
.flex-1         { flex: 1; }
.shrink-0       { flex-shrink: 0; }

/* Grid */
.grid           { display: grid; }
.grid-cols-2    { grid-template-columns: 1fr 1fr; }
.grid-cols-3    { grid-template-columns: 1fr 1fr 1fr; }
.grid-cols-4    { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* Spacing */
.mt-sm   { margin-top: 8px; }
.mt-md   { margin-top: 12px; }
.mt-lg   { margin-top: 16px; }
.mt-xl   { margin-top: 24px; }
.mb-sm   { margin-bottom: 8px; }
.mb-md   { margin-bottom: 12px; }
.mb-lg   { margin-bottom: 16px; }
.mb-xl   { margin-bottom: 24px; }
.p-sm    { padding: 8px; }
.p-md    { padding: 12px; }
.p-lg    { padding: 16px; }
.p-xl    { padding: 24px; }

/* Text */
.text-sm         { font-size: 0.8125rem; }
.text-xs         { font-size: 0.75rem; }
.text-lg         { font-size: 1.125rem; }
.text-secondary  { color: var(--text-secondary); }
.text-muted      { color: var(--text-muted); }
.text-center     { text-align: center; }
.text-right      { text-align: right; }
.font-medium     { font-weight: 500; }
.font-semibold   { font-weight: 600; }
.font-bold       { font-weight: 700; }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Misc */
.w-full          { width: 100%; }
.hidden          { display: none; }
.block           { display: block; }
.relative        { position: relative; }
.cursor-pointer  { cursor: pointer; }
.rounded-sm      { border-radius: var(--radius-sm); }
.rounded-md      { border-radius: var(--radius-md); }
.rounded-lg      { border-radius: var(--radius-lg); }
.rounded-xl      { border-radius: var(--radius-xl); }
.border          { border: 1px solid var(--border); }
.bg-card         { background: var(--card-bg); }
.shadow          { box-shadow: var(--shadow); }
.shadow-lg       { box-shadow: var(--shadow-lg); }

/* Scrollbar (nice on webkit) */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d6d3d1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a8a29e; }

/* ── 12. Responsive ────────────────────────────────────────────────────── */

/* Tablet */
@media (min-width: 640px) {
  .main-container { padding: 24px 24px 48px; }

  .table-grid-sm { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
}

/* Desktop */
@media (min-width: 768px) {
  :root { --header-h: 60px; }
  .app-header { padding: 0 24px; }
}

@media (min-width: 1024px) {
  .main-container { padding: 28px 32px 56px; }

  .grid-cols-lg-2 { grid-template-columns: 1fr 1fr; }
  .grid-cols-lg-3 { grid-template-columns: 1fr 1fr 1fr; }
}

/* Mobile overrides for tables → cards on small screens */
@media (max-width: 639px) {
  .table-wrapper table,
  .table-wrapper thead,
  .table-wrapper tbody,
  .table-wrapper tr,
  .table-wrapper th,
  .table-wrapper td {
    display: block;
  }
  .table-wrapper thead { display: none; }
  .table-wrapper tbody tr {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--card-bg);
    margin-bottom: 10px;
    box-shadow: var(--shadow);
  }
  .table-wrapper tbody tr:hover { background: var(--card-bg); }
  .table-wrapper tbody td {
    padding: 4px 0;
    border: none;
    display: flex;
    justify-content: space-between;
    gap: 8px;
  }
  .table-wrapper tbody td::before {
    content: attr(data-label);
    font-weight: 500;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
  }
  .table-wrapper tbody td:last-child { padding-bottom: 0; }

  .info-panel { grid-template-columns: 1fr; }
  .item-attributes { grid-template-columns: 1fr; }
  .item-card-header { flex-direction: column; }
  .item-card-footer { flex-direction: column; align-items: stretch; }
}
