:root {
    --primary: #1A1A1A;
    --primary-hover: #333333;
    --bg-main: #F6F4EE;
    --bg-card: #FFFFFF;
    --bg-sidebar: #111111;
    --text-main: #1A1A1A;
    --text-sidebar: #A1A1AA;
    --text-sidebar-hover: #FFFFFF;
    --text-muted: #6B7280;
    --border-color: #E5E7EB;
    --danger: #EF4444;
    --success: #10B981;
    --warning: #F59E0B;
    --warning-bg: #FEF3C7;
    --cf-orange: #F38020;
}

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@300;400;500;600;700&display=swap');

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

body {
    font-family: 'Google Sans', 'Product Sans', 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Typography Helpers */
h1, h2, h3, h4, h5 { color: var(--text-main); font-weight: 600; }
p { color: var(--text-muted); }

/* Buttons Premium */
.btn {
    padding: 0.6rem 1rem;
    border-radius: 6px;
    border: none;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-outline {
    background: transparent;
    border: 1px solid #D1D5DB;
    color: var(--text-main);
}
.btn-outline:hover {
    background: #F3F4F6;
}

.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
}

.text-danger { color: var(--danger) !important; }
.text-muted { color: var(--text-muted) !important; }
.font-semibold { font-weight: 600; }

/* Authentication Page */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: var(--bg-main);
}
.auth-card {
    background: var(--bg-card);
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border-color);
}
.brand { text-align: center; margin-bottom: 2rem; }
.logo { color: var(--primary); margin-bottom: 1rem; }
.brand h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }

/* Tabs */
.tabs { display: flex; margin-bottom: 2rem; background: #F3F4F6; padding: 0.25rem; border-radius: 8px; }
.tab { flex: 1; background: transparent; border: none; color: var(--text-muted); padding: 0.5rem; border-radius: 6px; cursor: pointer; font-weight: 600; transition: all 0.2s; }
.tab.active { background: var(--bg-card); color: var(--text-main); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

/* Forms */
.auth-form.hidden { display: none; }
.input-group { margin-bottom: 1.25rem; }
.input-group label { display: block; margin-bottom: 0.5rem; font-size: 0.875rem; color: var(--text-main); font-weight: 500;}
.input-group input, .input-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: #FFFFFF;
    border: 1px solid #D1D5DB;
    border-radius: 6px;
    color: var(--text-main);
    font-size: 0.875rem;
    transition: all 0.2s ease;
}
.input-group input:focus, .input-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(26, 26, 26, 0.1);
}

/* Dashboard Layout (Sidebar + Main) */
.dashboard-layout {
    display: flex;
    min-height: 100vh;
}
.sidebar { 
    width: 260px; 
    flex-shrink: 0; 
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #27272A;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); 
}
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 0.5rem;
    margin-bottom: 2rem;
    color: #FFFFFF;
    font-weight: 600;
    font-size: 1.1rem;
}
.main-content { 
    flex: 1; 
    min-width: 0; 
    padding: 2.5rem 3rem;
    background: var(--bg-main);
}

