/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 14px;
    color: #333;
    background: #f5f6fa;
    height: 100vh;
    overflow: hidden;
}

/* ===== LAYOUT ===== */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: 220px;
    min-width: 220px;
    background: #1a237e;
    color: #fff;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-header {
    padding: 20px 16px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header .logo-name {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.5px;
}

.sidebar-header .logo-sub {
    font-size: 11px;
    color: rgba(255,255,255,0.6);
    margin-top: 2px;
}

.sidebar nav {
    flex: 1;
    padding: 12px 0;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.4);
    padding: 12px 16px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    color: rgba(255,255,255,0.8);
    font-size: 13px;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
    user-select: none;
}

.nav-item:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.nav-item.active {
    background: rgba(255,255,255,0.12);
    color: #fff;
    border-left-color: #90caf9;
    font-weight: 600;
}

.nav-item .nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
    font-size: 11px;
    color: rgba(255,255,255,0.4);
}

.sidebar-footer a {
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    text-decoration: none;
}

.sidebar-footer a:hover { color: #fff; }

/* ===== MAIN CONTENT ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    min-width: 0;
}

/* ===== TOPBAR ===== */
.topbar {
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    min-height: 56px;
    flex-shrink: 0;
}

.topbar-title {
    font-size: 16px;
    font-weight: 600;
    color: #1a237e;
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: #666;
}

.user-badge .user-email {
    font-weight: 500;
    color: #333;
}

/* ===== CONTENT AREA ===== */
.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ===== PAGES ===== */
.page { display: none; }
.page.active { display: block; }

/* ===== STAT GRID ===== */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    border: 1px solid #e0e0e0;
    position: relative;
    overflow: hidden;
}

.stat-card .stat-icon {
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 28px;
    opacity: 0.7;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: #1a237e;
    line-height: 1;
    margin-bottom: 6px;
}

.stat-card .stat-label {
    font-size: 12px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== CARDS ===== */
.card {
    background: #fff;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    padding: 20px;
    margin-bottom: 16px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: #1a237e;
}

/* ===== TABLES ===== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.data-table th {
    background: #f5f6fa;
    text-align: left;
    padding: 10px 12px;
    font-weight: 600;
    color: #555;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 2px solid #e0e0e0;
    white-space: nowrap;
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: middle;
}

.data-table tbody tr:hover { background: #f9f9ff; }

.data-table tbody tr:last-child td { border-bottom: none; }

/* ===== FORMS ===== */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #444;
    margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    color: #333;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: #1a237e;
    box-shadow: 0 0 0 3px rgba(26, 35, 126, 0.1);
}

