:root {
  --primary: #0F766E;
  --primary-dark: #115E59;
  --surface: #FFFFFF;
  --bg: #F1F5F9;
  --border: #CBD5E1;
  --muted: #64748B;
  --text: #172033;
  --danger: #B91C1C;
  --blue: #1D4ED8;
  --info-bg: #ECFDF5;
  --nav-h: 64px;
  --header-h: 72px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-top: calc(var(--header-h) + var(--safe-top));
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 28px);
}

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: var(--primary-dark);
  color: #fff;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  min-height: calc(var(--header-h) + var(--safe-top));
}

.app-header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.app-header p {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.8);
}

.app-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 12px 24px;
}

.tab-panel[hidden] {
  display: none !important;
}

.section-title {
  margin: 0 0 12px;
  font-size: 1.05rem;
  color: var(--primary-dark);
}

.sub-title {
  margin: 8px 0 8px;
  font-size: 0.92rem;
  font-weight: 600;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.field span {
  font-weight: 500;
}

input[type="text"],
input[type="date"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: #fff;
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
}

textarea {
  min-height: 80px;
  resize: vertical;
}

select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 3px), calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

.info-box {
  background: var(--info-bg);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  white-space: pre-line;
}

.hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.btn {
  min-height: 48px;
  padding: 10px 14px;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  flex: 1 1 auto;
}

.btn:active {
  opacity: 0.88;
  transform: scale(0.98);
}

.btn-block {
  width: 100%;
  display: block;
  margin-top: 8px;
}

.btn-lg {
  font-size: 1.1rem;
  min-height: 52px;
}

.btn-primary { background: var(--primary); }
.btn-muted { background: var(--muted); }
.btn-danger { background: var(--danger); }
.btn-blue { background: var(--blue); }

.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.25);
}

.card-title {
  font-weight: 700;
  margin: 0 0 4px;
  font-size: 1rem;
}

.card-meta {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}

.card-amount {
  margin-top: 8px;
  font-weight: 700;
  color: var(--primary-dark);
  font-size: 1.05rem;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 24px 12px;
  font-size: 0.95rem;
}

.weekday-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.chip input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  flex-shrink: 0;
}

.chip span {
  pointer-events: none;
}

.chip:has(input:checked) {
  border-color: var(--primary);
  background: var(--info-bg);
  color: var(--primary-dark);
}

.day-count {
  font-weight: 700;
  margin: 10px 0 8px;
}

.day-count-error {
  color: var(--danger);
}

.input-error {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 2px rgba(185, 28, 28, 0.2);
}

.dates-list {
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  margin-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}

.date-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid #E2E8F0;
  min-height: 48px;
  font-size: 0.92rem;
}

.date-item:last-child {
  border-bottom: none;
}

.date-item input {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

.result-heading {
  margin: 0 0 12px;
  font-size: 1.1rem;
  color: var(--primary-dark);
}

.result-grid {
  margin: 0;
}

.result-grid > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 40px;
  border-bottom: 1px solid #E2E8F0;
  gap: 12px;
}

.result-grid dt {
  margin: 0;
  color: var(--text);
  font-size: 0.92rem;
}

.result-grid dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
  font-size: 0.95rem;
}

.total-banner {
  background: var(--primary-dark);
  color: #fff;
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  margin: 14px 0 10px;
}

.total-label {
  display: block;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.8);
  letter-spacing: 0.04em;
}

.total-tl {
  display: block;
  font-size: 1.75rem;
  font-weight: 800;
  margin-top: 6px;
}

.total-fx {
  display: block;
  font-size: 1.1rem;
  color: rgba(255, 255, 255, 0.85);
  margin-top: 6px;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: #fff;
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.06);
}

.nav-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--nav-h);
  cursor: pointer;
}

.nav-btn.active {
  color: var(--primary-dark);
  box-shadow: inset 0 3px 0 var(--primary);
}

.status-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--nav-h) + var(--safe-bottom));
  z-index: 45;
  background: #E2E8F0;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 4px 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 48px);
  transform: translateX(-50%);
  z-index: 60;
  max-width: calc(100% - 32px);
  background: #0f172a;
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.sticky-actions {
  position: sticky;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 36px);
  background: var(--bg);
  padding: 8px 0;
  z-index: 10;
}

@media (min-width: 768px) {
  .app-main {
    padding-top: 16px;
  }

  .app-header h1 {
    font-size: 1.25rem;
  }
}
