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

:root {
    --primary: #667eea;
    --primary-dark: #5a67d8;
    --success: #48bb78;
    --warning: #ed8936;
    --danger: #f56565;
    --info: #4299e1;
    --gray-50: #f7fafc;
    --gray-100: #edf2f7;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e0;
    --gray-400: #a0aec0;
    --gray-500: #718096;
    --gray-600: #4a5568;
    --gray-700: #2d3748;
    --gray-800: #1a202c;
    --sidebar-width: 240px;
    /* Brand colors (переопределяются JS из БД) */
    --sidebar-bg: #1a202c;
    --content-bg: #f7fafc;
    --btn-primary-bg: #667eea;
    --btn-primary-text: #ffffff;
    --btn-secondary-bg: #e2e8f0;
    --btn-secondary-text: #4a5568;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--content-bg);
    color: var(--gray-800);
    min-height: 100vh;
}

.app-body {
    display: block;
}

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
}

.logo {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--gray-700);
}

.logo-icon {
    font-size: 24px;
}

.logo-text {
    font-size: 18px;
    font-weight: 600;
}

.nav-menu {
    list-style: none;
    padding: 10px 0;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--gray-400);
    text-decoration: none;
    transition: all 0.2s;
}

.nav-link:hover {
    background: var(--gray-700);
    color: white;
}

.nav-link.active {
    background: var(--primary);
    color: white;
}

.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--gray-700);
    color: var(--gray-500);
}

/* Main Content */
.content {
    margin-left: var(--sidebar-width);
    padding: 30px;
    flex: 1;
    min-height: 100vh;
}

.page {
    /* видимость управляется Alpine x-show */
}

.page.active {
    display: block;
}

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

h1 {
    font-size: 24px;
    color: var(--gray-800);
}

h2 {
    font-size: 18px;
    color: var(--gray-700);
    margin-bottom: 15px;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
    border-color: var(--btn-primary-bg);
}

.btn-primary:hover {
    filter: brightness(0.9);
}

.btn-secondary {
    background: var(--btn-secondary-bg);
    color: var(--btn-secondary-text);
    border-color: var(--btn-secondary-bg);
}

.btn-secondary:hover {
    filter: brightness(0.9);
}

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

.btn-danger:hover {
    background: #e53e3e;
}

.btn-small {
    padding: 6px 12px;
    font-size: 13px;
}

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

.stat-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: white;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--gray-800);
}

.stat-label {
    font-size: 14px;
    color: var(--gray-500);
}

/* Dashboard Columns */
.dashboard-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.dashboard-column {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.recent-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.recent-item {
    padding: 12px;
    background: var(--gray-50);
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.recent-item-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.recent-item-title {
    font-weight: 500;
    color: var(--gray-700);
}

.recent-item-subtitle {
    font-size: 13px;
    color: var(--gray-500);
}

/* Filters */
.filters {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

.search-input {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    max-width: 400px;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
}

.filter-select {
    padding: 10px 15px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    background: white;
    cursor: pointer;
}

/* Data Table */
.data-table {
    width: 100%;
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 14px 16px;
    text-align: left;
}

.data-table th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-600);
    font-size: 13px;
    text-transform: uppercase;
    border-bottom: 1px solid var(--gray-200);
}

.data-table td {
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-700);
}

.data-table tr:hover td {
    background: var(--gray-50);
}

.data-table .actions {
    display: flex;
    gap: 8px;
}

.data-table tfoot td {
    background: var(--gray-50);
    font-weight: 600;
}

/* Status Badge */
.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.status-new {
    background: #bee3f8;
    color: #2b6cb0;
}

.status-in_progress {
    background: #fefcbf;
    color: #b7791f;
}

.status-waiting {
    background: #feebc8;
    color: #c05621;
}

.status-completed {
    background: #c6f6d5;
    color: #276749;
}

.status-issued {
    background: var(--gray-200);
    color: var(--gray-600);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-large {
    max-width: 700px;
}

.modal-xlarge {
    max-width: 900px;
}

.modal-auto {
    width: auto;
    min-width: 480px;
    max-width: 750px;
}

.modal-xxlarge {
    max-width: 95vw;
    width: 1300px;
}

.modal-resizable {
    max-width: 95vw;
    max-height: 95vh;
    width: 1300px;
    min-width: 700px;
    min-height: 500px;
    resize: both;
    overflow: auto;
    display: flex;
    flex-direction: column;
}

.modal-resizable .modal-header {
    flex-shrink: 0;
}

.modal-resizable .modal-footer {
    flex-shrink: 0;
}

.modal-resizable .template-editor-v2 {
    flex: 1;
    min-height: 0;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
}

.modal-header h2 {
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--gray-500);
}

