:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --text: #182033;
  --muted: #687386;
  --line: #dce2ec;
  --primary: #3559e0;
  --primary-strong: #2445c6;
  --success: #15825d;
  --danger: #b73a3a;
  --warning: #a16410;
  --shadow: 0 10px 30px rgba(24, 32, 51, .08);
  --radius: 20px;
  --radius-sm: 14px;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(53,89,224,.08), transparent 30rem),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

a {
  color: inherit;
}

.screen {
  width: min(100% - 28px, 980px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 0 max(28px, env(safe-area-inset-bottom));
}

.center-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
}

.loading-card,
.login-card {
  width: min(100%, 430px);
  background: rgba(255,255,255,.94);
  border: 1px solid rgba(220,226,236,.9);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto 12px;
  border: 4px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .85s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  font-size: 25px;
  background: linear-gradient(135deg, #172033, #3559e0);
  color: white;
}

.brand h1 {
  font-size: 1.35rem;
  line-height: 1.15;
  margin: 0;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: .92rem;
}

.field {
  display: grid;
  gap: 7px;
  margin: 14px 0;
}

.field label {
  font-weight: 700;
  font-size: .9rem;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px 13px;
  background: white;
  color: var(--text);
  outline: none;
}

.field textarea {
  resize: vertical;
  min-height: 82px;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(53,89,224,.12);
}

.btn {
  border: 0;
  border-radius: 13px;
  padding: 11px 15px;
  font-weight: 800;
  color: var(--text);
  background: var(--surface-2);
}

.btn:hover:not(:disabled) {
  filter: brightness(.985);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-strong);
}

.btn-danger {
  background: #fbe8e8;
  color: #9f2929;
}

.btn-success {
  background: #e4f6ef;
  color: #126a4d;
}

.btn-warning {
  background: #fff2dc;
  color: #8b5911;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
}

.btn-block { width: 100%; }

.helper {
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.45;
}

.error-box {
  margin: 12px 0;
  padding: 11px 13px;
  border-radius: 12px;
  background: #fbeaea;
  color: #942d2d;
  font-size: .9rem;
  display: none;
}

.error-box.show { display: block; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.topbar-left {
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.35rem, 5vw, 2rem);
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.icon-btn {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.8);
  border-radius: 12px;
  min-width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0,1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0,1fr));
}

.card {
  background: rgba(255,255,255,.94);
  border: 1px solid rgba(220,226,236,.88);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 5px 20px rgba(24, 32, 51, .055);
}

.card h2, .card h3 {
  margin-top: 0;
}

.balance-card {
  position: relative;
  overflow: hidden;
  min-height: 164px;
}

.balance-card::after {
  content: "";
  position: absolute;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  right: -45px;
  top: -45px;
  background: rgba(53,89,224,.08);
}

.balance-label {
  color: var(--muted);
  font-weight: 700;
}

.balance-number {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-top: 9px;
}

.balance-number strong {
  font-size: clamp(2.45rem, 10vw, 4.6rem);
  line-height: .95;
  letter-spacing: -0.055em;
}

.balance-number span {
  color: var(--muted);
  font-weight: 700;
}

.balance-period {
  margin-top: 12px;
  color: var(--muted);
  font-size: .9rem;
}

.section-title {
  margin: 24px 0 12px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.section-title h2 {
  margin: 0;
  font-size: 1.14rem;
}

.section-title p {
  margin: 0;
  color: var(--muted);
  font-size: .88rem;
}

.task-list {
  display: grid;
  gap: 10px;
}

.task-card {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 13px;
  align-items: center;
  background: white;
  border: 1px solid var(--line);
  border-radius: 17px;
  padding: 14px;
}

.task-card.done {
  background: #f1f8f5;
  border-color: #cce8dd;
}

.task-main {
  min-width: 0;
}

.task-title {
  font-weight: 850;
  margin: 0;
  line-height: 1.25;
}

.task-desc {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: .86rem;
}

.task-minutes {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #edf1ff;
  color: #2948bc;
  font-size: .82rem;
  font-weight: 850;
}

.task-action {
  min-width: 91px;
}

.empty-state {
  padding: 26px 18px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 17px;
  background: rgba(255,255,255,.6);
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 10px;
}

.quick-action {
  min-height: 92px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 7px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: white;
  padding: 11px;
  font-weight: 850;
}

.quick-action .emoji {
  font-size: 1.45rem;
}

.nav-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 8px;
  margin: 16px 0 6px;
  scrollbar-width: none;
}

