:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-soft: #f7faf9;
  --surface-strong: #eef4ff;
  --text: #101828;
  --muted: #667085;
  --line: #d9e2ec;
  --green: #16855c;
  --green-soft: #def7ec;
  --blue: #2563eb;
  --blue-soft: #e8efff;
  --amber: #b7791f;
  --amber-soft: #fff3d6;
  --red: #d64545;
  --red-soft: #ffe7e7;
  --violet: #6d5dfc;
  --violet-soft: #eeeafe;
  --shadow: 0 18px 50px rgba(32, 48, 67, 0.1);
  --shadow-soft: 0 8px 22px rgba(32, 48, 67, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(37, 99, 235, 0.08), rgba(22, 133, 92, 0.04) 320px, transparent 760px),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 42px;
}

.app-shell.is-locked {
  display: none;
}

.auth-shell {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 28px 16px;
}

.auth-shell.is-visible {
  display: flex;
}

.auth-card {
  width: min(460px, 100%);
  display: grid;
  gap: 16px;
  padding: 22px;
  border: 1px solid rgba(217, 226, 236, 0.95);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.auth-brand {
  display: grid;
  gap: 8px;
}

.auth-brand h1 {
  font-size: clamp(2rem, 7vw, 3rem);
}

.auth-brand p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.5;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.auth-tab {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 820;
}

.auth-tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

.auth-form {
  display: none;
  gap: 12px;
}

.auth-form.is-active {
  display: grid;
}

.auth-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 760;
}

.auth-form input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.auth-form input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.13);
}

.auth-submit {
  width: 100%;
}

.auth-message {
  min-height: 40px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.88rem;
}

.auth-message.is-success {
  background: var(--green-soft);
  color: var(--green);
}

.auth-message.is-error {
  background: var(--red-soft);
  color: var(--red);
}

.auth-message.is-info {
  background: var(--blue-soft);
  color: var(--blue);
}

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

.topbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2.15rem, 4vw, 3.55rem);
  line-height: 0.98;
  letter-spacing: 0;
}

h2 {
  font-size: 1.22rem;
  letter-spacing: 0;
}

h3 {
  font-size: 1rem;
  letter-spacing: 0;
}

.today-card,
.sync-chip,
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 0 13px;
  border: 1px solid rgba(217, 226, 236, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  box-shadow: var(--shadow-soft);
  white-space: nowrap;
}

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

.user-chip {
  max-width: 210px;
  color: var(--blue);
  background: var(--blue-soft);
}

.user-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sync-chip.is-online {
  background: var(--green-soft);
  border-color: rgba(22, 133, 92, 0.22);
  color: var(--green);
}

.sync-chip.is-busy {
  background: var(--blue-soft);
  border-color: rgba(37, 99, 235, 0.2);
  color: var(--blue);
}

.sync-chip.is-error {
  background: var(--red-soft);
  border-color: rgba(214, 69, 69, 0.2);
  color: var(--red);
}

.today-card svg,
.sync-chip svg,
.user-chip svg {
  width: 17px;
  height: 17px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 118px;
  padding: 18px;
  overflow: hidden;
  border: 1px solid rgba(217, 226, 236, 0.95);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.metric::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 3px;
  background: var(--green);
}

.metric-progress::after {
  background: var(--blue);
}

.metric-balance::after {
  background: var(--amber);
}

.metric-icon {
  display: grid;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
}

.metric-icon svg {
  width: 24px;
  height: 24px;
}

.metric-done .metric-icon {
  background: var(--green-soft);
  color: var(--green);
}

.metric-progress .metric-icon {
  background: var(--blue-soft);
  color: var(--blue);
}

.metric-balance .metric-icon {
  background: var(--amber-soft);
  color: var(--amber);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(1.36rem, 2.15vw, 2rem);
  line-height: 1.05;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  padding: 6px;
  border: 1px solid rgba(217, 226, 236, 0.95);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: var(--shadow-soft);
  margin-bottom: 16px;
}

.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 780;
}

