/* คลังข้อสอบ สพป.ระนอง — สีทะเลอันดามันและป่าชายเลน */
:root {
  --sea: #0E5A6B;
  --sea-deep: #0A3F4B;
  --mangrove: #2F6B4F;
  --sand: #F3F1EA;
  --paper: #FBFCFB;
  --ink: #17262B;
  --muted: #5A6B70;
  --line: #D5DEDC;
  --gold: #B8862B;
  --danger: #A23B2A;
  --ok: #2F6B4F;
  --radius: 10px;
  --head: 'Prompt', 'Sarabun', system-ui, sans-serif;
  --body: 'Sarabun', 'Leelawadee UI', 'Tahoma', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { font-size: 17px; }
body { margin: 0; font-family: var(--body); color: var(--ink); background: var(--paper); line-height: 1.6; }
a { color: var(--sea); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--gold); outline-offset: 2px;
}
h1, h2, h3 { font-family: var(--head); font-weight: 600; line-height: 1.3; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
.page { padding-top: 28px; padding-bottom: 48px; min-height: 70vh; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }

/* แถบบน */
.topbar { background: var(--sea-deep); color: #fff; }
.topbar-inner { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand strong { display: block; font-family: var(--head); font-weight: 600; font-size: 1.05rem; }
.brand small { display: block; font-size: .78rem; opacity: .8; }
.brand-mark { width: 38px; height: 38px; border-radius: 50%; background: var(--gold); color: var(--sea-deep);
  display: grid; place-items: center; font-family: var(--head); font-size: 1.2rem; }
.whoami { margin-left: auto; }
.mainnav { display: flex; gap: 4px; flex-wrap: wrap; order: 3; flex-basis: 100%; margin: 0 -10px; }
.mainnav a { color: #DCEBEE; text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: .95rem; }
.mainnav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.mainnav a.active { background: rgba(255,255,255,.16); color: #fff; }
.whoami { display: flex; gap: 12px; align-items: center; font-size: .88rem; flex-wrap: wrap; }
.whoami a { color: #DCEBEE; }
.nav-toggle { display: none; }
@media (max-width: 860px) {
  .nav-toggle { display: inline-block; margin-left: auto; background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.4);
    border-radius: 6px; padding: 4px 12px; font: inherit; }
  .mainnav { display: none; flex-basis: 100%; flex-direction: column; }
  .mainnav.open { display: flex; }
  .whoami { flex-basis: 100%; margin-left: 0; }
}

.sitefoot { border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; padding: 18px 0 28px; }

/* ปุ่มและฟอร์ม */
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 500; padding: 8px 16px;
  border-radius: 8px; border: 1px solid var(--sea); background: var(--sea); color: #fff; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--sea-deep); }
.btn-outline { background: transparent; color: var(--sea); }
.btn-outline:hover { background: #E7F0F1; }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-sm { padding: 4px 10px; font-size: .88rem; }
.btn-link { background: none; border: 0; color: var(--sea); padding: 0; text-decoration: underline; cursor: pointer; font: inherit; }
label { display: block; font-weight: 500; margin-bottom: 4px; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=datetime-local], input[type=date],
input[type=search], input[type=file], select, textarea {
  width: 100%; font: inherit; padding: 8px 10px; border: 1px solid #B9C7C5; border-radius: 8px; background: #fff; color: var(--ink);
}
textarea { min-height: 90px; }
.field { margin-bottom: 14px; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 760px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.hint { font-size: .85rem; color: var(--muted); margin-top: 3px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 18px; border: 1px solid; }
.alert-success { background: #E8F2EC; border-color: #A9CDB8; color: #1F4D37; }
.alert-danger { background: #F7E8E5; border-color: #E0B1A8; color: #7A2A1D; }
.alert-warning { background: #FBF3E2; border-color: #E5CD95; color: #6B4E10; }
.alert-info { background: #E7F0F1; border-color: #A9C8CD; color: var(--sea-deep); }

.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; }

/* หน้าเข้าสู่ระบบ */
.login-shell { min-height: 82vh; display: grid; grid-template-columns: 1.1fr 1fr; gap: 0; max-width: 980px; margin: 4vh auto 0;
  border-radius: 14px; overflow: hidden; border: 1px solid var(--line); background: #fff; }
.login-side { background: var(--sea-deep); color: #fff; padding: 44px; display: flex; flex-direction: column; justify-content: space-between; }
.login-side h1 { font-size: 2rem; }
.login-codes { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.login-codes span { font-family: var(--head); border: 1px solid rgba(255,255,255,.35); border-radius: 6px; padding: 2px 10px; }
.login-form { padding: 44px; display: flex; flex-direction: column; justify-content: center; }
@media (max-width: 760px) { .login-shell { grid-template-columns: 1fr; } .login-side, .login-form { padding: 28px; } }

/* หมวดหมู่ในหน้าแรก — จุดเด่นของหน้า: รหัสหมวดตัวใหญ่ */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; margin-bottom: 32px; }
.cat-tile { position: relative; display: block; padding: 18px 20px 20px; border-radius: var(--radius); color: #fff; text-decoration: none;
  background: var(--c, var(--sea)); min-height: 150px; overflow: hidden; }
.cat-tile .code { font-family: var(--head); font-weight: 600; font-size: 2.6rem; line-height: 1; letter-spacing: -.01em; }
.cat-tile .name { display: block; margin-top: 10px; font-weight: 500; }
.cat-tile .count { position: absolute; right: 16px; top: 16px; font-size: .85rem; background: rgba(255,255,255,.18);
  padding: 1px 10px; border-radius: 99px; }
.cat-tile:hover { filter: brightness(1.08); }

/* รายการแบบทดสอบ */
.exam-list { display: grid; gap: 10px; }
.exam-row { display: grid; grid-template-columns: 6px 1fr auto; gap: 14px; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px 14px 0; align-items: center; }
.exam-row .bar { align-self: stretch; background: var(--c, var(--sea)); border-radius: 0 4px 4px 0; }
.exam-row h3 { margin: 0 0 2px; font-family: var(--body); font-weight: 600; font-size: 1.05rem; }
.exam-row h3 a { color: var(--ink); text-decoration: none; }
.exam-row h3 a:hover { text-decoration: underline; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .88rem; color: var(--muted); }
.dl-count { text-align: right; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.dl-count b { display: block; font-family: var(--head); font-size: 1.3rem; color: var(--ink); }
.tag { display: inline-block; font-size: .8rem; padding: 0 8px; border-radius: 99px; background: #E7F0F1; color: var(--sea-deep); }
.tag-draft { background: #F1EDE2; color: #6B4E10; }
.tag-hidden { background: #EEE; color: #555; }
.tag-published { background: #E8F2EC; color: #1F4D37; }

.filters { display: grid; grid-template-columns: 2fr repeat(4, 1fr) auto; gap: 10px; align-items: end; margin-bottom: 18px; }
@media (max-width: 900px) { .filters { grid-template-columns: 1fr 1fr; } }

.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ตาราง */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; font-size: .9rem; color: var(--muted); background: #F6F8F7; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ไฟล์ */
.file-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.file-item:last-child { border-bottom: 0; }
.file-locked { color: var(--muted); font-size: .9rem; }

/* แดชบอร์ด */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
@media (max-width: 760px) { .stats { grid-template-columns: 1fr 1fr; } }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-family: var(--head); font-size: 1.7rem; line-height: 1.2; }
.stat span { color: var(--muted); font-size: .9rem; }

.tree-row td:first-child { padding-left: calc(10px + var(--d, 0) * 26px); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.pager { display: flex; gap: 6px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.pager a, .pager span { padding: 4px 11px; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; background: #fff; }
.pager span { background: var(--sea); color: #fff; border-color: var(--sea); }
.announce { border-left: 4px solid var(--gold); background: var(--sand); padding: 12px 16px; border-radius: 0 8px 8px 0; margin-bottom: 10px; }
.announce h3 { margin: 0 0 2px; font-size: 1rem; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* กราฟแท่งรายเดือน (ไม่ต้องโหลดไลบรารีภายนอก) */
.colchart { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; height: 220px; align-items: end; }
.colchart .col { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; text-align: center; }
.colchart .b { background: var(--sea); border-radius: 4px 4px 0 0; min-height: 2px; }
.colchart .v { font-size: .78rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.colchart .m { font-size: .74rem; color: var(--muted); margin-top: 4px; white-space: nowrap; }
