/* =========================================================
   COMPONENTS, CALENDAR GRID, LEDGER, MODALS & WIDGETS
   Complete Responsive Styles for Desktop, Tablet & Mobile
   ========================================================= */

/* --- Card Containers --- */
.app-card {
  background: var(--bg-card);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.25rem;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.card-title-group h3 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-title-group p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
}

.btn-primary {
  background: var(--primary-gradient);
  color: #ffffff;
  box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

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

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-emerald {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  box-shadow: var(--shadow-emerald);
}

.btn-emerald:hover {
  filter: brightness(1.1);
}

.btn-danger {
  background: linear-gradient(135deg, #f43f5e 0%, #e11d48 100%);
  color: #ffffff;
}

.btn-danger:hover {
  filter: brightness(1.1);
}

.btn-whatsapp {
  background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
  color: #ffffff;
  font-weight: 700;
  border-color: rgba(37, 211, 102, 0.3);
}

.btn-whatsapp:hover {
  filter: brightness(1.1);
}

.btn-whatsapp-sm {
  background: rgba(37, 211, 102, 0.15);
  color: #25D366;
  border: 1px solid rgba(37, 211, 102, 0.3);
  padding: 3px 9px;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.btn-whatsapp-sm:hover {
  background: #25D366;
  color: #ffffff;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* --- Stats Grid (With Zero Text Overflow) --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  width: 100%;
}

.stat-card {
  background: var(--bg-card);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast);
  overflow: hidden;
  box-sizing: border-box;
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.15);
}

.stat-icon-wrapper {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.25rem;
}

.stat-icon-wrapper.indigo { background: rgba(99, 102, 241, 0.15); color: var(--primary-light); }
.stat-icon-wrapper.emerald { background: rgba(16, 185, 129, 0.15); color: var(--accent-emerald); }
.stat-icon-wrapper.amber { background: rgba(245, 158, 11, 0.15); color: var(--accent-amber); }
.stat-icon-wrapper.rose { background: rgba(244, 63, 94, 0.15); color: var(--accent-rose); }
.stat-icon-wrapper.cyan { background: rgba(6, 182, 212, 0.15); color: var(--accent-cyan); }

.stat-content {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.stat-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-value {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0.1rem 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================================
   BIG VIBRANT P, H, A, M ATTENDANCE BUTTONS
   ========================================================= */
.status-btn-pill-large {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  user-select: none;
  width: 100%;
}

.status-btn-pill-large .pill-title {
  font-size: 1.1rem;
  font-weight: 850;
  letter-spacing: 0.02em;
}

/* Present (P) Large */
.btn-pill-present {
  background: rgba(16, 185, 129, 0.12);
  color: #10b981;
  border-color: rgba(16, 185, 129, 0.4);
}
.btn-pill-present:hover {
  background: rgba(16, 185, 129, 0.25);
  transform: translateY(-2px);
}
.btn-pill-present.active {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
  color: #ffffff !important;
  border-color: #ffffff !important;
  box-shadow: 0 0 18px rgba(16, 185, 129, 0.7) !important;
  transform: scale(1.04);
}

/* Half Day (H) Large */
.btn-pill-halfday {
  background: rgba(245, 158, 11, 0.12);
  color: #f59e0b;
  border-color: rgba(245, 158, 11, 0.4);
}
.btn-pill-halfday:hover {
  background: rgba(245, 158, 11, 0.25);
  transform: translateY(-2px);
}
.btn-pill-halfday.active {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%) !important;
  color: #ffffff !important;
  border-color: #ffffff !important;
  box-shadow: 0 0 18px rgba(245, 158, 11, 0.7) !important;
  transform: scale(1.04);
}

/* Absent (A) Large */
.btn-pill-absent {
  background: rgba(244, 63, 94, 0.12);
  color: #f43f5e;
  border-color: rgba(244, 63, 94, 0.4);
}
.btn-pill-absent:hover {
  background: rgba(244, 63, 94, 0.25);
  transform: translateY(-2px);
}
.btn-pill-absent.active {
  background: linear-gradient(135deg, #f43f5e 0%, #e11d48 100%) !important;
  color: #ffffff !important;
  border-color: #ffffff !important;
  box-shadow: 0 0 18px rgba(244, 63, 94, 0.7) !important;
  transform: scale(1.04);
}

/* Manual (M) Large */
.btn-pill-manual {
  background: rgba(139, 92, 246, 0.12);
  color: #a78bfa;
  border-color: rgba(139, 92, 246, 0.4);
}
.btn-pill-manual:hover {
  background: rgba(139, 92, 246, 0.25);
  transform: translateY(-2px);
}
.btn-pill-manual.active {
  background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%) !important;
  color: #ffffff !important;
  border-color: #ffffff !important;
  box-shadow: 0 0 18px rgba(139, 92, 246, 0.7) !important;
  transform: scale(1.04);
}

/* =========================================================
   CALENDAR & LEDGER STYLES (7-COLUMN GRID)
   ========================================================= */
.attendance-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  background: var(--bg-card);
  padding: 0.85rem 1rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}

.month-navigator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.current-month-display {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--primary-light);
  padding: 0.35rem 0.75rem;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.calculation-mode-pill {
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: var(--bg-input);
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
}

.calendar-container {
  background: var(--bg-card);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem;
  margin-bottom: 1.25rem;
  width: 100%;
  box-sizing: border-box;
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  text-align: center;
  margin-bottom: 8px;
  width: 100%;
}

.weekday-header {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--text-secondary);
  text-transform: uppercase;
  padding: 0.4rem 0;
  letter-spacing: 0.04em;
}

