/* Common styles shared between expense and budget pages */

/* Base styles */
body {
  overflow-y: auto;
  overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
  font-size: 14px;
}

* {
  font-family: inherit;
}

/* Loading animations */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

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

/* Loading progress bar */
#loading-progress {
  position: relative;
  z-index: 1501;
}

#loading-progress .progress-bar {
  width: 0%;
  height: 100%;
  min-width: 0%;
  background: linear-gradient(90deg, #3498db, #2ecc71, #3498db);
  background-size: 200% 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
  animation: progressShimmer 1.5s linear infinite;
}

/* Summary loading overlay */
.summary-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: 8px;
}

.summary-spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid #e0e0e0;
  border-top-color: #3498db;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Total container */
.total-container {
  position: relative;
  top: 0;
  left: 0;
  right: 0;
  background-color: transparent;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  border: none;
  overflow: visible;
  display: relative;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  margin: 10px auto;
  padding: 4px 30px;
  width: 100%;
  max-width: 800px;
  box-sizing: border-box;
  z-index: 100;
}

/* Budget cards container */
.budget-cards-container {
  position: relative;
  width: 100%;
  max-width: 800px;
  margin: 20px auto;
  background-color: transparent;
  border-radius: 12px;
  box-shadow: none !important;
  border: none;
  backdrop-filter: none;
  overflow: visible;
  z-index: 999;
  display: block;
  padding: 20px;
  overflow-x: hidden !important;
  box-sizing: border-box !important;
  overflow-anchor: none;
}

.budget-cards-container * {
  max-width: 100%;
  box-sizing: border-box;
  box-shadow: none !important;
}

/* Header info */
.header-info {
  position: absolute;
  top: 15px;
  right: 50px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 1002;
  pointer-events: none;
  background-color: transparent;
  padding: 0;
  border-radius: 0;
  backdrop-filter: none;
}

#record-number {
  display: block !important;
  position: absolute !important;
  top: 15px !important;
  left: 15px !important;
  font-family: inherit;
  font-size: 16px;
  color: #000;
  font-weight: 600;
  line-height: 1.5;
  z-index: 1004;
  pointer-events: none;
  background-color: transparent;
  margin: 0;
  padding: 0;
  width: auto;
  max-width: 200px;
  white-space: nowrap;
}

#record-date {
  position: absolute;
  top: 15px;
  right: 50px;
  font-family: inherit;
  font-size: 16px;
  color: #000;
  font-weight: 400;
  line-height: 1.5;
  z-index: 1002;
  pointer-events: none;
  background-color: transparent;
  width: auto;
  max-width: 300px;
  text-align: right;
}

/* Delete button */
.delete-button {
  position: absolute;
  top: 15px;
  right: 15px;
  z-index: 1003;
  min-width: 60px;
  padding: 6px 14px;
  border: 1px solid #dc3545;
  border-radius: 4px;
  background-color: #fff;
  color: #dc3545;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  text-align: center;
}

.delete-button:hover:not(:disabled) {
  background-color: #dc3545;
  color: #fff;
}

.delete-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: #fff;
  color: #dc3545;
}

/* Arrow buttons */
.arrow-button {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1001;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.35);
  color: #fff !important;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.arrow-button:hover {
  background-color: rgba(0, 0, 0, 0.5);
  transform: translateY(-50%) scale(1.1);
  color: #fff !important;
}

.arrow-button.left {
  left: 10px;
}

.arrow-button.right {
  right: 10px;
}

.arrow-button.right.plus {
  font-size: 14px;
  font-family: inherit;
}

/* Category select */
.category-select-row {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  margin-bottom: 8px;
  width: 100%;
  box-sizing: border-box;
  gap: 10px;
}

.category-select-label {
  font-size: 14px;
  color: #333;
  font-weight: 500;
  white-space: nowrap;
}

.category-select-container {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.category-select-display {
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 16px;
  background-color: #fff;
  cursor: pointer;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  box-sizing: border-box;
}

.category-select-text {
  flex: 1;
  word-break: break-word;
  white-space: normal;
  min-width: 0;
}

.category-select-arrow {
  font-size: 10px;
  color: #666;
  transition: transform 0.2s;
  flex-shrink: 0;
  line-height: 1;
}

.category-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background-color: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  z-index: 1000;
  max-height: 200px;
  overflow-y: auto;
  overflow-x: hidden;
  margin-top: 4px;
  scrollbar-width: thin;
  scrollbar-color: #ccc #f0f0f0;
  overflow-anchor: none;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.category-dropdown::-webkit-scrollbar {
  width: 8px;
}

.category-dropdown::-webkit-scrollbar-track {
  background: #f5f5f5;
}

.category-dropdown::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 4px;
}

