:root {
  --bg: #0f1420;
  --card: #1a2233;
  --card-2: #212c42;
  --border: #2c3750;
  --text: #eef1f8;
  --text-dim: #93a0bd;
  --accent: #4f7cff;
  --green: #2fbf85;
  --red: #ef5350;
  --orange: #f5a623;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(76px + var(--safe-bottom));
}

header.topbar {
  padding: calc(14px + var(--safe-top)) 18px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  border-bottom: 1px solid var(--border);
}

header.topbar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 700;
}

header.topbar .sub {
  font-size: 12px;
  color: var(--text-dim);
}

.icon-btn {
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
}

main {
  flex: 1;
  padding: 16px 16px 8px;
}

.view { display: none; }
.view.active { display: block; animation: fadeIn .15s ease-out; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Dashboard summary cards */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.summary-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.summary-card .label {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.summary-card .value {
  font-size: 20px;
  font-weight: 700;
}

.summary-card.wide { grid-column: 1 / -1; }
.summary-card.danger .value { color: var(--red); }
.summary-card.ok .value { color: var(--green); }
.summary-card.accent .value { color: var(--accent); }

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
  margin: 22px 0 10px;
}

.section-title:first-child { margin-top: 0; }

.empty-state {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 24px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* Item cards (borç / ödeme kalemi) */
.item-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.item-card.overdue { border-color: var(--red); background: linear-gradient(0deg, rgba(239,83,80,.08), rgba(239,83,80,.08)), var(--card); }
.item-card.due-soon { border-color: var(--orange); }

.item-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.item-name { font-weight: 700; font-size: 15px; }
.item-tag {
  font-size: 10px;
  color: var(--text-dim);
  background: var(--card-2);
  border-radius: 6px;
  padding: 2px 6px;
  display: inline-block;
  margin-top: 4px;
}

.item-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  white-space: nowrap;
}
.item-badge.overdue { background: rgba(239,83,80,.18); color: var(--red); }
.item-badge.due-soon { background: rgba(245,166,35,.18); color: var(--orange); }
.item-badge.ok { background: rgba(47,191,133,.15); color: var(--green); }

.item-rows {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}

.item-row .k { font-size: 11px; color: var(--text-dim); }
.item-row .v { font-size: 14px; font-weight: 600; }

.progress-bar {
  height: 6px;
  border-radius: 4px;
  background: var(--card-2);
  overflow: hidden;
  margin-top: 10px;
}
.progress-bar > div {
  height: 100%;
  background: var(--accent);
}

.item-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: white; flex: 1; }
.btn-ghost { background: var(--card-2); color: var(--text); border: 1px solid var(--border); }
.btn-danger-ghost { background: var(--card-2); color: var(--red); border: 1px solid var(--border); }
.btn-full { width: 100%; }
.btn-lg { padding: 13px; font-size: 15px; }

/* Bottom nav */
nav.bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
  max-width: 560px;
  margin: 0 auto;
  z-index: 20;
}

nav.bottomnav button {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 11px;
  padding: 10px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}
nav.bottomnav button .ic { font-size: 19px; }
nav.bottomnav button.active { color: var(--accent); }

/* FAB */
.fab {
  position: fixed;
  right: calc(50% - 264px);
  bottom: calc(84px + var(--safe-bottom));
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(79,124,255,.4);
  z-index: 20;
  cursor: pointer;
}
@media (max-width: 559px) {
  .fab { right: 18px; }
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: none;
  align-items: flex-end;
  z-index: 100;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--bg);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  max-height: 92vh;
  overflow-y: auto;
  padding: 18px 18px calc(24px + var(--safe-bottom));
  border-top: 1px solid var(--border);
}

.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  margin: 0 auto 14px;
}

.modal h2 { font-size: 17px; margin: 0 0 16px; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  font-family: inherit;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.type-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.type-tabs button {
  flex: 1;
  min-width: 30%;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 10px;
  padding: 9px 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.type-tabs button.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

/* Onboarding / household screen */
.onboard {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
  max-width: 480px;
  margin: 0 auto;
}
.onboard h1 { font-size: 24px; margin-bottom: 6px; }
.onboard p { color: var(--text-dim); font-size: 14px; line-height: 1.5; }
.onboard .code-display {
  background: var(--card);
  border: 1px dashed var(--accent);
  border-radius: 14px;
  padding: 18px;
  text-align: center;
  font-size: 28px;
  letter-spacing: 4px;
  font-weight: 700;
  margin: 16px 0;
}
.divider { text-align:center; color: var(--text-dim); font-size: 12px; margin: 18px 0; }

.toast {
  position: fixed;
  bottom: calc(90px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-2);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 30px;
  font-size: 13px;
  z-index: 200;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  padding: 4px;
}

.hidden { display: none !important; }
