/* Reset and base */
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: Arial, sans-serif;
  background: #121212;
  color: #e0e0e0;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
  min-height: 100vh;
}

.calculator {
  background: #1e1e1e;
  border-radius: 12px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  max-width: 1000px;
  width: 100%;
  display: flex;
  min-height: 670px;
  overflow: hidden;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 24px;
  overflow: visible;
}

h1 {
  text-align: center;
  margin: 0 0 12px 0;
  font-size: 1.5rem;
  color: #00bcd4;
  flex-shrink: 0;
}

.start-bank-container {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 12px;
  max-width: 300px;
}

.start-bank-container label {
  font-size: 0.9rem;
  color: #ccc;
  white-space: nowrap;
}

#startBank {
  flex: 1;
  padding: 8px 10px;
  font-size: 1rem;
  border-radius: 6px;
  border: 1px solid #444;
  background: #2a2a2a;
  color: #fff;
  text-align: left;
  min-width: 0;
}

button#clearBtn {
  padding: 8px 12px;
  font-size: 1rem;
  border-radius: 6px;
  border: none;
  background: #00bcd4;
  color: white;
  cursor: pointer;
  transition: background 0.2s;
}
button#clearBtn:hover {
  background: #0097a7;
}

/* Grid of inputs */
form#money-form {
  flex: 1;
  overflow: visible;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px 16px;
  margin-bottom: 16px;
}

h2 {
  grid-column: 1 / -1;
  margin: 12px 0 6px 0;
  font-size: 1.1rem;
  color: #ffca28;
  border-bottom: 1px solid #333;
  padding-bottom: 4px;
}

label {
  display: block;
  font-size: 0.85rem;
  color: #ccc;
  margin-bottom: 4px;
}

input[type="number"] {
  width: 100%;
  padding: 8px 10px;
  font-size: 1rem;
  border-radius: 6px;
  border: 1px solid #444;
  background: #2a2a2a;
  color: #fff;
  min-width: 0;
}

input[type="number"]:focus {
  outline: none;
  border-color: #00bcd4;
  box-shadow: 0 0 5px #00bcd4;
}

/* Totals */
.totals {
  margin-top: auto;
  padding-top: 12px;
  font-size: 1.25rem;
  font-weight: bold;
  color: #4caf50;
  text-align: center;
  flex-shrink: 0;
  border-top: 1px solid #333;
}

.totals .deposit {
  color: #ff9800;
  margin-left: 16px;
}

.save-entry-btn {
  background: #ff9800;
  border: none;
  color: white;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  margin-left: 10px;
  transition: background 0.2s;
}

.save-entry-btn:hover {
  background: #f57c00;
}

/* Side panel */
.side-panel {
  width: 320px;
  background: #222;
  border-left: 2px solid #333;
  padding: 16px 24px;
  color: #ccc;
  border-radius: 0 12px 12px 0;
  display: flex;
  flex-direction: column;
}

.side-panel h3 {
  margin: 0 0 12px 0;
  font-size: 1.2rem;
  color: #00bcd4;
  flex-shrink: 0;
}

#breakdownList {
  flex-grow: 1;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
}

#breakdownList li {
  padding: 4px 0;
  border-bottom: 1px solid #333;
  font-size: 0.9rem;
}

#breakdownList::-webkit-scrollbar {
  width: 6px;
}
#breakdownList::-webkit-scrollbar-thumb {
  background-color: #444;
  border-radius: 3px;
}

/* Toast styles */
#toast {
  visibility: hidden;
  min-width: 250px;
  background-color: #ea9320;
  color: white;
  text-align: center;
  border-radius: 8px;
  padding: 16px;
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1rem;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.5s ease-in-out, visibility 0.5s ease-in-out;
}

/* Floating buttons */
#helpBtn {
  position: fixed;
  bottom: 80px;
  right: 20px;
  background: #00bcd4;
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  color: white;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
  z-index: 999;
}

#historyBtn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #ff9800;
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  color: white;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
  z-index: 999;
}

#historyBtn:hover,
#helpBtn:hover {
  transform: scale(1.05);
}

/* Modal styles */
#helpModal,
#historyModal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(3px);
  z-index: 1100;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

#helpModal > div,
#historyModal > div {
  background: #1e1e1e;
  color: #e0e0e0;
  max-width: 480px;
  width: 100%;
  padding: 2rem;
  border-radius: 12px;
  position: relative;
  font-family: Arial, sans-serif;
  max-height: 90vh;
  overflow-y: auto;
}

#helpModal > div {
  box-shadow: 0 0 20px #00bcd4aa;
}

#historyModal > div {
  max-width: 600px;
  box-shadow: 0 0 20px #ff9800aa;
}

