/* ══════════════════════════════════════════════
   UI Components — Softever Benefits
   ตาม spec §6.7 UI Components
   ══════════════════════════════════════════════ */

/* ─── Card ─── */
.card {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
}

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

.card-value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
}

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

/* ─── Stat (Dashboard card) ─── */
.stat {
  text-align: center;
  padding: var(--space-md);
}

.stat-number {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  line-height: 1;
}

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

/* ─── Progress bar ─── */
.progress {
  height: 6px;
  background: var(--border);
  border-radius: var(--radius-full);
  margin-top: var(--space-sm);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--text);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

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

/* ─── Button ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--bg);
  transition: opacity 0.15s;
  min-height: 44px;
}

.btn:active {
  opacity: 0.7;
}

.btn-primary {
  background: var(--btn-bg);
  color: var(--btn-text);
  border-color: transparent;
}

.btn-danger {
  background: var(--red);
  color: #FFFFFF;
  border-color: transparent;
}

.btn-sm {
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--text-sm);
  min-height: 32px;
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* ─── Badge (status) ─── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-sm);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.badge-pending {
  color: var(--orange);
  background: rgba(255, 149, 0, 0.1);
}

.badge-approved {
  color: var(--green);
  background: rgba(52, 199, 89, 0.1);
}

.badge-rejected {
  color: var(--red);
  background: rgba(255, 59, 48, 0.1);
}

.badge-paid {
  color: var(--blue);
  background: rgba(0, 122, 255, 0.1);
}

/* ─── Form ─── */
.form-group {
  margin-bottom: var(--space-md);
}

.form-group label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  min-height: 44px;
  transition: border-color 0.15s;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--btn-bg);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-secondary);
}

/* ─── Date/Time native controls — match color-scheme to theme ─── */
input[type="date"],
input[type="time"] {
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  input[type="date"],
  input[type="time"] {
    color-scheme: dark;
  }
}

/* ─── Date input DD/MM/YYYY format ─── */
.date-wrap {
  position: relative;
}

.date-wrap input[type="date"] {
  color: transparent;
}

/* Hide native date text, separators, and selection highlights */
.date-wrap input[type="date"]::-webkit-datetime-edit {
  color: transparent;
  -webkit-text-fill-color: transparent;
}

.date-wrap input[type="date"]::-webkit-datetime-edit-day-field,
.date-wrap input[type="date"]::-webkit-datetime-edit-month-field,
.date-wrap input[type="date"]::-webkit-datetime-edit-year-field,
.date-wrap input[type="date"]::-webkit-datetime-edit-text {
  color: transparent;
  -webkit-text-fill-color: transparent;
  background: transparent;
}

/* Calendar icon — always visible */
.date-wrap input[type="date"]::-webkit-calendar-picker-indicator {
  position: relative;
  z-index: 1;
  opacity: 0.5;
  cursor: pointer;
}

@media (prefers-color-scheme: dark) {
  .date-wrap input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
    opacity: 0.7;
  }
}

.date-fmt {
  position: absolute;
  left: var(--space-md);
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-size: var(--text-base);
  color: var(--text);
  white-space: nowrap;
}

.date-fmt.is-empty {
  color: var(--text-secondary);
}

.date-wrap input[type="date"]:disabled + .date-fmt {
  opacity: 0.5;
}

/* ─── Time input 24-hour format ─── */
.time-wrap {
  position: relative;
}

.time-wrap input[type="time"] {
  color: transparent;
}

.time-wrap input[type="time"]::-webkit-datetime-edit {
  color: transparent;
  -webkit-text-fill-color: transparent;
}

.time-wrap input[type="time"]::-webkit-datetime-edit-hour-field,
.time-wrap input[type="time"]::-webkit-datetime-edit-minute-field,
.time-wrap input[type="time"]::-webkit-datetime-edit-ampm-field,
.time-wrap input[type="time"]::-webkit-datetime-edit-text {
  color: transparent;
  -webkit-text-fill-color: transparent;
  background: transparent;
}

.time-wrap input[type="time"]::-webkit-calendar-picker-indicator {
  position: relative;
  z-index: 1;
  opacity: 0.5;
  cursor: pointer;
}

@media (prefers-color-scheme: dark) {
  .time-wrap input[type="time"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
    opacity: 0.7;
  }
}

.time-fmt {
  position: absolute;
  left: var(--space-md);
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-size: var(--text-base);
  color: var(--text);
  white-space: nowrap;
}

