/*
 * kbill - hand-written CSS (no build step, no framework dependency)
 * แทนที่ Tailwind ทั้งหมด ใช้ชื่อคลาสเดิมที่มีอยู่แล้วในไฟล์ .php เพื่อไม่ต้องแก้ markup เพิ่ม
 * โทนสี: navy (#1e3a8a) สำหรับ sidebar + orange (#f97316) สำหรับปุ่มหลัก/accent (อิงจาก beauty.test)
 */

*, ::before, ::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
        "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font: inherit;
    cursor: pointer;
    border: none;
    background: none;
}

table {
    border-collapse: collapse;
}

input, select, textarea {
    font: inherit;
    color: inherit;
}

/* ===== Layout ===== */
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }
.block { display: block; }
.inline-block { display: inline-block; }
.inline { display: inline; }
.hidden { display: none; }

.flex-1 { flex: 1 1 0%; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.shrink-0 { flex-shrink: 0; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.self-center { align-self: center; }

.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }

.col-span-2 { grid-column: span 2 / span 2; }

.min-h-screen { min-height: 100vh; }
.min-w-0 { min-width: 0; }
.min-w-full { min-width: 100%; }
.w-full { width: 100%; }
.w-16 { width: 4rem; }
.w-20 { width: 5rem; }
.w-24 { width: 6rem; }
.max-h-20 { max-height: 5rem; }
.w-28 { width: 7rem; }
.w-32 { width: 8rem; }
.w-56 { width: 14rem; }
.w-60 { width: 15rem; }
.w-64 { width: 16rem; }
.w-72 { width: 18rem; }
.max-w-2xl { max-width: 42rem; }
.max-w-md { max-width: 28rem; }
.max-w-sm { max-width: 24rem; }
.max-w-xl { max-width: 36rem; }
.max-w-xs { max-width: 20rem; }
.ml-auto { margin-left: auto; }
.mr-3 { margin-right: 0.75rem; }

.overflow-x-auto { overflow-x: auto; }
.whitespace-nowrap { white-space: nowrap; }
.whitespace-pre-wrap { white-space: pre-wrap; }

/* ใช้กับข้อความที่ผ่าน render_rich_text() (**ตัวหนา** + bullet list) - คืนค่า padding ที่ reset ไปตอนต้นไฟล์ */
.rich-text ul { margin: 0.25rem 0; padding-left: 1.25rem; list-style-type: disc; }
.rich-text li { margin-bottom: 0.125rem; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.divide-y > * + * { border-top-width: 1px; border-top-style: solid; }
.divide-gray-100 > * + * { border-color: #f3f4f6; }

.space-x-2 > * + * { margin-left: 0.5rem; }
.space-y-1 > * + * { margin-top: 0.25rem; }
.space-y-2 > * + * { margin-top: 0.5rem; }
.space-y-4 > * + * { margin-top: 1rem; }
.space-y-6 > * + * { margin-top: 1.5rem; }

/* ===== Spacing ===== */
.p-2 { padding: 0.5rem; }
.p-3 { padding: 0.75rem; }
.p-4 { padding: 1rem; }
.p-5 { padding: 1.25rem; }
.p-6 { padding: 1.5rem; }
.p-8 { padding: 2rem; }

.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.px-3 { padding-left: 0.75rem; padding-right: 0.75rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.px-5 { padding-left: 1.25rem; padding-right: 1.25rem; }
.px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }

.py-0\.5 { padding-top: 0.125rem; padding-bottom: 0.125rem; }
.py-1 { padding-top: 0.25rem; padding-bottom: 0.25rem; }
.py-1\.5 { padding-top: 0.375rem; padding-bottom: 0.375rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-2\.5 { padding-top: 0.625rem; padding-bottom: 0.625rem; }
.py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }
.py-8 { padding-top: 2rem; padding-bottom: 2rem; }

.pt-2 { padding-top: 0.5rem; }

.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }

.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mt-8 { margin-top: 2rem; }

/* ===== Borders / radius / shadow ===== */
.border { border: 1px solid #e5e7eb; }
.border-b { border-bottom: 1px solid #e5e7eb; }
.border-t { border-top: 1px solid #e5e7eb; }
.border-l-4 { border-left: 4px solid transparent; }

.border-gray-100 { border-color: #f3f4f6; }
.border-gray-200 { border-color: #e5e7eb; }
.border-gray-300 { border-color: #d1d5db; }
.border-gray-800 { border-color: #1f2937; }
.border-red-200 { border-color: #fecaca; }
.border-red-300 { border-color: #fca5a5; }
.border-green-200 { border-color: #bbf7d0; }
.border-blue-200 { border-color: #bfdbfe; }
.border-orange-400 { border-color: #fb923c; }
.border-transparent { border-color: transparent; }

.rounded { border-radius: 0.25rem; }
.rounded-md { border-radius: 0.375rem; }
.rounded-lg { border-radius: 0.5rem; }
.rounded-full { border-radius: 9999px; }

.shadow { box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1); }
.shadow-sm { box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); }

/* ===== Typography ===== */
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.text-base { font-size: 1rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.text-2xl { font-size: 1.5rem; }

.font-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.font-normal { font-weight: 400; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.align-top { vertical-align: top; }

.list-disc { list-style-type: disc; }
.list-inside { list-style-position: inside; }

/* ===== Colors: background ===== */
.bg-white { background-color: #fff; }
.bg-gray-50 { background-color: #f9fafb; }
.bg-gray-100 { background-color: #f3f4f6; }
.bg-gray-200 { background-color: #e5e7eb; }
.bg-gray-900 { background-color: #1e3a8a; } /* navy sidebar, ตาม beauty.test */
.bg-gray-800 { background-color: #1e40af; } /* navy active item */
.bg-gray-700 { background-color: #374151; }
.bg-blue-50 { background-color: #eff6ff; }
.bg-blue-100 { background-color: #dbeafe; }
.bg-green-50 { background-color: #f0fdf4; }
.bg-green-100 { background-color: #dcfce7; }
.bg-red-50 { background-color: #fef2f2; }
.bg-red-100 { background-color: #fee2e2; }
.bg-yellow-100 { background-color: #fef9c3; }
.bg-orange-600 { background-color: #ea580c; }
.bg-green-600 { background-color: #16a34a; }

/* ===== Colors: text ===== */
.text-white { color: #fff; }
.text-gray-200 { color: #e5e7eb; }
.text-gray-300 { color: #bfdbfe; } /* navy theme: inactive sidebar link */
.text-gray-400 { color: #9ca3af; }
.text-gray-500 { color: #6b7280; }
.text-gray-600 { color: #4b5563; }
.text-gray-700 { color: #374151; }
.text-gray-800 { color: #1f2937; }
.text-gray-900 { color: #111827; }
.text-blue-600 { color: #2563eb; }
.text-blue-700 { color: #1d4ed8; }
.text-blue-800 { color: #1e40af; }
.text-green-700 { color: #15803d; }
.text-red-600 { color: #dc2626; }
.text-red-700 { color: #b91c1c; }
.text-yellow-700 { color: #a16207; }
.text-orange-600 { color: #ea580c; }

/* ===== Hover / focus states ===== */
.hover\:bg-gray-50:hover { background-color: #f9fafb; }
.hover\:bg-gray-600:hover { background-color: #4b5563; }
.hover\:bg-gray-700:hover { background-color: #374151; }
.hover\:bg-gray-800:hover { background-color: #1e40af; }
.hover\:bg-green-500:hover { background-color: #22c55e; }
.hover\:bg-orange-500:hover { background-color: #f97316; }
.hover\:bg-red-50:hover { background-color: #fef2f2; }
.hover\:border-orange-400:hover { border-color: #fb923c; }
.hover\:bg-gray-200:hover { background-color: #e5e7eb; }
.hover\:text-white:hover { color: #fff; }
.hover\:underline:hover { text-decoration: underline; }

.focus\:outline-none:focus { outline: none; }
.focus\:ring-2:focus { box-shadow: 0 0 0 2px #1f2937; }
.focus\:ring-gray-800:focus { box-shadow: 0 0 0 2px #1f2937; }

.cursor-not-allowed { cursor: not-allowed; }

/* ===== Responsive ===== */
@media (min-width: 640px) {
    .sm\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ===== Sidebar: collapsible + logo ===== */
#sidebar {
    transition: width 0.15s ease;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #1f2937;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    overflow: hidden;
    width: 100%;
    padding: 0.375rem;
    margin: -0.375rem;
    border-radius: 0.375rem;
}

.sidebar-logo:hover {
    background-color: #1e40af;
}

.sidebar-logo-text {
    color: #fff;
    font-weight: 700;
    font-size: 1.125rem;
    white-space: nowrap;
}

.kbill-logo {
    flex-shrink: 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    white-space: nowrap;
}

.sidebar-icon {
    flex-shrink: 0;
    width: 1.25rem;
    text-align: center;
    font-size: 1.05rem;
}

.sidebar-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

#sidebar.collapsed {
    width: 4rem;
}

#sidebar.collapsed .sidebar-label,
#sidebar.collapsed .sidebar-logo-text {
    display: none;
}

#sidebar.collapsed .sidebar-header {
    padding: 0.75rem 0.5rem;
    justify-content: center;
}

#sidebar.collapsed .sidebar-logo {
    width: auto;
    justify-content: center;
}

#sidebar.collapsed .sidebar-link {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

/* ===== Rich text editor (หมายเหตุ / เอกสารแนบ) — ดู assets/js/richtext.js ===== */

/* ก่อน JS init: ซ่อน toolbar/editable เหลือ textarea ธรรมดาไว้ (fallback ถ้า JS พัง/ปิด) */
.richtext-field .richtext-toolbar,
.richtext-field .richtext-editable {
    display: none;
}

.richtext-field[data-richtext-ready="1"] .richtext-toolbar {
    display: flex;
}

.richtext-field[data-richtext-ready="1"] .richtext-editable {
    display: block;
}

.richtext-field[data-richtext-ready="1"] .richtext-hidden-input {
    display: none;
}

.richtext-toolbar {
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem;
    border: 1px solid #d1d5db;
    border-bottom: none;
    border-radius: 0.375rem 0.375rem 0 0;
    background: #f9fafb;
}

.richtext-btn {
    width: 1.75rem;
    height: 1.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.25rem;
    background: #fff;
    color: #374151;
    font-size: 0.8125rem;
    cursor: pointer;
    line-height: 1;
}

.richtext-btn:hover {
    background: #f3f4f6;
}

.richtext-btn-italic {
    font-style: italic;
}

.richtext-swatches {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0 0.25rem;
    border-left: 1px solid #e5e7eb;
    border-right: 1px solid #e5e7eb;
}

.richtext-swatch {
    width: 1.125rem;
    height: 1.125rem;
    border: 1px solid #d1d5db;
    border-radius: 9999px;
    cursor: pointer;
    padding: 0;
}

.richtext-color-custom {
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border: 1px solid #d1d5db;
    border-radius: 0.25rem;
    background: #fff;
    cursor: pointer;
}

.richtext-editable {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 0 0 0.375rem 0.375rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    color: #111827;
    overflow-y: auto;
}

.richtext-editable:focus {
    outline: 2px solid #93c5fd;
    outline-offset: -1px;
}

.richtext-editable p {
    margin: 0 0 0.5rem 0;
}

.richtext-editable p:last-child {
    margin-bottom: 0;
}

.richtext-editable-sm {
    min-height: 3.5rem;
}

.richtext-editable-lg {
    min-height: 9rem;
}