.modal-close:hover {
    color: var(--gray-700);
}

/* Form */
form {
    padding: 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.form-group label {
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-700);
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
}

.form-group input[readonly] {
    background: var(--gray-100);
    cursor: not-allowed;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 15px 20px;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
    position: sticky;
    bottom: 0;
}

/* Tabs */
.modal-tabs {
    display: flex;
    gap: 5px;
    padding: 0 20px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.tab-btn {
    padding: 12px 20px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-500);
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--gray-700);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    padding: 20px;
}

.tab-content.active {
    display: block;
}

/* Parts Section */
.parts-section {
    background: var(--gray-50);
    border-radius: 8px;
    padding: 15px;
}

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

.parts-header h3 {
    margin: 0;
    font-size: 16px;
}

.parts-search-results {
    max-height: 300px;
    overflow-y: auto;
}

.part-result-item {
    padding: 12px;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s;
}

.part-result-item:hover {
    border-color: var(--primary);
    background: var(--gray-50);
}

.part-result-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.part-result-name {
    font-weight: 500;
}

.part-result-sku {
    font-size: 12px;
    color: var(--gray-500);
}

.part-result-stock {
    font-size: 14px;
    color: var(--success);
    font-weight: 500;
}

.part-result-stock.low {
    color: var(--danger);
}

/* Order Total Section */
.order-total-section {
    margin-top: 20px;
    padding: 20px;
    background: white;
    border-radius: 8px;
    border: 2px solid var(--gray-200);
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 15px;
}

.total-final {
    border-top: 2px solid var(--gray-300);
    margin-top: 10px;
    padding-top: 15px;
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}

/* Reports */
.reports-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.report-card {
    background: white;
    border-radius: 12px;
    padding: 30px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.report-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
}

.report-icon {
    font-size: 40px;
    margin-bottom: 15px;
}

.report-card h3 {
    font-size: 18px;
    color: var(--gray-800);
    margin-bottom: 8px;
}

.report-card p {
    color: var(--gray-500);
    font-size: 14px;
}

/* Templates */
.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.template-card {
    background: white;
    border-radius: 12px;
    padding: 25px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border: 2px solid transparent;
}

.template-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.template-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

.template-card h3 {
    font-size: 18px;
    color: var(--gray-800);
    margin-bottom: 8px;
}

.template-card p {
    color: var(--gray-500);
    font-size: 14px;
    margin-bottom: 15px;
}

.templates-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.template-list-item {
    background: white;
    padding: 15px 20px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Template Editor */
.template-editor {
    display: flex;
    gap: 20px;
    padding: 20px;
}

.template-sidebar {
    width: 200px;
    flex-shrink: 0;
}

.template-sidebar h4 {
    font-size: 14px;
    color: var(--gray-600);
    margin-bottom: 10px;
}

.variables-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 400px;
    overflow-y: auto;
}

.variable-item {
    padding: 8px 12px;
    background: var(--gray-50);
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

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

.template-main {
    flex: 1;
}

.code-editor {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    min-height: 400px;
    line-height: 1.5;
}

/* Print Document */
.print-document {
    padding: 40px;
    font-family: 'Times New Roman', serif;
    background: white;
}

.print-header {
    text-align: center;
    margin-bottom: 30px;
}

.print-header h2 {
    font-size: 20px;
    margin-bottom: 10px;
}

.print-header p {
    font-size: 14px;
    color: var(--gray-600);
}

.print-info {
    margin-bottom: 20px;
}

.print-row {
    display: flex;
    margin-bottom: 8px;
}

.print-label {
    width: 180px;
    font-weight: 600;
}

.print-value {
    flex: 1;
}

.print-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}

.print-table th,
.print-table td {
    border: 1px solid var(--gray-400);
    padding: 8px 12px;
    text-align: left;
}

.print-table th {
    background: var(--gray-100);
}

.print-signatures {
    display: flex;
    justify-content: space-between;
    margin-top: 50px;
}

.print-signature {
    text-align: center;
    width: 200px;
}

.print-signature-line {
    border-bottom: 1px solid var(--gray-800);
    margin-bottom: 5px;
    height: 40px;
}

/* Low stock warning */
.low-stock {
    color: var(--danger);
    font-weight: 500;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--gray-500);
}

