:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --ink: #17201d;
  --muted: #64716d;
  --line: #dfe5df;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --good: #047857;
  --bad: #b91c1c;
  --shadow: 0 14px 34px rgba(24, 39, 34, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans Bengali", "Hind Siliguri", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  line-height: 1.25;
  min-height: 42px;
  padding: 0 16px;
  touch-action: manipulation;
}

button:hover {
  background: var(--primary-dark);
}

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

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #10231f;
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
}

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

.brand-mark {
  align-items: center;
  background: #e7f8f4;
  border-radius: 8px;
  color: var(--primary-dark);
  display: grid;
  font-weight: 900;
  height: 42px;
  place-items: center;
  width: 42px;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: #a9bbb5;
  margin-top: 2px;
}

.nav {
  display: grid;
  gap: 8px;
}

.sidebar-user {
  align-items: center;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) 42px;
  margin-top: auto;
  padding-top: 16px;
}

.sidebar-user-link {
  align-items: center;
  border-radius: 8px;
  color: #ffffff;
  display: grid;
  gap: 10px;
  grid-template-columns: 42px minmax(0, 1fr);
  min-width: 0;
  text-decoration: none;
}

.sidebar-user-link:hover {
  color: #ffffff;
}

.user-avatar {
  align-items: center;
  background: #e7f8f4;
  border-radius: 8px;
  color: var(--primary-dark);
  display: grid;
  height: 42px;
  place-items: center;
  width: 42px;
}

.user-avatar svg {
  height: 20px;
  width: 20px;
}

.user-meta {
  min-width: 0;
}

.user-meta strong,
.user-meta small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-meta small {
  color: #a9bbb5;
  margin-top: 2px;
}

.sidebar-logout {
  background: #1d3a34;
  color: #ffffff;
  min-height: 42px;
  min-width: 42px;
}

.sidebar-logout:hover {
  background: #295249;
}

.nav-item {
  align-items: center;
  background: transparent;
  border-radius: 6px;
  color: #d7e4df;
  display: flex;
  font-weight: 700;
  min-height: 42px;
  padding: 0 16px;
  text-align: left;
  text-decoration: none;
  width: 100%;
}

.nav-item:hover,
.nav-item.active {
  background: #1d3a34;
  color: #fff;
}

.main {
  min-width: 0;
  padding: 28px;
}

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

.topbar-title {
  align-items: center;
  display: flex;
  gap: 12px;
  min-width: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.08;
}

h2 {
  font-size: 19px;
  margin-bottom: 16px;
}

.topbar p {
  color: var(--muted);
  line-height: 1.22;
  margin-top: 0px;
}

.toolbar {
  align-items: center;
  display: flex;
  gap: 10px;
}

.icon-button {
  align-items: center;
  display: inline-flex;
  font-size: 20px;
  justify-content: center;
  min-width: 44px;
  padding: 0;
}

.ghost-icon-button {
  background: #eef5f3;
  color: var(--primary-dark);
}

.ghost-icon-button:hover {
  background: #dcebe7;
}

.icon-button i,
.icon-button svg {
  height: 20px;
  width: 20px;
}

.sr-only {
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.menu-button {
  align-items: center;
  background: #eef5f3;
  border: 1px solid #d6e5e1;
  display: none;
  flex: 0 0 44px;
  height: 44px;
  justify-content: center;
  padding: 0;
  position: relative;
  width: 44px;
}

.menu-button:hover {
  background: #dcebe7;
}

.menu-line {
  background: var(--primary-dark);
  border-radius: 999px;
  display: block;
  height: 2px;
  position: absolute;
  width: 20px;
}

.menu-line:nth-child(1) {
  transform: translateY(-7px);
}

.menu-line:nth-child(3) {
  transform: translateY(7px);
}

.menu-overlay {
  display: none;
}

input,
select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-size: 16px;
  min-height: 42px;
  padding: 8px 10px;
  width: 100%;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 18px;
}

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

.metric span {
  color: var(--muted);
  display: block;
  font-size: 14px;
  margin-bottom: 8px;
}

.metric strong {
  display: block;
  font-size: 25px;
  line-height: 1.1;
}

.panel {
  margin-bottom: 18px;
  padding: 18px;
}

.panel-header {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.panel-header h2 {
  margin-bottom: 0;
}

#members .panel-header {
  margin-bottom: 14px;
}

