:root {
    --primary: #6366f1;
    --danger: #ef4444;    /* Status 0: Red */
    --success: #22c55e;   /* Status 1: Green */
    --premium: #a855f7;   /* Status 2: Purple */
    --bg-dark: #0f172a;
    --bg-light: #f8fafc;
    --text-main: #1e293b;
    --sidebar-width: 260px;
}

* {
    box-sizing: border-box;
    font-family: 'Kanit', sans-serif;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg-light);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* Auth Screen */
.auth-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.auth-card {
    background: white;
    padding: 40px;
    border-radius: 16px;
    width: 350px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.auth-card input {
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    border: 1px solid #ddd;
    border-radius: 8px;
}

.auth-card button {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

/* Sidebar - บังคับความกว้างคงที่ */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-dark);
    color: white;
    padding: 20px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.logo {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 40px;
    color: var(--primary);
}

.nav-menu li {
    list-style: none;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: 0.3s;
}

.nav-menu li:hover, .nav-menu li.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--primary);
}

.nav-menu li.logout {
    margin-top: auto;
    color: #94a3b8;
}

/* Main Content - ยืดให้เต็มพื้นที่ที่เหลือ */
.content {
    flex: 1;
    padding: 30px;
    width: calc(100% - var(--sidebar-width));
    display: flex;
    flex-direction: column;
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    width: 100%;
}

.header-title h1 {
    font-size: 28px;
}

.search-bar {
    position: relative;
    width: 350px;
}

.search-bar i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
}

.search-bar input {
    width: 100%;
    padding: 12px 12px 12px 40px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    outline: none;
}

/* Desktop Table Wrapper - ยืดเต็ม 100% */
.table-wrapper {
    background: white;
    border-radius: 12px;
    overflow-x: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 800px; /* กันตารางบีบจนอ่านไม่ออก */
}

th {
    background: #22233e;
    padding: 18px 15px;
    text-align: left;
    font-weight: 600;
    color: #f1f3f5;
    border-bottom: 2px solid #22233e;
    white-space: nowrap;
    cursor: pointer;          /* เปลี่ยนเมาส์เป็นรูปมือ */
    position: relative;       /* เผื่อมึงอยากใส่ไอคอนลูกศร */
    transition: all 0.2s ease; /* ทำให้สีมันนุ่มนวลเวลาเปลี่ยน */
    user-select: none; /* ป้องกันการเลือกข้อความโดยไม่ตั้งใจ */
}

th:hover {
    background-color: #c7ced7 !important; /* เปลี่ยนพื้นหลังเป็นสีเทาอ่อน */
    color: #22233e;     /* เปลี่ยนตัวหนังสือเป็นสีม่วงหลักของแอป */
}

td {
    padding: 18px 15px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
}

tr:hover td {
    background: #e8ebecb5;
}

/* Status Badges */
.status-badge {
    padding: 5px 14px;
    border-radius: 20px;
    color: white;
    font-size: 12px;
    font-weight: 600;
    display: inline-block;
}
.status-0 { background: var(--danger); }
.status-1 { background: var(--success); }
.status-2 { background: var(--premium); }

/* Mobile Navigation Bar */
.mobile-nav {
    display: none; /* ซ่อนบน PC */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-dark);
    padding: 10px 5px;
    justify-content: space-around;
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.2);
}

.mobile-nav button {
    background: none;
    border: none;
    color: #94a3b8;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    cursor: pointer;
}

.mobile-nav button i { color: white; }

/* Responsive */
@media (max-width: 1024px) {
    .sidebar { width: 200px; min-width: 200px; }
    .search-bar { width: 250px; }
}

@media (max-width: 768px) {
    body { flex-direction: column; }
    .content {
        padding-bottom: 80px !important; /* ดันขึ้นมา 100px เผื่อระยะนิ้วกดด้วย */
    }
    .sidebar { display: none; }
    .content { 
        width: 100%; 
        padding: 20px;
        padding-bottom: 80px; /* เผื่อที่ให้เมนูล่าง */
    }
    .main-header { flex-direction: column; align-items: flex-start; gap: 15px; }
    .search-bar { width: 100%; }
    .table-wrapper { display: none; }
    .mobile-grid { display: grid; grid-template-columns: 1fr; gap: 15px; width: 100%; }
    .mobile-nav { display: flex; }
}

.user-card {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    border-left: 5px solid #e2e8f0;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: white;
    width: 100%;
    max-width: 550px;
    border-radius: 20px;
    padding: 30px;
    position: relative; /* สำคัญ: เพื่อให้ปุ่มปิดอ้างอิงตำแหน่งกับกล่องนี้ */
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-right: 30px; /* เว้นที่ให้ปุ่มปิดไม่เบียดหัวข้อ */
}

/* ปุ่มปิดใหม่: ไร้กรอบ, อยู่ขวาบน, สวยหรู */
.close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: #f1f5f9; /* วงกลมเทาอ่อนๆ */
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%; /* ทำเป็นวงกลม */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #64748b;
    transition: all 0.2s ease;
    z-index: 10;
}

.close-btn:hover {
    background: #ff8787;
    color: #fffcfc;
    transform: rotate(90deg); /* หมุนนิดๆ ตอนจิ้ม เพิ่มความกวน */
}

.close-btn i {
    font-size: 20px; /* ขนาดกากบาท */
}

/* ยืด Content ให้เต็ม และจัดการ Header ให้ดูแพง */
.content {
    flex: 1;
    padding: 30px;
    max-width: 100%; /* สำคัญมาก */
    display: flex;
    flex-direction: column;
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 20px;
}

