/* Sala core styles. Mobile first, light and dark. */
@font-face {
  font-family: "Noto Sans Khmer";
  src: url("../fonts/noto-sans-khmer-khmer-400-normal.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
  unicode-range: U+1780-17FF, U+19E0-19FF, U+200C-200D, U+25CC;
}
@font-face {
  font-family: "Noto Sans Khmer";
  src: url("../fonts/noto-sans-khmer-khmer-700-normal.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
  unicode-range: U+1780-17FF, U+19E0-19FF, U+200C-200D, U+25CC;
}

:root {
  --bg: #f7f5ef;
  --surface: #ffffff;
  --surface-2: #f1eee6;
  --text: #1d2420;
  --muted: #5f6a64;
  --border: #e2ddd1;
  --primary: #1f6f5c;
  --primary-ink: #ffffff;
  --primary-soft: #e3f1ec;
  --accent: #d98a1b;
  --danger: #b4372c;
  --danger-soft: #fbe9e7;
  --success-soft: #e5f4ea;
  --success-ink: #1e5e36;
  --info-soft: #e8f0fb;
  --info-ink: #1f4b8a;
  --warn-soft: #fff4dc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --font: "Noto Sans Khmer", system-ui, -apple-system, "Segoe UI", Roboto, "Khmer UI", "Khmer OS", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --surface: #1b211e;
    --surface-2: #232b27;
    --text: #e8ece9;
    --muted: #9aa6a0;
    --border: #2e3833;
    --primary: #4cb79a;
    --primary-ink: #0d1411;
    --primary-soft: #1d3a31;
    --accent: #f0a63a;
    --danger: #ef7a6f;
    --danger-soft: #3a201d;
    --success-soft: #1b3324;
    --success-ink: #9bdcb2;
    --info-soft: #1c2a40;
    --info-ink: #a9c7f2;
    --warn-soft: #3a2f17;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 16px; line-height: 1.6;
  min-height: 100vh; display: flex; flex-direction: column;
}
:lang(km) body, html[lang="km"] body { line-height: 1.8; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.35; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; background: var(--surface-2); padding: .05em .35em; border-radius: 6px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.2rem 0; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1040px; margin: 0 auto; padding: .5rem 16px; display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.mainnav { display: flex; gap: .25rem; flex-wrap: wrap; order: 3; width: 100%; overflow-x: auto; }
.mainnav a { padding: .35rem .7rem; border-radius: 999px; text-decoration: none; color: var(--muted); white-space: nowrap; }
.mainnav a.active, .mainnav a:hover { background: var(--primary-soft); color: var(--primary); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
@media (min-width: 720px) {
  .mainnav { order: 0; width: auto; margin-left: 1rem; }
}
.langswitch { display: flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.langswitch a { padding: .15rem .6rem; font-size: .85rem; text-decoration: none; color: var(--muted); }
.langswitch a.active { background: var(--primary); color: var(--primary-ink); }
.count { display: inline-block; min-width: 1.4em; padding: 0 .4em; border-radius: 999px; background: var(--surface-2); color: var(--text); font-size: .78rem; text-align: center; line-height: 1.5; }
.mainnav .count, .count-alert { background: var(--accent); color: #fff; }

.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: .4rem; }
.usermenu summary::-webkit-details-marker { display: none; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; }
.uname { display: none; max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (min-width: 720px) { .uname { display: inline; } }
.usermenu-panel { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); min-width: 200px; padding: .35rem; display: flex; flex-direction: column; }
.usermenu-panel a, .usermenu-panel button { text-align: left; padding: .5rem .7rem; border-radius: 8px; color: var(--text); text-decoration: none; background: none; border: 0; font: inherit; cursor: pointer; }
.usermenu-panel a:hover, .usermenu-panel button:hover { background: var(--surface-2); }

/* Layout */
.container { max-width: 1040px; width: 100%; margin: 0 auto; padding: 1.25rem 16px 2rem; flex: 1; }
.footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card.narrow, .narrow { max-width: 460px; margin-left: auto; margin-right: auto; }
.center { text-align: center; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin-bottom: .2rem; }
.grid-2 { display: grid; gap: 1rem; }
@media (min-width: 720px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.muted { color: var(--muted); }
.small { font-size: .87rem; }
.lead { font-size: 1.1rem; }
.note { background: var(--warn-soft); padding: .6rem .8rem; border-radius: 10px; font-size: .92rem; }

/* Hero */
.hero { text-align: center; padding: 2rem 0 1rem; }
.hero h1 { font-size: 1.9rem; }
.hero-actions { display: flex; gap: .75rem; justify-content: center; flex-wrap: wrap; margin: 1.25rem 0; }
.features { display: grid; gap: 1rem; margin-top: 1rem; }
@media (min-width: 720px) { .features { grid-template-columns: repeat(3, 1fr); } }

/* Forms */
label { display: block; margin-bottom: .9rem; font-weight: 600; font-size: .95rem; }
input, select, textarea {
  display: block; width: 100%; margin-top: .3rem; padding: .65rem .75rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
  font: inherit; font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
input[type=checkbox], input[type=radio] { width: auto; display: inline-block; margin: 0; }
fieldset { border: 1px dashed var(--border); border-radius: 12px; padding: .7rem .9rem .2rem; margin: 0 0 1rem; }
legend { font-size: .9rem; color: var(--muted); padding: 0 .3rem; }
label > .small { font-weight: 400; display: block; margin-top: .25rem; }
.code-input { text-transform: uppercase; letter-spacing: .15em; font-family: ui-monospace, Menlo, Consolas, monospace; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.switch { display: flex; gap: .75rem; align-items: flex-start; font-weight: 600; padding: .5rem 0; }
.switch input[type=checkbox] { appearance: none; -webkit-appearance: none; width: 44px; height: 26px; border-radius: 999px; background: var(--border); position: relative; flex-shrink: 0; cursor: pointer; transition: background .15s; margin-top: .15rem; padding: 0; border: 0; }
.switch input[type=checkbox]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input[type=checkbox]:checked { background: var(--primary); }
.switch input[type=checkbox]:checked::after { transform: translateX(18px); }
.switch .small { font-weight: 400; }
.choice-row { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.choice { display: flex; align-items: center; gap: .4rem; border: 1px solid var(--border); border-radius: 10px; padding: .5rem .8rem; cursor: pointer; margin: 0; }
.copy-row { display: flex; gap: .5rem; align-items: center; }
.copy-row input { margin: 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; line-height: 1.3; min-height: 42px;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: .3rem .65rem; min-height: 34px; font-size: .88rem; }
.btn-lg { padding: .75rem 1.3rem; font-size: 1.05rem; min-height: 50px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-start; }
.inline-form { display: inline; }
.links-row { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
details.subform { margin-top: .75rem; }
details.subform > summary { list-style: none; display: inline-flex; }
details.subform > summary::-webkit-details-marker { display: none; }
details.subform[open] > summary { margin-bottom: .75rem; }

/* Alerts and badges */
.alert { padding: .75rem .9rem; border-radius: 12px; margin-bottom: 1rem; background: var(--info-soft); color: var(--info-ink); }
.alert ul { margin: 0; padding-left: 1.1rem; }
.alert-success { background: var(--success-soft); color: var(--success-ink); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-link { display: block; text-decoration: none; font-weight: 600; }
.badge { display: inline-block; font-size: .75rem; padding: .05rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 600; vertical-align: middle; }
.badge-active { background: var(--success-soft); color: var(--success-ink); }
.badge-pending { background: var(--warn-soft); color: var(--accent); }
.badge-rejected, .badge-disabled { background: var(--danger-soft); color: var(--danger); }

/* Tabs */
.tabs { display: flex; gap: .25rem; background: var(--surface-2); padding: .25rem; border-radius: 12px; margin-bottom: 1rem; }
.tabs a { flex: 1; text-align: center; padding: .5rem; border-radius: 9px; text-decoration: none; color: var(--muted); font-weight: 600; }
.tabs a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tabs-line { background: none; border-bottom: 1px solid var(--border); border-radius: 0; padding: 0; overflow-x: auto; }
.tabs-line a { flex: 0 0 auto; border-radius: 0; border-bottom: 2px solid transparent; padding: .5rem .9rem; }
.tabs-line a.active { background: none; box-shadow: none; border-bottom-color: var(--primary); color: var(--primary); }

/* Tables and lists */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .82rem; color: var(--muted); font-weight: 600; }
.table td.actions { white-space: nowrap; text-align: right; }
.table td.actions .inline-form + .inline-form { margin-left: .25rem; }
tr.is-disabled td { opacity: .6; }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { padding: .55rem 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: .75rem; align-items: center; flex-wrap: wrap; }
.plain-list li:last-child { border-bottom: 0; }
.pending-invite { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; }

/* Family */
.family-code { background: var(--primary-soft); border-radius: var(--radius); padding: .6rem .9rem; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.family-code .label { font-size: .85rem; color: var(--muted); }
.family-code .code, .big-code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.4rem; letter-spacing: .15em; color: var(--primary); }
.big-code { font-size: 1.8rem; font-weight: 700; margin: .3rem 0; }

/* Admin */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1rem; }
@media (min-width: 720px) { .stats { grid-template-columns: repeat(5, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem; display: flex; flex-direction: column; }
.stat-n { font-size: 1.7rem; font-weight: 700; }
.stat-l { color: var(--muted); font-size: .85rem; }
.family-row { display: flex; gap: 1rem; justify-content: space-between; flex-wrap: wrap; }
.family-row p { margin: 0 0 .2rem; }
.family-actions { display: flex; gap: .5rem; align-items: flex-start; flex-wrap: wrap; }
.family-actions details.subform { margin-top: 0; }
.search input { margin: 0; min-width: 240px; }

/* Child */
.hello { background: linear-gradient(135deg, var(--primary-soft), var(--surface)); }
.empty-state { text-align: center; padding: 2rem 1rem; }
.empty-icon { font-size: 2.5rem; }
.member-list { list-style: none; padding: 0; margin: 0; }
.member-list li { padding: .8rem 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: .75rem; flex-wrap: wrap; align-items: center; }
.member-list li:last-child { border-bottom: 0; }
.member-list li.is-disabled .member-info { opacity: .6; }
.member-list .btn-row .inline-form { display: inline-block; }
