/* =====================================================================
 * SafeMatch - shared component styles
 * Plain CSS (Tailwind's CDN build cannot @apply inside external files).
 * Brand: primary teal #14B8A6, success #10B981, error #EF4444, warning #F59E0B
 * ================================================================== */

:root {
    --sm-primary: #14b8a6;
    --sm-primary-dark: #0f766e;
    --sm-success: #10b981;
    --sm-error: #ef4444;
    --sm-warning: #f59e0b;
    --sm-info: #3b82f6;
    --sm-border: #e2e8f0;
    --sm-text: #1e293b;
    --sm-muted: #64748b;
    --sm-surface: #ffffff;
}

html { -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }

/* Touch-friendly square icon buttons */
.touch-target {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ---------- Cards ---------- */
.card {
    min-width: 0; /* let grid/flex children (e.g. charts) shrink on small screens */
    background: var(--sm-surface);
    border: 1px solid var(--sm-border);
    border-radius: 1rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 44px;
    padding: 0.5rem 1rem;
    border-radius: 0.625rem;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.25rem;
    border: 1px solid transparent;
    transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(20, 184, 166, .35); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--sm-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #0d9488; }
.btn-secondary { background: #fff; color: #334155; border-color: #cbd5e1; }
.btn-secondary:hover:not(:disabled) { background: #f8fafc; }
.btn-danger { background: var(--sm-error); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-success { background: var(--sm-success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #059669; }
.btn-ghost { background: transparent; color: #475569; }
.btn-ghost:hover:not(:disabled) { background: #f1f5f9; }
.btn-sm { min-height: 36px; padding: 0.375rem 0.75rem; font-size: 0.8125rem; }

/* Icon-only action buttons inside tables */
.icon-btn {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.5rem;
    color: #64748b;
    transition: background-color .15s, color .15s;
}
.icon-btn:hover { background: #f1f5f9; color: #0f172a; }
.icon-btn.danger:hover { background: #fef2f2; color: #dc2626; }
.icon-btn:focus-visible { outline: 2px solid var(--sm-primary); outline-offset: 1px; }
@media (pointer: coarse) { .icon-btn { width: 44px; height: 44px; } }

/* Loading spinner used inside buttons */
.spinner {
    width: 1rem;
    height: 1rem;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 9999px;
    animation: sm-spin .7s linear infinite;
    display: inline-block;
}
@keyframes sm-spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.form-label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #334155;
}
.form-label .req { color: var(--sm-error); margin-left: 2px; }
.form-input {
    display: block;
    width: 100%;
    min-height: 44px;
    padding: 0.5rem 0.75rem;
    border: 1px solid #cbd5e1;
    border-radius: 0.625rem;
    background: #fff;
    font-size: 16px; /* prevents iOS zoom on focus */
    color: var(--sm-text);
    transition: border-color .15s, box-shadow .15s;
}
@media (min-width: 640px) { .form-input { font-size: 0.875rem; } }
textarea.form-input { min-height: 88px; resize: vertical; }
/* Date inputs have a large intrinsic width; allow them to shrink inside flex rows */
.flex > .form-input { min-width: 0; }
.form-input:focus { outline: none; border-color: var(--sm-primary); box-shadow: 0 0 0 3px rgba(20, 184, 166, .2); }
.form-input:disabled { background: #f1f5f9; color: #64748b; }
.form-input.is-invalid { border-color: var(--sm-error); }
.form-input.is-invalid:focus { box-shadow: 0 0 0 3px rgba(239, 68, 68, .2); }
.form-error { margin-top: 0.25rem; font-size: 0.75rem; color: #dc2626; }
.form-hint { margin-top: 0.25rem; font-size: 0.75rem; color: var(--sm-muted); }

/* ---------- Tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table thead th {
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: #64748b;
    background: #f8fafc;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--sm-border);
    white-space: nowrap;
}
.data-table thead th.text-right { text-align: right; }
.data-table tbody td { padding: 0.75rem 1rem; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.data-table tbody tr { transition: background-color .1s; }
.data-table tbody tr:hover { background: #f0fdfa; }
.data-table tbody tr.row-highlight { background: #ccfbf1; }
.data-table th[data-sort] { cursor: pointer; user-select: none; }
.data-table th[data-sort]:hover { color: #0f172a; }
.data-table th[data-sort]::after { content: '↕'; margin-left: 4px; opacity: .35; font-size: .7rem; }
.data-table th[data-sort].sort-asc::after { content: '▲'; opacity: .9; }
.data-table th[data-sort].sort-desc::after { content: '▼'; opacity: .9; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-green { background: #d1fae5; color: #065f46; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-teal { background: #ccfbf1; color: #115e59; }

/* Traffic light dot */
.light-dot { width: 0.75rem; height: 0.75rem; border-radius: 9999px; display: inline-block; flex-shrink: 0; }
.light-green { background: var(--sm-success); }
.light-yellow { background: var(--sm-warning); }
.light-red { background: var(--sm-error); }
.light-discharged { background: #94a3b8; }

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal.hidden { display: none; }
@media (min-width: 640px) { .modal { align-items: center; padding: 1rem; } }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .55); }
.modal-panel {
    position: relative;
    width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    background: #fff;
    border-radius: 1rem 1rem 0 0;
    box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
    animation: sm-modal-in .18s ease-out;
}
@media (min-width: 640px) { .modal-panel { border-radius: 1rem; } }
@keyframes sm-modal-in { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: #fff;
    border-bottom: 1px solid var(--sm-border);
}
.modal-body { padding: 1.25rem; }
.modal-footer {
    position: sticky;
    bottom: 0;
    display: flex;
    flex-direction: column-reverse;
    gap: 0.5rem;
    padding: 1rem 1.25rem;
    background: #f8fafc;
    border-top: 1px solid var(--sm-border);
}
@media (min-width: 640px) { .modal-footer { flex-direction: row; justify-content: flex-end; } }
body.modal-open { overflow: hidden; }

/* ---------- Toasts ---------- */
.toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: 0.75rem;
    color: #fff;
    font-size: 0.875rem;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .2);
    animation: sm-toast-in .2s ease-out;
}
.toast-success { background: #059669; }
.toast-error { background: #dc2626; }
.toast-info { background: #2563eb; }
.toast-warning { background: #d97706; }
.toast.leaving { opacity: 0; transform: translateY(-6px); transition: all .2s; }
@keyframes sm-toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------- Detail lists ---------- */
.detail-grid { display: grid; grid-template-columns: repeat(1, minmax(0, 1fr)); gap: 0.75rem 1.5rem; }
@media (min-width: 640px) { .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.detail-grid dt { font-size: 0.75rem; color: var(--sm-muted); }
.detail-grid dd { font-size: 0.875rem; font-weight: 500; color: var(--sm-text); word-break: break-word; }

/* ---------- Skeleton loading ---------- */
.skeleton { background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%); background-size: 200% 100%; animation: sm-shimmer 1.2s infinite; border-radius: .375rem; }
@keyframes sm-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- QR scanner ---------- */
#qr-reader { width: 100%; border: none !important; }
#qr-reader video { border-radius: .75rem; }
#qr-reader__dashboard_section_csr button,
#qr-reader__dashboard button {
    min-height: 44px;
    padding: .5rem 1rem;
    border-radius: .625rem;
    background: var(--sm-primary);
    color: #fff;
    font-weight: 600;
    border: none;
    margin: .25rem;
}
#qr-reader__dashboard_section_swaplink { color: var(--sm-primary-dark) !important; }

/* Verification result banners */
.result-match { background: linear-gradient(135deg, #ecfdf5, #d1fae5); border-color: #6ee7b7; }
.result-mismatch { background: linear-gradient(135deg, #fef2f2, #fee2e2); border-color: #fca5a5; }

/* ---------- Charts ---------- */
.chart-box { position: relative; width: 100%; height: 260px; }
@media (min-width: 1024px) { .chart-box { height: 280px; } }

/* ---------- Print (QR bands) ---------- */
@media print {
    .no-print { display: none !important; }
    body { background: #fff; }
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Login alert shake ---------- */
.shake { animation: sm-shake .4s ease-in-out; }
@keyframes sm-shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}