.header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* ตารางแบบ Full-Width */
.table-wrapper {
    width: 100%;
    margin-top: 20px;
    flex: 1; /* ยืดตารางลงข้างล่างด้วยถ้าจอใหญ่ */
}

table {
    width: 100%;
    table-layout: auto; /* ให้คอลัมน์ปรับตามเนื้อหาแต่ยืดเต็ม 100% */
}

th {
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

th:hover {
    background: #e2e8f0;
}

/* ปุ่มแบบไอคอนบน PC */
.btn-icon-only {
    background: white;
    border: 1px solid #e2e8f0;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon-only:hover {
    background: var(--bg-light);
    color: var(--primary);
}

/* --- ส่วนของ Desktop (จอใหญ่) --- */
@media (min-width: 769px) {
    .mobile-grid { 
        display: none !important; /* บังคับซ่อน Card บนคอม */
    }
    .table-wrapper { 
        display: block !important; /* โชว์ตารางบนคอม */
    }
}

/* --- ส่วนของ Mobile (จอเล็ก) --- */
@media (max-width: 768px) {
    .table-wrapper { 
        display: none !important; /* บังคับซ่อนตารางบนมือถือ */
    }
    .mobile-grid { 
        display: grid !important; /* โชว์ Card บนมือถือ */
    }
}

.summary-widgets {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 25px;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    cursor: pointer;
    transition: 0.3s;
    border-bottom: 5px solid #cbd5e1;
}

.stat-card:hover { transform: translateY(-5px); box-shadow: 0 8px 15px rgba(0,0,0,0.1); }
.stat-card h2 { font-size: 32px; color: var(--text-main); margin-top: 5px; }

/* สีตาม Status */
.stat-card.restricted { border-color: var(--danger); }
.stat-card.trial { border-color: var(--success); }
.stat-card.premium { border-color: var(--premium); }

.filter-controls {
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}
.btn-clear { background: none; border: 1px solid #ddd; padding: 5px 10px; border-radius: 5px; cursor: pointer; }

@media (max-width: 768px) {
    .summary-widgets { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}

.btn-delete {
    width: 100%;
    padding: 14px;
    background: #fff1f2;
    color: #e11d48;
    border: 1.5px solid #fda4af;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px;
    transition: all 0.2s ease;
    margin-top: 30px;
}

.btn-delete:hover {
    background: #ffe4e6;
    border-color: #fb7185;
    transform: translateY(-2px);
}

.btn-delete i {
    font-size: 18px;
}

/* style.css */

/* จัดการช่องค้นหาให้แว่นขยายเข้าไปอยู่ข้างใน */
.search-wrapper {
    position: relative;
    width: 100%;
    max-width: 400px;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    pointer-events: none; /* กดทะลุไปที่ input ได้ */
    width: 18px;
    height: 18px;
}

#searchInput {
    width: 100%;
    padding: 12px 12px 12px 45px; /* เว้นซ้ายให้แว่นขยาย */
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #ffffff;
    font-size: 15px;
    transition: all 0.2s;
}

#searchInput:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
    outline: none;
}

/* ซ่อนปุ่มซ้ำซ้อนบนคอมถ้ามึงอยากเคลียร์พื้นที่ */
@media (min-width: 769px) {
    .header-actions button { display: none; } 
    /* เพราะเรามีปุ่มที่ Sidebar อยู่แล้วตามที่มึงบอก */
}

/* style.css */

.user-card {
    background: white;
    border-radius: 16px;
    padding: 15px;
    margin-bottom: 10px;
    border: 1px solid #f1f5f9;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.user-id-badge {
    font-family: monospace;
    font-weight: 600;
    color: var(--text-main);
    background: #f1f5f9;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 14px;
}

.card-body .info-row {
    margin-bottom: 10px;
    font-size: 14px;
}

.card-body .value { font-weight: 500; color: #1e293b; }
.card-body .label { color: #64748b; margin-right: 5px; }

.info-meta {
    display: flex;
    gap: 15px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed #e2e8f0;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: #64748b;
}

.meta-item.highlight {
    color: var(--primary);
    font-weight: 600;
}

.card-footer {
    margin-top: 10px;
    font-size: 12px;
    text-align: right;
    color: #94a3b8;
}
.user-card {
    background: white;
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 4px;
    border: 1px solid #f1f5f9;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px; /* ลดช่องว่างลง */
}

/* บรรทัดข้อมูลแบบ Compact */
.card-body-compact {
    display: flex;
    flex-direction: column;
    gap: 4px; /* บีบให้ชิดกัน */
}

.info-line {
    display: flex;
    justify-content: space-between; /* แยกซ้าย-ขวา */
    align-items: center;
    font-size: 13px;
}

.model-name {
    font-weight: 600;
    color: var(--text-main);
    max-width: 60%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.total-days {
    color: #64748b;
    font-size: 14px;
}

.total-days strong {
    color: rgb(29, 4, 56);
}

.info-line.second {
    font-size: 14px;
    color: #5c6d85;
    border-top: 1px solid #f8fafc;
    padding-top: 4px;
}

.info-line.second .highlight {
    color: rgb(5, 116, 167);
    font-weight: 500;
}

.search-wrapper {
    position: relative;
    width: 100%;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    z-index: 2;
}

#searchInput {
    padding-left: 40px !important; /* บังคับเว้นที่ให้ไอคอน */
}