/* จับคู่โทนสีกับ Theme.cs ฝั่ง WinForms: #C74634 (Oracle Red, ใช้เป็น accent) และ
   #3C4545 (Slate 150, สีโครงสร้างหลัก) ฟอนต์ใช้ Sarabun เหมือนกัน (fallback Noto Sans Thai) */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;600;700&display=swap');

:root {
  --ora-red: #C74634;
  --slate: #3C4545;
  --bg: #F0F2F5;
  --border: #D2DCEB;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: 'Sarabun', 'Noto Sans Thai', 'Leelawadee UI', Tahoma, sans-serif;
  background: var(--bg); color: #222;
}

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: #fff; padding: 14px 24px; border-bottom: 2px solid var(--slate);
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; min-width: 0; } /* [แก้] เป็นลิงก์ไป /Hub */
.brand-logo { font-size: 28px; }
.brand-title { font-size: 20px; font-weight: 700; color: #2e7d32; }
.brand-sub { font-size: 11px; letter-spacing: 1px; color: #888; }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.btn-home {
  background: var(--slate); color: #fff; padding: 6px 14px; border-radius: 4px;
  text-decoration: none; font-size: 13px; font-weight: 600; white-space: nowrap;
}
.btn-home:hover { background: #2B3232; }
.btn-logout {
  background: var(--ora-red); color: #fff; padding: 6px 14px; border-radius: 4px;
  text-decoration: none; font-size: 13px;
}

.shell { display: flex; min-height: calc(100vh - 60px); }
.menu-col { width: 220px; background: #fff; border-right: 1px solid var(--border); padding: 16px 0; }
.menu-col-title { padding: 0 16px 8px; font-size: 12px; color: #888; }
.menu-group {
  display: block; padding: 10px 16px; color: var(--slate); text-decoration: none;
  font-weight: 600; font-size: 14px; border-left: 3px solid transparent;
}
.menu-group:hover { background: #f5f7fa; border-left-color: var(--ora-red); }
.menu-note { padding: 12px 16px; font-size: 11px; color: #999; border-top: 1px solid var(--border); margin-top: 12px; }

/* [แก้] min-width: 0 — ไม่มีบรรทัดนี้ ตารางกว้างๆ จะดันกล่องเนื้อหา (และทั้งหน้า) ให้กว้างเกินจอ
   ตารางจึงเลื่อนแนวนอนในกรอบของตัวเองไม่ได้ (ต้นเหตุหน้าล้นจอบนมือถือ) */
.content { flex: 1; min-width: 0; padding: 24px 32px; }
.content-plain { padding: 60px 20px; }

.page-title { margin: 0 0 20px; font-size: 20px; color: var(--slate); }
.breadcrumb { color: #666; font-size: 14px; margin-bottom: 16px; }

.hub-group { margin-bottom: 28px; }
.hub-group h2 { font-size: 15px; color: var(--slate); border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.tile-grid { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; }
.tile {
  width: 158px; height: 96px; background: #1565c0; color: #fff; border-radius: 6px;
  padding: 12px; text-decoration: none; display: flex; flex-direction: column; justify-content: flex-end;
  position: relative;
}
.tile-th { font-weight: 700; font-size: 13px; }
.tile-en { font-size: 11px; opacity: .85; }
.tile-disabled { background: #90a4ae; }
.tile-badge {
  position: absolute; top: 6px; right: 6px; font-size: 9px; background: rgba(0,0,0,.25);
  padding: 2px 6px; border-radius: 10px;
}

.search-row { display: flex; gap: 8px; margin-bottom: 14px; }
.search-row input { flex: 1; max-width: 360px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 4px; }
.search-row button {
  background: var(--slate); color: #fff; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer;
}
.summary-row { margin-bottom: 10px; font-size: 14px; color: #444; }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--border); border-radius: 6px; }
table.grid { border-collapse: collapse; width: 100%; font-size: 13px; white-space: nowrap; }
table.grid th, table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
table.grid th { background: #f5f7fa; color: var(--slate); }
table.grid td.num { text-align: right; }
table.grid .empty { text-align: center; color: #999; padding: 24px; }
.error-box { background: #fdecea; color: #b3261e; padding: 12px 16px; border-radius: 6px; }
.note { font-size: 12px; color: #888; margin-top: 14px; }

.login-box { display: flex; justify-content: center; }
.login-card {
  background: #fff; padding: 32px; border-radius: 8px; width: 320px; text-align: center;
  box-shadow: 0 2px 10px rgba(0,0,0,.08);
}
.login-logo { font-size: 40px; }
.login-card h2 { margin: 6px 0 2px; color: #2e7d32; }
.login-sub { font-size: 12px; color: #888; margin-bottom: 16px; }
.login-error { background: #fdecea; color: #b3261e; padding: 8px; border-radius: 4px; margin-bottom: 12px; font-size: 13px; }
.login-card form { display: flex; flex-direction: column; gap: 4px; text-align: left; }
.login-card label { font-size: 12px; color: #666; margin-top: 8px; }
.login-card input { padding: 9px 10px; border: 1px solid var(--border); border-radius: 4px; font-size: 14px; }
.login-card button {
  margin-top: 18px; background: var(--ora-red); color: #fff; border: none; padding: 10px;
  border-radius: 4px; font-size: 14px; cursor: pointer;
}

.placeholder-box { text-align: center; padding: 60px 0; color: #666; }
.placeholder-icon { font-size: 40px; }

/* =====================================================================
   [ใหม่] มือถือ / จอแคบ — เมนูซ้ายพับเก็บ (ปุ่ม ☰), ตัดระยะขอบ, การ์ดเมนูเป็น 2 คอลัมน์
   ===================================================================== */
.menu-toggle {
  display: none; background: none; border: 1px solid var(--border); border-radius: 6px;
  font-size: 20px; line-height: 1; padding: 6px 10px; color: var(--slate); cursor: pointer;
}
.menu-backdrop { display: none; }

@media (max-width: 768px) {
  .topbar { padding: 10px 12px; gap: 8px; position: sticky; top: 0; z-index: 900; }
  .menu-toggle { display: block; }
  .brand { gap: 8px; }
  .brand-logo { font-size: 22px; }
  .brand-title { font-size: 18px; }
  .brand-sub { display: none; }
  .topbar-right { gap: 8px; font-size: 13px; flex-shrink: 0; }
  .topbar-user { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .btn-logout { padding: 6px 10px; font-size: 12px; white-space: nowrap; }
  .btn-home { padding: 6px 10px; font-size: 12px; }

  .shell { display: block; min-height: 0; }

  /* เมนูซ้ายเลื่อนออกมาจากด้านซ้าย */
  .menu-col {
    position: fixed; top: 0; left: 0; bottom: 0; width: 260px; max-width: 80vw; z-index: 1001;
    overflow-y: auto; transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,.15); padding-top: 20px;
  }
  .menu-group { padding: 12px 18px; font-size: 15px; }
  body.menu-open .menu-col { transform: translateX(0); }
  body.menu-open .menu-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1000;
  }
  body.menu-open { overflow: hidden; }

  .content { padding: 14px 12px; }
  .content-plain { padding: 30px 12px; }
  .page-title { font-size: 18px; margin-bottom: 14px; }

  /* หน้า Hub: การ์ด 2 คอลัมน์เต็มจอ */
  .tile-grid { gap: 10px; }
  .tile { width: calc(50% - 5px); height: 88px; }

  .search-row { flex-wrap: wrap; }
  .search-row input { max-width: none; min-width: 0; }

  .login-card { width: 100%; max-width: 340px; padding: 24px 20px; }

  /* iOS ซูมเข้าเองเมื่อแตะช่องที่ฟอนต์เล็กกว่า 16px */
  input, select, textarea { font-size: 16px; }
}

/* ===== [ใหม่ — หลายบริษัท] ชื่อบริษัทแถบบน · หน้าเลือกบริษัท · เปลี่ยนรหัสผ่าน ===== */
.topbar-company {
  padding: 5px 10px; border-radius: 4px; background: #eef1f1; border: 1px solid var(--border);
  color: var(--slate); text-decoration: none; font-weight: 600; white-space: nowrap;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}
a.topbar-company:hover { background: #e2e7e7; border-color: var(--slate); }
.btn-pass { color: inherit; text-decoration: none; font-size: 15px; opacity: .85; }
.btn-pass:hover { opacity: 1; }
.login-hint { font-size: 11px; color: #999; margin-top: 14px; }
.co-card { width: 420px; max-width: 100%; }
.co-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.co-list .co-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; margin: 0;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; color: #222; cursor: pointer; text-align: left; font-family: inherit;
}
.co-list .co-item:hover { border-color: #3C4545; background: #f5f7f7; }
.co-list .co-current { border-color: #2e7d32; background: #f1f8f1; }
.co-name { font-size: 15px; font-weight: 600; }
.co-meta { font-size: 12px; color: #777; }
.co-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 14px; margin-top: 16px; font-size: 13px; }
.co-links a { color: #555; }
@media (max-width: 768px) {
  .topbar-company { max-width: 110px; padding: 4px 8px; font-size: 12px; }
  .co-card { padding: 20px 14px; }
}

/* ===== [รอบ 3] หน้าจัดการผู้ใช้ / บริษัท ===== */
.adm-head h2 { margin: 0 0 4px; color: var(--slate); }
.adm-sub { font-size: 13px; color: #777; margin-bottom: 14px; }
.adm-msg { background: #e8f5e9; color: #1b5e20; padding: 9px 12px; border-radius: 4px; margin-bottom: 12px; font-size: 13px; }
.adm-err { background: #fdecea; color: #b3261e; padding: 9px 12px; border-radius: 4px; margin-bottom: 12px; font-size: 13px; }
.adm-ok { color: #2e7d32; font-weight: 600; }
.adm-warn { color: #b26a00; font-weight: 600; }
.adm-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.adm-card { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 14px 16px; }
.adm-card-title { font-weight: 700; color: var(--slate); margin-bottom: 10px; }
.adm-table-wrap { overflow-x: auto; }
.adm-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.adm-table th { text-align: left; background: #f3f5f7; color: #555; font-weight: 600; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.adm-table td { padding: 7px 8px; border-bottom: 1px solid #eef1f5; vertical-align: middle; }
.adm-table tr.adm-off td { color: #aaa; }
.adm-actions { white-space: nowrap; text-align: right; }
.adm-actions a { margin-right: 8px; }
.adm-inline { display: inline; }
.adm-link-danger { background: none; border: none; color: #b3261e; cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }
.adm-tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 10px; background: #eef1f1; color: #555; margin-left: 4px; }
.adm-tag-dark { background: var(--slate); color: #fff; }
.adm-tag-red { background: var(--ora-red); color: #fff; }
.adm-form { display: flex; flex-direction: column; gap: 4px; }
.adm-form label { font-size: 12px; color: #666; margin-top: 8px; }
.adm-form input[type=text], .adm-form select { padding: 8px 9px; border: 1px solid var(--border); border-radius: 4px; font-size: 14px; font-family: inherit; }
.adm-form .adm-ro { background: #f3f5f7; color: #666; }
.adm-checks { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.adm-checks label { margin-top: 4px; color: #333; font-size: 13px; }
.adm-note { font-size: 11px; color: #999; margin-top: 4px; }
.adm-sep { margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--border); font-size: 12px; font-weight: 600; color: var(--slate); }
.adm-buttons { display: flex; gap: 10px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.adm-btn { background: var(--ora-red); color: #fff; border: none; padding: 9px 16px; border-radius: 4px; font-size: 14px; cursor: pointer; font-family: inherit; }
.adm-btn:disabled { opacity: .7; cursor: wait; }
.adm-btn-sec { font-size: 13px; color: #555; }
@media (max-width: 900px) { .adm-grid { grid-template-columns: 1fr; } }

/* [รอบ 3.1] ช่องชื่อผู้ใช้ + ตัวย่อบริษัท (somchai | @yhm) */
.adm-suffix { display: flex; align-items: stretch; }
.adm-suffix input[type=text] { flex: 1; min-width: 0; border-top-right-radius: 0 !important; border-bottom-right-radius: 0 !important; }
.adm-suffix span { display: flex; align-items: center; padding: 0 10px; background: #f3f5f7; border: 1px solid var(--border); border-left: none; border-radius: 0 4px 4px 0; color: #555; font-size: 14px; font-weight: 600; white-space: nowrap; }
.adm-suffix-pre input[type=text] { border-radius: 0 4px 4px 0 !important; }
.adm-suffix-pre span { border-left: 1px solid var(--border); border-right: none; border-radius: 4px 0 0 4px; }
