﻿/* ระบบจัดการเช่า — Bravi Homes
   หน้าตากลาง ใช้ร่วมทุกหน้า: โทนสีทองตามโลโก้, ลายน้ำโลโก้กลางจอ, โครงเมนูข้าง (คอม) / ปุ่ม ☰ (มือถือ) */

:root {
  --gold: #bb9044;          /* สีทองของโลโก้ ใช้ตกแต่ง */
  --gold-dark: #8a6420;     /* ทองเข้ม ใช้กับปุ่มและลิงก์ (ตัวขาวบนพื้นนี้อ่านชัด) */
  --gold-soft: #f6efdf;     /* พื้นทองจาง ใช้กับเมนูที่เลือก */
  --ink: #1f2430;
  --ink-soft: #5b6372;
  --bg: #faf7f1;
  --card: #ffffff;
  --line: #e8e1d3;
  --red: #dc2626;
  --orange: #d97706;
  --green: #16a34a;
  --red-soft: #fdecec;
  --orange-soft: #fdf1df;
  --green-soft: #e4f6ea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 36, 48, 0.05), 0 4px 14px rgba(31, 36, 48, 0.06);
  --sidebar-w: 240px;
  --topbar-h: 60px;
  font-family: 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); font-size: 16px; line-height: 1.55; min-height: 100vh; }
img { max-width: 100%; }
a { color: var(--gold-dark); }
[hidden] { display: none !important; }

/* ลายน้ำโลโก้กลางจอ: อยู่บนสุดแต่กดทะลุได้ ไม่เลื่อนตาม ไม่บังข้อความ (ความทึบต่ำ) */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: url('/logo/logo.png') center / min(62vmin, 520px) no-repeat;
  opacity: 0.07;
  pointer-events: none;
  z-index: 9999;
}
@media print { body::after { opacity: 0.03; } }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid transparent; border-radius: 10px;
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--gold-dark); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #6f4f19; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { background: var(--gold-soft); }
.btn-danger { background: #fff; color: var(--red); border-color: #f3c0c0; }
.btn-danger:hover:not(:disabled) { background: var(--red-soft); }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn-block { width: 100%; }
:focus-visible { outline: 3px solid rgba(187, 144, 68, 0.55); outline-offset: 2px; }

/* ---------- ฟอร์ม ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 500; font-size: 15px; }
.field .hint { font-size: 13px; color: var(--ink-soft); }
.input-wrap { position: relative; }
input[type='text'], input[type='password'], input[type='search'], select {
  width: 100%; min-height: 46px; padding: 0 14px;
  font: inherit; font-size: 16px; /* 16px กัน iPhone ซูมหน้าจอเอง */
  color: var(--ink); background: #fff;
  border: 1px solid #d6cdb9; border-radius: 10px;
}
input:focus { border-color: var(--gold); outline: 3px solid rgba(187, 144, 68, 0.25); outline-offset: 0; }
.input-wrap input { padding-right: 76px; }
.toggle-pw {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  min-height: 34px; padding: 0 10px; border: 0; background: transparent;
  color: var(--gold-dark); font: inherit; font-size: 14px; cursor: pointer; border-radius: 8px;
}

/* ---------- การ์ด / ข้อความแจ้ง / ป้ายสถานะ ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.alert { padding: 12px 14px; border-radius: 10px; font-size: 15px; margin-bottom: 16px; border: 1px solid; }
.alert-error { background: var(--red-soft); border-color: #f3c0c0; color: #991b1b; }
.alert-ok { background: var(--green-soft); border-color: #b7e4c7; color: #166534; }
.alert-info { background: var(--gold-soft); border-color: #e6d5ad; color: #6b4d12; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 12px; border-radius: 999px; font-size: 14px; font-weight: 500; white-space: nowrap; }
.pill-red { background: var(--red-soft); color: #991b1b; }
.pill-orange { background: var(--orange-soft); color: #9a5b06; }
.pill-green { background: var(--green-soft); color: #166534; }
.pill-gray { background: #eceef2; color: var(--ink-soft); }

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 6px; margin-left: auto;
  background: var(--red); color: #fff; font-size: 13px; font-weight: 700; border-radius: 999px;
}

/* ---------- ตาราง ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: #f6f3ec; color: var(--ink-soft); font-weight: 500; font-size: 14px; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ตารางที่มี class table-cards: บนมือถือแต่ละแถวกลายเป็นการ์ด (ปุ่มไม่ต้องเลื่อนหา) ต้องใส่ data-label ในแต่ละ td */
@media (max-width: 700px) {
  .table-cards { min-width: 0; }
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .table-cards tr:last-child { border-bottom: 0; }
  .table-cards td { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 0; padding: 4px 0; text-align: right; }
  .table-cards td::before { content: attr(data-label); color: var(--ink-soft); font-size: 14px; text-align: left; }
  .table-cards td.actions-cell { padding-top: 10px; justify-content: flex-end; }
  .table-cards td.actions-cell::before { display: none; }
  .table-cards td.actions-cell .actions { width: 100%; }
  .table-cards td.actions-cell .btn { flex: 1; min-height: 44px; }
}

