/* Sovann Construction Tools — stylesheet (mobile-first) */
:root {
  --blue: #1769aa;
  --blue-dark: #12507f;
  --navy: #163b65;
  --green: #238636;
  --gray: #687582;
  --text: #202124;
  --muted: #5f6368;
  --bg: #f3f6fa;
  --card: #ffffff;
  --border: #dce3eb;
  --soft: #f7f9fc;
  --warn-bg: #fff6df;
  --warn-border: #f1d38a;
  --warn-text: #694d00;
  --info-bg: #e8f1fb;
  --info-border: #b9d3ee;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: 'Noto Sans Khmer', 'Khmer OS Battambang', 'Khmer UI', system-ui, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.8;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--blue); }
img { max-width: 100%; height: auto; }

.wrap { width: 100%; max-width: 960px; margin: 0 auto; padding: 0 16px; }

/* ---------- Header ---------- */
.site-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  display: block;
  padding: 10px 0 2px;
  text-decoration: none;
  color: var(--navy);
  font-weight: 700;
  font-size: 18px;
  line-height: 1.5;
}
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); line-height: 1.5; }
.nav {
  display: flex;
  gap: 4px;
  padding: 6px 0 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.nav a {
  flex: 0 0 auto;
  padding: 6px 14px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
  white-space: nowrap;
}
.nav a:hover { background: var(--bg); }
.nav a[aria-current="page"] { background: var(--blue); color: #fff; }

/* ---------- Main ---------- */
main { display: block; padding: 20px 0 28px; }

h1 { margin: 0 0 8px; font-size: 24px; line-height: 1.6; color: var(--navy); }
h2 { margin: 0 0 10px; font-size: 19px; line-height: 1.6; color: var(--navy); }
h3 { margin: 0 0 8px; font-size: 17px; line-height: 1.6; color: var(--navy); }
p { margin: 0 0 12px; }
.lead { color: var(--muted); font-size: 16px; margin-bottom: 18px; }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin: 0 0 16px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .05);
}

.prose ul, .prose ol { margin: 0 0 12px; padding-left: 22px; }
.prose li { margin-bottom: 6px; }
.prose dt { font-weight: 700; color: var(--navy); margin-top: 10px; }
.prose dd { margin: 0 0 6px 0; color: var(--text); }
.formula {
  display: block;
  margin: 6px 0 10px;
  padding: 8px 12px;
  background: var(--soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: Consolas, Menlo, 'Noto Sans Khmer', monospace;
  font-size: 14px;
  overflow-x: auto;
  white-space: nowrap;
}

/* ---------- Home cards ---------- */
.cards { display: grid; grid-template-columns: 1fr; gap: 14px; margin: 0 0 20px; }
.card-link {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-decoration: none;
  color: var(--text);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .05);
}
.card-link:active { opacity: .85; }
.card-link h2 { margin-bottom: 6px; }
.card-link p { color: var(--muted); font-size: 15px; flex: 1 1 auto; }
.card-link .go {
  display: block;
  margin-top: 6px;
  padding: 10px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  text-align: center;
}
.card-icon { font-size: 30px; line-height: 1.4; }

/* ---------- Forms ---------- */
.field { display: block; margin: 0 0 16px; min-width: 0; }
.row { display: grid; grid-template-columns: 1fr; gap: 0 10px; }

label { display: block; margin: 0 0 6px; font-size: 15px; font-weight: 700; }
.hint { display: block; margin: 4px 0 0; font-size: 12px; font-weight: 400; color: var(--muted); line-height: 1.7; }