/* Company Form */
.company-form-container {
    background: white;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Permissions Grid */
.permissions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    background: var(--gray-50);
    padding: 20px;
    border-radius: 8px;
}

.permission-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid var(--gray-200);
}

.permission-item:hover {
    border-color: var(--primary);
}

.permission-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* User Info in Sidebar */
.user-info {
    padding: 15px 20px;
    border-top: 1px solid var(--gray-700);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-name {
    color: var(--gray-300);
    font-size: 14px;
}

.btn-logout {
    background: none;
    border: none;
    color: var(--gray-500);
    cursor: pointer;
    font-size: 18px;
    padding: 5px;
    transition: color 0.2s;
}

.btn-logout:hover {
    color: var(--danger);
}

/* Login Modal Specific */
#login-modal {
    background: #f0f2f5;
}

#login-modal .modal-content {
    padding-bottom: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

#login-modal form {
    padding: 0 30px 30px;
}

/* Status badges for employees */
.status-active {
    background: #c6f6d5;
    color: #276749;
}

.status-inactive {
    background: #fed7d7;
    color: #c53030;
}

/* Disabled nav link */
.nav-link.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* Hidden elements */
.hidden {
    display: none !important;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 60px;
    }

    .logo-text,
    .nav-link span,
    .sidebar-footer {
        display: none;
    }

    .content {
        margin-left: 60px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .filters {
        flex-direction: column;
    }

    .search-input {
        max-width: none;
    }

    .template-editor {
        flex-direction: column;
    }

    .template-sidebar {
        width: 100%;
    }
}

/* Login Screen */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #f0f2f5;
}

.login-box {
    background: white;
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.login-icon {
    font-size: 48px;
    margin-bottom: 10px;
}

.login-header h1 {
    font-size: 22px;
    margin-bottom: 5px;
}

.login-header p {
    color: var(--gray-500);
    font-size: 14px;
}

.login-error {
    color: var(--danger);
    font-size: 14px;
    margin: 10px 0;
    padding: 8px 12px;
    background: #fff5f5;
    border-radius: 6px;
}

.btn-full {
    width: 100%;
}

/* Toast Notifications */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 20px;
    border-radius: 8px;
    color: white;
    z-index: 10001;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    max-width: 350px;
    cursor: pointer;
    animation: slideIn 0.3s ease;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--info); }

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

/* Brand page */
.color-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.color-row input[type="text"] {
    padding: 6px 10px;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    font-size: 14px;
}

/* ================================================================
   V3.3: KPI Cards, Charts Dashboard, Quill Editor, Date Filter
   ================================================================ */

/* --- Date Range Filter --- */
.date-filter {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.date-filter input[type="date"] {
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 13px;
    background: white;
}

.date-filter input[type="date"]:focus {
    outline: none;
    border-color: var(--primary);
}

.date-filter-sep {
    color: var(--gray-500);
    font-size: 14px;
}

/* --- KPI Grid --- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: white;
    border-radius: 12px;
    padding: 20px 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border-left: 4px solid var(--kpi-color, var(--primary));
    transition: transform 0.2s, box-shadow 0.2s;
}

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

.kpi-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: 4px;
    line-height: 1.2;
}

/* ===== PERMISSION TREE ===== */

.perm-tree {
    max-height: 450px;
    overflow-y: auto;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 4px;
}

.perm-group {
    margin-bottom: 2px;
}

.perm-group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--gray-100);
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.perm-group-header:hover {
    background: var(--gray-200);
}

.perm-group-arrow {
    font-size: 10px;
    transition: transform 0.2s;
    color: var(--gray-500);
    display: inline-block;
}

.perm-group-arrow.open {
    transform: rotate(90deg);
}

.perm-group-title {
    font-weight: 600;
    font-size: 14px;
    flex: 1;
}

.perm-group-count {
    font-size: 12px;
    color: var(--primary);
    font-weight: 600;
}

.perm-group-body {
    padding: 4px 0 4px 20px;
}

.perm-node {
    margin: 2px 0;
}

.perm-node-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.1s;
}

.perm-node-label:hover {
    background: var(--gray-50);
}

.perm-node-label.perm-parent {
    /* no extra style needed, just semantic */
}

.perm-node-label.perm-child {
    padding-left: 24px;
    color: var(--gray-600);
    font-size: 12px;
}

.perm-children {
    padding-left: 20px;
    border-left: 2px solid var(--gray-200);
    margin-left: 16px;
}

