/* c.css — สไตล์หน้านักเรียน C Sandbox (ทับ/เสริม style.css ที่ยกมาจาก SQL Sandbox)
 *
 * ⚠ style.css มีกฎ element selector และกฎ ID อย่าง `#login-screen { display:flex }`
 *   ที่แผ่มาถึงที่นี่ด้วย (gotcha ข้อ 13 ของโปรเจกต์เดิม) — เวลาเขียน flex container
 *   ใหม่ต้องระบุ justify-content เองเสมอ */

/* ⚠ ต้องมี — กฎ ID ใน style.css specificity สูงกว่า `[hidden]{display:none}` ของเบราว์เซอร์
 *   ทำให้ `el.hidden = true` ไม่ซ่อน (เคยทำให้หน้า login ค้างบังแอพหลังล็อกอินสำเร็จ) */
[hidden] { display: none !important; }

body { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
#app { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; width: 100%; }

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; }
.header-right { display: flex; align-items: center; gap: 12px; }
.who { color: var(--blue); font-weight: 600; }
.muted { color: var(--muted); }
.sm { font-size: 12px; }
.menu-btn { display: none; }

/* ── โครง 3 คอลัมน์ ── */
.shell {
  flex: 1 1 auto; min-height: 0;
  display: grid; grid-template-columns: 232px minmax(0, 1fr) 400px;
}

/* ── ไซด์บาร์ ── */
.side {
  border-right: 1px solid var(--border); overflow: auto;
  display: flex; flex-direction: column; gap: 4px; padding: 8px 6px;
}
.side-sec { display: flex; flex-direction: column; }
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px 4px; color: var(--muted); font-size: 12px; font-weight: 600;
}
.side-list { display: flex; flex-direction: column; }
.side-empty { color: var(--muted); font-size: 12px; padding: 6px 10px; }

.side-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13.5px;
}
.side-row:hover { background: var(--panel); }
.side-row.active { background: var(--panel-2); }
.row-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-acts { display: none; gap: 2px; }
.side-row:hover .row-acts { display: flex; }
.row-act {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 12px; padding: 2px 5px; border-radius: 4px; font-family: inherit;
}
.row-act:hover { background: var(--panel-2); color: var(--text); }
.row-check { color: var(--green); }

.ex-no {
  flex: 0 0 22px; height: 20px; line-height: 20px; text-align: center;
  background: var(--panel-2); border-radius: 5px; font-size: 11px; font-weight: 700;
}
.side-row.done .ex-no { background: var(--green); color: #06281a; }
.badge { background: var(--panel-2); border-radius: 10px; padding: 1px 8px; font-size: 11px; font-weight: 400; }

/* ── กลาง: หัวแถบ + โจทย์ + editor ── */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.io { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--border); }

.pane-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--muted); flex: 0 0 auto;
}
.pane-actions { display: flex; align-items: center; gap: 8px; }
.open-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.open-icon {
  background: var(--panel-2); color: var(--muted); border-radius: 4px;
  padding: 1px 7px; font-size: 11px; flex: 0 0 auto;
}
#open-title { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.prob {
  flex: 0 0 auto; max-height: 42%; overflow: auto;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.prob > summary {
  cursor: pointer; padding: 8px 12px; font-size: 13px; color: var(--blue);
  position: sticky; top: 0; background: var(--panel); user-select: none;
}
.prob-body { padding: 4px 14px 14px; }
.prob-body p { margin: 0 0 6px; line-height: 1.7; }

.CodeMirror { flex: 1 1 auto; min-height: 0; font-size: 14px; line-height: 1.55; }

/* ── ขวา: stdin + ผลลัพธ์ ── */
.io-box {
  flex: 0 0 120px; resize: none; background: var(--code-bg); color: var(--text);
  border: none; border-bottom: 1px solid var(--border); padding: 10px 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px;
}
.io-box:focus { outline: 1px solid var(--blue); outline-offset: -1px; }

/* ชี้ให้เห็นตอนโค้ดมี scanf แต่ยังไม่ได้ใส่ข้อมูล — กับดักที่เงียบที่สุดของโหมด batch */
.stdin-hint { color: var(--orange); font-size: 11px; }
body.needs-stdin .io-box { outline: 1px solid var(--orange); outline-offset: -1px; }
body.needs-stdin .io-box::placeholder { color: var(--orange); opacity: .75; }

.output { flex: 1 1 auto; overflow: auto; padding: 12px; min-height: 0; }
.placeholder { color: var(--muted); font-size: 13px; padding: 6px 0; }

pre.stdout, pre.stderr {
  background: var(--code-bg); border-radius: 6px; padding: 10px 12px; margin: 0 0 10px;
  white-space: pre-wrap; word-break: break-word; font-size: 13px; line-height: 1.5;
  max-height: 340px; overflow: auto;
}
pre.stderr { color: var(--orange); border-left: 3px solid var(--orange); }

.msg { border-radius: 6px; padding: 8px 12px; margin-bottom: 10px; font-size: 13.5px; line-height: 1.6; }
.msg.ok   { background: rgba(74,222,128,.12); color: var(--green);  border-left: 3px solid var(--green); }
.msg.err  { background: rgba(248,113,113,.12); color: var(--red);   border-left: 3px solid var(--red); }
.msg.warn { background: rgba(251,146,60,.12); color: var(--orange); border-left: 3px solid var(--orange); }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0; line-height: 1.6; }