.weekday-header.weekend {
  color: var(--accent-amber);
}

.calendar-days-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  width: 100%;
}

.calendar-day-cell {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  min-height: 75px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

.calendar-day-cell:hover {
  border-color: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.calendar-day-cell.empty-cell {
  background: transparent;
  border-color: transparent;
  cursor: default;
}

.calendar-day-cell.empty-cell:hover {
  transform: none;
  box-shadow: none;
}

.calendar-day-cell.is-today {
  border: 2px solid var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
}

.day-cell-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.day-number {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--text-primary);
}

.day-tag {
  font-size: 0.65rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

.day-earnings {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--accent-emerald);
}

.day-advances-tag {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--accent-rose);
  display: block;
}

.day-cell-status-present {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.4);
}
.day-cell-status-halfday {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.4);
}
.day-cell-status-absent {
  background: rgba(244, 63, 94, 0.12);
  border-color: rgba(244, 63, 94, 0.4);
}
.day-cell-status-manual {
  background: rgba(139, 92, 246, 0.12);
  border-color: rgba(139, 92, 246, 0.4);
}

.att-action-btn {
  background: var(--bg-input);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
  color: var(--text-primary);
  font-family: inherit;
}
.att-action-btn:hover {
  transform: translateY(-2px);
}
.att-btn-present.selected {
  background: rgba(16, 185, 129, 0.25);
  border-color: #10b981;
  color: #10b981;
}
.att-btn-halfday.selected {
  background: rgba(245, 158, 11, 0.25);
  border-color: #f59e0b;
  color: #f59e0b;
}
.att-btn-absent.selected {
  background: rgba(244, 63, 94, 0.25);
  border-color: #f43f5e;
  color: #f43f5e;
}
.att-btn-manual.selected {
  background: rgba(139, 92, 246, 0.25);
  border-color: #8b5cf6;
  color: #8b5cf6;
}

/* --- Ledger Split & Summary Box --- */
.ledger-split {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.25rem;
  align-items: start;
}

.salary-summary-box {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
}

.summary-row.net-payable {
  border-top: 2px dashed var(--border-color);
  padding-top: 0.75rem;
  margin-top: 0.25rem;
}

