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

body {
    font-family: 'Sarabun', 'Segoe UI', sans-serif;
    background-color: #f3f4f6;
    color: #1f2937;
    min-height: 100vh;
}

.app-container { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: 250px;
    background-color: #1f2937;
    color: white;
    padding: 20px 0;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-header {
    padding: 0 20px 20px;
    border-bottom: 1px solid #374151;
    margin-bottom: 20px;
}

.sidebar-header h1 { font-size: 1.25rem; font-weight: 700; color: #DC2626; }
.sidebar-header p { font-size: 0.75rem; color: #9ca3af; }

.sidebar-nav { list-style: none; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: #d1d5db;
    text-decoration: none;
    transition: all 0.2s;
}

.sidebar-nav a:hover, .sidebar-nav a.active { background-color: #374151; color: white; }
.sidebar-nav a.active { border-left: 3px solid #DC2626; }
.sidebar-nav svg { width: 20px; height: 20px; }

/* Main content */
.main-content { flex: 1; margin-left: 250px; padding: 24px; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.page-header h2 { font-size: 1.5rem; font-weight: 600; }

/* Cards */
.card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding: 20px;
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e5e7eb;
}

.card-header h3 { font-size: 1rem; font-weight: 600; }

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.stat-card .label { font-size: 0.875rem; color: #6b7280; margin-bottom: 4px; }
.stat-card .value { font-size: 1.5rem; font-weight: 700; color: #1f2937; }
.stat-card.primary .value { color: #DC2626; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary { background-color: #DC2626; color: white; }
.btn-primary:hover { background-color: #B91C1C; }
.btn-secondary { background-color: #6b7280; color: white; }
.btn-secondary:hover { background-color: #4b5563; }
.btn-outline { background-color: transparent; border: 1px solid #d1d5db; color: #374151; }
.btn-outline:hover { background-color: #f3f4f6; }
.btn-sm { padding: 6px 12px; font-size: 0.75rem; }
.btn-danger { background-color: #ef4444; color: white; }
.btn-danger:hover { background-color: #dc2626; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 500; color: #374151; margin-bottom: 6px; }

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.875rem;
    color: #000000;
    transition: border-color 0.2s;
}

.form-control:focus { outline: none; border-color: #DC2626; box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1); }
.form-control::placeholder { color: #6b7280; }

/* Tables */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid #e5e7eb; }
th { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; color: #6b7280; background-color: #f9fafb; }
td { font-size: 0.875rem; }
tr:hover { background-color: #f9fafb; }

/* Template grid */
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }

.template-card {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.template-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); }

.template-card .thumbnail {
    width: 100%;
    height: 160px;
    background-color: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
}

.template-card .thumbnail img { width: 100%; height: 100%; object-fit: cover; }
.template-card .info { padding: 16px; }
.template-card .info h4 { font-size: 1rem; font-weight: 600; margin-bottom: 4px; }
.template-card .info p { font-size: 0.75rem; color: #6b7280; margin-bottom: 12px; }
.template-card .actions { display: flex; gap: 8px; }

/* Asset grid */
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }

.asset-card {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: transform 0.2s;
}

.asset-card:hover { transform: scale(1.02); }
.asset-card .preview { width: 100%; height: 120px; background-color: #f3f4f6; display: flex; align-items: center; justify-content: center; }
.asset-card .preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.asset-card .name { padding: 8px; font-size: 0.75rem; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Editor */
.editor-container { display: flex; gap: 20px; height: calc(100vh - 120px); }
.editor-canvas-wrapper { flex: 1; background: #e5e7eb; border-radius: 8px; display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; }
.editor-canvas-wrapper canvas { box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2); }
.editor-sidebar { width: 320px; background: white; border-radius: 8px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); overflow-y: auto; }

.editor-toolbar { display: flex; gap: 8px; padding: 12px; background: white; border-radius: 8px; margin-bottom: 16px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); flex-wrap: wrap; }

.toolbar-btn { padding: 8px 12px; background: #f3f4f6; border: none; border-radius: 4px; cursor: pointer; display: flex; align-items: center; gap: 6px; font-size: 0.875rem; transition: background-color 0.2s; }
.toolbar-btn:hover { background: #e5e7eb; }
.toolbar-btn.active { background: #DC2626; color: white; }

/* Layers */
.layer-list { list-style: none; }
.layer-item { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid #e5e7eb; cursor: pointer; transition: background-color 0.2s; }
.layer-item:hover { background-color: #f9fafb; }
.layer-item.active { background-color: #fef2f2; border-left: 3px solid #DC2626; }
.layer-item .icon { width: 24px; height: 24px; background: #e5e7eb; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; }
.layer-item .name { flex: 1; font-size: 0.875rem; }
.layer-item .visibility { opacity: 0.5; cursor: pointer; }
.layer-item .visibility:hover { opacity: 1; }

/* Tabs */
.tabs { display: flex; border-bottom: 1px solid #e5e7eb; }
.tab { padding: 12px 16px; font-size: 0.875rem; font-weight: 500; color: #6b7280; cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.2s; }
.tab:hover { color: #374151; }
.tab.active { color: #DC2626; border-bottom-color: #DC2626; }
.tab-content { display: none; padding: 16px; }
.tab-content.active { display: block; }

/* Modal */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; opacity: 0; visibility: hidden; transition: all 0.2s; }
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal { background: white; border-radius: 12px; width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; transform: scale(0.9); transition: transform 0.2s; }
.modal-overlay.active .modal { transform: scale(1); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid #e5e7eb; }
.modal-header h3 { font-size: 1.125rem; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: #6b7280; }
.modal-body { padding: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 12px; padding: 16px 20px; border-top: 1px solid #e5e7eb; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 0.875rem; }
.alert-success { background-color: #d1fae5; color: #065f46; }
.alert-error { background-color: #fee2e2; color: #991b1b; }
.alert-warning { background-color: #fef3c7; color: #92400e; }

/* Toast */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 1100; }
.toast { background: #1f2937; color: white; padding: 12px 20px; border-radius: 6px; margin-top: 8px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); animation: slideIn 0.3s ease; }
.toast.success { background: #059669; }
.toast.error { background: #dc2626; }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Loading */
.loading { display: flex; align-items: center; justify-content: center; padding: 40px; }
.spinner { width: 40px; height: 40px; border: 3px solid #e5e7eb; border-top-color: #DC2626; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state { text-align: center; padding: 60px 20px; color: #6b7280; }
.empty-state svg { width: 64px; height: 64px; margin-bottom: 16px; opacity: 0.5; }
.empty-state h3 { font-size: 1.125rem; font-weight: 600; margin-bottom: 8px; color: #374151; }

/* File upload */
.file-upload { border: 2px dashed #d1d5db; border-radius: 8px; padding: 40px; text-align: center; cursor: pointer; transition: border-color 0.2s; }
.file-upload:hover { border-color: #DC2626; }
.file-upload.dragover { border-color: #DC2626; background-color: #fef2f2; }
.file-upload input { display: none; }

/* Properties */
.properties-section { margin-bottom: 20px; }
.properties-section h4 { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; color: #6b7280; margin-bottom: 12px; }
.properties-row { display: flex; gap: 12px; margin-bottom: 12px; }
.properties-row .form-group { flex: 1; margin-bottom: 0; }

/* Badge */
.badge { display: inline-block; padding: 2px 8px; font-size: 0.75rem; font-weight: 500; border-radius: 4px; }
.badge-success { background-color: #d1fae5; color: #065f46; }
.badge-warning { background-color: #fef3c7; color: #92400e; }
.badge-error { background-color: #fee2e2; color: #991b1b; }
.badge-info { background-color: #dbeafe; color: #1e40af; }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { width: 60px; padding: 10px 0; }
    .sidebar-header h1, .sidebar-header p, .sidebar-nav span { display: none; }
    .sidebar-nav a { justify-content: center; padding: 12px; }
    .main-content { margin-left: 60px; padding: 16px; }
    .editor-container { flex-direction: column; }
    .editor-sidebar { width: 100%; max-height: 300px; }
}
