/**
 * components.css
 * Clean, minimal, and calm components for Spense (สบายตา ไม่ตาลาย)
 */

/* ==========================================================================
   1. STATS DASHBOARD GRID
   ========================================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
}

.stat-card.primary-card {
  border-left: 3px solid var(--primary);
}

.stat-icon-wrap {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background-color: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.stat-icon-wrap.bg-green { background-color: var(--accent-green-bg); }
.stat-icon-wrap.bg-blue { background-color: var(--accent-blue-bg); }
.stat-icon-wrap.bg-amber { background-color: var(--accent-amber-bg); }

.stat-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 0.1rem;
}

.stat-number {
  font-size: 1.2rem;
  font-weight: 700;
  font-family: var(--font-heading);
  color: var(--text-primary);
}

.stat-number.text-green {
  color: var(--accent-green);
}

/* ==========================================================================
   2. TOOLBAR & FILTER CONTROLS
   ========================================================================== */
.toolbar-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-md);
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  min-width: 260px;
}

.search-box {
  position: relative;
  flex: 1;
  max-width: 360px;
}

.search-box input {
  width: 100%;
  padding: 0.45rem 1.8rem 0.45rem 2rem;
  background-color: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  color: var(--text-primary);
  outline: none;
}

.search-box input:focus {
  border-color: var(--primary);
  background-color: var(--bg-surface);
}

.search-icon {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.8rem;
  opacity: 0.5;
}