#closeHelp,
#closeHistory {
  position: absolute;
  top: 10px;
  right: 10px;
  background: transparent;
  border: none;
  font-size: 24px;
  cursor: pointer;
  font-weight: bold;
  line-height: 1;
}

#closeHelp {
  color: #00bcd4;
}

#closeHistory {
  color: #ff9800;
}

.history-item {
  background: #2a2a2a;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  border-left: 4px solid #ff9800;
}

.history-item:last-child {
  margin-bottom: 0;
}

.history-timestamp {
  font-size: 0.8rem;
  color: #aaa;
  margin-bottom: 6px;
}

.history-amounts {
  display: flex;
  justify-content: space-between;
  font-weight: bold;
}

.history-total {
  color: #4caf50;
}

.history-deposit {
  color: #ff9800;
}

#historyList {
  max-height: 400px;
  overflow-y: auto;
  margin-top: 15px;
}

#historyList::-webkit-scrollbar {
  width: 6px;
}
#historyList::-webkit-scrollbar-thumb {
  background-color: #444;
  border-radius: 3px;
}

.clear-history-btn {
  background: #f44336;
  border: none;
  color: white;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  margin-top: 15px;
  width: 100%;
  transition: background 0.2s;
}

.clear-history-btn:hover {
  background: #d32f2f;
}

/* Mobile styles */
@media (max-width: 768px) {
  body {
    padding: 5px;
    align-items: stretch;
  }

  .calculator {
    flex-direction: column;
    min-height: calc(100vh - 10px);
    height: auto;
    border-radius: 8px;
  }

  .main-content {
    padding: 12px 16px;
    order: 1;
  }

  h1 {
    font-size: 1.3rem;
    margin-bottom: 8px;
  }

  .start-bank-container {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    max-width: none;
    margin-bottom: 16px;
  }

  .start-bank-container label {
    font-size: 0.9rem;
  }

  #startBank {
    padding: 10px 12px;
    font-size: 1.1rem;
  }

  button#clearBtn {
    padding: 10px 16px;
    font-size: 1.1rem;
  }

  /* Two column grid on mobile */
  form#money-form {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px 10px;
  }

  h2 {
    font-size: 1rem;
    margin: 16px 0 8px 0;
  }

  label {
    font-size: 0.8rem;
    margin-bottom: 6px;
  }

  input[type="number"] {
    padding: 10px 12px;
    font-size: 1.1rem;
  }

  .totals {
    flex-direction: column;
    gap: 8px;
    font-size: 1.1rem;
    padding: 16px 0;
  }

  .totals .deposit {
    margin-left: 0;
  }

  /* Side panel becomes bottom panel on mobile */
  .side-panel {
    width: 100%;
    border-left: none;
    border-top: 2px solid #333;
    border-radius: 0 0 8px 8px;
    padding: 16px;
    order: 2;
    min-height: 200px;
    max-height: 300px;
  }

  .side-panel h3 {
    font-size: 1.1rem;
    text-align: center;
  }

  #breakdownList li {
    padding: 6px 0;
    font-size: 0.85rem;
  }

  #breakdownSum {
    font-size: 1.1rem !important;
    padding-top: 8px !important;
  }

  /* Adjust toast for mobile */
  #toast {
    min-width: calc(100% - 40px);
    max-width: calc(100% - 40px);
    left: 20px;
    right: 20px;
    transform: none;
    font-size: 0.9rem;
    padding: 12px;
  }

  /* Button adjustments for mobile */
  #helpBtn {
    width: 44px;
    height: 44px;
    font-size: 20px;
    bottom: 75px;
    right: 15px;
  }

  #historyBtn {
    width: 44px;
    height: 44px;
    font-size: 16px;
    bottom: 15px;
    right: 15px;
  }

  /* Help modal adjustments */
  #helpModal,
  #historyModal {
    padding: 15px;
  }

  #helpModal > div,
  #historyModal > div {
    padding: 1.5rem;
    font-size: 0.9rem;
  }
}

@media (max-width: 480px) {
  .main-content {
    padding: 8px 12px;
  }

  h1 {
    font-size: 1.2rem;
  }

  /* Single column on very small screens */
  form#money-form {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .totals {
    font-size: 1rem;
  }

  .side-panel {
    padding: 12px;
  }
}

/* Landscape orientation on mobile */
@media (max-height: 600px) and (orientation: landscape) {
  .calculator {
    flex-direction: row;
  }

  .side-panel {
    width: 280px;
    border-left: 2px solid #333;
    border-top: none;
    border-radius: 0 8px 8px 0;
    order: initial;
    min-height: auto;
    max-height: none;
  }

  form#money-form {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .main-content {
    overflow-y: auto;
  }
}