input, select {
  display: block;
  width: 100%;
  height: 52px;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #b8c2cc;
  border-radius: 8px;
  background-color: #fff;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  line-height: normal;
  box-shadow: none;
  -webkit-appearance: none;
  appearance: none;
}
select {
  padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, #5f6368 50%), linear-gradient(135deg, #5f6368 50%, transparent 50%);
  background-position: calc(100% - 21px) 50%, calc(100% - 15px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
input:focus, select:focus, button:focus-visible, a:focus-visible {
  outline: 3px solid rgba(23, 105, 170, .3);
  border-color: var(--blue);
}

.btns { display: grid; grid-template-columns: 1fr; gap: 10px; margin: 6px 0 16px; }
button {
  display: block;
  width: 100%;
  min-height: 52px;
  margin: 0;
  padding: 12px 8px;
  border: 0;
  border-radius: 8px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.5;
  text-align: center;
  white-space: normal;
  cursor: pointer;
  touch-action: manipulation;
  color: #fff;
}
button:active { opacity: .85; }
.btn-calc { background: var(--blue); }
.btn-reset { background: var(--gray); }
.btn-print { background: var(--green); }

/* ---------- Tabs ---------- */
.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin: 0 0 16px;
  padding: 4px;
  background: #e8eef5;
  border-radius: 10px;
}
.tab { min-height: 48px; padding: 8px 4px; font-size: 15px; color: #3c4043; background: transparent; }
.tab[aria-selected="true"] { color: #fff; background: var(--blue); box-shadow: 0 1px 4px rgba(0, 0, 0, .2); }
.is-hidden { display: none !important; }

/* ---------- Results ---------- */
.results { background: var(--soft); border: 1px solid var(--border); border-radius: 10px; padding: 12px; scroll-margin-top: 90px; }
.results h3 { text-align: center; margin-bottom: 12px; }
.result-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.result-item {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 2px 10px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid #e0e5eb;
  border-radius: 9px;
}
.result-label { font-size: 15px; font-weight: 700; color: #3c4043; }
.result-value { margin-left: auto; text-align: right; font-size: 21px; font-weight: 700; color: var(--blue); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.result-unit { min-width: 56px; font-size: 13px; color: var(--muted); }
.footnote { margin: 12px 0 0; font-size: 13px; color: var(--muted); text-align: center; }

.msg { display: none; margin: 0 0 14px; padding: 12px; border-radius: 8px; font-size: 14px; }
.msg.ok { display: block; background: #e6f4ea; color: #137333; border: 1px solid #b7dfc2; }
.msg.err { display: block; background: #fde8e8; color: #a50e0e; border: 1px solid #f5b7b7; }

.status { margin: 12px 0 0; padding: 10px 12px; border-radius: 8px; font-size: 14px; text-align: center; display: none; }
.status.good { display: block; background: #e6f4ea; color: #137333; border: 1px solid #b7dfc2; }
.status.warn { display: block; background: var(--warn-bg); color: var(--warn-text); border: 1px solid var(--warn-border); }
.status.bad { display: block; background: #fde8e8; color: #a50e0e; border: 1px solid #f5b7b7; }

.note { margin: 12px 0 0; padding: 12px; background: var(--info-bg); border: 1px solid var(--info-border); border-radius: 8px; color: var(--navy); font-size: 14px; }
.warning { margin: 14px 0 0; padding: 12px; background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 8px; color: var(--warn-text); font-size: 13px; }

/* ---------- Ad slots (hidden until code is configured in ads.js) ---------- */
.ad-slot { display: none; }
.ad-slot.has-ad { display: block; margin: 0 0 16px; text-align: center; min-height: 60px; overflow: hidden; }
.ad-slot.has-ad::before { content: 'ការផ្សាយពាណិជ្ជកម្ម'; display: block; font-size: 11px; color: var(--muted); line-height: 1.6; }

/* ---------- Footer ---------- */
.site-footer { background: #fff; border-top: 1px solid var(--border); padding: 18px 0 22px; font-size: 14px; color: var(--muted); text-align: center; }
.footer-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; margin: 0 0 8px; }
.footer-links a { text-decoration: none; font-weight: 700; }
.site-footer p { margin: 0 0 6px; }

/* ---------- Helpers ---------- */
.cols { display: grid; grid-template-columns: 1fr; gap: 16px; }
.cols > .panel { margin-bottom: 0; }
.stack > * + * { margin-top: 16px; }

/* ---------- Larger screens ---------- */
@media (min-width: 560px) {
  .row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .row.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .btns { grid-template-columns: 1fr 1fr; }
  .btns .btn-calc { grid-column: 1 / -1; }
  .result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .result-item { flex-direction: column; justify-content: center; align-items: center; min-height: 96px; text-align: center; }
  .result-label { font-weight: 400; color: var(--muted); font-size: 14px; }
  .result-value { margin-left: 0; text-align: center; font-size: 23px; }
  .result-unit { min-width: 0; }
}
/* list-style result rows (always one per line) */
@media (min-width: 560px) {
  .result-grid.list { grid-template-columns: 1fr; }
  .result-grid.list .result-item { flex-direction: row; justify-content: space-between; align-items: baseline; min-height: 0; text-align: left; }
  .result-grid.list .result-label { font-weight: 700; color: #3c4043; font-size: 15px; }
  .result-grid.list .result-value { margin-left: auto; text-align: right; font-size: 19px; }
}

@media (min-width: 760px) {
  h1 { font-size: 28px; }
  .cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .panel { padding: 22px; }
  .brand { display: inline-block; }
  .site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
  .nav { padding: 8px 0; }
}

/* ---------- Print: print only results ---------- */
@media print {
  .site-header, .site-footer, .ad-slot, .btns, .tabs, .lead, .prose, .hint { display: none !important; }
  body { background: #fff; }
  .panel { border: 0; box-shadow: none; padding: 0; }
}
