* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  background: #f5f6f8;
  color: #1f2937;
  -webkit-font-smoothing: antialiased;
}

.screen {
  min-height: 100vh;
}
.hidden {
  display: none !important;
}

/* Auth screens */
#setup-screen,
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#setup-screen.hidden,
#login-screen.hidden {
  display: none !important;
}

.card {
  background: #fff;
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  margin-bottom: 16px;
  max-width: 520px;
  width: 100%;
}

h1 {
  font-size: 22px;
  margin-bottom: 12px;
}
h2 {
  font-size: 15px;
  margin-bottom: 12px;
  color: #4b5563;
  font-weight: 600;
}
.hint {
  color: #6b7280;
  font-size: 14px;
  margin-bottom: 16px;
  line-height: 1.5;
}
.error {
  color: #dc2626;
  font-size: 13px;
  margin-top: 8px;
  min-height: 18px;
}

input,
textarea,
select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  margin-bottom: 12px;
  background: #fff;
  color: inherit;
  transition: border-color 0.15s;
}
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #3b82f6;
}
select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
.field-label {
  display: block;
  font-size: 13px;
  color: #6b7280;
  font-weight: 500;
  margin-bottom: 6px;
}
.field-label + input,
.field-label + select,
.field-label + textarea {
  margin-top: 0;
}
textarea {
  min-height: 72px;
  resize: vertical;
}
.note-counter {
  font-size: 12px;
  color: #9ca3af;
  text-align: right;
  margin-top: -8px;
  margin-bottom: 12px;
}

button {
  cursor: pointer;
  border: none;
  font-size: 15px;
  font-family: inherit;
}
.primary {
  width: 100%;
  background: #3b82f6;
  color: #fff;
  padding: 12px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 16px;
  transition: background 0.15s;
}
.primary:hover {
  background: #2563eb;
}
.secondary {
  width: 100%;
  background: #f3f4f6;
  color: #374151;
  padding: 12px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 16px;
  transition: background 0.15s;
}
.secondary:hover {
  background: #e5e7eb;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.modal-actions .primary,
.modal-actions .secondary {
  width: auto;
  flex: 1;
}
.modal-actions .primary {
  flex: 1.4;
}
.ghost {
  background: transparent;
  color: #6b7280;
  padding: 8px 12px;
  border-radius: 8px;
  transition: background 0.15s;
}
.ghost:hover {
  background: #f3f4f6;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #4b5563;
  margin-bottom: 12px;
  user-select: none;
  cursor: pointer;
}
.checkbox-row input {
  width: auto;
  margin: 0;
}

/* App layout */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: #fff;
  border-bottom: 1px solid #eef0f3;
}
.app-header h1 {
  font-size: 18px;
  margin: 0;
}
.app-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 10px;
  background: transparent;
  color: #6b7280;
  font-size: 24px;
  line-height: 1;
  font-weight: 300;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover {
  background: #f3f4f6;
  color: #374151;
}
.icon-btn svg {
  flex-shrink: 0;
}

.tabs {
  display: flex;
  background: #fff;
  border-bottom: 1px solid #eef0f3;
  position: sticky;
  top: 0;
  z-index: 10;
}
.tab {
  flex: 1;
  background: transparent;
  padding: 14px;
  color: #6b7280;
  border-bottom: 2px solid transparent;
  font-weight: 500;
  font-size: 15px;
  transition: color 0.15s, border-color 0.15s;
}
.tab.active {
  color: #3b82f6;
  border-bottom-color: #3b82f6;
}

.tab-panel {
  display: none;
  padding: 16px;
  max-width: 640px;
  margin: 0 auto;
}
.tab-panel.active {
  display: block;
}

