:root {
  color-scheme: light;
  font-family: Inter, system-ui, -apple-system, "Noto Sans Khmer", "Noto Sans SC", sans-serif;
  line-height: 1.45;
  --text: #342732;
  --muted: #695d67;
  --background: #f3e6ef;
  --background-image: radial-gradient(circle at top left, #dbc18a55, transparent 32rem), linear-gradient(145deg, #fbf2f8, #eee0e9);
  --surface: #fffafc;
  --primary: #684e65;
  --primary-hover: #563f53;
  --accent: #dbc18a;
  --border: #e4d8c3;
  --soft: #f6efe6;
  --focus: #dbc18a66;
  --shadow: #34273218;
  color: var(--text);
  background: var(--background);
}

:root[data-theme="burgundy"] {
  --text: #321d23;
  --muted: #6f5b60;
  --background: #f5e3df;
  --background-image: radial-gradient(circle at top right, #d6b36a55, transparent 30rem), linear-gradient(145deg, #fff4ed, #efd9d8);
  --surface: #fffaf7;
  --primary: #722f3f;
  --primary-hover: #5e2533;
  --accent: #d6b36a;
  --border: #e6d3c6;
  --soft: #f3e5e2;
  --focus: #d6b36a66;
  --shadow: #321d2318;
}

:root[data-theme="sage"] {
  --text: #263229;
  --muted: #5d695f;
  --background: #e7ede0;
  --background-image: radial-gradient(circle at top left, #c8a96b55, transparent 30rem), linear-gradient(145deg, #f4f3e8, #dfe9da);
  --surface: #fcfcf5;
  --primary: #52634f;
  --primary-hover: #40503e;
  --accent: #c8a96b;
  --border: #d8ddcf;
  --soft: #e8ede3;
  --focus: #c8a96b66;
  --shadow: #26322918;
}

:root[data-theme="midnight"] {
  --text: #18202d;
  --muted: #596274;
  --background: #e2e7f0;
  --background-image: radial-gradient(circle at top right, #d4b56a55, transparent 30rem), linear-gradient(145deg, #f2f1ed, #d8dfeb);
  --surface: #fafbfe;
  --primary: #24324a;
  --primary-hover: #182338;
  --accent: #d4b56a;
  --border: #d9dce4;
  --soft: #e8eaf0;
  --focus: #d4b56a66;
  --shadow: #18202d1c;
}

:root[data-theme="rose"] {
  --text: #433238;
  --muted: #74636a;
  --background: #f5e2e7;
  --background-image: radial-gradient(circle at top left, #d8be9166, transparent 30rem), linear-gradient(145deg, #fff2f3, #efd8df);
  --surface: #fff9fa;
  --primary: #986875;
  --primary-hover: #7e5360;
  --accent: #d8be91;
  --border: #ead7da;
  --soft: #f3e3e5;
  --focus: #d8be9166;
  --shadow: #43323818;
}

* { box-sizing: border-box; }
body {
  min-height: 100vh;
  margin: 0;
  background-color: var(--background);
  background-image: var(--background-image);
  background-attachment: fixed;
}
a { color: var(--primary); text-decoration: none; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .85rem max(1rem, calc((100% - 1200px) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar nav { position: relative; }
.brand { font-weight: 900; font-size: 1.35rem; -webkit-text-stroke: .35px currentColor; }
.topbar-menu summary {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--primary);
  font-size: 1.4rem;
  cursor: pointer;
  list-style: none;
}
.topbar-menu summary::-webkit-details-marker { display: none; }
.topbar-menu[open] summary { background: var(--soft); }
.topbar-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + .55rem);
  display: grid;
  gap: .8rem;
  min-width: 240px;
  padding: .85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px var(--shadow);
}
.account-menu { display: grid; gap: .65rem; padding-bottom: .8rem; border-bottom: 1px solid var(--border); }
.operator, td small { color: var(--muted); }
.theme-picker { display: grid; gap: .35rem; font-weight: 650; }
.theme-picker select { width: 100%; }
.languages { display: flex; gap: .35rem; }
.languages a { flex: 1; padding: .45rem .55rem; border-radius: 7px; text-align: center; }
.languages a:hover, .languages a[aria-current="page"] { background: var(--soft); font-weight: 700; }

.container { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.1rem;
  box-shadow: 0 4px 18px var(--shadow);
  margin-bottom: 1rem;
}
.narrow, .auth-card { max-width: 650px; margin: 3rem auto; }
.entry-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(220px, 1fr); gap: 1rem; }
.totals { display: flex; flex-direction: column; gap: .7rem; }
.totals strong { font-size: 1.8rem; color: var(--primary); }
.entry-card h1 { font-weight: 400; }
h1, h2 { margin-top: 0; }
form { display: grid; gap: .85rem; }
label { display: grid; gap: .35rem; font-weight: 650; }
input, select, button, .button {
  font: inherit;
  border-radius: 9px;
  border: 1px solid var(--border);
  padding: .7rem .8rem;
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
}
input:focus, select:focus { outline: 3px solid var(--focus); border-color: var(--primary); }
button, .button {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}
button:hover, .button:hover { background: var(--primary-hover); }
.secondary { background: var(--surface); color: var(--primary); }
.secondary:hover { background: var(--soft); }
.danger, .danger:hover { background: #a72e35; border-color: #a72e35; color: #fff; }
.small { min-height: 34px; padding: .35rem .55rem; font-size: .9rem; }
.link-button { border: 0; background: none; color: var(--primary); padding: 0; min-height: auto; }
.link-button:hover { background: none; color: var(--primary-hover); }
.inline { display: inline-flex; }
.money-grid, .admin-grid, .stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.stats { grid-template-columns: repeat(3, 1fr); }
.stats .card { display: grid; }
.stats strong { font-size: 1.8rem; }
.actions, .section-heading, .row-actions, .user-actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.section-heading { justify-content: space-between; }
.search { display: flex; grid-auto-flow: column; }

.notice { padding: .75rem 1rem; border-radius: 9px; margin-bottom: 1rem; }
.notice.success {
  position: fixed;
  top: 5.25rem;
  right: 1rem;
  z-index: 40;
  width: max-content;
  max-width: calc(100vw - 2rem);
  margin: 0;
  padding: .8rem 1rem;
  background: var(--surface);
  color: #25432f;
  border: 1px solid #d5e5da;
  border-left: 4px solid #278556;
  font-weight: 650;
  box-shadow: 0 8px 24px var(--shadow);
  animation: toast-in .2s ease-out, toast-out .2s ease-in 2.8s forwards;
}
.notice.success::before { content: "✓"; margin-right: .55rem; color: #278556; font-weight: 800; }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(12px); } }
.new-name-label { width: fit-content; padding: .35rem .65rem; margin-bottom: .8rem; border-radius: 999px; background: #fff3cd; color: #684f08; font-weight: 700; }
.guest-label { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.guest-new-name { padding: .2rem .5rem; border-radius: 999px; background: #fff3cd; color: #684f08; font-weight: 700; }
.success { background: #dff4e6; color: #165b35; }
.error { background: #ffe2e2; color: #86232a; }
.warning { background: #fff3cd; color: #684f08; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
pre { white-space: pre-wrap; max-width: 500px; }
.autocomplete { position: relative; }
.autocomplete > input { width: 100%; }
.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 8px 25px var(--shadow);
  z-index: 20;
  max-height: 260px;
  overflow: auto;
}
.suggestions button { display: block; width: 100%; border: 0; border-radius: 0; background: var(--surface); color: var(--text); text-align: left; }
.suggestions button:hover { background: var(--soft); }
.modal { position: fixed; inset: 0; background: #0008; display: grid; place-items: center; padding: 1rem; z-index: 50; }
.modal[hidden] { display: none; }
.modal-card { background: var(--surface); border-radius: 14px; padding: 1.3rem; width: min(520px, 100%); max-height: 90vh; overflow: auto; }
#edit-modal .modal-card { width: min(760px, 100%); }
.modal-card > .actions { justify-content: flex-end; }
.delete-modal-card { max-width: 420px; }
.confirmation { display: grid; grid-template-columns: 1fr 2fr; gap: .65rem; }
.confirmation dt { font-weight: 700; }
.confirmation dd { margin: 0; font-size: 1.15rem; }
.reset-form { display: inline-flex; grid-auto-flow: column; }
.reset-form input { min-width: 150px; }
.guest-input::-webkit-search-cancel-button { cursor: pointer; }

@media (max-width: 760px) {
  .topbar-menu-panel { max-width: calc(100vw - 1.4rem); }
  .entry-grid, .money-grid, .admin-grid, .stats { grid-template-columns: 1fr; }
  .section-heading { align-items: stretch; }
  .search { grid-auto-flow: row; }
  .container { padding: .7rem; }
  .autocomplete input { width: 100%; }
  .card { border-radius: 10px; padding: .85rem; }
  th, td { padding: .55rem; }
  .row-actions, .user-actions { min-width: 150px; }
}

@media (max-width: 599px) {
  .autocomplete, #edit-modal .autocomplete { width: 100%; }
  .suggestions { top: 100%; left: 0; width: 100%; }
}
