:root {
    --fb-purple: #4D2886;
    --fb-purple-dark: #3a1d68;
    --fb-purple-light: #6b3fb0;
    --fb-magenta: #E50051;
    --fb-magenta-dark: #b8003f;
    --fb-orange: #F39116;
    --fb-orange-dark: #d97706;
    --fb-yellow: #FBEC15;

    --brand-primary: var(--fb-purple);
    --brand-accent: var(--fb-orange);
    --brand-action: var(--fb-magenta);

    --bg-page: #f7f5fa;
    --bg-card: #ffffff;
    --text-primary: #1a1a1a;
    --text-muted: #6b7280;
    --border-soft: #e8e5ee;

    --shadow-sm: 0 1px 2px rgba(77, 40, 134, 0.05), 0 1px 3px rgba(77, 40, 134, 0.07);
    --shadow-md: 0 4px 6px -1px rgba(77, 40, 134, 0.08), 0 2px 4px -1px rgba(77, 40, 134, 0.05);
    --shadow-lg: 0 10px 25px -5px rgba(77, 40, 134, 0.12), 0 8px 10px -6px rgba(77, 40, 134, 0.06);

    --radius: 8px;
    --radius-lg: 12px;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

/* ===== TOPBAR ===== */
.topbar {
    background: linear-gradient(135deg, var(--fb-purple) 0%, var(--fb-purple-dark) 100%);
    color: #fff;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 28px;
    max-width: 1600px;
    margin: 0 auto;
}
.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    letter-spacing: 0.2px;
}
.brand-logo {
    height: 32px;
    display: flex;
    align-items: center;
}
.brand-logo img {
    height: 100%;
    width: auto;
    display: block;
}
.brand-name {
    line-height: 1.15;
    font-size: 1.05rem;
}
.brand-sub {
    display: block;
    font-size: 0.7rem;
    opacity: 0.7;
    font-weight: 400;
    margin-top: 3px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
}
.topbar-nav {
    display: flex;
    gap: 4px;
    align-items: center;
}
.nav-link-custom {
    color: rgba(255, 255, 255, 0.8);
    padding: 8px 14px;
    border-radius: var(--radius);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.nav-link-custom:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}
.nav-link-custom.active {
    color: #fff;
    background: rgba(243, 145, 22, 0.2);
    box-shadow: inset 0 -2px 0 var(--fb-orange);
}
.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    font-size: 0.8rem;
    margin-left: 12px;
}
.user-chip .role-badge {
    background: var(--fb-orange);
    color: #fff;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.btn-logout {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.85);
    padding: 7px 11px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    margin-left: 8px;
    text-decoration: none;
    font-size: 0.85rem;
}
.btn-logout:hover {
    background: var(--fb-magenta);
    border-color: var(--fb-magenta);
    color: #fff;
}

/* ===== PAGE ===== */
.page {
    max-width: 1600px;
    margin: 0 auto;
    padding: 28px;
}
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 22px;
    gap: 16px;
    flex-wrap: wrap;
}
.page-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--brand-primary);
    margin: 0;
    letter-spacing: -0.3px;
}
.page-subtitle {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin: 4px 0 0 0;
}