.tab svg {
  width: 18px;
  height: 18px;
}

.tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 9px 24px rgba(32, 48, 67, 0.1);
}

.panel {
  display: none;
  overflow: hidden;
  border: 1px solid rgba(217, 226, 236, 0.95);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.panel.is-active {
  display: block;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff, var(--surface-soft));
}

.panel-head p {
  margin-top: 6px;
  max-width: 680px;
  color: var(--muted);
  line-height: 1.5;
}

.finance-summary,
.admin-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.finance-summary span,
.admin-summary span {
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.finance-summary strong,
.admin-summary strong {
  color: var(--text);
}

.entry-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.entry-form label,
.admin-form label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 760;
}

.entry-form input,
.entry-form select,
.admin-form input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  outline: none;
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease,
    background 140ms ease;
}

.entry-form input:focus,
.entry-form select:focus,
.admin-form input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.13);
}

.entry-form input[type="range"] {
  padding: 0;
  border: 0;
  min-height: 22px;
  accent-color: var(--green);
}

.field-note,
.range-readout {
  color: var(--muted);
  font-size: 0.8rem;
}

.finance-type-field {
  align-self: stretch;
}

.type-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 44px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.type-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-weight: 820;
}

.type-toggle-btn svg {
  width: 17px;
  height: 17px;
}

.type-toggle-btn.is-active[data-finance-type="income"] {
  background: var(--green-soft);
  color: var(--green);
}

.type-toggle-btn.is-active[data-finance-type="expense"] {
  background: var(--red-soft);
  color: var(--red);
}

.category-add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
}

.category-add-row input {
  min-height: 38px;
}

.primary-btn,
.secondary-btn,
.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border-radius: 6px;
  padding: 0 16px;
  font-weight: 820;
  text-decoration: none;
  white-space: nowrap;
}

.primary-btn {
  align-self: end;
  border: 0;
  background: var(--green);
  color: #fff;
  box-shadow: 0 10px 22px rgba(22, 133, 92, 0.22);
}

.primary-btn:hover {
  background: #106f4b;
}

.secondary-btn,
.file-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.secondary-btn:hover,
.file-btn:hover {
  border-color: rgba(37, 99, 235, 0.34);
  color: var(--blue);
}

.primary-btn svg,
.secondary-btn svg,
.file-btn svg {
  width: 18px;
  height: 18px;
}

.compact-btn {
  min-height: 42px;
}

.mini-btn {
  min-height: 38px;
  padding: 0 11px;
}

.file-btn input {
  display: none;
}

.danger-file-btn:hover {
  border-color: rgba(214, 69, 69, 0.45);
  color: var(--red);
}

.list {
  display: grid;
  gap: 10px;
  padding: 18px 20px 20px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 170px;
  border: 1px dashed #c4d0dc;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  text-align: center;
  padding: 20px;
}

.item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left-width: 5px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 6px 18px rgba(32, 48, 67, 0.04);
}

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

.item-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 820;
}

.item-title span {
  overflow-wrap: anywhere;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.86rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: #25324a;
  font-weight: 760;
}

.priority-high {
  border-left-color: var(--red);
}

.priority-high .priority-pill {
  background: var(--red-soft);
  color: var(--red);
}

.priority-medium {
  border-left-color: var(--amber);
}

.priority-medium .priority-pill {
  background: var(--amber-soft);
  color: var(--amber);
}

.priority-low {
  border-left-color: var(--green);
}

.priority-low .priority-pill {
  background: var(--green-soft);
  color: var(--green);
}

.task-check {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  accent-color: var(--green);
}

.item.is-complete .item-title span {
  color: var(--muted);
  text-decoration: line-through;
}

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

.icon-btn {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
}

.icon-btn:hover {
  border-color: rgba(214, 69, 69, 0.4);
  color: var(--red);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.goal-progress-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 760;
}

.goal-progress-row strong {
  color: var(--text);
}

.progress-shell {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5edf4;
  margin-top: 10px;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--blue));
}

