/* E-POWER documentation site — self-contained, light/dark + Khmer/English */
:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --ink: #1d2733;
  --muted: #5b6b7c;
  --line: #dfe5ec;
  --brand: #c0392b;          /* E-POWER red */
  --brand-soft: #fdf0ee;
  --accent: #1f6f8b;
  --accent-soft: #eaf4f7;
  --ok: #2e7d32;
  --ok-soft: #e6f4e7;
  --warn: #b26a00;
  --code-bg: #f0f3f6;
  --shadow: 0 1px 3px rgba(16, 30, 44, .08);
}
/* dark palette — applied by OS preference (when no manual choice) or by the toggle */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12181f; --panel: #1a222c; --ink: #e4ebf2; --muted: #93a4b5;
    --line: #2b3947; --brand: #e8695a; --brand-soft: #2c1f1d;
    --accent: #5fb3cf; --accent-soft: #16303a; --ok-soft: #1d3320;
    --code-bg: #232e3a; --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  --bg: #12181f; --panel: #1a222c; --ink: #e4ebf2; --muted: #93a4b5;
  --line: #2b3947; --brand: #e8695a; --brand-soft: #2c1f1d;
  --accent: #5fb3cf; --accent-soft: #16303a; --ok-soft: #1d3320;
  --code-bg: #232e3a; --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

/* language visibility: default English; [data-lang=km] flips */
.km { display: none; }
:root[data-lang="km"] .km { display: inline; }
:root[data-lang="km"] .en { display: none; }
:root[data-lang="km"] body { line-height: 1.9; }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, "Helvetica Neue", "Noto Sans Khmer", "Khmer OS System", "Khmer OS", sans-serif;
  font-size: 15.5px;
  line-height: 1.65;
  background: var(--bg);
  color: var(--ink);
}

/* layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 260px; flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 1.2rem .9rem 2rem;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.content { flex: 1; min-width: 0; padding: 2rem clamp(1rem, 4vw, 3.4rem) 4rem; max-width: 1100px; }
@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { position: static; width: 100%; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
}

/* sidebar */
.logo { font-size: 1.15rem; font-weight: 700; color: var(--brand); letter-spacing: .3px; margin: 0 .35rem .1rem; }
.logo small { display: block; color: var(--muted); font-weight: 400; font-size: .72rem; letter-spacing: .4px; }
.nav-group { margin-top: 1.1rem; }
.nav-group > span {
  display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--muted); margin: 0 .35rem .3rem;
}
.sidebar a {
  display: block; padding: .34rem .6rem; border-radius: 7px;
  color: var(--ink); text-decoration: none; font-size: .92rem;
}
.sidebar a:hover { background: var(--accent-soft); }
.sidebar a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

/* toolbar: theme + language switch */
.toolbar { display: flex; gap: .4rem; margin: .8rem .35rem 0; align-items: center; }
.toolbar button {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: .28rem .6rem; font-size: .85rem; cursor: pointer;
  font-family: inherit;
}
.toolbar button:hover { background: var(--accent-soft); }
.toolbar button.on { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); font-weight: 700; }
#themeBtn { margin-left: auto; font-size: .95rem; }

/* typography */
h1 { font-size: 1.75rem; margin: .2rem 0 .4rem; letter-spacing: -.01em; }
h1 + p.lead, p.lead { color: var(--muted); margin-top: 0; font-size: 1.02rem; max-width: 68ch; }
h2 {
  font-size: 1.28rem; margin: 2.6rem 0 .7rem; padding-bottom: .35rem;
  border-bottom: 2px solid var(--line);
}
h3 { font-size: 1.02rem; margin: 1.6rem 0 .4rem; color: var(--accent); }
p { max-width: 80ch; }
a { color: var(--accent); }
code {
  font-family: "SF Mono", ui-monospace, Consolas, Menlo, monospace;
  font-size: .84em; background: var(--code-bg);
  padding: .12em .38em; border-radius: 5px;
}

/* cards / grids */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .9rem; margin: 1.2rem 0; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 1rem 1.1rem; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 .3rem; font-size: 1rem; color: inherit; }
.card p { margin: 0; font-size: .88rem; color: var(--muted); }
.card a { text-decoration: none; }

/* flow diagram (vertical steps) */
.flow { list-style: none; margin: 1.1rem 0 1.6rem; padding: 0; max-width: 740px; counter-reset: step; }
.flow > li {
  counter-increment: step;
  position: relative;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: .65rem .9rem .65rem 3rem;
  margin: 0 0 1.05rem; box-shadow: var(--shadow);
}
.flow > li::before {
  content: counter(step);
  position: absolute; left: .8rem; top: .72rem;
  width: 1.55rem; height: 1.55rem; border-radius: 50%;
  background: var(--brand); color: #fff;
  font-size: .8rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.flow > li:not(:last-child)::after {
  content: "";
  position: absolute; left: 50%; bottom: -1.05rem;
  width: 2px; height: 1.05rem; background: var(--line);
}
.flow b:first-child { color: var(--brand); }
.flow small { color: var(--muted); display: block; margin-top: .1rem; }
.flow .who {
  float: right; font-size: .68rem; letter-spacing: .04em;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 20px; padding: .1rem .55rem; margin-left: .6rem;
}

/* branch box inside a flow */
.branch {
  margin: .45rem 0 0; padding: .5rem .75rem;
  border-left: 3px solid var(--accent); background: var(--accent-soft);
  border-radius: 0 8px 8px 0; font-size: .88rem;
}
.branch b { color: var(--accent); }

/* rules / notes */
.rules {
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--warn);
  border-radius: 0 10px 10px 0; padding: .7rem 1.1rem; margin: 1rem 0 1.6rem; max-width: 740px;
}
.rules h4 { margin: .1rem 0 .35rem; font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--warn); }
.rules ul { margin: .2rem 0 .3rem 1.1rem; padding: 0; }
.rules li { margin: .28rem 0; font-size: .92rem; }
.note { border-left-color: var(--ok); }
.note h4 { color: var(--ok); }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; margin: 1rem 0 1.6rem; font-size: .9rem; background: var(--panel); box-shadow: var(--shadow); border-radius: 10px; overflow: hidden; }
th, td { text-align: left; padding: .5rem .8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--code-bg); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
tr:last-child td { border-bottom: 0; }

/* status pills */
.pill { display: inline-block; padding: .05rem .55rem; border-radius: 20px; font-size: .78rem; font-weight: 600; }
.pill.open { background: var(--accent-soft); color: var(--accent); }
.pill.close { background: var(--ok-soft); color: var(--ok); }
.pill.cancel { background: var(--brand-soft); color: var(--brand); }

/* header strip + footer */
.crumb { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; margin-bottom: .2rem; }
footer {
  margin-top: 4rem; padding-top: 1rem; border-top: 1px solid var(--line);
  color: var(--muted); font-size: .8rem;
}