.form-textarea { resize: vertical; min-height: 80px; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* ===== BUTTONS ===== */
.btn-primary,
.btn-success,
.btn-danger,
.btn-secondary,
.btn-sm {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: opacity 0.15s, transform 0.1s;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary,
.btn-success,
.btn-danger,
.btn-secondary { padding: 9px 18px; }

.btn-primary { background: #1a237e; color: #fff; }
.btn-primary:hover { background: #283593; }

.btn-success { background: #2e7d32; color: #fff; }
.btn-success:hover { background: #388e3c; }

.btn-danger { background: #c62828; color: #fff; }
.btn-danger:hover { background: #d32f2f; }

.btn-secondary { background: #f5f5f5; color: #333; border: 1px solid #d0d0d0; }
.btn-secondary:hover { background: #eeeeee; }

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
    border-radius: 4px;
}

.btn-primary.btn-sm { background: #1a237e; color: #fff; }
.btn-danger.btn-sm { background: #c62828; color: #fff; }
.btn-secondary.btn-sm { background: #f5f5f5; color: #333; border: 1px solid #d0d0d0; }
.btn-success.btn-sm { background: #2e7d32; color: #fff; }

button:active { transform: scale(0.98); }

/* ===== BADGES ===== */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.badge-active { background: #e8f5e9; color: #2e7d32; }
.badge-inactive { background: #f5f5f5; color: #757575; }
.badge-coming-soon { background: #fff3e0; color: #e65100; }
.badge-admin { background: #e3f2fd; color: #1565c0; }
.badge-client { background: #f3e5f5; color: #6a1b9a; }
.badge-module { background: #e8eaf6; color: #3949ab; margin: 2px; }

/* ===== MODULE GRID ===== */
.module-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.module-card {
    background: #fff;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    padding: 20px;
    transition: box-shadow 0.15s, border-color 0.15s;
    cursor: pointer;
    position: relative;
}

.module-card:hover {
    box-shadow: 0 4px 12px rgba(26,35,126,0.1);
    border-color: #c5cae9;
}

.module-card.assigned {
    border-color: #1a237e;
    background: #f3f4fb;
}

.module-card.coming-soon {
    opacity: 0.7;
    cursor: default;
}

.module-icon {
    font-size: 32px;
    margin-bottom: 10px;
    display: block;
}

.module-name {
    font-size: 14px;
    font-weight: 600;
    color: #1a237e;
    margin-bottom: 4px;
}

.module-desc {
    font-size: 12px;
    color: #777;
    margin-bottom: 10px;
    line-height: 1.4;
}

.module-status {
    position: absolute;
    top: 12px;
    right: 12px;
}

/* ===== MODULE TOGGLE (Admin Client Detail) ===== */
.module-assign-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.module-assign-card {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 16px;
    background: #fff;
    transition: border-color 0.15s;
}

.module-assign-card.assigned {
    border-color: #1a237e;
    background: #f3f4fb;
}

.module-assign-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.toggle-switch {
    position: relative;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #ccc;
    border-radius: 22px;
    transition: 0.2s;
}

.toggle-slider:before {
    position: absolute;
    content: '';
    width: 16px;
    height: 16px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: 0.2s;
}

.toggle-switch input:checked + .toggle-slider { background: #1a237e; }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(18px); }

/* ===== TABS ===== */
.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #e0e0e0;
    margin-bottom: 20px;
}

.tab-btn {
    padding: 10px 20px;
    background: none;
    border: none;
    font-size: 13px;
    font-weight: 600;
    color: #888;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover { color: #1a237e; }
.tab-btn.active { color: #1a237e; border-bottom-color: #1a237e; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ===== MODAL ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: #fff;
    border-radius: 8px;
    padding: 24px;
    max-width: 520px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e0e0e0;
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 700;
    color: #1a237e;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #888;
    padding: 4px;
    line-height: 1;
}
.modal-close:hover { color: #333; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #e0e0e0;
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: #999;
}

.empty-state .empty-icon {
    font-size: 40px;
    margin-bottom: 12px;
    display: block;
    opacity: 0.5;
}

.empty-state p { font-size: 14px; }

/* ===== ALERTS ===== */
.alert-success,
.alert-error {
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alert-success { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }
.alert-error { background: #ffebee; color: #c62828; border: 1px solid #ef9a9a; }

#alert-container {
    position: fixed;
    top: 70px;
    right: 24px;
    z-index: 2000;
    width: 320px;
}

#alert-container .alert-success,
#alert-container .alert-error {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: slideIn 0.2s ease;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ===== INFO GRID ===== */
.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.info-item label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    margin-bottom: 4px;
}

.info-item .info-value {
    font-size: 14px;
    color: #333;
}

.info-item input.info-edit {
    font-size: 14px;
    padding: 6px 10px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    width: 100%;
    font-family: inherit;
}

.info-item input.info-edit:focus {
    outline: none;
    border-color: #1a237e;
}

/* ===== CHECKBOX GROUP ===== */
.checkbox-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: 4px;
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    cursor: pointer;
}

.checkbox-item:hover { background: #f0f0f0; }

.checkbox-item input[type="checkbox"] {
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: #1a237e;
}

/* ===== LOGIN PAGE ===== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a237e 0%, #283593 50%, #3949ab 100%);
}

.login-card {
    background: #fff;
    width: 380px;
    border-radius: 12px;
    padding: 40px 36px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo .login-title {
    font-size: 24px;
    font-weight: 800;
    color: #1a237e;
    letter-spacing: 0.5px;
}

.login-logo .login-sub {
    font-size: 13px;
    color: #888;
    margin-top: 4px;
}

/* ===== MISCELLANEOUS ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.page-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: #1a237e;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #1a237e;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    background: none;
    border: none;
    padding: 0;
    margin-bottom: 16px;
}

.back-btn:hover { text-decoration: underline; }

.actions-cell {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.total-row {
    display: flex;
    justify-content: flex-end;
    padding: 12px 16px;
    font-weight: 700;
    font-size: 14px;
    color: #1a237e;
    border-top: 2px solid #e0e0e0;
    background: #f9f9ff;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .module-grid { grid-template-columns: repeat(2, 1fr); }
    .module-assign-grid { grid-template-columns: repeat(2, 1fr); }
    .info-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .sidebar { width: 180px; min-width: 180px; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .module-grid { grid-template-columns: 1fr; }
    .module-assign-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .content-area { padding: 16px; }
}

/* ── Workflow result panel ───────────────────────────────────────── */
.workflow-result-panel {
    max-height: 400px;
    overflow-y: auto;
    border-radius: 4px;
}