/* ===== ROLE PERMISSION INFO BOX ===== */
.perm-info-box {
    padding: 15px;
    background: #e8f0fe;
    border-radius: 8px;
    color: #1a73e8;
    margin-top: 20px;
}

.kpi-label {
    font-size: 13px;
    color: var(--gray-500);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* ===== WELCOME MODAL (open testing) ===== */
.welcome-modal .modal-content {
    max-width: 560px;
    padding: 44px 48px 36px;
    text-align: center;
}

.welcome-icon {
    font-size: 64px;
    margin-bottom: 20px;
    display: block;
    animation: welcomePulse 1.5s ease-in-out;
}

@keyframes welcomePulse {
    0% { transform: scale(0.8); opacity: 0; }
    60% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

.welcome-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--gray-800);
    margin: 0 0 20px;
    line-height: 1.3;
}

.welcome-text {
    font-size: 14px;
    color: var(--gray-600);
    line-height: 1.7;
    margin: 0 0 14px;
    text-align: left;
    padding: 0 4px;
}

.welcome-footer {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid var(--gray-200);
    text-align: center;
}

.welcome-btn {
    min-width: 140px;
    font-size: 16px;
    padding: 12px 40px;
}

.kpi-sub {
    font-size: 12px;
    color: var(--gray-400);
    margin-top: 2px;
}

/* --- Charts Grid --- */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.chart-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.chart-card h3 {
    font-size: 16px;
    color: var(--gray-700);
    margin-bottom: 16px;
    font-weight: 600;
}

.chart-card {
    min-height: 320px;
    display: flex;
    flex-direction: column;
}

.chart-card canvas {
    flex: 1;
    min-height: 250px;
    max-height: 300px;
    width: 100% !important;
}

.chart-card-full {
    grid-column: 1 / -1;
}

/* --- Contenteditable Template Editor --- */
.template-editor-v2 {
    display: flex;
    gap: 20px;
    padding: 20px;
    overflow: hidden;
}

.template-editor-v2 .template-sidebar {
    width: 220px;
    flex-shrink: 0;
    overflow-y: auto;
}

.template-editor-v2 .template-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.template-editor-v2 .template-main .form-group:last-of-type {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Toolbar */
.tpl-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 6px 8px;
    background: var(--gray-50);
    border: 1px solid var(--gray-300);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    flex-wrap: wrap;
}

.tpl-toolbar button {
    width: 30px;
    height: 30px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    color: var(--gray-700);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.tpl-toolbar button:hover {
    background: var(--gray-200);
    border-color: var(--gray-300);
}

.tpl-sep {
    width: 1px;
    height: 20px;
    background: var(--gray-300);
    margin: 0 4px;
}

/* Editor area */
.tpl-editor {
    flex: 1;
    min-height: 300px;
    padding: 12px 15px;
    border: 1px solid var(--gray-300);
    border-radius: 0 0 6px 6px;
    background: white;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    overflow-y: auto;
    outline: none;
}

.tpl-editor:focus {
    border-color: var(--primary);
}

.tpl-editor h2 { font-size: 20px; margin: 8px 0; }
.tpl-editor h3 { font-size: 16px; margin: 6px 0; }
.tpl-editor table { border-collapse: collapse; width: 100%; margin: 8px 0; }
.tpl-editor td, .tpl-editor th { border: 1px solid #cbd5e0; padding: 6px 10px; }
.tpl-editor img { max-width: 100%; }

/* --- Variable Groups in Sidebar --- */
.var-group {
    margin-bottom: 14px;
}

.var-group-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.variable-chip {
    display: inline-block;
    padding: 6px 10px;
    margin: 2px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: 'Consolas', 'Monaco', monospace;
    color: var(--gray-700);
}

.variable-chip:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* --- Print Document v2 --- */
.print-document-v2 {
    padding: 20px;
    background: white;
}

/* Print Styles */
@media print {
    .sidebar,
    .modal-footer,
    .modal-close,
    .no-print {
        display: none !important;
    }

    .modal {
        position: static;
        background: white;
    }

    .modal-content {
        max-width: 100%;
        border-radius: 0;
    }

    .print-document {
        padding: 0;
    }

    .chart-card canvas {
        max-height: 200px;
    }
}

/* ===== HIDDEN FIELD (no view permission) ===== */
.field-hidden {
    padding: 10px 12px;
    border: 1px dashed var(--gray-300);
    border-radius: 6px;
    color: var(--gray-400);
    font-style: italic;
    font-size: 14px;
    background: var(--gray-50);
    user-select: none;
    min-height: 42px;
    display: flex;
    align-items: center;
}