/* ── ข้อความ error ที่แปลไทยแล้ว ── */
.diags { display: flex; flex-direction: column; gap: 8px; }
.diag { background: var(--panel); border-radius: 6px; padding: 8px 10px; border-left: 3px solid var(--red); }
.diag.warning { border-left-color: var(--orange); }
.diag-head { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.diag-loc { color: var(--blue); font-size: 12px; font-weight: 600; }
.diag-kind { color: var(--muted); font-size: 11px; }
.diag-thai { font-size: 13.5px; line-height: 1.65; margin-bottom: 5px; }
.diag-raw {
  display: block; color: var(--muted); font-size: 11.5px; background: var(--code-bg);
  padding: 4px 8px; border-radius: 4px; white-space: pre-wrap; word-break: break-word;
}

.save-status { font-size: 12px; color: var(--muted); }
.save-status.ok    { color: var(--green); }
.save-status.dirty { color: var(--orange); }
.save-status.err   { color: var(--red); }

/* ── โจทย์ / ผลตรวจ ── */
.sample { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 8px 0; }
.sample-label { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.sample pre, .test-grid pre {
  background: var(--code-bg); border-radius: 6px; padding: 8px 10px; margin: 0;
  font-size: 13px; white-space: pre-wrap; word-break: break-word; max-height: 180px; overflow: auto;
}
.ex-explain {
  background: rgba(56,189,248,.08); border-left: 3px solid var(--blue);
  padding: 10px 12px; border-radius: 6px; line-height: 1.7; margin-bottom: 12px; font-size: 13.5px;
}
.tests { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.test { background: var(--panel); border-radius: 6px; padding: 10px 12px; border-left: 3px solid var(--panel-2); }
.test.ok  { border-left-color: var(--green); }
.test.bad { border-left-color: var(--red); }
.test-head { font-size: 13px; margin-bottom: 6px; }
.test-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 6px 0; }
.test-grid > div { min-width: 0; }

/* ── ปุ่ม ── */
.btn-primary, .btn-ghost {
  font-family: inherit; font-size: 14px; border-radius: 6px; cursor: pointer;
  padding: 7px 14px; border: 1px solid transparent;
}
.btn-primary { background: var(--blue); color: #06283a; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .55; cursor: default; }
.btn-ghost { background: none; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--panel-2); }
.btn-primary.sm, .btn-ghost.sm { padding: 4px 10px; font-size: 12.5px; }

/* ── login ── */
.login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 50; padding: 20px; overflow: auto;
}
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 28px; width: min(460px, 100%); display: flex; flex-direction: column; gap: 12px;
  text-align: left;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-sub { margin: 0; color: var(--muted); font-size: 13.5px; }
.login-prev {
  background: rgba(251,146,60,.12); color: var(--orange); border-radius: 6px;
  padding: 8px 10px; font-size: 12.5px; line-height: 1.5;
}
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-card input, .login-card select {
  background: var(--code-bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 8px 10px; font-family: inherit; font-size: 14px;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.login-error { color: var(--red); font-size: 13px; margin: 0; }

/* ── toast ── */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); color: var(--text); padding: 10px 18px;
  border-radius: 8px; font-size: 14px; z-index: 100; box-shadow: 0 4px 20px rgba(0,0,0,.4);
}
.toast.ok { background: var(--green); color: #06281a; }

/* ── จอแคบ: ไซด์บาร์กลายเป็น drawer · io ลงมาข้างล่าง ── */
@media (max-width: 1100px) {
  .shell { grid-template-columns: 200px minmax(0, 1fr) 330px; }
}
@media (max-width: 880px) {
  .menu-btn { display: inline-block; }
  .shell { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .side {
    position: fixed; top: 0; bottom: 0; left: 0; width: 250px; z-index: 60;
    background: var(--bg); transform: translateX(-100%); transition: transform .18s;
  }
  .side.open { transform: none; box-shadow: 4px 0 24px rgba(0,0,0,.5); }
  .io { border-left: none; border-top: 1px solid var(--border); max-height: 45vh; }
  .row3 { grid-template-columns: 1fr; }
}

/* ── terminal โหมดโต้ตอบ ──
 * ต้องพิมพ์ "ต่อท้าย prompt" ในสายข้อความเดียวกัน ไม่ใช่กล่องแยกข้างล่าง
 * เพราะโปรแกรมเมนูจะพิมพ์ "เลือก: " แล้วรอ — ถ้าแยกกล่อง เด็กจะไม่เห็นว่ากำลังตอบอะไร */
.term { flex: 1 1 auto; min-height: 0; position: relative; display: flex; }
#term-out {
  flex: 1 1 auto; margin: 0; padding: 12px; overflow: auto; min-height: 0;
  background: var(--code-bg); color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px; line-height: 1.55; white-space: pre-wrap; word-break: break-word;
  cursor: text;
}
/* input จริงต้องอยู่ใน DOM และ focus ได้ (เพื่อให้ IME ไทย + paste ทำงาน)
   แต่ต้องมองไม่เห็น — ใช้ opacity:0 ไม่ใช่ display:none เพราะ display:none จะ focus ไม่ได้ */
.term-key {
  position: absolute; opacity: 0; width: 1px; height: 1px;
  border: none; padding: 0; left: 0; bottom: 0;
}
.caret {
  display: inline-block; width: 7px; height: 1.05em; vertical-align: text-bottom;
  background: var(--blue); animation: blink 1.1s step-end infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* บอกว่า "กำลังรอข้อมูล" — จำเป็นเพราะโจทย์บังคับไม่ให้พิมพ์ prompt
   จอจะว่างสนิท เด็กแยกไม่ออกว่ารอข้อมูล กับ โปรแกรมค้าง */
.term-wait {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: rgba(251,146,60,.14); color: var(--orange);
  padding: 5px 12px; font-size: 12px; border-top: 1px solid rgba(251,146,60,.3);
}