.category-option {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 14px;
  word-break: break-word;
  white-space: normal;
  border-bottom: 1px solid #f0f0f0;
}

.category-option:hover {
  background-color: #f5f5f5;
}

.category-option:last-child {
  border-bottom: none;
}

/* Item container */
.item-container {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 15px;
  margin-bottom: 0px;
  margin-top: 60px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background-color: rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  box-shadow: none !important;
}

/* Item input - title style */
#item-input {
  width: 100%;
  max-width: 100%;
  margin: 0;
  display: block;
  padding: 15px 20px;
  border: none;
  border-radius: 0;
  font-size: 24px;
  font-weight: 700;
  font-family: inherit;
  color: #1a1a1a;
  background-color: transparent;
  outline: none;
  box-sizing: border-box;
  border-bottom: 3px solid #e0e0e0;
  transition: all 0.3s ease;
  line-height: 1.2;
  height: auto;
}

#item-input:focus {
  border-bottom-color: #4CAF50;
  border-bottom-width: 4px;
}

/* Input row */
.input-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 8px;
  margin-bottom: 8px;
  width: 100%;
  box-sizing: border-box;
  gap: 10px;
}

.input-row label {
  font-size: 14px;
  color: #333;
  font-weight: 500;
  white-space: nowrap;
}

label[for="item-input"] {
  display: none;
}

.input-row input,
.input-row textarea {
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 16px;
  font-family: inherit;
  background-color: #fff;
  flex: 1;
  height: 32px;
  box-sizing: border-box;
}

#note-input {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 16px;
  background-color: #fff;
  min-height: 60px;
  resize: vertical;
}

/* Select row */
.select-row {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  margin-bottom: 8px;
  width: 100%;
  box-sizing: border-box;
  gap: 10px;
}

.select-row label {
  font-size: 14px;
  color: #333;
  font-weight: 500;
  white-space: nowrap;
}