/* ---------- หน้าเข้าสู่ระบบ ---------- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-box { width: 100%; max-width: 420px; }
.auth-logo { display: block; width: min(220px, 60%); margin: 0 auto 4px; }
.auth-title { text-align: center; margin: 0 0 18px; font-size: 20px; font-weight: 700; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: #f1ece0; border-radius: 12px; padding: 4px; margin-bottom: 20px; }
.tab { min-height: 42px; border: 0; background: transparent; border-radius: 9px; font: inherit; font-weight: 500; color: var(--ink-soft); cursor: pointer; }
.tab[aria-selected='true'] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(31, 36, 48, 0.12); }

/* ---------- โครงหน้าหลังเข้าสู่ระบบ ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column;
  transform: translateX(-100%); transition: transform 0.22s ease;
}
.sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, 0.25); }
.sidebar-brand { padding: 18px 16px 10px; text-align: center; border-bottom: 1px solid var(--line); }
.sidebar-brand img { width: 132px; }
.sidebar-brand small { display: block; color: var(--ink-soft); font-size: 13px; margin-top: 2px; }
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 0 12px;
  border-radius: 10px; color: var(--ink); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: #f6f3ec; }
.nav a[aria-current='page'] { background: var(--gold-soft); color: #5e4310; }
.backdrop { position: fixed; inset: 0; background: rgba(31, 36, 48, 0.45); z-index: 30; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: rgba(255, 255, 255, 0.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { min-width: 44px; min-height: 44px; border: 1px solid var(--line); background: #fff; border-radius: 10px; font-size: 20px; cursor: pointer; }
.who { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-soft); }
.who .short { display: none; }
.who strong { color: var(--ink); font-weight: 500; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { padding: 20px 16px 48px; width: 100%; max-width: 1100px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h2 { margin: 0; font-size: 20px; }
.muted { color: var(--ink-soft); }
.empty { text-align: center; padding: 40px 16px; color: var(--ink-soft); }

@media (min-width: 900px) {
  .sidebar { transform: none; }
  .main { margin-left: var(--sidebar-w); }
  .menu-btn, .backdrop { display: none; }
  .content { padding: 28px 28px 56px; }
}
@media (max-width: 520px) {
  .who strong { display: none; }
  .who .full { display: none; }
  .who .short { display: inline; }
  .topbar h1 { font-size: 16px; }
}

/* ---------- ส่วนเพิ่มสำหรับหน้าข้อมูลหลัก ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .grow { flex: 1; min-width: 180px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { min-height: 38px; padding: 0 14px; border: 1px solid var(--line); background: #fff; border-radius: 999px; font: inherit; font-size: 14px; cursor: pointer; color: var(--ink); }
.chip[aria-pressed='true'] { background: var(--gold-soft); border-color: var(--gold); color: #5e4310; font-weight: 500; }
.status-btn { border: 0; font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; min-height: 34px; }
.status-btn .caret { margin-left: 6px; opacity: 0.6; font-size: 12px; }
.req { color: var(--red); }
.sub { color: var(--ink-soft); font-size: 13px; display: block; }
.tag { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--orange-soft); color: #9a5b06; margin-left: 6px; white-space: nowrap; }
.tag-red { background: var(--red-soft); color: #991b1b; }
a.row-link { color: inherit; text-decoration: none; font-weight: 500; }
a.row-link:hover { color: var(--gold-dark); text-decoration: underline; }

/* ป๊อปอัป */
dialog.modal { border: 0; border-radius: 16px; padding: 0; width: min(580px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); color: var(--ink); background: #fff; }
dialog.modal::backdrop { background: rgba(31, 36, 48, 0.55); }
dialog.modal form { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 18px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); background: #fcfaf6; border-radius: 0 0 16px 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.field-wide { grid-column: 1 / -1; }
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice { justify-content: flex-start; font-size: 17px; min-height: 52px; }
@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; }
}
input[type='number'], input[type='tel'], input[type='date'], input[type='month'], input[type='file'] {
  width: 100%; min-height: 46px; padding: 0 14px; font: inherit; font-size: 16px; color: var(--ink); background: #fff; border: 1px solid #d6cdb9; border-radius: 10px;
}
input[type='file'] { padding: 9px 12px; }

/* ข้อความแจ้งสั้นๆ */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 10000; display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100vw - 24px)); }
.toast { padding: 12px 16px; border-radius: 12px; font-size: 15px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); color: #fff; background: #1f2430; }
.toast-ok { background: #166534; }
.toast-error { background: #991b1b; }

/* หน้ารายละเอียดห้อง */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 0; }
.kv dt { color: var(--ink-soft); }
.kv dd { margin: 0; }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin: 24px 0 10px; }
.section-title h3 { margin: 0; font-size: 18px; }
.history { list-style: none; margin: 0; padding: 0; }
.history li { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.history li:last-child { border-bottom: 0; }

/* โน้ต */
textarea { width: 100%; min-height: 96px; padding: 10px 14px; font: inherit; font-size: 16px; line-height: 1.5; color: var(--ink); background: #fff; border: 1px solid #d6cdb9; border-radius: 10px; resize: vertical; }
textarea:focus { border-color: var(--gold); outline: 3px solid rgba(187, 144, 68, 0.25); outline-offset: 0; }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.note-preview { margin-top: 2px; max-width: 420px; }

/* ช่องค่าปรับในตารางรายเดือน: ป้าย คำอธิบาย ปุ่ม เรียงเป็นแนวตั้งในกล่องเดียว */
.fee-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; max-width: 320px; }
.fee-cell .sub { white-space: normal; }
@media (max-width: 700px) {
  .fee-cell { align-items: flex-end; text-align: right; max-width: 100%; }
  .fee-cell .actions { justify-content: flex-end; }
}

/* ปุ่มสลับเลือกตัวเลือกเดียว (เช่น ไม่มีค่าปรับ / มีค่าปรับ) */
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #f1ece0; padding: 4px; border-radius: 12px; }
.seg { min-height: 44px; border: 0; border-radius: 9px; background: transparent; font: inherit; font-weight: 500; color: var(--ink-soft); cursor: pointer; }
.seg[aria-pressed='true'] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(31, 36, 48, 0.15); }