/* Type toggle */
.type-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #f3f4f6;
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 12px;
}
.type-btn {
  background: transparent;
  padding: 10px;
  border-radius: 8px;
  color: #6b7280;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}
.type-btn.active[data-type="expense"] {
  background: #fef2f2;
  color: #dc2626;
}
.type-btn.active[data-type="income"] {
  background: #ecfdf5;
  color: #059669;
}

/* Record list */
.record-list {
  list-style: none;
}
.record-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid #f3f4f6;
  gap: 12px;
}
.record-item:last-child {
  border-bottom: none;
}
.record-info {
  flex: 1;
  min-width: 0;
}
.record-note {
  font-size: 14px;
  color: #1f2937;
  word-break: break-word;
  line-height: 1.4;
}
.record-note.muted {
  color: #9ca3af;
  font-style: italic;
}
.record-meta {
  font-size: 12px;
  color: #9ca3af;
  margin-top: 4px;
}
.record-amount {
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  align-self: center;
}
.record-amount.income {
  color: #059669;
}
.record-amount.expense {
  color: #dc2626;
}
.record-actions {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-self: center;
  flex-shrink: 0;
}
.record-edit,
.record-delete {
  background: transparent;
  color: #cbd1d8;
  font-size: 12px;
  padding: 4px 6px;
}
.record-edit:hover {
  color: #3b82f6;
}
.record-delete:hover {
  color: #dc2626;
}

/* Edit modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
#settings-modal {
  z-index: 101;
}
.modal.hidden {
  display: none !important;
}
@media (min-width: 480px) {
  .modal {
    align-items: center;
    padding: 16px;
  }
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}
.modal-panel {
  position: relative;
  z-index: 1;
  max-width: 520px;
  width: 100%;
  max-height: min(90vh, 620px);
  overflow-y: auto;
  margin: 0;
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
}
@media (min-width: 480px) {
  .modal-panel {
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  }
}

.settings-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}
.settings-modal-head h2 {
  margin: 0;
}
.settings-section-title {
  font-size: 14px;
  font-weight: 600;
  color: #4b5563;
  margin: 12px 0 8px;
}
.settings-modal-panel .hint {
  margin-bottom: 12px;
}

.operators-manage-list {
  list-style: none;
  margin-bottom: 4px;
}
.operators-manage-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #f3f4f6;
  font-size: 15px;
}
.operators-manage-list li:last-child {
  border-bottom: none;
}
.operators-manage-list .empty {
  padding: 12px 0;
  text-align: center;
  border: none;
}
.operator-remove {
  background: transparent;
  color: #9ca3af;
  font-size: 13px;
  padding: 6px 10px;
  flex-shrink: 0;
}
.operator-remove:hover {
  color: #dc2626;
}
.operator-add-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin-top: 4px;
}
.operator-add-row input {
  flex: 1;
  margin-bottom: 0;
}
.btn-inline {
  width: auto;
  flex: 0 0 auto;
  min-width: 88px;
  padding-left: 16px;
  padding-right: 16px;
}

.empty {
  color: #9ca3af;
  text-align: center;
  padding: 20px 0;
  font-size: 14px;
}

/* Summary */
.period-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  background: #f3f4f6;
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 12px;
}
.period-btn {
  background: transparent;
  padding: 9px;
  border-radius: 8px;
  color: #6b7280;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}
.period-btn.active {
  background: #fff;
  color: #3b82f6;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.period-picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}
.period-picker-row .period-input {
  flex: 1;
  margin-bottom: 0;
}
.period-picker-row .ghost {
  font-size: 22px;
  line-height: 1;
  padding: 6px 12px;
}

.year-breakdown {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.year-breakdown th,
.year-breakdown td {
  padding: 10px 8px;
  border-bottom: 1px solid #f3f4f6;
}
.year-breakdown th {
  font-weight: 600;
  color: #6b7280;
  font-size: 13px;
  text-align: left;
}
.year-breakdown tr:last-child td {
  border-bottom: none;
}
.year-breakdown .right {
  text-align: right;
}
.year-breakdown .income-text {
  color: #059669;
}
.year-breakdown .expense-text {
  color: #dc2626;
}

.summary-numbers {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.num-block {
  text-align: center;
  padding: 14px 6px;
  border-radius: 10px;
  background: #f9fafb;
}
.num-label {
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 6px;
}
.num-value {
  font-size: 18px;
  font-weight: 700;
}
.num-block.income .num-value {
  color: #059669;
}
.num-block.expense .num-value {
  color: #dc2626;
}
.num-block.balance .num-value {
  color: #1f2937;
}

@media (max-width: 380px) {
  .num-value {
    font-size: 15px;
  }
}