.summary-row.net-payable .amount {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--accent-emerald);
}

/* --- Members Grid --- */
.members-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.85rem;
  width: 100%;
}

.member-card {
  background: var(--bg-card);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.member-card:hover {
  transform: translateY(-2px);
  border-color: rgba(99, 102, 241, 0.4);
  box-shadow: var(--shadow-md);
}

.member-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.member-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1rem;
  color: #ffffff;
  flex-shrink: 0;
}

.member-info {
  min-width: 0;
  flex: 1;
}

.member-name {
  font-size: 0.95rem;
  font-weight: 750;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-designation {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.member-phone {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.member-salary-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-input);
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-md);
  margin-bottom: 0.75rem;
}

.salary-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
}

.salary-amount {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-light);
}

.member-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border-color);
}

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-monthly { background: rgba(99, 102, 241, 0.15); color: var(--primary-light); }
.badge-daily { background: rgba(6, 182, 212, 0.15); color: var(--accent-cyan); }
.badge-present { background: var(--status-present-bg); color: var(--status-present); }
.badge-halfday { background: var(--status-halfday-bg); color: var(--status-halfday); }
.badge-absent { background: var(--status-absent-bg); color: var(--status-absent); }
.badge-manual { background: var(--status-manual-bg); color: var(--status-manual); }

/* --- Forms & Inputs --- */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.form-control {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition-fast);
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.segmented-control {
  display: flex;
  background: var(--bg-input);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.segmented-control label {
  flex: 1;
  text-align: center;
  cursor: pointer;
}

.segmented-control input[type="radio"] {
  display: none;
}

.segmented-control span {
  display: block;
  padding: 0.45rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.segmented-control input[type="radio"]:checked + span {
  background: var(--primary);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

/* --- Modals --- */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: none !important;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  pointer-events: none;
}

.modal-backdrop.open {
  display: flex !important;
  pointer-events: auto !important;
}

.modal-dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 101;
}

.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  z-index: 10;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 800;
}

.modal-body {
  padding: 1.25rem;
}

.modal-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* --- Table Styles --- */
.app-table {
  width: 100%;
  border-collapse: collapse;
}

.app-table th {
  text-align: left;
  padding: 0.65rem 0.85rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
}

.app-table td {
  padding: 0.65rem 0.85rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border-color);
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 820px) {
  .ledger-split {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }
  .stat-card {
    padding: 0.65rem 0.75rem;
    gap: 0.45rem;
  }
  .stat-icon-wrapper {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }
  .stat-label {
    font-size: 0.65rem;
  }
  .stat-value {
    font-size: 1.05rem;
  }
  .status-btn-pill-large {
    min-height: 44px;
    padding: 0.4rem;
  }
  .status-btn-pill-large .pill-title {
    font-size: 1rem;
  }
  .calendar-container {
    padding: 0.5rem;
  }
  .calendar-weekdays {
    gap: 3px;
  }
  .weekday-header {
    font-size: 0.68rem;
    padding: 0.2rem 0;
  }
  .calendar-days-grid {
    gap: 3px;
  }
  .calendar-day-cell {
    min-height: 52px;
    padding: 3px 4px;
    border-radius: 6px;
  }
  .day-number {
    font-size: 0.75rem;
  }
  .day-tag {
    font-size: 0.55rem;
    padding: 1px 3px;
  }
  .day-earnings {
    font-size: 0.62rem;
  }
  .ledger-split {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 1rem;
  }
  .transactions-table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .salary-summary-box {
    width: 100%;
    padding: 0.85rem;
    box-sizing: border-box;
  }
  .app-table th, .app-table td {
    padding: 0.45rem 0.5rem;
    font-size: 0.78rem;
  }
  .modal-dialog {
    max-width: 95vw;
    border-radius: var(--radius-lg);
  }
}