.nav-tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  white-space: nowrap;
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 9px 14px;
  font-weight: 800;
  color: var(--muted);
}

.tab-btn.active {
  background: var(--text);
  color: white;
  border-color: var(--text);
}

.panel[hidden] { display: none !important; }

.parent-task-row,
.history-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.parent-task-row:last-child,
.history-row:last-child {
  border-bottom: 0;
}

.muted { color: var(--muted); }

.small { font-size: .84rem; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: .78rem;
  font-weight: 800;
  background: var(--surface-2);
}

.pill.inactive {
  background: #f5e9e9;
  color: #913535;
}

.history-value {
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.history-value.positive { color: var(--success); }
.history-value.negative { color: var(--danger); }

.history-actions {
  display: flex;
  gap: 7px;
  margin-top: 7px;
}

.days-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0,1fr));
  gap: 7px;
}

.day-option {
  position: relative;
}

.day-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.day-option span {
  display: grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: white;
  font-size: .82rem;
  font-weight: 800;
}

.day-option input:checked + span {
  border-color: var(--primary);
  background: #edf1ff;
  color: #2948bc;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
  background: rgba(10,15,25,.46);
  padding: 16px;
}

.modal {
  width: min(100%, 540px);
  max-height: min(88vh, 760px);
  overflow-y: auto;
  border-radius: 23px 23px 18px 18px;
  background: white;
  padding: 20px;
  box-shadow: 0 25px 70px rgba(0,0,0,.22);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.18rem;
}

.modal-actions {
  display: flex;
  gap: 9px;
  justify-content: flex-end;
  margin-top: 18px;
}

.toast-root {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(calc(100% - 28px), 470px);
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: rgba(24,32,51,.95);
  color: white;
  border-radius: 13px;
  padding: 11px 14px;
  box-shadow: var(--shadow);
  animation: toast-in .18s ease-out;
}

.toast.error { background: rgba(155,42,42,.97); }
.toast.success { background: rgba(19,109,78,.97); }

@keyframes toast-in {
  from { transform: translateY(7px); opacity: 0; }
}

.install-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 11px 13px;
  background: #edf1ff;
  color: #243f9e;
  border: 1px solid #d7e0ff;
  border-radius: 14px;
  font-size: .88rem;
}

.install-banner[hidden] { display: none; }

@media (max-width: 700px) {
  .grid-2, .grid-3 {
    grid-template-columns: 1fr;
  }

  .quick-actions {
    grid-template-columns: repeat(3, minmax(0,1fr));
  }

  .topbar {
    align-items: flex-start;
  }

  .task-card {
    grid-template-columns: minmax(0,1fr);
  }

  .task-action {
    width: 100%;
  }

  .task-action .btn {
    width: 100%;
  }
}

@media (max-width: 430px) {
  .screen {
    width: min(100% - 20px, 980px);
  }

  .card {
    padding: 15px;
    border-radius: 17px;
  }

  .quick-actions {
    grid-template-columns: 1fr;
  }

  .quick-action {
    min-height: 64px;
    grid-template-columns: auto 1fr;
    justify-items: start;
    text-align: left;
  }

  .days-grid {
    gap: 5px;
  }

  .day-option span {
    min-height: 38px;
    font-size: .75rem;
  }
}