.goal-subtasks {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.subtask-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 720;
}

.subtask-check-wrap {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.subtask-check-wrap span {
  overflow-wrap: anywhere;
}

.subtask-row.is-complete .subtask-check-wrap span {
  color: var(--muted);
  text-decoration: line-through;
}

.subtask-delete {
  width: 30px;
  height: 30px;
}

.subtask-delete svg {
  width: 16px;
  height: 16px;
}

.goal-empty-tasks {
  padding: 10px 12px;
  border: 1px dashed #c4d0dc;
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.86rem;
}

.goal-task-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
  margin-top: 10px;
}

.goal-task-form input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 11px;
  outline: none;
}

.goal-task-form input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.13);
}

.money-income {
  border-left-color: var(--green);
}

.money-expense {
  border-left-color: var(--red);
}

.amount-income {
  color: var(--green);
}

.amount-expense {
  color: var(--red);
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1.2fr) minmax(260px, 0.9fr);
  gap: 14px;
  padding: 18px 20px 20px;
}

.admin-card {
  display: grid;
  gap: 14px;
  align-content: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
  box-shadow: var(--shadow-soft);
}

.admin-card:first-child {
  grid-row: span 2;
}

.superadmin-grid {
  grid-template-columns: minmax(260px, 0.72fr) minmax(360px, 1.28fr);
}

.superadmin-grid .admin-card:first-child {
  grid-row: auto;
}

.users-card {
  min-width: 0;
}

.users-list {
  display: grid;
  gap: 10px;
  max-height: 520px;
  overflow: auto;
  padding-right: 2px;
}

.user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.user-row-main {
  min-width: 0;
}

.user-row-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-weight: 820;
}

.user-row-title span:first-child {
  overflow-wrap: anywhere;
}

.user-row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

.user-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.small-select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 8px;
}

.status-active {
  background: var(--green-soft);
  color: var(--green);
}

.status-blocked {
  background: var(--red-soft);
  color: var(--red);
}

.role-superadmin {
  background: var(--violet-soft);
  color: var(--violet);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 9px;
}

.section-title svg {
  width: 20px;
  height: 20px;
  color: var(--violet);
}

.toggle-row {
  display: flex !important;
  grid-template-columns: auto 1fr;
  align-items: center;
  flex-direction: row;
  gap: 10px !important;
  color: var(--text) !important;
}

.toggle-row input {
  width: 19px;
  min-height: 19px;
  accent-color: var(--green);
}

.button-row,
.sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.admin-stats {
  display: grid;
  gap: 8px;
}

.admin-stats span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--muted);
}

.admin-stats strong {
  color: var(--text);
}

.status-message {
  min-height: 40px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.status-message.is-success {
  background: var(--green-soft);
  color: var(--green);
}

.status-message.is-error {
  background: var(--red-soft);
  color: var(--red);
}

.status-message.is-info {
  background: var(--blue-soft);
  color: var(--blue);
}

@media (max-width: 940px) {
  .metrics,
  .entry-form,
  .admin-grid {
    grid-template-columns: 1fr 1fr;
  }

  .primary-btn {
    grid-column: 1 / -1;
  }

  .admin-card:first-child {
    grid-row: auto;
    grid-column: 1 / -1;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 16px;
  }

  .topbar,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .finance-summary,
  .admin-summary {
    justify-content: stretch;
  }

  .today-card,
  .sync-chip,
  .user-chip,
  .finance-summary span,
  .admin-summary span {
    justify-content: center;
    width: 100%;
  }

  .metrics,
  .entry-form,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .tabs {
    display: flex;
    overflow-x: auto;
  }

  .tab {
    min-width: 118px;
    flex: 0 0 auto;
  }

  .item {
    grid-template-columns: 1fr;
  }

  .actions {
    justify-content: flex-end;
  }

  .button-row,
  .sync-actions,
  .user-actions {
    flex-direction: column;
  }

  .secondary-btn,
  .file-btn,
  .small-select {
    width: 100%;
  }

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