.clear-btn {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.select-wrapper select {
  padding: 0.45rem 1.6rem 0.45rem 0.7rem;
  background-color: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  color: var(--text-primary);
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2212%22%20height%3D%2212%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%2364748B%22%20stroke-width%3D%222%22%3E%3Cpolyline%20points%3D%226%209%2012%2015%2018%209%22%3E%3C%2Fpolyline%3E%3C%2Fsvg%3E");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
}

.view-switch-group {
  display: flex;
  background-color: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.view-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.65rem;
  font-size: 0.82rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.view-btn:hover {
  color: var(--text-primary);
}

.view-btn.active {
  background-color: var(--bg-surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   3. CLEAN TABLE / SPREADSHEET (NO HOVER FLICKER, VERY READABLE)
   ========================================================================== */
.table-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  width: 100%;
}

.clean-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
  line-height: 1.5;
}

.clean-table th {
  background-color: var(--bg-surface-subtle);
  color: var(--text-secondary);
  font-family: var(--font-heading);
  font-weight: 600;
  padding: 0.75rem 0.85rem;
  border-bottom: 2px solid var(--border-color);
  font-size: 0.85rem;
  white-space: nowrap;
}

.clean-table td {
  padding: 0.6rem 0.85rem;
  vertical-align: top;
  color: var(--text-primary);
}

/* Clear separation between days */
.day-group-body {
  border-bottom: 1.5px solid var(--border-color);
}

.day-group-body:last-of-type {
  border-bottom: none;
}

/* Sub-row subtle separation within the same day */
.table-row-item td.col-item,
.table-row-item td.col-amount {
  border-bottom: 1px dashed var(--border-subtle);
}

.table-row-item:last-child td.col-item,
.table-row-item:last-child td.col-amount {
  border-bottom: none;
}

/* Text styles */
.font-date {
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.summary-content {
  color: var(--text-primary);
  font-weight: 500;
  line-height: 1.45;
  white-space: pre-line;
}

.col-item {
  color: var(--text-primary);
}

.note-discount {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 400;
  margin-left: 0.25rem;
}

.col-amount {
  font-family: var(--font-heading);
  font-weight: 500;
  white-space: nowrap;
}

.font-total {
  font-family: var(--font-heading);
  font-weight: 700;
  color: var(--primary);
  font-size: 0.95rem;
  white-space: nowrap;
}

/* Action buttons */
.action-buttons {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.btn-text {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 0.15rem 0.35rem;
  border-radius: var(--radius-sm);
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-color);
  transition: all var(--transition-fast);
}

.btn-text:hover {
  background-color: var(--bg-surface-hover);
  color: var(--text-primary);
}

.btn-text.danger:hover {
  background-color: var(--accent-rose-bg);
  color: var(--accent-rose);
  border-color: var(--accent-rose-border);
}

/* Grand total footer */
.table-grand-total-row td {
  background-color: var(--bg-surface-subtle);
  padding: 0.85rem;
  border-top: 2px solid var(--border-color);
}

.grand-total-val {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
}

.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }

/* ==========================================================================
   4. TIMELINE / CARD VIEW
   ========================================================================== */
.timeline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 0.85rem;
}

.day-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

.day-card-header {
  padding: 0.7rem 0.85rem;
  background-color: var(--bg-surface-subtle);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.date-title {
  font-size: 0.92rem;
  font-weight: 600;
  font-family: var(--font-heading);
}

.card-actions {
  display: flex;
  gap: 0.3rem;
}

.activity-summary-box {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px dashed var(--border-subtle);
}

.activity-text {
  font-size: 0.88rem;
  color: var(--text-primary);
  line-height: 1.45;
  white-space: pre-line;
}

.expenses-section {
  padding: 0.75rem 0.85rem;
  flex: 1;
}

.expense-items-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.expense-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0;
  font-size: 0.86rem;
  border-bottom: 1px dashed var(--border-subtle);
}

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

.item-name {
  color: var(--text-primary);
}

.item-price {
  font-family: var(--font-heading);
  font-weight: 600;
  white-space: nowrap;
}

.no-expenses-msg {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.day-card-footer {
  padding: 0.65rem 0.85rem;
  background-color: var(--bg-surface-subtle);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.day-total-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.day-total-amount {
  font-size: 1.05rem;
  font-weight: 700;
  font-family: var(--font-heading);
  color: var(--primary);
}

/* ==========================================================================
   5. MODAL DIALOG & INPUT ROWS
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(15, 23, 42, 0.5);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 660px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 0.85rem 1.15rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 600;
}

.modal-close {
  font-size: 1.1rem;
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-form {
  padding: 1rem 1.15rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-label {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-label.mb-0 {
  margin-bottom: 0;
}

.required {
  color: var(--accent-rose);
}

.date-input-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.form-input, .form-textarea {
  width: 100%;
  padding: 0.45rem 0.65rem;
  background-color: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  color: var(--text-primary);
  outline: none;
}

.form-input:focus, .form-textarea:focus {
  border-color: var(--primary);
  background-color: var(--bg-surface);
}

.form-textarea {
  resize: vertical;
  min-height: 55px;
  line-height: 1.4;
}

.thai-date-badge {
  font-size: 0.78rem;
  color: var(--primary);
  background-color: var(--primary-light);
  border: 1px solid var(--primary-border);
  padding: 0.3rem 0.55rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.expense-items-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.35rem;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.discount-pill-info {
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* Header Columns for Expense List */
.expense-header-columns {
  display: grid;
  grid-template-columns: 42px 1fr 135px 100px 100px 32px;
  gap: 0.45rem;
  padding: 0.35rem 0.55rem;
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
}

.col-head-title {
  text-align: left;
}

.expense-rows-container {
  display: flex;
  flex-direction: column;
  max-height: 240px;
  overflow-y: auto;
  border-left: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.expense-input-row {
  padding: 0.4rem 0.55rem;
  border-bottom: 1px solid var(--border-subtle);
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.expense-input-row.row-moved-highlight {
  background-color: var(--primary-light);
  transition: background-color 0.4s ease;
}

.expense-input-row:last-child {
  border-bottom: none;
}

.row-fields-grid {
  display: grid;
  grid-template-columns: 42px 1fr 135px 100px 100px 32px;
  gap: 0.45rem;
  align-items: center;
}

.col-field-order {
  display: flex;
  flex-direction: column;
  gap: 2px;
  justify-content: center;
  align-items: center;
  height: 34px;
}

.btn-order-move {
  width: 100%;
  height: 15px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  background-color: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: 2px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  transition: all var(--transition-fast);
}

.btn-order-move:hover:not(:disabled) {
  background-color: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-order-move:disabled {
  opacity: 0.2;
  cursor: not-allowed;
}

.input-item-title,
.select-discount-type,
.input-money-wrap {
  width: 100%;
  height: 34px;
}

.input-item-title {
  padding: 0 0.55rem;
  background-color: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  outline: none;
}

.input-item-title:focus {
  border-color: var(--primary);
  background-color: var(--bg-surface);
}

.select-discount-type {
  padding: 0 0.4rem;
  background-color: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  outline: none;
  cursor: pointer;
}

.select-discount-type:focus {
  border-color: var(--primary);
}

.input-money-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.currency-tag {
  position: absolute;
  left: 0.45rem;
  font-size: 0.76rem;
  color: var(--text-muted);
  pointer-events: none;
}

.input-money-wrap input {
  width: 100%;
  height: 100%;
  padding: 0 0.45rem 0 1.2rem;
  background-color: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  outline: none;
}

.input-money-wrap input:focus {
  border-color: var(--primary);
  background-color: var(--bg-surface);
}

.input-money-wrap.disabled-view {
  opacity: 0.45;
}

.input-money-wrap.disabled-view input {
  background-color: var(--bg-surface-subtle);
  cursor: not-allowed;
}

.btn-remove-row {
  width: 32px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  background-color: var(--bg-app);
  border: 1px solid var(--border-color);
  font-size: 0.8rem;
}

.btn-remove-row:hover {
  background-color: var(--accent-rose-bg);
  color: var(--accent-rose);
  border-color: var(--accent-rose-border);
}

.btn-add-item {
  width: 100%;
  padding: 0.45rem;
  border: 1px dashed var(--primary);
  background-color: var(--primary-light);
  color: var(--primary);
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 500;
  font-family: var(--font-heading);
  margin-top: 0.3rem;
}

.btn-add-item:hover {
  background-color: #DBEAFE;
}

.modal-summary-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
  flex-wrap: wrap;
}

.modal-summary-text {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}

.modal-summary-text .lbl {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.modal-summary-text .val {
  font-size: 1.15rem;
  font-family: var(--font-heading);
  color: var(--primary);
  font-weight: 700;
}

.modal-summary-text .savings-val {
  font-size: 0.74rem;
  color: var(--accent-green);
  font-weight: 600;
}

.modal-buttons-group {
  display: flex;
  gap: 0.45rem;
}

.btn-modal {
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  font-weight: 600;
  font-family: var(--font-heading);
}

.btn-modal.primary {
  background-color: var(--primary);
  color: #FFFFFF;
}

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

.btn-modal.secondary {
  background-color: var(--bg-surface-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-modal.secondary:hover {
  background-color: var(--bg-surface-hover);
}

.btn-modal.danger {
  background-color: var(--accent-rose);
  color: #FFFFFF;
}

/* Confirmation Modal */
.modal-confirm-card {
  max-width: 380px;
  padding: 1.15rem;
  text-align: center;
  align-items: center;
}

.confirm-icon {
  font-size: 1.8rem;
  margin-bottom: 0.35rem;
}

.confirm-title {
  font-size: 1.05rem;
  margin-bottom: 0.35rem;
}

.confirm-message {
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 1.15rem;
}

.confirm-actions {
  display: flex;
  gap: 0.55rem;
  width: 100%;
  justify-content: center;
}

/* Toast */
.toast-notification {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  background-color: var(--text-primary);
  color: var(--bg-surface);
  font-size: 0.86rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 2000;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast-notification.show {
  opacity: 1;
  transform: translateY(0);
}

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

.toast-notification.error {
  background-color: var(--accent-rose);
  color: #FFFFFF;
}

.empty-state-box {
  text-align: center;
  padding: 2.5rem 1rem;
  background-color: var(--bg-surface);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  margin-top: 1rem;
}

.empty-icon {
  font-size: 2rem;
  margin-bottom: 0.4rem;
  opacity: 0.5;
}
