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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #f5f7fa;
  color: #1e293b;
  line-height: 1.6;
}

header {
  background: #1e3a5f;
  color: white;
  padding: 24px 16px;
}

.header-content {
  max-width: 1100px;
  margin: 0 auto;
}

.header-content h1 {
  font-size: 28px;
  font-weight: 700;
}

.subtitle {
  font-size: 14px;
  opacity: 0.8;
  margin-top: 2px;
}

.header-summary {
  max-width: 1100px;
  margin: 16px auto 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.summary-card {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
}

.summary-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.8;
}

.summary-value {
  font-size: 22px;
  font-weight: 700;
  margin-top: 4px;
}

.summary-value.income { color: #4ade80; }
.summary-value.expense { color: #f87171; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

section {
  background: white;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

section h2 {
  font-size: 16px;
  font-weight: 600;
  color: #1e3a5f;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid #e2e8f0;
}

.row-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.row-split section {
  margin-bottom: 0;
}

.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid #e2e8f0;
  margin-bottom: 14px;
}

.tab-btn {
  background: transparent;
  border: none;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.2s;
}

.tab-btn:hover {
  color: #1e3a5f;
}

.tab-btn.active {
  color: #1e3a5f;
  border-bottom-color: #1e3a5f;
}

.tab-panel.hidden {
  display: none;
}

.initial-balance-section {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.initial-balance-section label {
  font-weight: 600;
  font-size: 14px;
}

.initial-balance-section input {
  width: 180px;
}

.period-display {
  font-size: 13px;
  color: #475569;
  background: #f1f5f9;
  padding: 6px 12px;
  border-radius: 6px;
}

.close-book-hint {
  font-size: 13px;
  color: #64748b;
  margin-bottom: 12px;
}

.closed-periods-section {
  padding-bottom: 20px;
}

.closed-periods-section h3 {
  font-size: 14px;
  font-weight: 600;
  color: #1e3a5f;
  margin: 16px 0 12px;
  padding-top: 12px;
  border-top: 2px solid #e2e8f0;
}

#closedPeriodsList {
  list-style: none;
  padding: 0;
  margin: 0;
}

.closed-period-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  margin-bottom: 8px;
  background: #f8fafc;
}

.btn-view-period {
  background: transparent;
  border: none;
  color: #1e3a5f;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  padding: 0;
}

.btn-view-period:hover {
  text-decoration: underline;
}

.closed-period-meta {
  font-size: 13px;
  color: #64748b;
  white-space: nowrap;
}

.archive-section {
  margin-top: 8px;
}

.archive-section table {
  background: #fff;
  border: 1px solid #e2e8f0;
}

.archive-section tbody td {
  background: #f8fafc;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.form-row:last-child {
  margin-bottom: 0;
}

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

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 4px;
}

.form-action {
  justify-content: flex-end;
}

.filter-action {
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
}

input, select, button {
  font-family: inherit;
  font-size: 14px;
}

input, select {
  padding: 8px 12px;
  border: 1.5px solid #cbd5e1;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.2s;
  background: white;
}

input:focus, select:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.radio-group {
  display: flex;
  gap: 16px;
  padding: 8px 0;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 14px;
}

.radio-income { color: #16a34a; font-weight: 600; }
.radio-expense { color: #dc2626; font-weight: 600; }

.btn {
  padding: 8px 18px;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  font-size: 14px;
}

.btn:hover { opacity: 0.9; }
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: #1e3a5f;
  color: white;
}

.btn-secondary {
  background: #3b82f6;
  color: white;
}

.btn-cancel {
  background: #e2e8f0;
  color: #475569;
}

.btn-export {
  background: #16a34a;
  color: white;
}

.btn-danger-small {
  background: transparent;
  border: 1.5px solid #fca5a5;
  color: #dc2626;
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 4px;
}

.btn-edit-small {
  background: transparent;
  border: 1.5px solid #93c5fd;
  color: #2563eb;
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 4px;
}

.hidden { display: none !important; }

.filter-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.export-section {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 20px;
}

.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  background: #f1f5f9;
  color: #475569;
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

tbody tr:hover {
  background: #f8fafc;
}

tbody tr.row-income {
  background: #dcfce7;
}

tbody tr.row-income:hover {
  background: #bbf7d0;
}

.text-income {
  color: #16a34a;
  font-weight: 600;
}

.text-expense {
  color: #dc2626;
  font-weight: 600;
}

.text-negative {
  color: #dc2626 !important;
  font-weight: 700 !important;
}

.text-positive {
  color: #16a34a;
  font-weight: 600;
}

.amount-col {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.empty-message {
  text-align: center;
  color: #94a3b8;
  padding: 32px 0;
  font-size: 15px;
}

footer {
  text-align: center;
  padding: 20px;
  color: #94a3b8;
  font-size: 13px;
}

@media (max-width: 768px) {
  .form-row {
    grid-template-columns: 1fr;
  }

  .row-split {
    grid-template-columns: 1fr;
  }

  .header-summary {
    grid-template-columns: 1fr;
  }

  .filter-row {
    flex-direction: column;
  }

  table {
    font-size: 13px;
  }

  thead th, tbody td {
    padding: 8px;
  }
}