.time-fmt.is-empty {
  color: var(--text-secondary);
}

.time-wrap input[type="time"]:disabled + .time-fmt {
  opacity: 0.5;
}

.textarea {
  min-height: 88px;
  resize: vertical;
}

.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 d='M3 4.5L6 7.5L9 4.5' fill='none' stroke='%23999' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-md) center;
  padding-right: var(--space-xl);
}

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

.form-error {
  font-size: var(--text-xs);
  color: var(--red);
  margin-top: var(--space-xs);
}

/* ─── File upload ─── */
.file-upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-lg);
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: border-color 0.15s;
}

.file-upload:active {
  border-color: var(--btn-bg);
}

.file-upload input[type="file"] {
  display: none;
}

/* ─── Table (responsive) ─── */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

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

.table th,
.table td {
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  white-space: nowrap;
}

.table th {
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}

.table td {
  border-bottom: 1px solid var(--divider);
}

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

/* ─── List item ─── */
.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  border-bottom: 1px solid var(--divider);
}

.list-item:last-child {
  border-bottom: none;
}

.list-item-icon {
  font-size: var(--text-xl);
  flex-shrink: 0;
  width: 32px;
  text-align: center;
}

.list-item-content {
  flex: 1;
  min-width: 0;
}

.list-item-title {
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
}

.list-item-sub {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.list-item-value {
  flex-shrink: 0;
  text-align: right;
}

/* ─── Empty state ─── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl) var(--space-md);
  text-align: center;
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: var(--space-md);
}

.empty-state-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-medium);
  margin-bottom: var(--space-xs);
}

.empty-state-text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* ─── Chip ─── */
.chip {
  display: inline-flex;
  align-items: center;
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-full);
  background: var(--bg-secondary);
  color: var(--text);
  white-space: nowrap;
}

.chip-active {
  background: var(--btn-bg);
  color: var(--btn-text);
}

.chip-group {
  display: flex;
  gap: var(--space-sm);
  overflow-x: auto;
  padding-bottom: var(--space-xs);
  -webkit-overflow-scrolling: touch;
}

.chip-group::-webkit-scrollbar {
  display: none;
}

/* ─── Avatar ─── */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-secondary);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  flex-shrink: 0;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-sm {
  width: 28px;
  height: 28px;
  font-size: var(--text-xs);
}

.avatar-lg {
  width: 56px;
  height: 56px;
  font-size: var(--text-lg);
}

/* ─── Tabs ─── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex-shrink: 0;
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.tab-active {
  color: var(--text);
  border-bottom-color: var(--text);
}

/* ─── Modal ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}

.modal {
  background: var(--bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-lg);
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.modal-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xl);
  color: var(--text-secondary);
}

.modal-body {
  margin-bottom: var(--space-md);
}

.modal-actions {
  display: flex;
  gap: var(--space-sm);
}

.modal-actions .btn {
  flex: 1;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

/* ─── Toast ─── */
.toast-container {
  position: fixed;
  top: var(--space-md);
  left: var(--space-md);
  right: var(--space-md);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--bg);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toastIn 0.2s ease;
}

.toast-success {
  background: var(--green);
  color: #FFFFFF;
}

.toast-error {
  background: var(--red);
  color: #FFFFFF;
}

.toast-hide {
  animation: toastOut 0.2s ease forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-12px); }
}

/* ─── Bottom navigation ─── */
.nav-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 900;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-sm) 0;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  transition: color 0.15s;
}

.nav-item-active {
  color: var(--text);
}

.nav-item-icon {
  font-size: var(--text-xl);
  line-height: 1;
}

/* ─── Quick actions grid ─── */
.action-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-sm);
}

.action-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  text-align: center;
}

.action-item-icon {
  font-size: var(--text-2xl);
  line-height: 1;
}

/* ─── Confirm dialog ─── */
.confirm-text {
  font-size: var(--text-base);
  text-align: center;
  padding: var(--space-md) 0;
}

/* ─── Skeleton loading ─── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-secondary) 25%,
    var(--divider) 50%,
    var(--bg-secondary) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

.skeleton-text {
  height: 14px;
  margin-bottom: var(--space-sm);
}

.skeleton-title {
  height: 20px;
  width: 60%;
  margin-bottom: var(--space-sm);
}

.skeleton-card {
  height: 80px;
  margin-bottom: var(--space-sm);
}

@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