.ghost-button {
  background: #eef5f3;
  color: var(--primary-dark);
}

.ghost-button:hover {
  background: #dcebe7;
}

.summary-controls {
  margin-bottom: 12px;
}

.summary-detail {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.summary-person,
.summary-line {
  align-items: center;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 12px;
}

.summary-person {
  background: #f9faf8;
}

.summary-person small {
  color: var(--muted);
  display: block;
  margin-top: 2px;
}

.summary-line:last-child {
  border-bottom: 0;
}

.summary-line span {
  color: var(--muted);
  font-weight: 800;
}

.summary-line strong {
  text-align: right;
}

.empty-state {
  color: var(--muted);
  padding: 14px;
}

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

table {
  border-collapse: collapse;
  min-width: 780px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

td {
  font-size: 14px;
}

.amount-good {
  color: var(--good);
  font-weight: 800;
}

.amount-bad {
  color: var(--bad);
  font-weight: 800;
}

.split,
.entry-grid {
  display: grid;
  gap: 18px;
}

.entry-tabs {
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0 0 14px;
  padding: 0 0 14px;
  width: min(100%, 354px);
}

.entry-tab {
  background: #eef5f3;
  border: 1px solid #d6e5e1;
  color: var(--primary-dark);
  font-size: 13px;
  min-height: 40px;
  min-width: 0;
  overflow-wrap: anywhere;
  padding: 0 8px;
  white-space: normal;
}

.entry-tab:hover,
.entry-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

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

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

.entry-grid .entry-panel {
  display: none;
}

.entry-grid .entry-panel.active {
  display: grid;
}

.form-panel,
.meal-form,
.member-form,
.login-panel {
  display: grid;
  gap: 13px;
}

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

.meal-form h2,
.meal-count-row {
  grid-column: 1 / -1;
}

.meal-count-row {
  display: grid;
  gap: 13px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  font-weight: 700;
  gap: 6px;
}

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

.check-row input {
  min-height: auto;
  width: auto;
}

.activity-list,
.member-list,
.my-stats {
  display: grid;
  gap: 10px;
}

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

.activity,
.member-card {
  align-items: center;
  background: #f9faf8;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 12px;
}

.stat-card {
  align-content: space-between;
  background: #f9faf8;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  min-height: 112px;
  padding: 14px;
}

.stat-card span {
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.stat-card > strong {
  display: block;
  font-size: 24px;
  line-height: 1.1;
  text-align: right;
}

.balance-card {
  background: #f0fdfa;
  border-color: #99f6e4;
}

.activity small,
.member-card small,
.stat-card small {
  color: var(--muted);
  display: block;
  margin-top: 3px;
}

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

.delete-member-button {
  background: #fee2e2;
  color: var(--bad);
  flex: 0 0 38px;
  min-height: 38px;
  min-width: 38px;
}

.delete-member-button:hover {
  background: #fecaca;
}

.notice {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  color: #9a3412;
  margin-bottom: 18px;
  padding: 12px 14px;
}

.hidden {
  display: none !important;
}

.auth-shell {
  align-items: center;
  display: grid;
  min-height: 100vh;
  padding: 22px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin: 0 auto;
  padding: 22px;
  width: min(100%, 430px);
}

.auth-brand {
  color: var(--ink);
  margin-bottom: 18px;
}

.auth-tabs {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 16px;
}

.auth-tab {
  background: #eef5f3;
  border: 1px solid #d6e5e1;
  color: var(--primary-dark);
}

.auth-tab.active,
.auth-tab:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

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

.auth-form.active,
#adminRegisterForm {
  display: grid;
}

.auth-form h1 {
  font-size: 24px;
  margin-bottom: 2px;
}

body.modal-open {
  overflow: hidden;
}

.modal {
  align-items: center;
  bottom: 0;
  display: grid;
  justify-items: center;
  left: 0;
  padding: 18px;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 50;
}

.modal-backdrop {
  background: rgba(15, 23, 42, 0.48);
  bottom: 0;
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 18px;
  position: relative;
  width: min(100%, 420px);
  z-index: 1;
}

.modal-header {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 4px;
}

.modal-header h2 {
  margin-bottom: 0;
}

.modal-close {
  background: #eef5f3;
  color: var(--primary-dark);
  flex: 0 0 40px;
  min-height: 40px;
  min-width: 40px;
}

.modal-close:hover {
  background: #dcebe7;
}

@media print {
  .sidebar,
  .toolbar,
  .nav,
  .sidebar-user,
  .ghost-button,
  .notice,
  .menu-button,
  .menu-overlay {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .main {
    padding: 0;
  }

  .panel,
  .metric {
    box-shadow: none;
  }
}

@media (max-width: 980px) {
  body.menu-open {
    overflow: hidden;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    bottom: 0;
    box-shadow: 14px 0 38px rgba(0, 0, 0, 0.22);
    left: 0;
    max-width: calc(100vw - 72px);
    overflow-y: auto;
    position: fixed;
    top: 0;
    transform: translateX(-105%);
    transition: transform 180ms ease;
    width: 280px;
    z-index: 30;
  }

  .sidebar-user {
    margin-top: auto;
  }

  body.menu-open .sidebar {
    transform: translateX(0);
  }

  .menu-overlay {
    background: rgba(15, 23, 42, 0.42);
    bottom: 0;
    display: block;
    left: 0;
    opacity: 0;
    pointer-events: none;
    position: fixed;
    right: 0;
    top: 0;
    transition: opacity 180ms ease;
    z-index: 20;
  }

  body.menu-open .menu-overlay {
    opacity: 1;
    pointer-events: auto;
  }

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

  .nav-item {
    font-size: 14px;
    min-height: 42px;
    padding: 0 12px;
    text-align: left;
  }

  .menu-button {
    display: inline-flex;
  }

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

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

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

@media (max-width: 640px) {
  body {
    background: #ffffff;
  }

  .main,
  .sidebar {
    padding: 18px;
  }

  .sidebar {
    padding-bottom: 12px;
  }

  .brand {
    margin-bottom: 14px;
  }

  .brand-mark {
    height: 38px;
    width: 38px;
  }

  .brand strong {
    font-size: 15px;
  }

  .brand small {
    font-size: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
  }

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

  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 17px;
    margin-bottom: 12px;
  }

  .summary-person,
  .summary-line {
    padding: 10px 12px;
  }

  .topbar p {
    margin-top: 0;
  }

  .toolbar {
    width: 100%;
  }

  .toolbar input {
    flex: 1;
    min-width: 0;
  }

  .panel {
    border-left: 0;
    border-radius: 0;
    border-right: 0;
    box-shadow: none;
    margin-left: -18px;
    margin-right: -18px;
    padding: 16px 18px;
  }

  .modal-card {
    border-left: 1px solid var(--line);
    border-radius: 8px;
    border-right: 1px solid var(--line);
    margin-left: 0;
    margin-right: 0;
    padding: 16px;
  }

  .entry-tabs {
    background: #ffffff;
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: -2px 0 14px;
    padding: 0 0 14px;
    width: min(100%, 354px);
  }

  .entry-tab {
    background: #eef5f3;
    border: 1px solid #d6e5e1;
    color: var(--primary-dark);
    font-size: 13px;
    min-height: 40px;
    min-width: 0;
    overflow-wrap: anywhere;
    padding: 0 8px;
    white-space: normal;
  }

  .entry-tab:hover,
  .entry-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
  }

  .entry-grid .entry-panel {
    display: none;
  }

  .entry-grid .entry-panel.active {
    display: grid;
  }

  .metric {
    box-shadow: none;
    padding: 14px;
  }

  .metric strong {
    font-size: 21px;
  }

  .entry-grid,
  .split,
  .meal-form {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .meal-count-row {
    gap: 8px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .meal-count-row input {
    padding-left: 8px;
    padding-right: 8px;
  }

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

  .table-wrap {
    overflow-x: visible;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tr {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 10px;
    overflow: hidden;
  }

  td {
    align-items: start;
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(110px, 42%) minmax(0, 1fr);
    min-height: 42px;
    padding: 10px 12px;
    text-align: right;
    white-space: normal;
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    color: var(--muted);
    content: attr(data-label);
    font-weight: 800;
    text-align: left;
  }

  td[colspan] {
    display: block;
    text-align: left;
  }

  td[colspan]::before {
    content: "";
    display: none;
  }

  .activity,
  .member-card {
    align-items: flex-start;
    gap: 8px;
  }

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

  .stat-card {
    min-height: 104px;
    padding: 12px;
  }

  .stat-card > strong {
    font-size: 21px;
    text-align: left;
  }

  .activity strong,
  .member-card strong,
  .stat-card strong {
    overflow-wrap: anywhere;
  }
}
