:root {
  color-scheme: light;
  --bg: #eef3fa;
  --surface: #ffffff;
  --surface-alt: #f5f9fd;
  --border: #d9e4f1;
  --text: #13233f;
  --text-muted: #5d7291;
  --primary: #1d63d6;
  --primary-dark: #14479c;
  --primary-tint: #e6effc;
  --sky: #0ea5e9;
  --success: #17845a;
  --success-bg: #e5f7ee;
  --danger: #d6483f;
  --danger-bg: #fceae8;
  --shadow: 0 1px 2px rgba(19,35,63,.04), 0 8px 24px -12px rgba(19,35,63,.12);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Sarabun', 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0a1220; --surface: #121d31; --surface-alt: #172338; --border: #263a58;
    --text: #e8eefa; --text-muted: #93a8c9;
    --primary: #5b95f5; --primary-dark: #8fb6f8; --primary-tint: #1b2c4a;
    --sky: #38bdf8; --success: #3ecf8e; --success-bg: #123527;
    --danger: #f0776d; --danger-bg: #3a1c1a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a1220; --surface: #121d31; --surface-alt: #172338; --border: #263a58;
  --text: #e8eefa; --text-muted: #93a8c9;
  --primary: #5b95f5; --primary-dark: #8fb6f8; --primary-tint: #1b2c4a;
  --sky: #38bdf8; --success: #3ecf8e; --success-bg: #123527;
  --danger: #f0776d; --danger-bg: #3a1c1a;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
h1, h2, h3 { font-family: var(--font); text-wrap: balance; }

/* ---------- Top bar ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow); }
.topbar-inner {
  max-width: 880px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap; min-height: 58px;
}
.logos { display: flex; align-items: center; gap: 8px; flex: none; }
.logo-img { height: 32px; width: auto; display: block; }
.logo-prestressing { border-radius: 6px; }
.logo-supplies { background: #fff; border-radius: 6px; padding: 3px 7px; height: 26px; }
.brand-divider { width: 1px; height: 24px; background: var(--border); flex: none; }
.brand-block { display: flex; flex-direction: column; line-height: 1.15; flex: none; }
.brand { font-size: 14px; font-weight: 700; }
.brand-sub { font-size: 10.5px; color: var(--text-muted); letter-spacing: .08em; font-weight: 600; }
.topnav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; align-items: center; }
.topnav a {
  font-family: var(--font); font-size: 13.5px; font-weight: 500;
  color: var(--text-muted); text-decoration: none; padding: 7px 13px; border-radius: 999px; cursor: pointer;
}
.topnav a:hover, .topnav a.active { color: var(--text); background: var(--surface-alt); }
.icon-btn {
  width: 34px; height: 34px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-alt); color: var(--text); font-size: 15px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; margin-left: 6px; flex: none;
}
.icon-btn:hover { border-color: var(--primary); }

.page { max-width: 880px; margin: 0 auto; padding: 32px 20px 70px; }

/* ---------- Hero / section heads ---------- */
.eyebrow {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  color: var(--primary); letter-spacing: .04em; margin-bottom: 8px;
}
.eyebrow::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--sky); }
h1 { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.subtitle { margin: 0; color: var(--text-muted); font-size: 14px; }

/* ---------- Tiles (home) ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-top: 22px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; text-decoration: none; color: var(--text);
  display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow);
}
.tile-icon {
  width: 34px; height: 34px; border-radius: 9px; background: var(--primary-tint); color: var(--primary);
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.tile-title { font-weight: 700; font-size: 14.5px; }
.tile-desc { font-size: 12px; color: var(--text-muted); line-height: 1.5; }
.tile-co { font-size: 10.5px; color: var(--text-muted); margin-top: auto; padding-top: 6px; border-top: 1px dashed var(--border); }

/* ---------- Card / form ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-head h3 { margin: 0; font-size: 14.5px; font-weight: 700; }
.co-tag { font-size: 11px; font-weight: 700; color: var(--primary); background: var(--primary-tint); padding: 4px 10px; border-radius: 999px; }
.card-body { padding: 20px; }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 5px; }
.row > .field { margin-bottom: 0; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.field .hint { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

input[type="text"], input[type="date"], input[type="number"], input[type="password"], select {
  width: 100%; font-family: var(--font); font-size: 14px; padding: 9px 11px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-alt); color: var(--text);
}
input:focus, select:focus { outline: none; border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 3px var(--primary-tint); }

.item-row { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 8px; }
.item-row .field { margin-bottom: 0; }

.btn { font-family: var(--font); font-weight: 700; font-size: 14px; padding: 10px 20px; border-radius: var(--radius-sm); border: none; cursor: pointer; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--primary-tint); border-color: var(--primary); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }
.btn:disabled { opacity: .6; cursor: default; }

.result-box { margin-top: 16px; padding: 14px 16px; border-radius: var(--radius-sm); background: var(--success-bg); color: var(--success); font-size: 14px; }
.result-box a { color: inherit; font-weight: 700; }
.error-box { margin-top: 16px; padding: 14px 16px; border-radius: var(--radius-sm); background: var(--danger-bg); color: var(--danger); font-size: 14px; white-space: pre-wrap; }

/* ---------- History ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs button {
  font-family: var(--font); font-size: 13px; font-weight: 600; padding: 7px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); cursor: pointer;
}
.tabs button.active { background: var(--primary); border-color: var(--primary); color: #fff; }

table.history {
  width: 100%; border-collapse: collapse; font-size: 13.5px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
table.history th {
  text-align: left; font-size: 11px; font-weight: 700; color: var(--text-muted); letter-spacing: .03em; text-transform: uppercase;
  padding: 11px 14px; background: var(--surface-alt); border-bottom: 1px solid var(--border);
}
table.history td { padding: 12px 14px; border-bottom: 1px solid var(--border); }
table.history tr:last-child td { border-bottom: none; }
table.history td:first-child { font-weight: 700; font-variant-numeric: tabular-nums; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge-ok { background: var(--success-bg); color: var(--success); }
.badge-void { background: var(--danger-bg); color: var(--danger); }

/* ---------- Login page ---------- */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 320px; margin: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 30px 26px; }
.login-icon { display: flex; justify-content: center; margin-bottom: 16px; }
.login-icon img { height: 46px; border-radius: 10px; }
.login-card h1 { font-size: 17px; text-align: center; margin: 0 0 4px; }
.login-sub { text-align: center; color: var(--text-muted); font-size: 13px; margin: 0 0 22px; }