/* ===== TOOLBAR ===== */
.toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.search-box {
    flex: 1;
    min-width: 260px;
    max-width: 480px;
    position: relative;
}
.search-box input {
    width: 100%;
    padding: 10px 14px 10px 40px;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.search-box input:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(77, 40, 134, 0.1);
}
.search-box i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}
.search-result-info {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ===== CARD ===== */
.card-modern {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    border: 1px solid var(--border-soft);
}

/* ===== TABLE ===== */
.table-modern {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.table-modern thead th {
    background: linear-gradient(180deg, #faf8fc 0%, #f3eff7 100%);
    color: var(--brand-primary);
    font-weight: 700;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 14px 14px;
    border-bottom: 2px solid var(--border-soft);
    text-align: left;
    white-space: nowrap;
}
.table-modern tbody td {
    padding: 14px;
    border-bottom: 1px solid var(--border-soft);
    color: var(--text-primary);
    vertical-align: middle;
}
.table-modern tbody tr:last-child td { border-bottom: none; }
.table-modern tbody tr { transition: background 0.1s; }
.table-modern tbody tr:hover { background: #faf8fc; }

/* ===== BUTTONS ===== */
.btn-modern {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    line-height: 1;
    font-family: inherit;
}
.btn-modern:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary-m {
    background: var(--brand-primary);
    color: #fff;
}
.btn-primary-m:hover:not(:disabled) {
    background: var(--fb-purple-light);
    box-shadow: var(--shadow-md);
}
.btn-accent-m {
    background: var(--brand-action);
    color: #fff;
    font-weight: 600;
}
.btn-accent-m:hover:not(:disabled) {
    background: var(--fb-magenta-dark);
    box-shadow: var(--shadow-md);
}
.btn-orange-m {
    background: var(--fb-orange);
    color: #fff;
    font-weight: 600;
}
.btn-orange-m:hover:not(:disabled) {
    background: var(--fb-orange-dark);
    box-shadow: var(--shadow-md);
}
.btn-outline-m {
    background: transparent;
    border-color: var(--border-soft);
    color: var(--text-primary);
}
.btn-outline-m:hover:not(:disabled) {
    background: var(--bg-page);
    border-color: var(--text-muted);
}
.btn-icon-m {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    margin-right: 4px;
    background: transparent;
    border: 1px solid var(--border-soft);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}
.btn-icon-m:hover { background: var(--bg-page); color: var(--text-primary); }
.btn-icon-m.action-export {
    background: rgba(243, 145, 22, 0.1);
    color: var(--fb-orange-dark);
    border-color: rgba(243, 145, 22, 0.3);
}
.btn-icon-m.action-export:hover { background: var(--fb-orange); color: #fff; border-color: var(--fb-orange); }
.btn-icon-m.action-edit {
    background: rgba(77, 40, 134, 0.08);
    color: var(--fb-purple);
    border-color: rgba(77, 40, 134, 0.2);
}
.btn-icon-m.action-edit:hover { background: var(--fb-purple); color: #fff; border-color: var(--fb-purple); }
.btn-icon-m.action-delete {
    background: rgba(229, 0, 81, 0.08);
    color: var(--fb-magenta);
    border-color: rgba(229, 0, 81, 0.25);
}
.btn-icon-m.action-delete:hover { background: var(--fb-magenta); color: #fff; border-color: var(--fb-magenta); }

/* ===== FORMS ===== */
.form-group-m { margin-bottom: 16px; }
.form-label-m {
    display: block;
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--brand-primary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.form-control-m,
.form-select-m {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: inherit;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
    color: var(--text-primary);
}
.form-control-m:focus,
.form-select-m:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(77, 40, 134, 0.1);
}
.form-control-m:disabled,
.form-select-m:disabled {
    background: #f5f3f8;
    color: var(--text-muted);
    cursor: not-allowed;
}
.form-help { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

.input-group-m { display: flex; gap: 0; }
.input-group-m .form-control-m {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}
.input-group-m .btn-modern {
    border-radius: 0;
    border: 1px solid var(--border-soft);
    border-left: none;
    padding: 0 12px;
}
.input-group-m .btn-modern:last-child {
    border-top-right-radius: var(--radius);
    border-bottom-right-radius: var(--radius);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}
.form-divider { border: none; border-top: 1px solid var(--border-soft); margin: 22px 0; }
.section-title {
    color: var(--brand-primary);
    font-weight: 700;
    margin-bottom: 14px;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 8px;
}
.section-title i { color: var(--brand-action); }

/* ===== MODAL ===== */
.modal-content {
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
.modal-header {
    border-bottom: 1px solid var(--border-soft);
    padding: 20px 24px;
}
.modal-title {
    font-weight: 700;
    color: var(--brand-primary);
    font-size: 1.1rem;
}
.modal-body { padding: 24px; }
.modal-footer { border-top: 1px solid var(--border-soft); padding: 16px 24px; gap: 8px; }

/* ===== BADGES ===== */
.badge-m {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.badge-viewer { background: rgba(107, 114, 128, 0.15); color: #4b5563; }
.badge-editor { background: rgba(77, 40, 134, 0.12); color: var(--fb-purple); }
.badge-admin { background: var(--fb-orange); color: #fff; }
.badge-create { background: rgba(243, 145, 22, 0.15); color: var(--fb-orange-dark); }
.badge-update { background: rgba(77, 40, 134, 0.12); color: var(--fb-purple); }
.badge-delete { background: rgba(229, 0, 81, 0.12); color: var(--fb-magenta); }

/* ===== STATUS / NOTICES ===== */
.notice {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-bottom: 12px;
    border-left: 3px solid;
}
.notice-info {
    background: rgba(77, 40, 134, 0.06);
    color: var(--fb-purple);
    border-color: var(--fb-purple);
}
.notice-success {
    background: rgba(243, 145, 22, 0.1);
    color: var(--fb-orange-dark);
    border-color: var(--fb-orange);
}
.notice-error {
    background: rgba(229, 0, 81, 0.08);
    color: var(--fb-magenta);
    border-color: var(--fb-magenta);
}

.source-status { font-size: 0.78rem; margin-top: 6px; color: var(--text-muted); }
.source-status.text-success { color: var(--fb-orange-dark); font-weight: 500; }
.source-status.text-danger { color: var(--fb-magenta); font-weight: 500; }

.selected-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}
.selected-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: linear-gradient(135deg, rgba(77, 40, 134, 0.1), rgba(243, 145, 22, 0.08));
    color: var(--brand-primary);
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-weight: 600;
    margin-top: 6px;
    border: 1px solid rgba(77, 40, 134, 0.15);
}
.selected-pill i { color: var(--fb-orange); }
.selected-pill .pill-remove {
    background: transparent;
    border: none;
    color: var(--fb-magenta);
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
    margin-left: 2px;
    font-weight: 700;
}
.selected-pill .pill-remove:hover { color: var(--fb-magenta-dark); }
.badge-multi {
    background: var(--fb-orange);
    color: #fff;
    margin-left: 4px;
}
.selected-pill.stream-pill {
    background: linear-gradient(135deg, rgba(229, 0, 81, 0.08), rgba(243, 145, 22, 0.08));
}
.selected-pill.stream-pill i { color: var(--fb-magenta); }
.pill-mul-label {
    color: var(--text-muted);
    font-weight: 500;
    margin: 0 1px 0 4px;
}
.pill-mul-input {
    width: 54px;
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    background: #fff;
    color: var(--brand-primary);
}
.pill-mul-input:focus {
    outline: none;
    border-color: var(--brand-primary);
}

/* ===== LOGIN ===== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse at top right, rgba(243, 145, 22, 0.25) 0%, transparent 50%),
        radial-gradient(ellipse at bottom left, rgba(229, 0, 81, 0.2) 0%, transparent 50%),
        linear-gradient(135deg, var(--fb-purple-dark) 0%, var(--fb-purple) 100%);
    padding: 20px;
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: var(--radius-lg);
    padding: 40px;
    box-shadow: 0 25px 70px rgba(0, 0, 0, 0.35);
}
.login-brand {
    text-align: center;
    margin-bottom: 32px;
}
.login-logo {
    height: 60px;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-logo img { height: 100%; width: auto; display: block; }
.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--brand-primary);
    margin: 0 0 6px 0;
}
.login-subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0;
}

/* ===== CHECKBOX ===== */
.checkbox-m {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 18px 0;
    cursor: pointer;
    user-select: none;
    font-size: 0.9rem;
    color: var(--text-primary);
}
.checkbox-m input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--brand-primary);
    cursor: pointer;
}

/* ===== UTIL ===== */
.flex { display: flex; }
.text-muted-m { color: var(--text-muted); }
.text-nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* responsive */
@media (max-width: 768px) {
    .topbar-inner { padding: 10px 16px; flex-wrap: wrap; }
    .page { padding: 16px; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .user-chip { display: none; }
    .brand-name { font-size: 0.95rem; }
    .brand-sub { display: none; }
}
