/* ===== SHARED THEME SYSTEM ===== */
/* ใช้ร่วมกันทุกหน้าใน summermain, summerci, summeradmin */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@300;400;600;700&display=swap');

/* ===== THEME VARIABLES ===== */
[data-theme="light"] {
    --bg-body: linear-gradient(135deg, #fffcf0 0%, #ffebd8 100%);
    --bg: #ffffff;
    --card: #ffffff;
    --sidebar-bg: #ffffff;
    --border: #ffedd5;
    --border-subtle: #fed7aa;
    --row-bg: #fff7ed;
    --text: #1e293b;
    --text-muted: #9a3412;
    --primary: #f97316;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --accent: #ea580c;
    --primary-glow: rgba(249, 115, 22, 0.2);
    --primary-gradient: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
}

[data-theme="dark"] {
    --bg-body: radial-gradient(circle at top, #1e293b 0%, #050b18 100%);
    background-color: #050b18;
    /* Fallback for the whole html if needed */
    --bg: #050b18;
    --card: #0a1128;
    --sidebar-bg: #0a1128;
    --border: #1e2640;
    --border-subtle: rgba(248, 155, 41, 0.1);
    --row-bg: rgba(248, 155, 41, 0.05);
    --text: #ffffff;
    --text-muted: #94a3b8;
    --primary: #f89b29;
    --success: #10b981;
    --warning: #fbbf24;
    --danger: #ef4444;
    --accent: #ffcc33;
    --primary-glow: rgba(248, 155, 41, 0.4);
    --primary-gradient: linear-gradient(135deg, #f89b29 0%, #ffcc33 100%);
}

/* ===== GLOBAL RESET ===== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Noto Sans Thai', sans-serif;
    background: var(--bg-body);
    color: var(--text);
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
    scroll-behavior: smooth;
}

/* ===== DYNAMIC TABLE STYLES ===== */
.table-wrapper {
    overflow-x: hidden;
    /* ✅ ซ่อน scrollbar แนวนอน */
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

.modern-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 10px;
    table-layout: auto;
    /* ✅ ให้ตารางปรับขนาดตาม content */
}

.modern-table th {
    padding: 15px 20px;
    text-align: left;
    color: var(--primary);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 13px;
    letter-spacing: 1px;
    border-bottom: 2px solid var(--border-subtle);
    background: var(--card);
    white-space: nowrap;
}

.modern-table tbody tr:not(.row-cat-header) {
    background: var(--row-bg);
    transition: all 0.2s ease;
}

.modern-table tbody tr:not(.row-cat-header):hover {
    background: var(--border-subtle);
    transform: translateX(2px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.modern-table td {
    padding: 18px 20px;
    font-size: 15px;
    border: none;
    vertical-align: top;
    /* ✅ จัดข้อความชิดบน */
    line-height: 1.8;
    /* ✅ เพิ่มระยะห่างบรรทัด */
    word-wrap: break-word;
    /* ✅ ตัดคำยาว */
    word-break: break-word;
    /* ✅ บังคับตัดคำ */
    white-space: normal;
    /* ✅ อนุญาตให้ขึ้นบรรทัดใหม่ */
    max-width: none;
    /* ✅ ไม่จำกัดความกว้าง */
    min-width: 80px;
    /* ✅ ความกว้างขั้นต่ำ */
}

/* คอลัมน์แรก (ลำดับ) */
.modern-table td:first-child {
    border-left: 1px solid var(--border);
    border-radius: 12px 0 0 12px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    width: 60px;
    text-align: center;
    font-weight: 700;
    color: var(--text);
}

/* ✅ คอลัมน์ที่สอง (รายการ) ให้กว้างขึ้น */
.col-name {
    min-width: 280px !important;
}

/* คอลัมน์สุดท้าย */
.modern-table td:last-child {
    border-right: 1px solid var(--border);
    border-radius: 0 12px 12px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

/* คอลัมน์ตรงกลาง */
.modern-table td:not(:first-child):not(:last-child) {
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

/* แถวหัวข้อหมวดหมู่ */
.row-cat-header td {
    background: linear-gradient(90deg, transparent, var(--border-subtle), transparent) !important;
    color: var(--primary) !important;
    font-weight: 800;
    text-align: center;
    font-size: 18px;
    padding: 25px !important;
    letter-spacing: 3px;
    border: none !important;
    white-space: normal !important;
}

/* ✅ คอลัมน์พิเศษสำหรับกฎหมาย (ป้องกันข้อความซ้อน) */
.col-fine,
.col-jail {
    min-width: 120px !important;
    white-space: nowrap !important;
    font-weight: 700;
    color: var(--text);
    /* เปลี่ยนจาก var(--primary) เป็น var(--text) ซึ่งเป็นสีขาวในโหมดมืด */
    text-align: center;
}

/* ✅ ทำให้คอลัมน์ถัดจากรายการเป็นสีขาวทั้งหมด (ค่าปรับ, จำคุก, ฯลฯ) */
.modern-table td:nth-child(n+3) {
    color: var(--text);
}

/* คลาสสำหรับตัวหนังสือสีแดงบางส่วน */
.text-red {
    color: #ef4444 !important;
    font-weight: bold;
}

.rule-img {
    height: 40px;
    width: auto;
    object-fit: contain;
    vertical-align: middle;
    border-radius: 6px;
    margin-right: 12px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-subtle);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: zoom-in;
    display: inline-block;
}

.rule-img:hover {
    transform: scale(1.15) rotate(2deg);
    border-color: var(--primary);
    box-shadow: 0 8px 15px var(--primary-glow);
}

/* ===== COMMON COMPONENTS ===== */

/* ✅ Floating Theme Toggle (Automatic) */
.floating-theme-toggle {
    position: fixed;
    bottom: 30px;
    left: 30px;
    width: 60px;
    height: 60px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    z-index: 9999;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.floating-theme-toggle:hover {
    transform: scale(1.1) rotate(15deg);
    border-color: var(--primary);
    box-shadow: 0 15px 35px var(--primary-glow);
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Noto Sans Thai', sans-serif;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--primary-glow);
}

.card {
    background: var(--card);
    border-radius: 16px;
    padding: 25px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {

    .modern-table th,
    .modern-table td {
        padding: 12px 15px;
        font-size: 14px;
    }

    .modern-table td:first-child {
        width: 50px;
    }

    .row-cat-header td {
        font-size: 16px;
        padding: 20px !important;
    }

    .theme-toggle-btn {
        width: 45px;
        height: 45px;
        font-size: 20px;
        top: 15px;
        right: 15px;
    }
}

@media (max-width: 480px) {

    .modern-table th,
    .modern-table td {
        padding: 10px 12px;
        font-size: 13px;
    }

    .modern-table td:first-child {
        width: 40px;
    }

    .theme-toggle-btn {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
}