.user-profile {
    padding: 1rem 0.5rem;
    border-top: 1px solid #27272A;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: auto;
}
.avatar { background: #27272A; width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #FFFFFF; overflow: hidden;}
.role-badge { display: inline-block; padding: 0.1rem 0.4rem; border-radius: 4px; background: rgba(255,255,255,0.1); color: #FFFFFF; font-size: 0.65rem; font-weight: 600;}
.user-profile-info { flex: 1; overflow: hidden; }
.user-profile-info .email { font-size: 0.85rem; color: #FFFFFF; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;}

.side-nav { display: flex; flex-direction: column; gap: 0.25rem; }
.nav-item { 
    background: transparent; 
    border: none; 
    color: var(--text-sidebar); 
    padding: 0.6rem 0.75rem; 
    border-radius: 6px; 
    text-align: left; 
    cursor: pointer; 
    font-weight: 500; 
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s; 
}
.nav-item svg { width: 18px; height: 18px; opacity: 0.7; }
.nav-item:hover { color: var(--text-sidebar-hover); background: rgba(255,255,255,0.05);}
.nav-item.active { background: rgba(255,255,255,0.1); color: #FFFFFF; }
.nav-item.active svg { opacity: 1; }

.dashboard-header { margin-bottom: 2rem; display: flex; justify-content: space-between; align-items: flex-end;}
.dashboard-header h2 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.dashboard-header p { font-size: 0.875rem;}

/* Stats & Cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.5rem; }
.stat-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.stat-card h3 { font-size: 0.875rem; color: var(--text-main); font-weight: 600; margin-bottom: 0.75rem; }
.stat-value { font-size: 1.5rem; font-weight: 600; color: var(--text-main);}
.status-active { display: inline-flex; align-items: center; gap: 0.5rem; }
.status-active::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--success); }

.content-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
    margin-bottom: 1.5rem;
}
.content-card.no-pad { padding: 0; overflow: hidden; }

/* Responsive Table container */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.admin-table { width: 100%; border-collapse: collapse; text-align: left; min-width: 600px;}
.admin-table th, .admin-table td { padding: 1rem 1.5rem; border-bottom: 1px solid var(--border-color); font-size: 0.875rem;}
.admin-table th { background: #FFFFFF; font-weight: 600; color: var(--text-main); }
.admin-table tr:hover { background: #F9FAFB; }

/* Modal */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(26,26,26,0.6);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
    padding: 1rem;
}
.modal.hidden { display: none; }
.modal-content {
    background: var(--bg-card);
    width: 100%; max-width: 800px;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
    max-height: 90vh;
    display: flex; flex-direction: column;
}
.modal-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 1.1rem; }
.modal-body { padding: 1.5rem; overflow-y: auto; }
.modal-footer { margin-top: 1.5rem; display: flex; justify-content: flex-end; gap: 0.75rem; }
.close-btn { background: #F3F4F6; width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; border: none; color: var(--text-main); font-size: 1.25rem; cursor: pointer; transition: 0.2s;}
.close-btn:hover { background: #E5E7EB; }

/* Toast Notifications */
#toastContainer {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    z-index: 9999;
}
.toast {
    background: var(--bg-card);
    color: var(--text-main);
    padding: 1rem 1.25rem;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    border-left: 4px solid var(--primary);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transform: translateX(120%);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    font-weight: 500;
    font-size: 0.875rem;
}
.toast.toast-show {
    transform: translateX(0);
    opacity: 1;
}
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }

/* Loaders */
.spinner { border: 2px solid rgba(255,255,255,0.3); border-radius: 50%; border-top: 2px solid white; width: 16px; height: 16px; animation: spin 0.8s linear infinite; }
.btn-outline .spinner { border: 2px solid rgba(0,0,0,0.1); border-top: 2px solid var(--text-main); }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Mobile Menu Button */
.mobile-header {
    display: none;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-sidebar);
    padding: 1rem 1.5rem;
    color: white;
}
.mobile-menu-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
}

/* Responsive Overhaul */
@media (max-width: 768px) {
    .dashboard-layout { flex-direction: column; }
    
    .mobile-header { display: flex; }
    .main-content { padding: 1.5rem 1rem; }
    
    .sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        height: 100vh;
        width: 260px;
        z-index: 100;
        box-shadow: 5px 0 25px rgba(0,0,0,0.2);
    }
    .sidebar.open { left: 0; }
    
    .sidebar-overlay {
        position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
        background: rgba(0,0,0,0.5); z-index: 90;
        display: none; opacity: 0; transition: opacity 0.3s;
    }
    .sidebar-overlay.open { display: block; opacity: 1; }
    
    .dashboard-header h2 { font-size: 1.25rem; }
    .dashboard-header { flex-direction: column; align-items: flex-start; gap: 1rem; }
    
    .modal-content { max-height: 95vh; border-radius: 12px; margin: 0.5rem; width: calc(100% - 1rem) !important;}
    .modal-header, .modal-body { padding: 1rem; }
    
    #toastContainer { bottom: 1rem; right: 1rem; left: 1rem; align-items: center; }
    .toast { width: 100%; justify-content: center; transform: translateY(120%); }
    .toast.toast-show { transform: translateY(0); }
}

/* Utilities */
.hidden { display: none !important; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1.5rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-auto { margin-top: auto; }
.w-full { width: 100%; }

/* Fix Quill Toolbar for Light Mode */
.ql-toolbar.ql-snow { background-color: #F9FAFB !important; border: 1px solid var(--border-color) !important; border-top-left-radius: 6px; border-top-right-radius: 6px; border-bottom: none !important;}
#editor-container { background: #FFFFFF !important; color: var(--text-main) !important; border: 1px solid var(--border-color) !important; border-bottom-left-radius: 6px; border-bottom-right-radius: 6px; }

/* Front-end Blog Adjustments */
.navbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 50;
}
.nav-container { max-width: 1200px; margin: 0 auto; padding: 0 1.5rem; display: flex; justify-content: space-between; align-items: center;}
.brand-sm { display: flex; align-items: center; gap: 0.75rem; font-weight: 700; color: var(--text-main); font-size: 1.25rem;}
.nav-links { display: flex; gap: 1rem; align-items: center; }

.dashboard-container { max-width: 900px; margin: 3rem auto; padding: 0 1.5rem; }
.blog-grid { display: grid; grid-template-columns: 1fr; gap: 2rem; }
.blog-card { transition: all 0.2s ease; border: 1px solid var(--border-color); }
.blog-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.05);}
.cursor-pointer { cursor: pointer; }
.line-clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

.post-viewer { max-width: 800px; margin: 0 auto; animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1); }
.post-view-title { font-size: 2.5rem; margin-bottom: 1rem; line-height: 1.2; font-weight: 700;}
.post-meta { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border-color); }
.post-view-content { padding: 0 !important; color: var(--text-main); font-size: 1.125rem; line-height: 1.7; }
.ql-snow .ql-editor img { border-radius: 8px; margin: 1.5rem 0; border: 1px solid var(--border-color);}

/* Editor Layout */
.editor-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 1.5rem;
}
.editor-main {
    background: #FFFFFF;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    border: 1px solid var(--border-color);
}
.editor-title-input {
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--border-color);
    padding: 1.5rem;
    font-size: 2.25rem;
    font-weight: 700;
    font-family: inherit;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    color: var(--text-main);
}
.editor-title-input:focus {
    outline: none;
}
.editor-title-input::placeholder {
    color: #D1D5DB;
}
.editor-sidebar {
    background: #FFFFFF;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    height: fit-content;
}

@media (max-width: 768px) {
    .editor-layout { grid-template-columns: 1fr; }
    #tabEditor { margin: -1.5rem -1rem !important; padding: 1.5rem 1rem !important; }
    #tabEditor header { margin: -1.5rem -1rem 1.5rem !important; padding: 1rem !important; }
}

.hero { padding: 6rem 1.5rem; text-align: center; background: #FFFFFF; border-bottom: 1px solid var(--border-color); }
.hero h1 { font-size: 3rem; font-weight: 700; margin-bottom: 1rem; line-height: 1.2;}
.hero p { font-size: 1.125rem; color: var(--text-muted); max-width: 600px; margin: 0 auto; line-height: 1.6;}
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