.select-container {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.select-display {
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 16px;
  font-family: inherit;
  background-color: #fff;
  cursor: pointer;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  box-sizing: border-box;
}

.select-text {
  flex: 1;
  word-break: break-word;
  white-space: normal;
  min-width: 0;
  font-family: inherit;
}

.select-arrow {
  font-size: 10px;
  color: #666;
  transition: transform 0.2s;
  flex-shrink: 0;
  line-height: 1;
}

.select-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background-color: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  z-index: 1000;
  max-height: 200px;
  overflow-y: auto;
  overflow-x: hidden;
  margin-top: 4px;
  scrollbar-width: thin;
  scrollbar-color: #ccc #f0f0f0;
  overflow-anchor: none;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.select-option {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  word-break: break-word;
  white-space: normal;
  border-bottom: 1px solid #f0f0f0;
}

.select-option:hover {
  background-color: #f5f5f5;
}

/* Save button */
.save-button {
  padding: 10px 20px;
  margin: 5px auto 0 auto;
  display: block;
  background-color: #4CAF50;
  color: #fff !important;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 500;
  min-width: 120px;
  transition: all 0.2s;
}

.save-button:hover {
  background-color: #43a047;
  transform: scale(1.03);
  color: #fff !important;
}

.save-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Columns container (summary) */
.columns-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.income-column,
.expense-column,
.total-column {
  display: flex;
  align-items: center;
  gap: 10px;
}

.income-title,
.expense-title,
.total-title {
  margin: 0;
  color: #1976d2;
  font-size: 20px;
  font-weight: 500;
}

.income-amount,
.expense-amount,
.total-amount {
  font-size: 24px;
  font-weight: bold;
  color: #1976d2;
}

.total-amount.positive,
.total-title.positive {
  color: #2e7d32;
}

.total-amount.negative,
.total-title.negative {
  color: #d32f2f;
}

/* History button */
.history-button {
  display: inline-block;
  margin-left: 20px;
  padding: 4px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background-color: #fff;
  color: #333;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.history-button:hover {
  background-color: #f5f5f5;
}

/* Month select */
.month-select-wrapper {
  width: auto;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin: 0 0 0 50px;
}

.month-select-label {
  margin-right: 8px;
  font-size: 14px;
  color: #333;
}

.month-select {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid #ccc;
  font-size: 14px;
}

.post-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Responsive design */
@media (min-width: 769px) {
  .budget-cards-container {
    max-width: 800px !important;
  }
}

@media (max-width: 768px) {
  /* Prevent iOS zoom on input focus */
  input,
  textarea,
  select,
  .input-row input,
  .input-row textarea,
  #item-input,
  #note-input,
  #actual-cost-input,
  #record-cost-input {
    font-size: 16px !important;
    touch-action: manipulation;
  }

  .total-container {
    height: auto !important;
    min-height: auto !important;
    margin: 20px 0 !important;
    left: calc(-50vw + 50%) !important;
    right: calc(-50vw + 50%) !important;
    width: 100vw !important;
    max-width: 100vw !important;
    padding: 10px 20px !important;
    box-sizing: border-box !important;
  }

  .columns-container {
    gap: 4px !important;
  }

  .item-container {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 15px !important;
  }

  .item-container input {
    font-size: 24px !important;
    padding: 12px 15px !important;
    max-width: 100% !important;
    margin: 0 !important;
  }

  .budget-cards-container {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    margin-top: 20px !important;
    padding-left: 15px !important;
    padding-right: 15px !important;
    box-sizing: border-box !important;
    position: relative !important;
  }

  .header-info {
    width: calc(100% - 30px) !important;
    left: 15px !important;
    right: 15px !important;
    top: 5px !important;
    align-items: flex-start !important;
  }

  #record-number {
    display: block !important;
    position: absolute !important;
    top: 5px !important;
    left: 15px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    color: #000 !important;
    z-index: 1004 !important;
    pointer-events: none !important;
    background-color: transparent !important;
    margin-bottom: 10px !important;
  }

  #record-date {
    position: absolute !important;
    top: 30px !important;
    left: 15px !important;
    font-size: 16px !important;
    color: #000 !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    width: auto !important;
    text-align: left !important;
  }

  .item-container {
    margin-top: 75px !important;
    padding-top: 15px !important;
  }

  .total-amount-text {
    font-size: 18px !important;
  }

  .total-title-text {
    font-size: 16px !important;
  }

  #actual-cost-input,
  #record-cost-input {
    height: 32px !important;
    padding: 6px 10px !important;
    font-size: 16px !important;
    box-sizing: border-box !important;
    width: 100% !important;
    flex: 1 !important;
  }
}

@media (max-width: 420px) {
  .total-container {
    width: 100% !important;
    max-width: 100% !important;
    left: 0 !important;
    right: 0 !important;
    margin: 10px 0 !important;
    padding: 10px 15px !important;
    box-sizing: border-box !important;
  }

  .budget-cards-container {
    width: 100% !important;
    max-width: 100% !important;
    margin: 10px 0 !important;
    padding: 10px 15px !important;
    box-sizing: border-box !important;
  }

  .item-container {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 10px !important;
    box-sizing: border-box !important;
  }

  .header-info {
    width: calc(100% - 20px) !important;
    left: 10px !important;
    right: 10px !important;
  }

  #record-number {
    display: block !important;
    position: absolute !important;
    top: 5px !important;
    left: 10px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    color: #000 !important;
    z-index: 1004 !important;
    pointer-events: none !important;
    background-color: transparent !important;
    margin-bottom: 10px !important;
  }

  #record-date {
    position: absolute !important;
    top: 30px !important;
    left: 10px !important;
    font-size: 16px !important;
    color: #000 !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    width: auto !important;
    text-align: left !important;
  }

  .item-container {
    margin-top: 75px !important;
    padding-top: 15px !important;
  }

  .delete-button {
    right: 10px !important;
    top: 5px !important;
  }

  .arrow-button.left {
    left: 5px !important;
  }

  .arrow-button.right {
    right: 5px !important;
  }

  .category-select-row,
  .input-row,
  .select-row {
    padding: 6px !important;
    gap: 8px !important;
  }

  .category-select-container,
  .select-container {
    min-width: 0 !important;
  }
}
