*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #f4f6f8;
  color: #1a1a2e;
  line-height: 1.5;
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
}

h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

h3 {
  margin: 0 0 1rem;
  font-size: 1rem;
}

.subtitle {
  margin: 0 0 1.5rem;
  color: #5c6370;
  font-size: 0.95rem;
}

.card {
  background: #fff;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.settings-card {
  margin-bottom: 1.5rem;
}

.import-card {
  margin-bottom: 1.5rem;
}

.import-card textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  font-size: 0.85rem;
  font-family: ui-monospace, monospace;
  margin-bottom: 1rem;
  resize: vertical;
  background: #fff;
}

.import-card input[type="file"] {
  width: 100%;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.import-template {
  margin-bottom: 1rem;
}

.import-template summary {
  cursor: pointer;
  color: #3b6fd9;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.import-template pre {
  margin: 0.5rem 0;
  padding: 0.75rem;
  background: #f8f9fb;
  border-radius: 8px;
  font-size: 0.8rem;
  overflow-x: auto;
}

.import-template-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.import-download-link {
  display: inline-block;
  text-decoration: none;
  text-align: center;
}

.import-errors {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: #fdf0ef;
  border-radius: 8px;
  font-size: 0.85rem;
}

.import-errors ul {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
}

.import-card .btn-primary {
  width: 100%;
}

.ical-card {
  margin-bottom: 1.5rem;
}

.card-hint {
  margin: -0.5rem 0 1rem;
  color: #5c6370;
  font-size: 0.9rem;
}

.ical-url-row input[type="text"] {
  flex: 1;
  margin-bottom: 0;
  font-size: 0.85rem;
}

.ical-url-row button {
  flex-shrink: 0;
  white-space: nowrap;
}

label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 500;
  font-size: 0.9rem;
}

input[type="password"],
input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 1rem;
  background: #fff;
}

input:focus,
select:focus {
  outline: 2px solid #3b6fd9;
  outline-offset: 1px;
  border-color: #3b6fd9;
}

button {
  cursor: pointer;
  font-size: 0.95rem;
  border-radius: 8px;
  border: none;
  padding: 0.65rem 1rem;
}

.btn-primary {
  background: #3b6fd9;
  color: #fff;
  font-weight: 500;
}

.btn-primary:hover {
  background: #2f5bb5;
}

.btn-secondary {
  background: transparent;
  color: #3b6fd9;
  border: 1px solid #3b6fd9;
  font-weight: 500;
}

.btn-secondary:hover {
  background: #eef3fc;
}

.btn-danger {
  background: transparent;
  color: #c0392b;
  border: 1px solid #e8b4b0;
  font-weight: 500;
}

.btn-danger:hover {
  background: #fdf0ef;
}

button[type="submit"]:not(.btn-secondary):not(.btn-danger) {
  width: 100%;
}

.error {
  margin-top: 0.75rem;
  color: #c0392b;
  font-size: 0.9rem;
}

.success {
  margin-top: 0.75rem;
  color: #1e7e34;
  font-size: 0.9rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.panel-header h1 {
  margin: 0;
}

#logout-btn {
  background: transparent;
  color: #5c6370;
  border: 1px solid #d0d5dd;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

#logout-btn:hover {
  background: #f0f2f5;
  color: #1a1a2e;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 0.75rem;
}

.section-header h2 {
  margin: 0;
}

.section-header .btn-primary {
  padding: 0.5rem 0.85rem;
  font-size: 0.85rem;
  white-space: nowrap;
}

.inline-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.inline-field input {
  width: 5rem;
  margin-bottom: 0;
}

.field-hint {
  color: #5c6370;
  font-size: 0.9rem;
}

.payments-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.completions-card {
  margin-bottom: 1.5rem;
}

.completions-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.completions-list li {
  font-size: 0.85rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid #eef0f3;
}

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

.completions-list .completion-source {
  color: #5c6370;
  font-size: 0.8rem;
}

.payment-item.paid {
  opacity: 0.75;
  background: #f8faf8;
}

.paid-badge {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: #e8f5e9;
  color: #2e7d32;
  white-space: nowrap;
}

.btn-paid {
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #c8e6c9;
  font-weight: 500;
}

.btn-paid:hover {
  background: #dcedc8;
}

.payment-item {
  padding: 1.25rem;
}

.payment-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.payment-badges {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.payment-item-header h3 {
  margin: 0;
  font-size: 1rem;
}

.type-badge {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: #eef3fc;
  color: #3b6fd9;
  white-space: nowrap;
}

.badge {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  background: #fff3cd;
  color: #856404;
}

.payment-amount {
  margin: 0 0 0.75rem;
  font-weight: 600;
  font-size: 1.05rem;
}

.payment-dates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 1rem;
  margin: 0 0 1rem;
  font-size: 0.85rem;
}

.payment-dates > div:last-child {
  grid-column: 1 / -1;
}

.payment-dates dt {
  color: #5c6370;
  font-weight: 400;
  margin: 0;
}

.payment-dates dd {
  margin: 0.15rem 0 0;
  font-weight: 500;
}

.payment-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.payment-actions button {
  flex: 1 1 auto;
  min-width: 5.5rem;
  padding: 0.5rem;
  font-size: 0.85rem;
}

.empty-state {
  text-align: center;
  color: #5c6370;
  font-size: 0.95rem;
  padding: 2rem 1rem;
  border: 1px dashed #d0d5dd;
  border-radius: 8px;
}

dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  max-width: calc(100vw - 2rem);
  width: 420px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

dialog form {
  padding: 1.5rem;
}

.dialog-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.dialog-actions button {
  flex: 1;
}

[hidden] {
  display: none !important;
}

@media (max-width: 400px) {
  .payment-dates {
    grid-template-columns: 1fr;
  }

  .payment-dates > div:last-child {
    grid-column: auto;
  }
}
